xref: /btstack/port/raspi/README.md (revision a06b9aecee6380b8671ea2b004d921a39fce6d14)
16d6471dcSMatthias Ringwald# BTstack Port for Raspberry Pi 3 with BCM4343 Bluetooth/Wifi Controller
26d6471dcSMatthias Ringwald
3d9bed121SMatthias RingwaldTested with Raspberry Pi 3 Model B V1.2, Raspberry Pi 3 Model B+, and Raspberry Pi Zero W V1.1.
46d6471dcSMatthias Ringwald
56e4c47b0SMatthias RingwaldWith minor fixes, the port should also work with older Raspberry Pi models that use the [RedBear pHAT](https://redbear.cc/product/rpi/iot-phat.html). See TODO at the end.
66d6471dcSMatthias Ringwald
76e4c47b0SMatthias Ringwald## Raspberry Pi 3 / Zero W Setup
86d6471dcSMatthias Ringwald
96e4c47b0SMatthias RingwaldThere are various options for setting up the Raspberry Pi, have a look at the Internet. Here's what we did:
106d6471dcSMatthias Ringwald
116d6471dcSMatthias Ringwald### Install Raspian Stretch Lite:
126d6471dcSMatthias Ringwald
136d6471dcSMatthias Ringwald- Insert empty SD Card
146d6471dcSMatthias Ringwald- Download Raspian Stretch Lite from https://www.raspberrypi.org/downloads/raspbian/
156d6471dcSMatthias Ringwald- Install Etcher from https://etcher.io
166d6471dcSMatthias Ringwald- Run Etcher:
176d6471dcSMatthias Ringwald  - Select the image you've download before
186d6471dcSMatthias Ringwald  - Select your SD card
196d6471dcSMatthias Ringwald  - Flash!
206d6471dcSMatthias Ringwald
216d6471dcSMatthias Ringwald### Configure Wifi
226d6471dcSMatthias Ringwald
236d6471dcSMatthias RingwaldCreate the file wpa_supplicant.conf in the root folder of the SD Card with your Wifi credentials:
246d6471dcSMatthias Ringwald
256d6471dcSMatthias Ringwald	ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
266d6471dcSMatthias Ringwald	network={
276d6471dcSMatthias Ringwald	    ssid="YOUR_NETWORK_NAME"
286d6471dcSMatthias Ringwald	    psk="YOUR_PASSWORD"
296d6471dcSMatthias Ringwald	    key_mgmt=WPA-PSK
306d6471dcSMatthias Ringwald	}
316d6471dcSMatthias Ringwald
326d6471dcSMatthias RingwaldAlternatively, just plug-it in via Ethernet - unless you have a Raspberry Pi Zero W.
336d6471dcSMatthias Ringwald
346d6471dcSMatthias Ringwald### Enable SSH
356d6471dcSMatthias Ringwald
366d6471dcSMatthias RingwaldCreate an empty file called 'ssh' in the root folder of the SD Card to enable SSH.
376d6471dcSMatthias Ringwald
386d6471dcSMatthias Ringwald### Boot
396d6471dcSMatthias Ringwald
40*a06b9aecSMatthias RingwaldIf everything was setup correctly, it should now boot up and join your Wifi network. You can reach it via mDSN as 'raspberrypi.local' and log in with user: pi, password: raspberry.
416d6471dcSMatthias Ringwald
426d6471dcSMatthias Ringwald### Disable bluez
436d6471dcSMatthias Ringwald
446d6471dcSMatthias RingwaldBy default, bluez will start up using the the BCM4343. To make it available to BTstack, you can disable its system services:
456d6471dcSMatthias Ringwald
466d6471dcSMatthias Ringwald	$ sudo systemctl disable hciuart
476d6471dcSMatthias Ringwald    $ sudo systemctl disable bthelper
486d6471dcSMatthias Ringwald	$ sudo systemctl disable bluetooth
496d6471dcSMatthias Ringwald
506d6471dcSMatthias Ringwaldand if you don't want to restart, you can stop them right away. Otherwise, please reboot here.
516d6471dcSMatthias Ringwald
526d6471dcSMatthias Ringwald	$ sudo systemctl stop hciuart
536d6471dcSMatthias Ringwald    $ sudo systemctl stop bthelper
546d6471dcSMatthias Ringwald	$ sudo systemctl stop bluetooth
556d6471dcSMatthias Ringwald
566d6471dcSMatthias RingwaldIf needed, they can be re-enabled later as well.
576d6471dcSMatthias Ringwald
586d6471dcSMatthias Ringwald## Compilation
596d6471dcSMatthias Ringwald
606d6471dcSMatthias RingwaldThe Makefile assumes cross-compilation using the regular GCC Cross Toolchain for gnueabihf: arm-linux-gnueabihf-gcc. This should be available in your package manager. Read on for a heavy, but easy-to-use approach.
616d6471dcSMatthias Ringwald
626d6471dcSMatthias Ringwald### Compile using Docker
636d6471dcSMatthias Ringwald
646d6471dcSMatthias RingwaldFor non-Linux users, we recommend to use a [Raspberry Pi Cross-Compiler in a Docker Container](https://github.com/sdt/docker-raspberry-pi-cross-compiler).
656d6471dcSMatthias RingwaldPlease follow the installation instructions in the README.
666d6471dcSMatthias Ringwald
676d6471dcSMatthias RingwaldThen, setup a shared folder in Docker that contains the BTstack repository.
686d6471dcSMatthias RingwaldNow, go to the BTstack repository and 'switch' to the Raspberry Pi Cross-Compiler container:
696d6471dcSMatthias Ringwald
706d6471dcSMatthias Ringwald	$ rpxc bash
716d6471dcSMatthias Ringwald
726d6471dcSMatthias RingwaldThe default images doesn't have a Python installation, so we manually install it:
736d6471dcSMatthias Ringwald
746d6471dcSMatthias Ringwald	$ sudo apt-get install python
756d6471dcSMatthias Ringwald
766d6471dcSMatthias RingwaldChange to the port/raspi folder inside the BTstack repo:
776d6471dcSMatthias Ringwald
786d6471dcSMatthias Ringwald	$ cd btstack/port/raspi
796d6471dcSMatthias Ringwald
806d6471dcSMatthias Ringwaldand compile as usual:
816d6471dcSMatthias Ringwald
826d6471dcSMatthias Ringwald	$ make
836d6471dcSMatthias Ringwald
846d6471dcSMatthias RingwaldFor regular use, it makes sense to add Python permanently to the Docker container. See documentation at GitHub.
856d6471dcSMatthias Ringwald
866d6471dcSMatthias Ringwald## Running the examples
876d6471dcSMatthias Ringwald
88d9bed121SMatthias RingwaldCopy one of the examples to the Rasperry Pi and just run them. BTstack will power cycle the Bluetooth Controller on models without hardware flowcontrol, i.e., Pi 3 A/B. With flowcontrol, e.g Pi Zero W and Pi 3 A+/B+, the firmware will only uploaded on first start.
896d6471dcSMatthias Ringwald
906d6471dcSMatthias Ringwald	pi@raspberrypi:~ $ ./le_counter
916d6471dcSMatthias Ringwald	Packet Log: /tmp/hci_dump.pklg
926d6471dcSMatthias Ringwald	Hardware UART without flowcontrol
936d6471dcSMatthias Ringwald	Phase 1: Download firmware
946d6471dcSMatthias Ringwald	Phase 2: Main app
956d6471dcSMatthias Ringwald	BTstack counter 0001
966d6471dcSMatthias Ringwald	BTstack up and running at B8:27:EB:27:AF:56
976d6471dcSMatthias Ringwald
9884b427c3SMatthias Ringwald## Bluetooth Hardware Overview
9984b427c3SMatthias Ringwald
10084b427c3SMatthias RingwaldModel                    | Bluetooth Controller                                    | UART Type | UART Flowcontrol | BT_REG_EN   | HCI Transport | Baudrate
10184b427c3SMatthias Ringwald-------------------------|---------------------------------------------------------|-----------|------------------|-------------|---------------|----------
10284b427c3SMatthias RingwaldOlder                    | None                                                    |           |                  |             |               |
10384b427c3SMatthias RingwaldPi 3 Model A, Model B    | [CYW43438](http://www.cypress.com/file/298076/download) | Hardware  | No               | 128         | H5            | 921600
10484b427c3SMatthias RingwaldPi 3 Model A+, Model B + | [CYW43455](http://www.cypress.com/file/358916/download) | Hardware  | Yes              | 129 (See 1) | H4            | 921600 (See 2)
10584b427c3SMatthias RingwaldPi Zero W                | [CYW43438](http://www.cypress.com/file/298076/download) | Hardware  | Yes              | 45          | H4            | 921600
10684b427c3SMatthias Ringwald
10784b427c3SMatthias Ringwald1. Model A+/B+ have BT_REG_EN AND WL_REG_EN on the same (virtual) GPIO 129. A Bluetooth Controller power cycle also shuts down Wifi (temporarily). BTstack avoids a power cycle on A+/B+.
10884b427c3SMatthias Ringwald2. Model A+/B+ support 3 mbps baudrate. Not enabled/activated yet.
10984b427c3SMatthias Ringwald
1106d6471dcSMatthias Ringwald## TODO
1116e4c47b0SMatthias Ringwald- Raspberry Pi Zero W: Check if higher baud rate can be used, 3 mbps does not work.
1126d6471dcSMatthias Ringwald- Raspberry + RedBear IoT pHAT (AP6212A = BCM4343) port: IoT pHAT need to get detected and the UART configured appropriately.
113