Jump to content

OrangePi Lite2 & 3 Bluetooth


data

Recommended Posts

hciattach is not necessary, the kernel does that automatically if configured like this:

 

https://megous.com/git/linux/commit/?h=opi3-5.2&id=0c27ac4b4586bc2c0dded85b5bf82f78531d01c3

 

Sorry, I don't have guide to make BT work, because there's shouldn't be much to configure. All you need is a kernel with the support and then you just need to configure BT address (btmgmt public-addr) for your device. Kernel part is something armbian should figure out.

 

Link to comment
Share on other sites

15 hours ago, megi said:

hciattach is not necessary, the kernel does that automatically if configured like this:

 

 

Allright, so I just wait for 5.2 Kernel and hope for the best. Thanks for your answer though!

 

And even if it did not work, it was kinda fun to try to figure out how that works. Even though everything with drivers (firmware) is still insane complicated on Linux :)

Link to comment
Share on other sites

On 5/27/2019 at 8:37 PM, data said:

Do you know if these patches are included in the current lite2 built?

I don't see them in armbian. Anyway, I only have Opi 3 working, and lite2 may have a different bluetooth chip.

Link to comment
Share on other sites

On 5/30/2019 at 3:50 AM, megi said:

I don't see them in armbian. Anyway, I only have Opi 3 working, and lite2 may have a different bluetooth chip.

If I convert DTB to DTS (and back) and add this:

 

/* There's the BT part of the AP6256 connected to that UART */ &uart1 { pinctrl-names = "default"; pinctrl-0 = <&uart1_pins>, <&uart1_rts_cts_pins>; uart-has-rtscts; status = "okay"; bluetooth { compatible = "brcm,bcm4345c5"; clocks = <&rtc 1>; clock-names = "lpo"; device-wakeup-gpios = <&r_pio 1 2 GPIO_ACTIVE_HIGH>; /* PM2 */ host-wakeup-gpios = <&r_pio 1 1 GPIO_ACTIVE_HIGH>; /* PM1 */ shutdown-gpios = <&r_pio 1 4 GPIO_ACTIVE_HIGH>; /* PM4 */ max-speed = <1500000>; }; };

 

And copy https://github.com/orangepi-xunlong/OrangePiH6_external/tree/master/ap6256 to:

/lib/firmware/brcm/(BCM4345C5.hcd)

 

Am I correct that it will it work then? (I'm using a OPi3)

Link to comment
Share on other sites

Seems i found some workaround for OPi Lite2 board under  latest armbian image for OPi lite2 (Linux orangepilite2 5.2.5-sunxi64 #5.92).

 

uart1 is configured properly by board DTB (no loaded uart1 overlay!) but bt chip on ttyS1 not answered.

 

Board schematics (OrangePi_Lite2_Schematics_v2.0.pdf) is strange: BT-RST-N pulled up to vcc (R139 on schematics) and pulled down to GND (R147).

 

After boot pin PM4 (BT-REG-ON -> BT-RST-N) is unclaimed and seems BT-RST-N actually has low level.

cat /sys/kernel/debug/pinctrl/*/pinmux-pins

pin 388 (PM4): UNCLAIMED

 

1. Try pull up this pin:

echo 388 > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio388/direction
echo 1 >/sys/class/gpio/gpio388/value
 

2. load hci_uart module and do attach to uart1:

modprobe hci_uart

hciattach /dev/ttyS1 any
 

3. now i see two hci devices:

root@orangepilite2:~# hciconfig
hci1:   Type: Primary  Bus: UART
        BD Address: AA:AA:AA:AA:AA:AA  ACL MTU: 1021:8  SCO MTU: 64:1
        DOWN
        RX bytes:712 acl:0 sco:0 events:38 errors:0
        TX bytes:464 acl:0 sco:0 commands:44 errors:0

hci0:   Type: Primary  Bus: SDIO
        BD Address: 00:00:00:00:00:00  ACL MTU: 0:0  SCO MTU: 0:0
        DOWN
        RX bytes:0 acl:0 sco:0 events:0 errors:0
        TX bytes:0 acl:0 sco:0 commands:0 errors:0

 

4.  try to up hci1:

hciconfig hci1 up

 

5. hci1 up and running now.

root@orangepilite2:~# hciconfig hci1
hci1:   Type: Primary  Bus: UART
        BD Address: AA:AA:AA:AA:AA:AA  ACL MTU: 1021:8  SCO MTU: 64:1
        UP RUNNING
        RX bytes:1410 acl:0 sco:0 events:74 errors:0
        TX bytes:895 acl:0 sco:0 commands:80 errors:0
 

root@orangepilite2:~# hciconfig hci1 version
hci1:   Type: Primary  Bus: UART
        BD Address: AA:AA:AA:AA:AA:AA  ACL MTU: 1021:8  SCO MTU: 64:1
        HCI Version: 4.1 (0x7)  Revision: 0x0
        LMP Version: 4.1 (0x7)  Subversion: 0x6119
        Manufacturer: Broadcom Corporation (15)
 

 

Link to comment
Share on other sites

Do you need only the first file or all the others too?

 

BCM4345C5.hcd add ap6256 firmware8 months ago

config.txt add ap6256 firmware8 months ago

fw_bcm43456c5_ag.bin add ap6256 firmware8 months ago

fw_bcm43456c5_ag_apsta.bin add ap6256 firmware8 months ago

nvram.txt

 

well, I got them to the directory, but they show up in green, does that mean anything. If it look at it with lsattr it looks the same:

 

--------------e---- ./BCM4345C5.hcd
 

and with hciconfig it still show the BT device as 0000000 and not working

files.png

Link to comment
Share on other sites

@rawaaw

Good job. Have you tried if it is actually working? I don't get any results from hcitool scan

And there is an error in dmesg when the device is initialized as described by you above:

[ 3068.025249] Bluetooth: hci1: command 0x1003 tx timeout

 

 But I have the feeling we are almost there, at least for the OPi Lite2

 

When I try specific parameters for hciattach, I get the following:

 

root@orangepilite2:~# hciattach /dev/ttyS1 bcm43xx 921600 noflow -
bcm43xx_init
Patch not found, continue anyway
Set Controller UART speed to 921600 bit/s
Device setup complete
root@orangepilite2:~# hciconfig hci1 up
Can't init device hci1: Connection timed out (110)

Link to comment
Share on other sites

>>Have you tried if it is actually working?

actually :) I use this board for working with BLE devices.

 

i use armbian:

Linux orangepilite2 5.2.5-sunxi64 #5.92 SMP Fri Aug 2 07:51:38 CEST 2019 aarch64 aarch64 aarch64 GNU/Linux

Ubuntu 18.04.3 LTS \n \l
 

also check user 'data' post at april 27  

cd /lib/firmware/brcm
cp brcmfmac43455-sdio.txt brcmfmac43455-sdio.xunlong,orangepi-lite2.txt
 

also i compilted brcm_patchram_plus for change mac address.

https://github.com/phelum/CT_Bluetooth/blob/master/brcm_patchram_plus.c

  gcc -o brcm_patchram_plus brcm_patchram_plus.c

 

#/bin/sh
echo 388 > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio388/direction
echo 1 >/sys/class/gpio/gpio388/value

sleep 1
/root/brcm_patchram_plus --bd_addr 11:22:33:44:55:66 /dev/ttyS1
sleep 1

hciattach /dev/ttyS1 any

hciconfig hci1 up
hciconfig hci1

exit 0

 

root@orangepilite2:~# ./hci.sh
Device setup complete
hci1:   Type: Primary  Bus: UART
        BD Address: 11:22:33:44:55:66  ACL MTU: 1021:8  SCO MTU: 64:1
        UP RUNNING
        RX bytes:668 acl:0 sco:0 events:34 errors:0
        TX bytes:423 acl:0 sco:0 commands:34 errors:0
 

BLE actually working:

 

root@orangepilite2:~# hcitool -i hci1 lescan
LE Scan ...
EB:98:F8:C0:XX:XX (unknown)
EB:98:F8:C0:XX:XX Mi Band 3
EE:1A:6E:72:YY:YY (unknown)
EE:1A:6E:72:YY:YY Mi Smart Band 4
 

root@orangepilite2:~# gatttool -t random -i hci1 -b EB:98:F8:C0:XX:XX -I
[EB:98:F8:C0:XX:XX][LE]> connect
Attempting to connect to EB:98:F8:C0:XX:XX
Connection successful
[EB:98:F8:C0:XX:XX][LE]> char-desc
handle: 0x0001, uuid: 00002800-0000-1000-8000-00805f9b34fb
handle: 0x0002, uuid: 00002803-0000-1000-8000-00805f9b34fb
handle: 0x0003, uuid: 00002a00-0000-1000-8000-00805f9b34fb
handle: 0x0004, uuid: 00002803-0000-1000-8000-00805f9b34fb
handle: 0x0005, uuid: 00002a01-0000-1000-8000-00805f9b34fb
.....
 

 

 

Link to comment
Share on other sites

>>root@orangepilite2:~# hciattach /dev/ttyS1 bcm43xx 921600 noflow -

 

When i tried attach 6255 by this way BT adapter hangs up.

So i set mac address with brcm_patchram_plus and  do attach adapter as generic hci device with 

hciattach /dev/ttyS1 any

 

see my previous post for detailes  

 

 

 

Link to comment
Share on other sites

@rawaaw

Great, works on nightly

Linux orangepilite2 5.3.0-sunxi64 #5.97.190919 SMP Thu Sep 19 02:51:56 CEST 2019 aarch64 GNU/Linux

from 4 days ago as well. I just missed the patchram command last time I tried.

By the way, I am user data who wrote the post on April 27th :)  And I am happy to see that my initial efforts finally led to success!

 

So ladies and gentlemen, attached you'll find an archive with a working init-script for the ap6255 bluetooth chip.

Move the included files to the according directories and modify the MAC-Address in /etc/default/ap6255 to your needs

 

activate bluetooth with

# service ap6255-bluetooth start

 

check status:

# service ap6255-bluetooth status

 

enable on boot:

# systemctl enable ap6255-bluetooth

 

 

@Igor

Include this in the upcoming snapshots please!

 

And thanks to everybody who made this possible!

 

ap6255_bluetooth.zip

Link to comment
Share on other sites

7 hours ago, data said:

Include this in the upcoming snapshots please!


You can do it as well :)

Unpack ZIP here:
https://github.com/armbian/build/tree/master/packages/bsp

Copy files to rootfs here:
https://github.com/armbian/build/blob/master/config/sources/sun50iw6.conf#L48-L58


Another example (almost identical):

https://github.com/armbian/build/blob/master/config/sources/cubox.conf#L78-L81

 

Then create a pull request.

Link to comment
Share on other sites

3 hours ago, SchmuseTigger said:

 

>>I activated UART in the armbian-config

 

As i understood you have opi 3 board.

Wifi/BT is AP6255 and pins for connecting BT part to CPU the same as on opi lite2.

http://www.orangepi.org/downloadresources/OrangePi3/2019-01-23/orangepi3_b1a3a5d8f07c69d0da699e77d6.html

  

Did you enabled uart1 with overlay ?

 

Default .dtb for opi lite2 (i don't know what about opi3 board) already has uart1.

You should not activate uart1 overlay in this case. 

 

You may check this for your board with dtc -I dtb -O dts  /boot/dtb-xxx-sunxi64/allwinner/sun50i-h6-xxx.dtb

Check lines in the output like this:

....

                       uart1-pins {
                                pins = "PG6", "PG7";
                                function = "uart1";
                                phandle = <0x1d>;
                        };

                        uart1-rts-cts-pins {
                                pins = "PG8", "PG9";
                                function = "uart1";
                                phandle = <0x1e>;
                        };
...

 

Also you may check pin assignment with

cat /sys/kernel/debug/pinctrl/*/pinmux-pins

If uart1 initialized you can see lines:

...

pin 198 (PG6): 5000400.serial (GPIO UNCLAIMED) function uart1 group PG6
pin 199 (PG7): 5000400.serial (GPIO UNCLAIMED) function uart1 group PG7
pin 200 (PG8): 5000400.serial (GPIO UNCLAIMED) function uart1 group PG8
pin 201 (PG9): 5000400.serial (GPIO UNCLAIMED) function uart1 group PG9
...

 

Did you load hci_uart module with modprobe before enable BT chip and hciattach ?

 

PS:

What result of 'hciconfig hci0' command ?

 

 

Link to comment
Share on other sites

Well, I try to do all those things. But most of it looks kinda alien to me. From the bottom up, no I did nothing with a modprobe. The pins say:

 

pin 198 (PG6): 5000400.serial (GPIO UNCLAIMED) function uart1 group PG6
pin 199 (PG7): 5000400.serial (GPIO UNCLAIMED) function uart1 group PG7
pin 200 (PG8): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 201 (PG9): (MUX UNCLAIMED) (GPIO UNCLAIMED)

 

So seems they are not connected

 

now the other thing above with the dtb file:

 

I found the first one:

 

               uart1-pins {

                                pins = "PG6\0PG7";

                                function = "uart1";

                                phandle = < 0x1e >;

                        };

 

and the second:

 

                        uart1-rts-cts-pins {

                                pins = "PG8\0PG9";

                                function = "uart1";

                                phandle = < 0x1f >;

                        };

 

And to the HCI config:

 


hci0:   Type: Primary  Bus: USB
        BD Address: 00:15:83:0C:BF:EB  ACL MTU: 339:8  SCO MTU: 128:2
        UP RUNNING
        RX bytes:966 acl:0 sco:0 events:41 errors:0
        TX bytes:901 acl:0 sco:0 commands:41 errors:0
 

And the other one (the first one is a usb one that unfortunatly is not a LE so it does not work with what I want to do with it)

 

And second one is still:

 


hci1:   Type: Primary  Bus: SDIO
        BD Address: 00:00:00:00:00:00  ACL MTU: 0:0  SCO MTU: 0:0
        DOWN
        RX bytes:0 acl:0 sco:0 events:0 errors:0
        TX bytes:0 acl:0 sco:0 commands:0 errors:0
 

So, it seems I have to connect the device with modprobe to actually use those uart/gpio pins somehow?

 

Link to comment
Share on other sites

For everyone that need a working Bluetooth on OPi3 i've found a fast solution:

 

I'm using this version of Armbian:

Linux orangepi3 5.3.1-sunxi64 #5.98.190930 SMP Mon Sep 30 02:43:17 CEST 2019 aarch64 GNU/Linux

 

There is no need to use extra overlay or enable uart1, all the configurations are just present on sun50i-h6-orangepi-3.dtb.

 

You can use the procedure indicated on previous post:

 

and change the patching line to:

 

/usr/bin/timeout 20s /usr/bin/brcm_patchram_plus  --patchram /lib/firmware/brcm/BCM4345C5.hcd  --no2bytes --bd_addr $MAC_OPTIONS /dev/$PORT 2>&1

 

Bluetooth must start without problem ....

 

I've seen that a patch for bluetooth on OPi3 is just developed :

 

https://lkml.org/lkml/2019/8/23/320

 

but i don't known if and when it will be included into mainline distribution.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines