Zephyr Notes Entry: Supported boards Date: Wed Apr 1 18:40:03 EDT 2020 https://docs.zephyrproject.org/latest/boards/arm/stm32_min_dev/doc/index.html https://docs.zephyrproject.org/latest/boards/arm/stm32f0_disco/doc/index.html https://docs.zephyrproject.org/latest/boards/arm/stm32f030_demo/doc/index.html https://docs.zephyrproject.org/latest/boards/arm/stm32f4_disco/doc/index.html https://docs.zephyrproject.org/latest/boards/arm/nrf52840_mdk/doc/index.html Entry: setting up Date: Wed Apr 1 19:08:17 EDT 2020 $ cd /nix/exo $ west init zephyr-project $ cd zephyr-project/ $ west update $ west zephyr-export The latter one crashes on a Python f string, introduced in 3.6 and I have 3.5 Installed 3.7.2 from nix. Another issue: requirements-run-test.txt contains: pyocd>=0.24.0 which fails install due to rust error on cmsis_pack_manager pip install --user cmsis_pack_manager Why the hell is there a rust package in there? https://github.com/ARMmbed/cmsis-pack-manager The needs: rustup update stable rustup default stable So pip isn't too smart. It installs everything that it is asked to install even if it is already installed. Smart skipping is done only for things that are not directly mentioned. Wow this shit really is complex and hard to get going. OK this is a problem with nix. Nix is a fucking pain in the ass. cd /nix/exo/zephyr-project/zephyr export PYTHONPATH=/home/tom/.local/lib/python3.7/site-packages west build -p auto -b stm32_min_dev_blue samples/basic/blinky Entry: STLink-V2 Date: Thu Apr 2 11:38:33 EDT 2020 https://www.youtube.com/watch?v=dB4xIs0-Kb4 https://devzone.nordicsemi.com/f/nordic-q-a/38670/nrf52840-and-st-link-v2 So it should work. I have just one left? Maybe order some more then. After installing OpenOCD 0.10.0 (Debian had 0.9.x) it works with nrf52.cnf: root@zoe:/etc/net/udev/openocd# ./openocd_nRF52_STLink.sh Open On-Chip Debugger 0.10.0 Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html Info : auto-selecting first available session transport "hla_swd". To override use 'transport select '. Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD adapter speed: 10000 kHz Info : Unable to match requested speed 10000 kHz, using 4000 kHz Info : Unable to match requested speed 10000 kHz, using 4000 kHz Info : clock speed 4000 kHz Info : STLINK v2 JTAG v17 API v2 SWIM v4 VID 0x0483 PID 0x3748 Info : using stlink api v2 Info : Target voltage: 3.251098 Info : nrf52.cpu: hardware has 6 breakpoints, 4 watchpoints Entry: blinky on nRF52 board Date: Fri Apr 3 09:32:21 EDT 2020 First find out which board this should be. Entry: nRF52 board Date: Fri Apr 3 09:36:47 EDT 2020 This one is supported: https://wiki.makerdiary.com/nrf52840-mdk/ https://docs.zephyrproject.org/latest/boards/arm/nrf52840_mdk/doc/index.html I have this one: https://wiki.makerdiary.com/nrf52840-mdk-usb-dongle/ LEDs are the same on both P0.22 green P0.23 red P0.24 blue So that should be fine. Trying it out: cd /nix/exo/zephyr-project/zephyr . ~/.zephyrrc export PYTHONPATH=/home/tom/.local/lib/python3.7/site-packages west build -p auto -b nrf52840_mdk samples/basic/blinky [117/122] Linking C executable zephyr/zephyr_prebuilt.elf Memory region Used Size Region Size %age Used FLASH: 12188 B 1 MB 1.16% SRAM: 3956 B 256 KB 1.51% IDT_LIST: 56 B 2 KB 2.73% The dts for this board is here: tom@panda:/nix/exo/zephyr-project/zephyr$ cat ./boards/arm/nrf52840_mdk/nrf52840_mdk.dts Entry: load failed Date: Fri Apr 3 09:47:36 EDT 2020 (gdb) file /i/panda/nix/exo/zephyr-project/zephyr/build/zephyr/zephyr.elf A program is being debugged already. Are you sure you want to change the file? (y or n) y Reading symbols from /net/10.1.3.2/vol/2/panda/nix/exo/zephyr-project/zephyr/build/zephyr/zephyr.elf...done. (gdb) load Loading section rom_start, size 0x100 lma 0x0 Loading section text, size 0x2ac2 lma 0x100 Loading section .ARM.exidx, size 0x8 lma 0x2bc4 Load failed I don't have the energy to debug that now. Possible solution: https://github.com/marcelobarrosalmeida/openocd_nrf52 Entry: 802.15.4 is not BLE link layer Date: Fri Apr 3 18:09:14 EDT 2020 http://www.diva-portal.org/smash/get/diva2:872772/FULLTEXT01.pdf Entry: Setting up the BLE example Date: Fri Apr 24 14:00:02 EDT 2020 https://www.zephyrproject.org/getting-started-with-zephyr-rtos-on-nordic-nrf52832-hackable/ 1. ninja menuconfig + 'D' to save defconfig (rename to prj.conf?) 2. where to save dts? Entry: UART output Date: Mon Apr 27 11:35:48 EDT 2020 So I want to see what is coming out of the uart. How do I know which pin is the uart? ./build/zephyr/zephyr.dts uart0: uart@40002000 { reg = < 0x40002000 0x1000 >; interrupts = < 0x2 0x1 >; status = "okay"; label = "UART_0"; compatible = "nordic,nrf-uart"; current-speed = < 0x1c200 >; tx-pin = < 0x14 >; rx-pin = < 0x13 >; rts-pin = < 0x5 >; cts-pin = < 0x7 >; }; uart1: uart@40028000 { compatible = "nordic,nrf-uarte"; reg = < 0x40028000 0x1000 >; interrupts = < 0x28 0x1 >; status = "disabled"; label = "UART_1"; }; What are the pin numbers? model = "nRF52840-MDK Dev Kit"; As usual, pin naming isn't universal. Start with what's on the board's doc site: This is the config I'm using for zephyr and is the board used for the client, but not the board I have myself. https://github.com/makerdiary/nrf52840-mdk TXD P0.20 RXD P0.19 I have this board: https://github.com/makerdiary/nrf52840-mdk-usb-dongle The pins are marked. With USB connector on top LEFT: 1 VIN 2 +5V 3 GDN 4 P0.04 5 P0.05 6 P0.06 7 P0.07 8 P0.08 9 P0.09 10 P0.10 RIGHT: 1 +3v3V 2 GND 3 RST 4 SWDCLK 5 SWDIO 6 P0.19 RXD 7 P0.20 TXD 8 P0.21 9 P0.02 10 P0.03 Entry: BT840 pinout Date: Mon Apr 27 15:14:09 EDT 2020 Can up, antenna top LEFT 1 P26 SDA 2 P27 SCL 3 P00 XL1 4 P01 XL2 5 P02 AIN0 6 P03 AIN1 7 P09 NFC1 8 P10 NFC2 RIGHT 16 SWDIO 15 SWCLK 14 P18 RST 13 P13 LED 12 P100 SWO 11 P11 BUTTON 10 GND 9 VDD Entry: uart config Date: Tue Apr 28 23:36:14 EDT 2020 uart0: uart@40002000 { reg = < 0x40002000 0x1000 >; interrupts = < 0x2 0x1 >; status = "okay"; label = "UART_0"; compatible = "nordic,nrf-uart"; current-speed = < 0x1c200 >; tx-pin = < 0x14 >; rx-pin = < 0x13 >; rts-pin = < 0x5 >; cts-pin = < 0x7 >; }; uart1: uart@40028000 { compatible = "nordic,nrf-uarte"; reg = < 0x40028000 0x1000 >; interrupts = < 0x28 0x1 >; status = "disabled"; label = "UART_1"; }; 0x14 is P0.20 0x13 is P0.19 #x1c200 115200 Entry: dts Date: Tue Apr 28 23:40:43 EDT 2020 So I have dts modifications I want to make. What is the proper way to include those in the git archive and build? Maybe first look at what a board directory looks like in the zephyr tree. /nix/exo/zephyr-project/zephyr/boards/arm/nrf52840_mdk This has some explanation: https://www.zephyrproject.org/getting-started-with-zephyr-rtos-on-nordic-nrf52832-hackable/ It seems to suggest to add a board file to the zephyr-project Can I just put that in the main source tree? EDIT: I don't see a way to put that in the application source tree, so it is simplest to add a zephyr fork and use that. Entry: Compiling BLE example Date: Fri May 8 14:07:51 EDT 2020 Example has bitrotted, so track down some errors. [ 9%] Building C object CMakeFiles/app.dir/src/main.c.obj In file included from /home/tom/exo/zephyr/ble/src/main.c:18: /home/tom/exo/zephyr/ble/src/main.c:67:17: warning: initialization of 'void (*)(const struct bt_gatt_attr *, u16_t)' {aka 'void (*)(const struct bt_gatt_attr *, short unsigned int)'} from incompatible pointer type 'struct bt_gatt_ccc_cfg *' [-Wincompatible-pointer-types] 67 | BT_GATT_CCC(T_ccc_cfg, T_ccc_cfg_changed), | void (*)(const struct bt_gatt_attr *, u16_t) aka void (*)(const struct bt_gatt_attr *, short unsigned int) != struct bt_gatt_ccc_cfg * That's odd. Ok I'm going to have to index this. Indexed. So what is going on here? BT_GATT_CCC(T_ccc_cfg, T_ccc_cfg_changed), gatt.h says: /** @def BT_GATT_CCC * @brief Client Characteristic Configuration Declaration Macro. * * Helper macro to declare a CCC attribute. * * @param _changed Configuration changed callback. * @param _perm CCC access permissions. */ #define BT_GATT_CCC(_changed, _perm) \ BT_GATT_CCC_MANAGED(((struct _bt_gatt_ccc[]) \ {BT_GATT_CCC_INITIALIZER(_changed, NULL, NULL)}), _perm) So this is just another macro. API docs from https://docs.zephyrproject.org/1.9.0/api/bluetooth.html say: BT_GATT_CCC(_cfg, _cfg_changed) Client Characteristic Configuration Declaration Macro. Helper macro to declare a CCC attribute. Parameters _cfg: Initial configuration. _cfg_changed: Configuration changed callback. So what am I running? tom@panda:/nix/exo/zephyr-project/zephyr$ cat VERSION VERSION_MAJOR = 2 VERSION_MINOR = 2 PATCHLEVEL = 99 VERSION_TWEAK = 0 EXTRAVERSION = This is the old definition from: https://github.com/zephyrproject-rtos/zephyr/blob/v1.9-branch/include/bluetooth/gatt.h /** @def BT_GATT_CCC * @brief Client Characteristic Configuration Declaration Macro. * * Helper macro to declare a CCC attribute. * * @param _cfg Initial configuration. * @param _cfg_changed Configuration changed callback. */ #define BT_GATT_CCC(_cfg, _cfg_changed) \ { \ .uuid = BT_UUID_GATT_CCC, \ .perm = BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, \ .read = bt_gatt_attr_read_ccc, \ .write = bt_gatt_attr_write_ccc, \ .user_data = (&(struct _bt_gatt_ccc) { .cfg = _cfg, \ .cfg_len = ARRAY_SIZE(_cfg), \ .cfg_changed = _cfg_changed, }),\ } It's probably going to be easier to start from another example. Entry: BLE testing with Bluez Date: Sat May 9 12:55:00 EDT 2020 https://bcdevices.github.io/zephyr/ble/2019/10/30/zephyr-ble-testing.html Entry: Looking for some other examples Date: Sat May 9 12:56:24 EDT 2020 https://www.novelbits.io/zephyr-getting-started-bluetooth-low-energy-development/ But this is just advertising for their course on bluetooth which is not public. Entry: Compare Bluetooth docs between 1.9 and 2.2.99 Date: Sat May 9 13:21:08 EDT 2020 https://docs.zephyrproject.org/1.9.0/api/bluetooth.html https://docs.zephyrproject.org/latest/reference/bluetooth/index.html Entry: BLE example Date: Mon May 11 11:20:26 EDT 2020 1.9 and 2.2.99 seem significantly different. I am confused. Let's look for a different example. There are a couple in the source tree. I'm not bootstrapped far enough yet to pick a good one, so let's just pick this one: zephyr-project/zephyr/samples/bluetooth/peripheral/src/main.c EDIT: This uses the heart rate service that is already part of zephyr: zephyr/subsys/bluetooth/services/hrs.c So it probably needs to be enabled in the config. Bluetooth -> GATT Services -> GATT Heart Rate service Entry: Found a new example Date: Tue May 26 20:12:40 EDT 2020 This is sufficiently complex and not too complex: zephyr-project/zephyr/samples/bluetooth/peripheral/src/main.c Some questions: - What is Client Configuration Change? Entry: Weird error Date: Tue May 26 20:37:06 EDT 2020 +*** Booting Zephyr OS build zephyr-v2.2.0-1076-g9162e7d81298 *** Bluetooth initialized Advertising failed to start (err -11) The error is returned by: bt_le_adv_start * @return -ENOMEM No free connection objects available for connectable * advertiser. * @return -ECONNREFUSED When connectable advertising is requested and there * is already maximum number of connections established * in the controller. * This error code is only guaranteed when using Zephyr * controller, for other controllers code returned in * this case may be -EIO. I had removed: if (IS_ENABLED(CONFIG_SETTINGS)) { settings_load(); } So don't! Entry: BLE GATT indicate Date: Tue May 26 22:07:33 EDT 2020 Like notification, but with confirmation. Entry: Single reader? Date: Tue May 26 23:07:34 EDT 2020 It does seem to be possible, because the pointer to the attribute is passed into the read/write function, and it is possible to pass a type-tagged thing in there such that the read/write function can do some dispatch. Entry: Multiple notifications? Date: Wed May 27 00:30:00 EDT 2020 It seems that Nordic app does caching and I don't find a reliable way to clear the cache.. Also I seem to have an issue with multiple notifications. Here's a service that has multiple sensors, from samples/bluetooth/peripheral_esp/src/main.c BT_GATT_SERVICE_DEFINE(ess_svc, BT_GATT_PRIMARY_SERVICE(BT_UUID_ESS), /* Temperature Sensor 1 */ BT_GATT_CHARACTERISTIC(BT_UUID_TEMPERATURE, BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, BT_GATT_PERM_READ, read_u16, NULL, &sensor_1.temp_value), BT_GATT_DESCRIPTOR(BT_UUID_ES_MEASUREMENT, BT_GATT_PERM_READ, read_es_measurement, NULL, &sensor_1.meas), BT_GATT_CUD(SENSOR_1_NAME, BT_GATT_PERM_READ), BT_GATT_DESCRIPTOR(BT_UUID_VALID_RANGE, BT_GATT_PERM_READ, read_temp_valid_range, NULL, &sensor_1), BT_GATT_DESCRIPTOR(BT_UUID_ES_TRIGGER_SETTING, BT_GATT_PERM_READ, read_temp_trigger_setting, NULL, &sensor_1), BT_GATT_CCC(temp_ccc_cfg_changed, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE), /* Temperature Sensor 2 */ BT_GATT_CHARACTERISTIC(BT_UUID_TEMPERATURE, BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, BT_GATT_PERM_READ, read_u16, NULL, &sensor_2.temp_value), BT_GATT_DESCRIPTOR(BT_UUID_ES_MEASUREMENT, BT_GATT_PERM_READ, read_es_measurement, NULL, &sensor_2.meas), BT_GATT_CUD(SENSOR_2_NAME, BT_GATT_PERM_READ), BT_GATT_DESCRIPTOR(BT_UUID_VALID_RANGE, BT_GATT_PERM_READ, read_temp_valid_range, NULL, &sensor_2), BT_GATT_DESCRIPTOR(BT_UUID_ES_TRIGGER_SETTING, BT_GATT_PERM_READ, read_temp_trigger_setting, NULL, &sensor_2), BT_GATT_CCC(temp_ccc_cfg_changed, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE), /* Humidity Sensor */ BT_GATT_CHARACTERISTIC(BT_UUID_HUMIDITY, BT_GATT_CHRC_READ, BT_GATT_PERM_READ, read_u16, NULL, &sensor_3.humid_value), BT_GATT_CUD(SENSOR_3_NAME, BT_GATT_PERM_READ), BT_GATT_DESCRIPTOR(BT_UUID_ES_MEASUREMENT, BT_GATT_PERM_READ, read_es_measurement, NULL, &sensor_3.meas), ); Entry: BLE on linux Date: Sun May 31 19:37:13 EDT 2020 don't use bluetoothctl for querying characteristics. use gatttool. "-t random" is required. gatttool -b 7D:EE:B0:80:2E:F8 -I -t random https://stackoverflow.com/questions/15657007/bluetooth-low-energy-listening-for-notifications-indications-in-linux [7D:EE:B0:80:2E:F8][LE]> char-desc 0x27 0x28 handle: 0x0027, uuid: 0000ffa3-0000-1000-8000-00805f9b34fb handle: 0x0028, uuid: 00002902-0000-1000-8000-00805f9b34fb To turn on notifications, write 0100 to the ccc char-write-req 0x0031 0100 Entry: serial radio Date: Mon Jun 1 00:39:35 EDT 2020 https://lists.zephyrproject.org/g/users/topic/zephyr_compatible_motes_for/31617871?p=,,,20,0,0,0::recentpostdate%2Fsticky,,,20,2,0,31617871 https://www.zephyrproject.org/introducing-the-zephyr-reel-board/ https://github.com/zephyrproject-rtos/zephyr/tree/master/samples/net/wpan_serial Entry: ipv6 over ble Date: Mon Jun 1 13:36:23 EDT 2020 https://blog.nordicsemi.com/getconnected/why-run-ipv6-over-bluetooth-low-energy Entry: BLE midi Date: Mon Jun 1 13:38:27 EDT 2020 From 2016. Probably by now it is part of bluez? https://www.youtube.com/watch?v=eKnC9_Buxus https://bugs.archlinux.org/task/56776 Since 5.44 Debian has 5.43 But it's not enabled by default.