NanoPi M1+ Bluetooth not working

NanoPi M1+

I enable Bluetooth using dietpi-config>advanced, but no device found in hcitool at all
When I use the FriendlyElec linux distributions bluetooth works just fine
maybe the config files don’t take the serial port into account? Or something else?
just bought 100 of these NanoPi M1+ for a project that requires bluetooth for headless setting up Wifi parameters. Once I am done, I will publish the code to this forum for headless wifi setup.
Please help, as I am buried in application code right now
Thanks everyone so much in advance!!

G_DIETPI_VERSION_CORE=8
G_DIETPI_VERSION_SUB=14
G_DIETPI_VERSION_RC=2
G_GITBRANCH=‘master’
G_GITOWNER=‘MichaIng’
G_LIVE_PATCH_STATUS[0]=‘not applicable’
G_LIVE_PATCH_STATUS[1]=‘not applied’
G_LIVE_PATCH_STATUS[2]=‘not applied’### Creating a bug report/issue

Bullseye
Linux DietPi 5.15.89-sunxi #22.11.4 SMP Mon Jan 23 21:58:30 UTC 2023 armv7l GNU/Linux
NanoPi M1 Plus (armv7l)
Power Supply: 2.1A USB port
SD Card: PNY 32Gb

let me ping our developer @MichaIng

Sadly this SBC is not officially supported by Armbian anymore. Hence while the sunxi kernel for H3 SBCs is generally maintained, no tests or care for it regarding NanoPi M1+ are done, so that features can break at any time. Also there is no device tree overlay for enabling Bluetooth.

However, the kernel still ships a device tree for M1+. There is no rfkill block, is it?

apt install rfkill
rfkill

Are there related errors among kernel logs?

dmesg -l 0,1,2,3
dmesg | grep -Ei 'bt|bluetooth'

WiFi itself however works, fine, right?

Seems as though the bluetooth is not enabled at all

WiFi does work just fine and the board is stable for a few days of testing at least. Ill be beating it up connecting it with nodejs to a Microchip processor at 230K baud for lots of data transfer and logging and displaying the data on the HDMI screen. I need bluetooth for initial SSID and password setup for the installing customer.

Jack

root@DietPi:~# rfkill
ID TYPE DEVICE      SOFT      HARD
 0 wlan phy0   unblocked unblocked
root@DietPi:~# dmesg -l 0,1,2,3
[    6.521844] lima 1c40000.gpu: dev_pm_opp_set_regulators: no regulator (mali) found: -19
[    7.039633] debugfs: File 'Capture' in directory 'dapm' already present!
root@DietPi:~# dmesg | grep -Ei 'bt|bluetooth'
[    1.869460] Btrfs loaded, crc32c=crc32c-generic, zoned=no, fsverity=yes

Is there a related device tree node?

find /proc/device-tree/ -name status -exec echo -ne '\n{}: ' \; -exec cat {} \;
/proc/device-tree/sound_hdmi/status: okay
/proc/device-tree/usb2-vbus/status: disabled
/proc/device-tree/display-engine/status: okay
/proc/device-tree/usb1-vbus/status: disabled
/proc/device-tree/soc/spdif@1c21000/status: disabled
/proc/device-tree/soc/serial@1c28000/status: okay
/proc/device-tree/soc/camera@1cb0000/status: disabled
/proc/device-tree/soc/usb@1c1b000/status: okay
/proc/device-tree/soc/mmc@1c0f000/status: okay
/proc/device-tree/soc/hdmi@1ee0000/status: okay
/proc/device-tree/soc/usb@1c1d400/status: okay
/proc/device-tree/soc/usb@1c1a400/status: disabled
/proc/device-tree/soc/mmc@1c11000/status: okay
/proc/device-tree/soc/pwm@1c21400/status: disabled
/proc/device-tree/soc/i2s@1c22800/status: okay
/proc/device-tree/soc/pwm@1f03800/status: disabled
/proc/device-tree/soc/usb@1c1d000/status: okay
/proc/device-tree/soc/usb@1c1a000/status: disabled
/proc/device-tree/soc/phy@1c19400/status: okay
/proc/device-tree/soc/i2c@1c2b400/status: disabled
/proc/device-tree/soc/i2s@1c22400/status: disabled
/proc/device-tree/soc/usb@1c1c400/status: okay
/proc/device-tree/soc/spi@1c69000/status: disabled
/proc/device-tree/soc/mmc@1c10000/status: okay
/proc/device-tree/soc/codec@1c22c00/status: disabled
/proc/device-tree/soc/serial@1c28800/status: disabled
/proc/device-tree/soc/i2c@1f02400/status: disabled
/proc/device-tree/soc/i2c@1c2b000/status: disabled
/proc/device-tree/soc/i2s@1c22000/status: disabled
/proc/device-tree/soc/usb@1c1c000/status: okay
/proc/device-tree/soc/serial@1c28400/status: disabled
/proc/device-tree/soc/usb@1c19000/status: disabled
/proc/device-tree/soc/usb@1c1b400/status: okay
/proc/device-tree/soc/ethernet@1c30000/status: okay
/proc/device-tree/soc/spi@1c68000/status: disabled
/proc/device-tree/soc/i2c@1c2ac00/status: disabled
/proc/device-tree/soc/ir@1f02000/status: okay
/proc/device-tree/soc/serial@1c28c00/status: okay
/proc/device-tree/psci/status: okay
/proc/device-tree/ahci-5v/status: disabled
/proc/device-tree/chosen/framebuffer-tve/status: disabled
/proc/device-tree/chosen/framebuffer-hdmi/status: disabled
/proc/device-tree/usb0-vbus/status: disabled

Any hints or fixes? I’m desparate :frowning:

Did you ever solve this? I am facing the same issue.

Okay so there is no device tree node for Bluetooth either. I think I did not recognise that it is internally attached via serial interface, like on RPi.

Which serial devices are available?

ls -l /dev/ttyS*

Does something like this work, if e.g. /dev/ttyS1 is available?

hciattach /dev/ttyS1 any 115200

/dev/ttyS0 is the default serial console, and I am pretty sure it is not used for Bluetooth. But could be tested as well. Just disable the login console on this device then, via dietpi-config > advanced options > serial/UART.

Closer, at least now running grep -i “blue” returns something. previously it didn’t. Here is the output

# hciattach /dev/ttyS1 any 115200
Device setup complete
# dmesg | grep -i "blue"
[   62.504341] Bluetooth: Core ver 2.22
[   62.504502] NET: Registered PF_BLUETOOTH protocol family
[   62.504512] Bluetooth: HCI device and connection manager initialized
[   62.504535] Bluetooth: HCI socket layer initialized
[   62.504547] Bluetooth: L2CAP socket layer initialized
[   62.504571] Bluetooth: SCO socket layer initialized
[   62.557337] Bluetooth: HCI UART driver ver 2.3
[   62.557378] Bluetooth: HCI UART protocol H4 registered
[   62.557386] Bluetooth: HCI UART protocol BCSP registered
[   62.557497] Bluetooth: HCI UART protocol LL registered
[   62.557505] Bluetooth: HCI UART protocol ATH3K registered
[   62.557549] Bluetooth: HCI UART protocol Three-wire (H5) registered
[   62.557761] Bluetooth: HCI UART protocol Broadcom registered
[   63.368321] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[   63.368353] Bluetooth: BNEP filters: protocol multicast
[   63.368378] Bluetooth: BNEP socket layer initialized
[   64.606457] Bluetooth: hci0: command 0x1003 tx timeout
[   64.611720] Bluetooth: hci0: Opcode 0x1003 failed: -110
# systemctl status bluetooth.service
● bluetooth.service - Bluetooth service
     Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; preset: enabled)
     Active: active (running) since Fri 2023-06-30 07:48:05 PDT; 57s ago
       Docs: man:bluetoothd(8)
   Main PID: 1534 (bluetoothd)
     Status: "Running"
      Tasks: 1 (limit: 2027)
     Memory: 1.7M
        CPU: 216ms
     CGroup: /system.slice/bluetooth.service
             └─1534 /usr/libexec/bluetooth/bluetoothd

Jun 30 07:48:05  bluetoothd[1534]: Bluetooth daemon 5.66
Jun 30 07:48:05  systemd[1]: Started bluetooth.service - Bluetooth service.
Jun 30 07:48:05  bluetoothd[1534]: Starting SDP server
Jun 30 07:48:05  bluetoothd[1534]: profiles/audio/vcp.c:vcp_init() D-Bus experimental not enabled
Jun 30 07:48:05  bluetoothd[1534]: src/plugin.c:plugin_init() Failed to init vcp plugin
Jun 30 07:48:05  bluetoothd[1534]: profiles/audio/mcp.c:mcp_init() D-Bus experimental not enabled
Jun 30 07:48:05  bluetoothd[1534]: src/plugin.c:plugin_init() Failed to init mcp plugin
Jun 30 07:48:05  bluetoothd[1534]: profiles/audio/bap.c:bap_init() D-Bus experimental not enabled
Jun 30 07:48:05  bluetoothd[1534]: src/plugin.c:plugin_init() Failed to init bap plugin
Jun 30 07:48:05  bluetoothd[1534]: Bluetooth management interface 1.22 initialized
# bluetoothctl
Agent registered
[bluetooth]# list
[bluetooth]#

You could go though further serial devices and see whether one of these works:

hciattach /dev/ttyS3 any 115200

The vendor images use a brcm_patchram_plus binary blob which seems to be similar to hciattach. I hope this is not required on mainline kernel:

#!/bin/bash

### BEGIN INIT INFO
# Provides:             brcm_patchram_plus
# Required-Start:       $remote_fs $syslog
# Required-Stop:        $remote_fs $syslog
# Default-Start:        2 3 4 5
# Default-Stop:
# Short-Description:    brcm_patchram_plus
### END INIT INFO

function reset_bt()
{
    BTWAKE=/proc/bluetooth/sleep/btwake
    if [ -f ${BTWAKE} ]; then
        echo 0 > ${BTWAKE}
    fi
    index=`rfkill list | grep $1 | cut -f 1 -d":"` 
    if [[ -n ${index}} ]]; then
        rfkill block ${index}
        sleep 1
        rfkill unblock ${index}
        sleep 1
    fi
}

rm -rf /var/log/brcm
brcm_try_log=/var/log/brcm/brcm_try.log
brcm_log=/var/log/brcm/brcm.log
brcm_err_log=/var/log/brcm/brcm_err.log
[ -d /var/log/brcm ] || mkdir -p /var/log/brcm

board=`cat /sys/class/sunxi_info/sys_info | grep board_name`
board=${board#*FriendlyElec }
[ -z ${board} ] && board=`cat /etc/hostname`
case ${board} in
    NanoPi-Duo2 )
        uart_dev=ttyS2
        chip=ap6212
        ;;
    NanoPi-H6-with-AP6255 )
        uart_dev=ttyS1
        chip=ap6255
        ;;
    NanoPi-NEO-Air|NanoPi-M1-Plus|NanoPi-NEO-Plus2|NanoPi-NEO-Plus2-H3|NanoPi-R1 )
        chip=ap6212
        uart_dev=ttyS3
        ;;
    * )
        echo "This board may not have BT module." >${brcm_try_log}
        exit 0
        ;;
esac

case "$1" in
    start|"")
        index=`rfkill list | grep "sunxi-bt" | cut -f 1 -d":"`
        
        if [ -d /sys/class/rfkill/rfkill${index} ]; then
            reset_bt "sunxi-bt"
            chmod 0660 /sys/class/rfkill/rfkill${index}/state
            chmod 0660 /sys/class/rfkill/rfkill${index}/type
            chgrp dialout /sys/class/rfkill/rfkill${index}/state
            chgrp dialout /sys/class/rfkill/rfkill${index}/type

            # generate MAC address
            if [ -f /sys/bus/nvmem/devices/sunxi-sid0/nvmem ]; then
                MACADDRESS=`md5sum /sys/bus/nvmem/devices/sunxi-sid0/nvmem | cut -b 1-12 | sed -r ':1;s/(.*[^:])([^:]{2})/\1:\2/;t1'`
            else
                MACADDRESS=`md5sum /sys/class/sunxi_info/sys_info | cut -b 1-12 | sed -r ':1;s/(.*[^:])([^:]{2})/\1:\2/;t1'` # for all sunxi kernel of FriendlyElec
            fi
            echo ${MACADDRESS} >/tmp/bt_macaddress

            # download firmware
            let TIMEOUT=90
            while [ ${TIMEOUT} -gt 0 ]; do
                killall -9 /bin/brcm_patchram_plus
                /bin/brcm_patchram_plus -d --patchram /lib/firmware/${chip}/ --enable_hci --bd_addr ${MACADDRESS} --no2bytes --tosleep 5000 /dev/${uart_dev} >${brcm_log} 2>&1 &
                sleep 30
                cur_time=`date "+%H-%M-%S"`
                if grep "Done setting line discpline" ${brcm_log}; then
                    echo "${cur_time}: bt firmware download ok($((TIMEOUT/30)))" >> ${brcm_try_log}
                    if ! grep "fail" ${brcm_try_log}; then
                        reset_bt "hci0"
                        hciconfig hci0 up
                        hciconfig >> ${brcm_try_log}    
                        #reboot
                    fi
                    break
                else
                    echo "${cur_time}: bt firmware download fail($((TIMEOUT/30)))" >> ${brcm_try_log}
                    cp ${brcm_log} ${brcm_err_log}
                    reset_bt "sunxi-bt"
                fi
                TIMEOUT=$((TIMEOUT-30))
            done
        fi
        ;;

    stop)
        kill `ps --no-headers -C brcm_patchram_plus -o pid`
        ;;
    *)
        echo "Usage: brcm_patchram_plus start|stop" >&2
        exit 3
        ;;
esac

There ttyS3 is used for Allwinner H3 SBCs, but it is not necessarily the same on our mainline kernel. It reveals ap6212 as chip, but it is not a type/ID directly supported by hciattach, hence we can only use any: hciattach(1) — bluez — Debian bookworm — Debian Manpages

The trick in original command is to use -r
I can get it to attach to ttyS0 or ttyS1, but not any other serial. I can attach the Console to any serial from the dietpi config, but not using the hciattach.

When I connect to ttyS0/1, I still cannot see an attached bluetooth controller although I don’t see errors.

Blockquote root@:~# hciattach -r /dev/ttyS1 any 115200
Device setup complete
root@:~# dmesg | grep -i “blue”
[ 48.005928] Bluetooth: Core ver 2.22
[ 48.006118] NET: Registered PF_BLUETOOTH protocol family
[ 48.006129] Bluetooth: HCI device and connection manager initialized
[ 48.006155] Bluetooth: HCI socket layer initialized
[ 48.006167] Bluetooth: L2CAP socket layer initialized
[ 48.006193] Bluetooth: SCO socket layer initialized
[ 48.063734] Bluetooth: HCI UART driver ver 2.3
[ 48.063767] Bluetooth: HCI UART protocol H4 registered
[ 48.063775] Bluetooth: HCI UART protocol BCSP registered
[ 48.063901] Bluetooth: HCI UART protocol LL registered
[ 48.063911] Bluetooth: HCI UART protocol ATH3K registered
[ 48.063958] Bluetooth: HCI UART protocol Three-wire (H5) registered
[ 48.064162] Bluetooth: HCI UART protocol Broadcom registered
[ 48.675822] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[ 48.675854] Bluetooth: BNEP filters: protocol multicast
[ 48.675876] Bluetooth: BNEP socket layer initialized
root@:~# bluetoothctl
Agent registered
[bluetooth]# list
[bluetooth]# exit
root@:~# sysetmctl start bluetooth.service
-bash: sysetmctl: command not found
root@:~# systemctl restart bluetooth.service
root@:~# systemctl status bluetooth.service
● bluetooth.service - Bluetooth service
Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; preset: enabled)
Active: active (running) since Sat 2023-07-01 08:35:40 PDT; 6s ago
Docs: man:bluetoothd(8)
Main PID: 1625 (bluetoothd)
Status: “Running”
Tasks: 1 (limit: 2027)
Memory: 492.0K
CPU: 202ms
CGroup: /system.slice/bluetooth.service
└─1625 /usr/libexec/bluetooth/bluetoothd
Jul 01 08:35:40 bluetoothd[1625]: Bluetooth daemon 5.66
Jul 01 08:35:40 systemd[1]: Started bluetooth.service - Bluetooth service.
Jul 01 08:35:40 bluetoothd[1625]: Starting SDP server
Jul 01 08:35:40 bluetoothd[1625]: profiles/audio/vcp.c:vcp_init() D-Bus experimental not enabled
Jul 01 08:35:40 bluetoothd[1625]: src/plugin.c:plugin_init() Failed to init vcp plugin
Jul 01 08:35:40 bluetoothd[1625]: profiles/audio/mcp.c:mcp_init() D-Bus experimental not enabled
Jul 01 08:35:40 bluetoothd[1625]: src/plugin.c:plugin_init() Failed to init mcp plugin
Jul 01 08:35:40 bluetoothd[1625]: profiles/audio/bap.c:bap_init() D-Bus experimental not enabled
Jul 01 08:35:40 bluetoothd[1625]: src/plugin.c:plugin_init() Failed to init bap plugin
Jul 01 08:35:40 bluetoothd[1625]: Bluetooth management interface 1.22 initialized
root@:~# rfkill list
0: hci0: Bluetooth
Soft blocked: no
Hard blocked: no

Here is the error for ttyS3

:~# hciattach -r /dev/ttyS3 any 115200
Can’t get port settings: Input/output error
Can’t initialize device: Input/output error

I did reboot between hciattach commands as I couldn’t figure out the detach command :face_with_diagonal_mouth:

Not sure if this helps, but I ran setserial and this is the output, perhaps a layer needs to be added?

root@:/boot# setserial -g /dev/ttyS0
/dev/ttyS0, UART: 16550A, Port: 0x0000, IRQ: 136

root@:/boot# setserial -g /dev/ttyS1
/dev/ttyS1, UART: 16550A, Port: 0x0000, IRQ: 137

root@:/boot# setserial -g /dev/ttyS2
/dev/ttyS2, UART: unknown, Port: 0x0000, IRQ: 0

root@:/boot# setserial -g /dev/ttyS3
/dev/ttyS3, UART: unknown, Port: 0x0000, IRQ: 0

root@:/boot# setserial -g /dev/ttyS4
/dev/ttyS4, UART: unknown, Port: 0x0000, IRQ: 0

root@:/boot# setserial -g /dev/ttyS5
/dev/ttyS5, UART: unknown, Port: 0x0000, IRQ: 0

root@:/boot# setserial -g /dev/ttyS6
/dev/ttyS6, UART: unknown, Port: 0x0000, IRQ: 0

I added uart0 uart1 uart2 uart3 to the overlays and now I can run hciattach -r /dev/ttyS3 any 115200

Still no Bluetooth adapter available or started.

root@:~# hciattach -r /dev/ttyS3 any 115200
Device setup complete
root@:~# dmesg | grep -i “blue”
[ 53.614595] Bluetooth: Core ver 2.22
[ 53.614780] NET: Registered PF_BLUETOOTH protocol family
[ 53.614789] Bluetooth: HCI device and connection manager initialized
[ 53.614813] Bluetooth: HCI socket layer initialized
[ 53.614825] Bluetooth: L2CAP socket layer initialized
[ 53.614850] Bluetooth: SCO socket layer initialized
[ 53.697332] Bluetooth: HCI UART driver ver 2.3
[ 53.697365] Bluetooth: HCI UART protocol H4 registered
[ 53.697373] Bluetooth: HCI UART protocol BCSP registered
[ 53.697500] Bluetooth: HCI UART protocol LL registered
[ 53.697510] Bluetooth: HCI UART protocol ATH3K registered
[ 53.697560] Bluetooth: HCI UART protocol Three-wire (H5) registered
[ 53.697773] Bluetooth: HCI UART protocol Broadcom registered
[ 54.437487] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[ 54.437519] Bluetooth: BNEP filters: protocol multicast
[ 54.437544] Bluetooth: BNEP socket layer initialized
root@:~# rfkill list
0: hci0: Bluetooth
Soft blocked: no
Hard blocked: no
root@:~# hciconfig hci0 up
Can’t init device hci0: Operation not supported (95)
root@:~# hcitool scan
Device is not available: No such device
root@:~# bluetoothctl
Agent registered
[bluetooth]# list
[bluetooth]# power on
No default controller available
[bluetooth]#

Any other suggestions would be appreciated.

Exact same problem with NanoPi NEO Air…

any update? i also got the same problem with Orange PI 4 LTS

when I try hciconfig hci0 up, I got Can't init device hci0: Connection timed out (110). The result from rfkill is

0 bluetooth bluetooth unblocked unblocked

thanks!