Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions port/raspi/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,19 @@ gatt_browser
gatt_browser.h
gatt_counter
gatt_counter.h
gatt_device_information_query
gatt_device_information_query.h
gatt_heart_rate_client
gatt_streamer_server
gatt_streamer_server.h
hfp_ag_demo
hfp_hf_demo
hid_host_demo
hid_keyboard_demo
hid_mouse_demo
hog_boot_host_demo
hog_host_demo
hog_host_demo.h
hog_keyboard_demo
hog_keyboard_demo.h
hog_mouse_demo
Expand All @@ -47,6 +53,7 @@ le_counter.h
le_credit_based_flow_control_mode_client
le_credit_based_flow_control_mode_server
le_credit_based_flow_control_mode_server.h
le_mitm
le_streamer
le_streamer.h
le_streamer_client
Expand Down
5 changes: 4 additions & 1 deletion port/raspi/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ CORE += \
# examples
include ${BTSTACK_ROOT}/example/Makefile.inc

# use (cross)compiler for Raspi
# for Raspberry PI 3 and Zero W
CC = arm-linux-gnueabihf-gcc

# for Raspberry PI 4
# CC = aarch64-linux-gnu-gcc

CFLAGS += -g -Wall -Werror \
-I$(BTSTACK_ROOT)/platform/embedded \
-I$(BTSTACK_ROOT)/platform/posix \
Expand Down
21 changes: 21 additions & 0 deletions port/raspi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@ Tested with Raspberry Pi 3 Model B V1.2, Raspberry Pi 3 Model B+, and Raspberry

With 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.

## Raspberry Pi 4B

Tested with Debian Release 12 (Bookworm), first check if you have `/dev/serial0` and `/dev/serial1` available:

```bash
$ ls -lah /dev/ser*
lrwxrwxrwx 1 root root 7 Mar 24 14:40 /dev/serial0 -> ttyAMA0
lrwxrwxrwx 1 root root 5 Mar 24 14:40 /dev/serial1 -> ttyS0
```

If those are not made, you have to modify your `/boot/firmware/config.txt` by adding:

```
[all]
dtoverlay=miniuart-bt
dtparam=krnbt=off
```

Then after restart the device symlinks should be there. To compile for 64 bit arm use `CC = aarch64-linux-gnu-gcc` in Makefile.

## Raspberry Pi 3 / Zero W Setup

There are various options for setting up the Raspberry Pi, have a look at the Internet. Here's what we did:
Expand Down Expand Up @@ -102,6 +122,7 @@ Model | Bluetooth Controller
Older | None | | | | |
Pi 3 Model A, Model B | [CYW43438](http://www.cypress.com/file/298076/download) | Hardware | No | 128 | H5 | 921600
Pi 3 Model A+, Model B + | [CYW43455](http://www.cypress.com/file/358916/download) | Hardware | Yes | 129 (See 1) | H4 | 921600 (See 2)
Pi 4 Model B | | Hardware | Yes | 129 | H4 | 921600
Pi Zero W | [CYW43438](http://www.cypress.com/file/298076/download) | Hardware | Yes | 45 | H4 | 921600

1. 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+.
Expand Down
2 changes: 1 addition & 1 deletion port/raspi/btstack_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#define ENABLE_SDP_DES_DUMP
#define ENABLE_SOFTWARE_AES128

// Warm Boot needed if connected via Wifi on Raspberry Pi 3A+ or 3B+
// Warm Boot needed if connected via Wifi on Raspberry Pi 3A+ or 3B+, 4B
// #define ENABLE_CONTROLLER_WARM_BOOT

// BTstack configuration. buffers, sizes, ...
Expand Down
16 changes: 11 additions & 5 deletions port/raspi/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,10 @@ static int raspi_get_bd_addr(bd_addr_t addr){

// see https://github.com/RPi-Distro/pi-bluetooth/blob/master/usr/bin/btuart
// on UART_INVALID errno is set
static uart_type_t raspi_get_bluetooth_uart_type(void){
static uart_type_t raspi_get_bluetooth_uart_type(const int model){
if (model == MODEL_4B) {
return UART_HARDWARE_FLOW;
}

uint8_t deviceUart0[21] = { 0 };
FILE *fd = fopen( "/proc/device-tree/aliases/uart0", "r" );
Expand Down Expand Up @@ -328,7 +331,8 @@ int main(int argc, const char * argv[]){
// set UART config based on raspi Bluetooth UART type
int bt_reg_en_pin = -1;
bool power_cycle = true;
switch (raspi_get_bluetooth_uart_type()){
int model = raspi_get_model();
switch (raspi_get_bluetooth_uart_type(model)) {
case UART_SOFTWARE_NO_FLOW:
// ??
bt_reg_en_pin = 128;
Expand All @@ -348,10 +352,12 @@ int main(int argc, const char * argv[]){
// Raspberry Pi 3A+ vgpio 129 but WLAN + BL
// Raspberry Pi 3B+ vgpio 129 but WLAN + BL
transport_config.flowcontrol = 1;
int model = raspi_get_model();
if (model == MODEL_ZERO_W){
bt_reg_en_pin = 45;
transport_config.baudrate_main = 921600;
} else if (model == MODEL_4B) {
bt_reg_en_pin = 129;
transport_config.baudrate_main = 921600;
} else {
bt_reg_en_pin = 129;
transport_config.baudrate_main = 3000000;
Expand All @@ -361,7 +367,7 @@ int main(int argc, const char * argv[]){
power_cycle = false;
#else
// warn about power cycle on devices with shared reg_en pins
if (model == MODEL_3APLUS || model == MODEL_3BPLUS){
if (model == MODEL_3APLUS || model == MODEL_3BPLUS || model == MODEL_4B){
printf("Wifi and Bluetooth share a single RESET line and BTstack needs to reset Bluetooth -> SSH over Wifi will fail\n");
printf("Please add ENABLE_CONTROLLER_WARM_BOOT to btstack_config.h to enable startup without RESET\n");
}
Expand Down Expand Up @@ -411,7 +417,7 @@ int main(int argc, const char * argv[]){

main_argc = argc;
main_argv = argv;

// power cycle Bluetooth controller on older models without flowcontrol
if (power_cycle){
btstack_control_raspi_set_bt_reg_en_pin(bt_reg_en_pin);
Expand Down
2 changes: 2 additions & 0 deletions port/raspi/raspi_get_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ int raspi_get_model()
case 0x9020e0:
model = MODEL_3APLUS;
break;
case 0xc03111:
model = MODEL_4B;
default:
break;
}
Expand Down
1 change: 1 addition & 0 deletions port/raspi/raspi_get_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define MODEL_3B 2
#define MODEL_3BPLUS 3
#define MODEL_3APLUS 4
#define MODEL_4B 5

int raspi_get_model();

Expand Down