Bluetooth Not Recognized on Raspberry Pi 4

This is for ARMv8 based devices

Bluetooth Not Recognized on Raspberry Pi 4

Postby tmmd » Sat Jan 25, 2020 10:26 pm

Hi there,

I'm trying to get my RasPi4 setup with Arch Linux ARM, and am running into an issue with the bluetooth. My system doesn't currently seem to be recognizing the bluetooth module on the RasPi.

Some specifics about the behaviour I'm seeing is when I use bluetoothctl and its list, agent on, and power on commands I get the following output:

$this->bbcode_second_pass_code('', '[thomas@alarmpi ~]$ bluetoothctl
Agent registered
[bluetooth]# list
[bluetooth]# agent on
Agent is already registered
[bluetooth]# power on
No default controller available')

This is the main sort of behaviour that's making me think that the bluetooth module isn't being recognized, but I've tried a few other bluetoothctl commands that also respond with No default controller available (or similar). Let me know if there's more info you could use, either from bluetoothctl or from other commands.

At this point, I'm thinking there's some package I need to download, as I've already run into a few of these sorts of problems trying to set up Arch Linux ARM. The bluetooth related packages that I have already downloaded are bluez, bluez-hid2hci, bluez-utils-compat, and pi-bluetooth. Let me know if there are any other packages I should have installed, or if there's something I should be doing with one of these packages.

Anyways, any pointers you can give me about what to do/research would be a huge help. Thanks!
tmmd
 
Posts: 17
Joined: Sun Jan 19, 2020 3:34 am

Re: Bluetooth Not Recognized on Raspberry Pi 4

Postby tmmd » Wed Feb 05, 2020 1:55 am

Bump? I'm still not having any luck with the bluetooth on my RasPi4.

I booted it using an SD card with LibreElec installed and was able to discover my cell phone through bluetooth, so that should mean the issue is with my ArchARM install and not with the RasPi hardware. I've also booted into ArchARM and tried using hcitool, which gave me the following result:

$this->bbcode_second_pass_code('', 'hcitool dev
Devices:')

That seems to backup my suspicion that the bluetooth device isn't being recognized in the first place.

Again, any thoughts or pointers you could spare would be a huge help. Thanks!
tmmd
 
Posts: 17
Joined: Sun Jan 19, 2020 3:34 am

Re: Bluetooth Not Recognized on Raspberry Pi 4

Postby whitelynx » Fri Feb 07, 2020 5:41 am

I'm running into the exact same issue; no devices show up in bluetoothctl with the "list" command, and it says "No default controller available" on commands that require a controller. (even when running bluetoothctl as root) I'm unable to figure out what package contains the "hcitool" command, though, so I can't try that.

I've tried digging into lsusb and lspci output, but I don't see anything in either of those that looks like a Bluetooth controller. I've also made sure to install the firmware-brcm43xx package, since I figured that might be the correct firmware.

Since you said you had bluetooth working on LibreELEC... does that distro have anything different in its config.txt? I'm thinking maybe there's a special device tree overlay we need to specify to get this working on the rpi4...
whitelynx
 
Posts: 4
Joined: Fri Feb 07, 2020 5:09 am

Re: Bluetooth Not Recognized on Raspberry Pi 4

Postby whitelynx » Fri Feb 07, 2020 5:57 am

One thing I've noticed is that all the instructions I come across seem to mention there being an "hciuart" service in systemd that is supposed to manage the bluetooth interface, but that service doesn't seem to exist on this install. I also can't find it by searching with pacman. I'm starting to think the lack of this service might be to blame for bluetooth not functioning...

Also, I noticed that /opt/vc/bin/dtoverlay doesn't actually show any overlays as being enabled, even though I have two of them enabled in /boot/config.txt. I'm starting to think my config.txt isn't being processed, except it seems like OpenGL support is actually working. (which as far as I know requires the vc4-fkms-v3d overlay)

I'll try and keep digging...
whitelynx
 
Posts: 4
Joined: Fri Feb 07, 2020 5:09 am

Re: Bluetooth Not Recognized on Raspberry Pi 4

Postby whitelynx » Fri Feb 07, 2020 11:40 pm

I managed to actually get Bluetooth working! It was a bit involved.

A caveat to the following instructions: there's probably a cleaner way of doing this; this is just what I was able to put together quickly. Eventually I might clean this up and stick it in an AUR package or something, though if anyone else wants to do it first, feel free.

I started out with pi-bluetooth, but ended up having to make several changes to the btuart script, since hciattach is deprecated. Here's my final /usr/bin/btuart script:
$this->bbcode_second_pass_code('', '#!/bin/sh

HCIATTACH=/usr/bin/btattach
if grep -q "Pi 4" /proc/device-tree/model; then
BDADDR=
else
SERIAL=`cat /proc/device-tree/serial-number | cut -c9-`
B1=`echo $SERIAL | cut -c3-4`
B2=`echo $SERIAL | cut -c5-6`
B3=`echo $SERIAL | cut -c7-8`
BDADDR=`printf b8:27:eb:%02x:%02x:%02x $((0x$B1 ^ 0xaa)) $((0x$B2 ^ 0xaa)) $((0x$B3 ^ 0xaa))`
fi

uart0="`cat /proc/device-tree/aliases/uart0`"
serial1="`cat /proc/device-tree/aliases/serial1`"

if [ "$uart0" = "$serial1" ] ; then
uart0_pins="`wc -c /proc/device-tree/soc/gpio@7e200000/uart0_pins/brcm\,pins | cut -f 1 -d ' '`"
if [ "$uart0_pins" = "16" ] ; then
$HCIATTACH /dev/serial1 bcm43xx 3000000 flow - $BDADDR
else
$HCIATTACH /dev/serial1 bcm43xx 921600 noflow - $BDADDR
fi
else
$HCIATTACH /dev/serial1 bcm43xx 460800 noflow - $BDADDR
fi')

I also copied /lib/systemd/system/hciuart.service from pi-bluetooth:
$this->bbcode_second_pass_code('', '[Unit]
Description=Configure Bluetooth Modems connected by UART
ConditionFileNotEmpty=/proc/device-tree/soc/gpio@7e200000/bt_pins/brcm,pins
Requires=dev-serial1.device
After=dev-serial1.device

[Service]
Type=simple
ExecStart=/usr/bin/btuart

[Install]
WantedBy=multi-user.target')

I also directly copied 90-pi-bluetooth.rules from pi-bluetooth to the appropriate place.

Finally, I copied some bits from Raspbian's 99-com.rules into /etc/udev/rules.d/99-serial.rules:
$this->bbcode_second_pass_code('', 'KERNEL=="ttyAMA[01]", PROGRAM="/bin/sh -c '\
ALIASES=/proc/device-tree/aliases; \
if cmp -s $ALIASES/uart0 $ALIASES/serial0; then \
echo 0;\
elif cmp -s $ALIASES/uart0 $ALIASES/serial1; then \
echo 1; \
else \
exit 1; \
fi\
'", SYMLINK+="serial%c"

KERNEL=="ttyS0", PROGRAM="/bin/sh -c '\
ALIASES=/proc/device-tree/aliases; \
if cmp -s $ALIASES/uart1 $ALIASES/serial0; then \
echo 0; \
elif cmp -s $ALIASES/uart1 $ALIASES/serial1; then \
echo 1; \
else \
exit 1; \
fi \
'", SYMLINK+="serial%c"')


After all that, I was finally able to run bluetoothctl and successfully pair my phone to the Pi.

I've posted these files in a gist for reference: https://gist.github.com/whitelynx/9f9bd ... ff14bce2e8
whitelynx
 
Posts: 4
Joined: Fri Feb 07, 2020 5:09 am

Re: Bluetooth Not Recognized on Raspberry Pi 4

Postby ivanich » Sat Feb 08, 2020 2:42 pm

And that's my approach, installed pi-bluetooth from aur and tweaked brcm43438.service.
$this->bbcode_second_pass_code('', '

root@raspberrypi:[~]: systemctl cat brcm43438.service
# /etc/systemd/system/brcm43438.service
[Unit]
Description=Broadcom BCM43438 bluetooth HCI
ConditionPathIsDirectory=/proc/device-tree/soc/gpio@7e200000/bt_pins
Before=bluetooth.service
After=dev-ttyAMA0.device

[Service]
Type=simple
ExecStart=/usr/bin/hciattach -n /dev/ttyAMA0 bcm43xx 921600 noflow -
[Install]
WantedBy=multi-user.target

# /etc/systemd/system/brcm43438.service.d/override.conf
[Service]
ExecStart=/usr/bin/hciattach -n /dev/ttyAMA0 bcm43xx 3000000 flow -
')
ivanich
 
Posts: 10
Joined: Wed Dec 04, 2019 3:00 pm

Re: Bluetooth Not Recognized on Raspberry Pi 4

Postby tmmd » Sat Feb 08, 2020 7:39 pm

Thanks so much for all the info! I've tried copying the files you mentioned to their relevant places on my machine, but am running into an issue where the hciuart.service is failing to start. I found the PID for hciuart.service and journalctl gave me the following error message:

$this->bbcode_second_pass_code('', 'sudo journalctl _PID=319
Feb 08 12:12:25 alarmpi systemd[319]: hciuart.service: Failed to execute command: Permission denied
Feb 08 12:12:25 alarmpi systemd[319]: hciuart.service: Failed at step EXEC spawning /usr/bin/btuart: Permission denied')

Any chance you ran across this on your end and know what to do? I enabled hciuart.service through sudo on my regular user account, and I sudo-ed into vim to create/save each of your files, so I would have assumed I wouldn't run into a permissions problem. Of course, let me know if I should have done something differently (and let me know if there's other info you could use).

Not sure if it's related, but after poking around the only device/file/name from your files that I've noticed doesn't seem to be on my install is the dev-serial1.device from hciuart.service. When I run systemctl -t device, there's no entry for dev-serial1.device, so maybe systemd needs to load this device somehow before it can get hciuart.service up and running? If so, any thoughts on how to do it? Or maybe this is unrelated to the permissions issue?

Anyways, I'll try poking around in this some more over the next couple days, but any pointers you can share would be a huge help. Thanks again!
tmmd
 
Posts: 17
Joined: Sun Jan 19, 2020 3:34 am

Re: Bluetooth Not Recognized on Raspberry Pi 4

Postby tmmd » Fri Feb 14, 2020 12:18 am

Quick update. Someone got back to me on reddit (https://www.reddit.com/r/archlinuxarm/c ... erry_pi_4/) and their solution worked for me. I followed the steps here (https://gist.github.com/shenghaoyang/92 ... 3e640663c2) and everything looks to be working great now.
tmmd
 
Posts: 17
Joined: Sun Jan 19, 2020 3:34 am

Re: Bluetooth Not Recognized on Raspberry Pi 4

Postby whitelynx » Wed Mar 11, 2020 2:31 am

$this->bbcode_second_pass_quote('tmmd', 'T')hanks so much for all the info! I've tried copying the files you mentioned to their relevant places on my machine, but am running into an issue where the hciuart.service is failing to start. I found the PID for hciuart.service and journalctl gave me the following error message:

$this->bbcode_second_pass_code('', 'sudo journalctl _PID=319
Feb 08 12:12:25 alarmpi systemd[319]: hciuart.service: Failed to execute command: Permission denied
Feb 08 12:12:25 alarmpi systemd[319]: hciuart.service: Failed at step EXEC spawning /usr/bin/btuart: Permission denied')

Any chance you ran across this on your end and know what to do?


That just means you didn't make /usr/bin/btuart executable when you created it. This should fix it:

$this->bbcode_second_pass_code('', 'sudo chmod +x /usr/bin/btuart')
whitelynx
 
Posts: 4
Joined: Fri Feb 07, 2020 5:09 am

Re: Bluetooth Not Recognized on Raspberry Pi 4

Postby VinnieThePooh » Fri Apr 10, 2020 4:24 pm

Thank You very much for all info; it was only way I could have Bluetooth on aarch64; all that stuff with dtoverlay work on 32 bit but on 64 bit it doesn't unfortunately.
Just a 2 cents: my bash complains against zero byte while exec
$this->bbcode_second_pass_code('', 'uart0="`cat /proc/device-tree/aliases/uart0`"
serial1="`cat /proc/device-tree/aliases/serial1`"')
so a better way is use
$this->bbcode_second_pass_code('', 'uart0=$(tr -d '\0' </proc/device-tree/aliases/uart0)
serial1=$(tr -d '\0' </proc/device-tree/aliases/serial1)')
instead of
VinnieThePooh
 
Posts: 5
Joined: Fri Apr 10, 2020 3:16 pm


Return to ARMv8 Devices

Who is online

Users browsing this forum: No registered users and 7 guests