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