xref: /btstack/port/raspi/README.md (revision 09cf8159072d80e092b9c303cea9b43a81b36aee)
1# BTstack Port for Raspberry Pi 3 with BCM4343 Bluetooth/Wifi Controller
2
3Tested with Raspberry Pi 3 Model B V1.2 and Raspberry Pi Zero W V1.1.
4
5With 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.
6
7## Raspberry Pi 3 / Zero W Setup
8
9There are various options for setting up the Raspberry Pi, have a look at the Internet. Here's what we did:
10
11### Install Raspian Stretch Lite:
12
13- Insert empty SD Card
14- Download Raspian Stretch Lite from https://www.raspberrypi.org/downloads/raspbian/
15- Install Etcher from https://etcher.io
16- Run Etcher:
17  - Select the image you've download before
18  - Select your SD card
19  - Flash!
20
21### Configure Wifi
22
23Create the file wpa_supplicant.conf in the root folder of the SD Card with your Wifi credentials:
24
25	ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
26	network={
27	    ssid="YOUR_NETWORK_NAME"
28	    psk="YOUR_PASSWORD"
29	    key_mgmt=WPA-PSK
30	}
31
32Alternatively, just plug-it in via Ethernet - unless you have a Raspberry Pi Zero W.
33
34### Enable SSH
35
36Create an empty file called 'ssh' in the root folder of the SD Card to enable SSH.
37
38### Boot
39
40If everything was setup correctly, it should now boot up and join your Wifi network. You can reach it via mDSN as 'raspberrypi.local'.
41
42### Disable bluez
43
44By default, bluez will start up using the the BCM4343. To make it available to BTstack, you can disable its system services:
45
46	$ sudo systemctl disable hciuart
47    $ sudo systemctl disable bthelper
48	$ sudo systemctl disable bluetooth
49
50and if you don't want to restart, you can stop them right away. Otherwise, please reboot here.
51
52	$ sudo systemctl stop hciuart
53    $ sudo systemctl stop bthelper
54	$ sudo systemctl stop bluetooth
55
56If needed, they can be re-enabled later as well.
57
58## Compilation
59
60The 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.
61
62### Compile using Docker
63
64For 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).
65Please follow the installation instructions in the README.
66
67Then, setup a shared folder in Docker that contains the BTstack repository.
68Now, go to the BTstack repository and 'switch' to the Raspberry Pi Cross-Compiler container:
69
70	$ rpxc bash
71
72The default images doesn't have a Python installation, so we manually install it:
73
74	$ sudo apt-get install python
75
76Change to the port/raspi folder inside the BTstack repo:
77
78	$ cd btstack/port/raspi
79
80and compile as usual:
81
82	$ make
83
84For regular use, it makes sense to add Python permanently to the Docker container. See documentation at GitHub.
85
86## Running the examples
87
88Copy one of the examples to the Rasperry Pi and just run them. BTstack will always power cycle the Bluetooth Controller.
89
90	pi@raspberrypi:~ $ ./le_counter
91	Packet Log: /tmp/hci_dump.pklg
92	Hardware UART without flowcontrol
93	Phase 1: Download firmware
94	Phase 2: Main app
95	BTstack counter 0001
96	BTstack up and running at B8:27:EB:27:AF:56
97
98## TODO
99- Raspberry Pi Zero W: Check if higher baud rate can be used, 3 mbps does not work.
100- Raspberry + RedBear IoT pHAT (AP6212A = BCM4343) port: IoT pHAT need to get detected and the UART configured appropriately.
101