Search code examples
linuxbluetoothraspberry-piembedded-linuxraspbian

Bluetooth module not loaded sometimes on reboot in Raspbian Buster, Raspberry Pi 4


I have written a bluez application on Raspbian Buster, Raspberry Pi 4. In some reboots, the bluetooth module and service are not loaded.

On checking the bluetooth.service with command: $ sudo systemctl status bluetooth.service, I see, Condition check resulted in Bluetooth service being skipped.

I checked $ lsmod and $ dmesg logs for both issue and non-issue conditions.

The difference I find in the lsmod is shown below: lsmod diff

The difference I find in the dmesg log is shown below: dmesg diff

The left side is the issue case and the right side is non issue case.

How can I fix the issue so that the bluetooth works consistently? I am using Raspbian Lite OS 2020-02-14.

Update 1 [03 Feb 2021]: I checked the journalctl log for the issue case and found this:

Feb 03 11:52:18 pi btuart[373]: Failed to reset chip, invalid HCI event
Feb 03 11:52:18 pi btuart[373]: Can't initialize device: Success
Feb 03 11:52:18 pi btuart[373]: bcm43xx_init
Feb 03 11:52:18 pi systemd[1]: hciuart.service: Control process exited, code=exited, status=1/FAILURE
Feb 03 11:52:18 pi systemd[1]: hciuart.service: Failed with result 'exit-code'.
Feb 03 11:52:18 pi systemd[1]: Failed to start Configure Bluetooth Modems connected by UART.

Update 2 [03 Feb 2021]: My /boot/config.txt contents:

dtparam=i2c_arm=on

dtparam=spi=on
dtoverlay=mcp2515-can0,oscillator=8000000,interrupt=25
dtoverlay=spi1-1cs

# Enable audio (loads snd_bcm2835)
dtparam=audio=on

[pi4]
# Enable DRM VC4 V3D driver on top of the dispmanx display stack
dtoverlay=vc4-fkms-v3d
max_framebuffers=2

[all]
dtoverlay=vc4-fkms-v3d

disable_splash=1
enable_uart=1
max_usb_current=1

dtoverlay=uart2
dtoverlay=i2c-rtc,ds3231
gpu_mem=256

My cmdline.txt contents:

console=tty1 root=PARTUUID=738a4d67-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait logo.nologo vt.global_cursor_default=0 consoleblank=1 loglevel=1 quiet

Solution

  • My orientation sensor was interfaced to UART2 of Raspberry Pi 4. On getting suggestion from @svin83 , I disabled UART2. After that I rebooted the Pi 4 10 times and the bluetooth worked correctly all the times.

    I moved the sensor to I2C-3 bus in Raspberry Pi 4.

    As per the documentation, UART Configuration, the UART2 should not have interfered with bluetooth functionality, but it turns out it does.