Circuit Sword Bluetooth

dasfool
Posts: 19
Joined: Sat Aug 05, 2017 9:33 pm
Has thanked: 4 times
Been thanked: 6 times

Circuit Sword Bluetooth

Post by dasfool » Wed Jun 27, 2018 2:27 pm

Has anyone been able to get Bluetooth working with Kite's Circuit Sword?

Is this still the most up to date information?
Kite wrote:Hardware wise it does [have bluetooth] but I haven't enabled/tested it as I don't think it's as simple as just 'turning it on' so if someone wants to give it a go then please let me know how it goes (this might be a starting place https://github.com/lwfinger/rtl8723bs_bt) as it is connected to the hardware serial port of the Pi

User avatar
kite
Posts: 972
Joined: Thu May 12, 2016 4:30 am
Location: UK
Has thanked: 246 times
Been thanked: 361 times
Contact:

Re: Circuit Sword Bluetooth

Post by kite » Thu Jun 28, 2018 2:21 am

I've not made any attempt to work on bluetooth, but if you want to give it a go, the GPIO pins used and wired up already to the module are:

GPIO32 - TXD -- > RX on module
GPIO33 - RXD --> TX on module

CTS and RST have not been connected at all, hopefully that's not a problem.

It's the same module used on the CHIP so this may also help: https://github.com/NextThingCo/rtl8723ds_bt
This looks interesting too: https://github.com/Miouyouyou/MyyQi/issues/7
There appears to be a guide (altho for the PIN64) here: https://nanite.co/tag/rtl8723bs/
Stock clearance - CLOSED: viewtopic.php?f=38&t=12064
Kite's Mailing List: https://goo.gl/forms/e97uUvPOfUxPWdz82
Kite's FAQ: https://kiteretro.com/faq/


ImageImageImageImageImage

User avatar
AntFJ
Posts: 178
Joined: Thu Nov 16, 2017 8:09 pm
Has thanked: 37 times
Been thanked: 115 times

Re: Circuit Sword Bluetooth

Post by AntFJ » Mon Oct 01, 2018 12:06 pm

kite wrote:
Thu Jun 28, 2018 2:21 am
I've not made any attempt to work on bluetooth, but if you want to give it a go, the GPIO pins used and wired up already to the module are:

GPIO32 - TXD -- > RX on module
GPIO33 - RXD --> TX on module

CTS and RST have not been connected at all, hopefully that's not a problem.

It's the same module used on the CHIP so this may also help: https://github.com/NextThingCo/rtl8723ds_bt
This looks interesting too: https://github.com/Miouyouyou/MyyQi/issues/7
There appears to be a guide (altho for the PIN64) here: https://nanite.co/tag/rtl8723bs/
kite - you mentioned in another thread pins on the board for an extra usb... can you point these out? I want to add an internal bluetooth dongle via usb. I'm not entirely sure if it will work but I want to give it a try.

User avatar
kite
Posts: 972
Joined: Thu May 12, 2016 4:30 am
Location: UK
Has thanked: 246 times
Been thanked: 361 times
Contact:

Re: Circuit Sword Bluetooth

Post by kite » Mon Oct 01, 2018 2:49 pm

AntFJ wrote:
Mon Oct 01, 2018 12:06 pm
kite - you mentioned in another thread pins on the board for an extra usb... can you point these out? I want to add an internal bluetooth dongle via usb. I'm not entirely sure if it will work but I want to give it a try.
Yeah, it's slightly different depending on which version you have.. but both are right next to the USB C charging port:
- 1.1E: There are some solder pads (DP, DM, GND) in that area, where it looks like a chip is meant to go.
- 1.2A: There is a 4pin JST header in this place with DP, DM, GND, POWER
Stock clearance - CLOSED: viewtopic.php?f=38&t=12064
Kite's Mailing List: https://goo.gl/forms/e97uUvPOfUxPWdz82
Kite's FAQ: https://kiteretro.com/faq/


ImageImageImageImageImage

User avatar
AntFJ
Posts: 178
Joined: Thu Nov 16, 2017 8:09 pm
Has thanked: 37 times
Been thanked: 115 times

Re: Circuit Sword Bluetooth

Post by AntFJ » Mon Oct 01, 2018 3:15 pm

Perfect I'll take a look when the board arrives in a couple weeks
kite wrote:
Mon Oct 01, 2018 2:49 pm
AntFJ wrote:
Mon Oct 01, 2018 12:06 pm
kite - you mentioned in another thread pins on the board for an extra usb... can you point these out? I want to add an internal bluetooth dongle via usb. I'm not entirely sure if it will work but I want to give it a try.
Yeah, it's slightly different depending on which version you have.. but both are right next to the USB C charging port:
- 1.1E: There are some solder pads (DP, DM, GND) in that area, where it looks like a chip is meant to go.
- 1.2A: There is a 4pin JST header in this place with DP, DM, GND, POWER

User avatar
kite
Posts: 972
Joined: Thu May 12, 2016 4:30 am
Location: UK
Has thanked: 246 times
Been thanked: 361 times
Contact:

Re: Circuit Sword Bluetooth

Post by kite » Mon Oct 01, 2018 3:48 pm

Ah in that case yours will be version 1.3A, which is the same (in this regard) as 1.2A :) you can use the included JST cable for it, and they're easy to buy online (JST SH 4 pin)
Stock clearance - CLOSED: viewtopic.php?f=38&t=12064
Kite's Mailing List: https://goo.gl/forms/e97uUvPOfUxPWdz82
Kite's FAQ: https://kiteretro.com/faq/


ImageImageImageImageImage

User avatar
ThompsonTinkers
Posts: 39
Joined: Sat Jan 28, 2017 9:36 pm
Has thanked: 57 times
Been thanked: 20 times

Re: Circuit Sword Bluetooth

Post by ThompsonTinkers » Sat Oct 06, 2018 5:21 pm

I've actually managed to get this working! No guarantees that I've got it working the right way, though.

First, add this to /boot/config.txt:

Code: Select all

force_turbo=1
enable_uart=1
dtoverlay=uart0,txd0_pin=32,rxd0_pin=33,pin_func=7
Next, go into raspi-config -> Interfacing Options -> Serial and disable the login shell on serial, but enable the serial port hardware.

And reboot.

When you come back, it's a good time to checkout and compile https://github.com/lwfinger/rtl8723bs_bt

I found that the included start_bt.sh script didn't do a good job of guessing the serial port device on my Circuit Sword. Here's a hardcoded version:

Code: Select all

#!/bin/bash
TTY="/dev/ttyAMA0"
echo "Using device $TTY for Bluetooth"

if [ ! -f /lib/firmware/rtl_bt/rtlbt_config ];
then
        mkdir -p /lib/firmware/rtl_bt/
        cp rtlbt_* /lib/firmware/rtl_bt/.
fi
./rtk_hciattach -n -s 115200 $TTY rtk_h5 > hciattach.txt 2>&1 &
Now run that, and check dmesg. You should see something like:

Code: Select all

...
[   54.528820] uart-pl011 3f201000.serial: no DMA platform data
[   55.427986] Bluetooth: Core ver 2.22
[   55.428234] NET: Registered protocol family 31
[   55.428242] Bluetooth: HCI device and connection manager initialized
[   55.428291] Bluetooth: HCI socket layer initialized
[   55.428309] Bluetooth: L2CAP socket layer initialized
[   55.428365] Bluetooth: SCO socket layer initialized
[   55.438117] Bluetooth: HCI UART driver ver 2.3
[   55.438145] Bluetooth: HCI UART protocol H4 registered
Caveats so far:
  • This doesn’t run at boot, so you have to start_bt.sh each time you want to use it.
  • The RTL8723 module doesn’t seem to reboot at the same time as the CM3. If it can’t sync (check hciattach.txt) try power cycling the circuit sword.
  • I’ve installed a few different bluetooth utilities, and I have not yet tried this set of instructions from a stock install. I might have missed something.
I’ll leave configuring bluetooth peripherals as an exercise to the reader (for now). I’ve managed to get a bluetooth keyboard paired through bluetoothctl, but I have not tried any other type of hardware.

User avatar
kite
Posts: 972
Joined: Thu May 12, 2016 4:30 am
Location: UK
Has thanked: 246 times
Been thanked: 361 times
Contact:

Re: Circuit Sword Bluetooth

Post by kite » Sun Oct 07, 2018 12:33 am

NICE! I got something similar but it seems i missed out the console over serial thing. I'll have an experiment too and see if there's anything to make it more reliable.. i can then include those fixes as default in the image (providing it works enough!)
Stock clearance - CLOSED: viewtopic.php?f=38&t=12064
Kite's Mailing List: https://goo.gl/forms/e97uUvPOfUxPWdz82
Kite's FAQ: https://kiteretro.com/faq/


ImageImageImageImageImage

User avatar
kite
Posts: 972
Joined: Thu May 12, 2016 4:30 am
Location: UK
Has thanked: 246 times
Been thanked: 361 times
Contact:

Re: Circuit Sword Bluetooth

Post by kite » Mon Oct 08, 2018 3:10 am

Just wanted to reply saying that I've tried it out and works :) You can omit the 'force_turbo=1' because UART0 is the hardware one, not the CPU controlled software one (which would require that line).

Ok so the following statement is true with regards to bluetooth:

If you issue a 'reboot' command, when the system comes back up the bluetooth radio will not work. You must do a full power cycle (main power switch == OFF!).

The reason is that the 'reset' pin for the radio is pulled up to 3.3v, meaning that it doesn't get 'reset on reboot'. I'm working on a slight hardware mod to fix this which will involve soldering a wire to a pin so that on a reboot the radio is reset properly :) I haven't found the best pin to use yet (basically need a pin that on boot pulls to GND and then goes floating/high). It's important that this happens RIGHT at power on because it also resets the wifi side of the chip, which we really shouldn't do after all drivers have loaded etc :)

I will look to add this to the Circuit Sword image by default, and when I have the hardware mod I'll post it and also update the design files so that future versions 'just work'
Stock clearance - CLOSED: viewtopic.php?f=38&t=12064
Kite's Mailing List: https://goo.gl/forms/e97uUvPOfUxPWdz82
Kite's FAQ: https://kiteretro.com/faq/


ImageImageImageImageImage

User avatar
ThompsonTinkers
Posts: 39
Joined: Sat Jan 28, 2017 9:36 pm
Has thanked: 57 times
Been thanked: 20 times

Re: Circuit Sword Bluetooth

Post by ThompsonTinkers » Mon Oct 08, 2018 7:50 pm

It looks like rtk_hciattach connects at 115200 bps. Then as part of configuring the module, it raises the bitrate. On mine, it sets it to 4928002 bps [1]. I haven’t tried writing it, but I suspect it might be possible to reconnect at the higher rate on a warm boot.

I wrote a systemd file to get this up and running at boot.

Code: Select all

[Unit]
Description=RTL8723 Bluetooth Support
 
[Service]
ExecStart=/root/rtl8723bs_bt/start_bt.sh
 
[Install]
WantedBy=multi-user.target
Alias=rtk-attach.service
And updated start_bt.sh to be a little less tied to running from a specific directory.

Code: Select all

#!/bin/bash
TTY="/dev/ttyAMA0"
LOGFILE="/var/log/hciattach.log"
BASE="/root/rtl8723bs_bt"
echo "Using device $TTY for Bluetooth"

if [ ! -f /lib/firmware/rtl_bt/rtlbt_config ]; then
    mkdir -p /lib/firmware/rtl_bt/
    cp ${BASE}/rtlbt_* /lib/firmware/rtl_bt/.
fi

"${BASE}/rtk_hciattach" -n -s 115200 "$TTY" rtk_h5 > "$LOGFILE" 2>&1
I’m not a big fan of how it copies the firmware in each time. Do you know if there’s a specific reason to check for that on each boot?

[1]: I think the 2 on the end places a lot of trust in the precision of the system clock. :lol:

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest