From 39e977f917b14d92deb52778464cd0b938f38eb4 Mon Sep 17 00:00:00 2001 From: Jari Pennanen Date: Sun, 23 Mar 2025 20:46:32 +0200 Subject: [PATCH 1/4] Raspi: Ignore new demo files --- port/raspi/.gitignore | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/port/raspi/.gitignore b/port/raspi/.gitignore index 862855d90e..fa19fd4b27 100644 --- a/port/raspi/.gitignore +++ b/port/raspi/.gitignore @@ -26,6 +26,9 @@ 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 @@ -33,6 +36,9 @@ 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 @@ -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 From 8348fdb13deebdf7e360367caf2d818735c19774 Mon Sep 17 00:00:00 2001 From: Jari Pennanen Date: Mon, 24 Mar 2025 12:35:06 +0200 Subject: [PATCH 2/4] Add Raspberry Pi 4B model constant --- port/raspi/raspi_get_model.c | 2 ++ port/raspi/raspi_get_model.h | 1 + 2 files changed, 3 insertions(+) diff --git a/port/raspi/raspi_get_model.c b/port/raspi/raspi_get_model.c index 68953a76cf..4541957ada 100644 --- a/port/raspi/raspi_get_model.c +++ b/port/raspi/raspi_get_model.c @@ -49,6 +49,8 @@ int raspi_get_model() case 0x9020e0: model = MODEL_3APLUS; break; + case 0xc03111: + model = MODEL_4B; default: break; } diff --git a/port/raspi/raspi_get_model.h b/port/raspi/raspi_get_model.h index 18dea47ad6..505fcca3e5 100644 --- a/port/raspi/raspi_get_model.h +++ b/port/raspi/raspi_get_model.h @@ -6,6 +6,7 @@ #define MODEL_3B 2 #define MODEL_3BPLUS 3 #define MODEL_3APLUS 4 +#define MODEL_4B 5 int raspi_get_model(); From 9d134ed4174dc779dba7b1f6972dc7e3ce81c068 Mon Sep 17 00:00:00 2001 From: Jari Pennanen Date: Mon, 24 Mar 2025 14:57:18 +0200 Subject: [PATCH 3/4] Minimal changes to get 4B working --- port/raspi/Makefile | 5 ++++- port/raspi/btstack_config.h | 2 +- port/raspi/main.c | 16 +++++++++++----- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/port/raspi/Makefile b/port/raspi/Makefile index 803b1f07ec..0f08c389bb 100644 --- a/port/raspi/Makefile +++ b/port/raspi/Makefile @@ -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 \ diff --git a/port/raspi/btstack_config.h b/port/raspi/btstack_config.h index 6cddb7981d..7cd0c49c54 100644 --- a/port/raspi/btstack_config.h +++ b/port/raspi/btstack_config.h @@ -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, ... diff --git a/port/raspi/main.c b/port/raspi/main.c index 94e1a575e5..071da6ee11 100644 --- a/port/raspi/main.c +++ b/port/raspi/main.c @@ -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" ); @@ -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; @@ -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; @@ -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"); } @@ -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); From 1f6ce53bc056a1a9753128004982a44758e6e190 Mon Sep 17 00:00:00 2001 From: Jari Pennanen Date: Mon, 24 Mar 2025 15:08:01 +0200 Subject: [PATCH 4/4] Raspberry pi 4 readme --- port/raspi/README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/port/raspi/README.md b/port/raspi/README.md index ff0164b736..3c15002a15 100644 --- a/port/raspi/README.md +++ b/port/raspi/README.md @@ -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: @@ -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+.