diff --git a/examples/zephyr/gateway/Kconfig b/examples/zephyr/gateway/Kconfig index 94a9d673..3a359d08 100644 --- a/examples/zephyr/gateway/Kconfig +++ b/examples/zephyr/gateway/Kconfig @@ -15,12 +15,14 @@ config SAMPLE_POUCH_GATEWAY_BT_AUTO_BOND bool default y if BOARD_NRF52_BSIM_NATIVE default y if BOARD_NRF9160DK_NRF52840 + default y if BOARD_THINGY91X_NRF5340_CPUAPP_NS # This option is used only for automated tests config SAMPLE_POUCH_GATEWAY_BT_AUTO_CONFIRM bool default y if BOARD_NRF52_BSIM_NATIVE default y if BOARD_NRF9160DK_NRF52840 + default y if BOARD_THINGY91X_NRF5340_CPUAPP_NS config EXAMPLE_COAP_CLIENT_SYNC_PERIOD_S int "CoAP client sync period (s)" diff --git a/examples/zephyr/gateway/README.md b/examples/zephyr/gateway/README.md index c4f7977d..91c61240 100644 --- a/examples/zephyr/gateway/README.md +++ b/examples/zephyr/gateway/README.md @@ -50,6 +50,84 @@ mcumgr --conntype serial --connstring $SERIAL_PORT fs upload $KEY_FILE /lfs1/cre where `$SERIAL_PORT` is the serial port for the device, like `/dev/ttyACM0` on Linux, or `COM1` on Windows. +### Provisioning with littlefs binary + +Credentials can also be provisioned by creating a LittleFS binary image +containing the certificate and key files, then flashing it directly to the +storage partition on the device. + +This approach is useful when MCUmgr USB/serial provisioning is not available, +such as on platforms where the UART is used for other purposes (e.g. serial +modem communication on a Thingy91x-based gateway). + +Install the `littlefs_tools` Python package: + +```bash +pip install littlefs_tools +``` + +Create a directory structure for the credentials: + +```bash +mkdir -p littlefs/credentials +``` + +Place your DER-encoded certificate and private key files into the +`littlefs/credentials/` directory: + +``` +littlefs/ +└── credentials + ├── crt.der + └── key.der +``` + +Generate the LittleFS binary image: + +```bash +littlefs create -s littlefs -i image.bin -b 4096 -c 8 +``` + +Convert the binary to Intel HEX format at the appropriate flash offset for the +target platform: + +```bash +arm-zephyr-eabi-objcopy -I binary -O ihex --change-addresses image.bin lfs_storage.hex +``` + +The `` is the flash address of the `storage_partition` +in the device tree. See the platform-specific examples below. + +Flash the HEX file to the device: + +```bash +nrfutil device program \ + --firmware lfs_storage.hex \ + --core application \ + --options chip_erase_mode=ERASE_RANGES_TOUCHED_BY_FIRMWARE,reset=RESET_SYSTEM,verify=VERIFY_READ +``` + +#### Thingy:91 X + +For the Thingy:91 X, the nRF5340 application core has the storage partition +at address `0xF8000`. Use `arm-zephyr-eabi-objcopy` from the Zephyr SDK to +convert the binary: + +```bash +/path/to/zephyr-sdk-0.17.2/arm-zephyr-eabi/bin/arm-zephyr-eabi-objcopy \ + -I binary -O ihex --change-addresses 0xF8000 image.bin lfs_storage.hex +``` + +Ensure the SWD switch (`SW2`) is set to `nRF53`, then flash to the nRF5340 +application core: + +```bash +nrfutil device program \ + --firmware lfs_storage.hex \ + --core application \ + --options chip_erase_mode=ERASE_RANGES_TOUCHED_BY_FIRMWARE,reset=RESET_SYSTEM,verify=VERIFY_READ +``` + ## WiFi Gateway Using the NXP frdm_rw612 By default the frdm_rw612 will build with Ethernet support, but may diff --git a/examples/zephyr/gateway/boards/thingy91x_nrf5340_cpuapp.conf b/examples/zephyr/gateway/boards/thingy91x_nrf5340_cpuapp.conf index b4b13c29..4d96b47c 100644 --- a/examples/zephyr/gateway/boards/thingy91x_nrf5340_cpuapp.conf +++ b/examples/zephyr/gateway/boards/thingy91x_nrf5340_cpuapp.conf @@ -1,3 +1,6 @@ +# Reduce max connected BT devices help with RAM usage +CONFIG_BT_MAX_CONN=8 + # PPP networking over Serial Modem CONFIG_NET_L2_PPP=y CONFIG_NET_L2_PPP_OPTION_DNS_USE=y @@ -15,7 +18,7 @@ CONFIG_MODEM_CELLULAR=y # MTU must accommodate PPP frames (up to 1500 bytes for IP packets) CONFIG_MODEM_CMUX_MTU=1500 CONFIG_MODEM_CELLULAR_UART_BUFFER_SIZES=6000 -CONFIG_MODEM_CMUX_WORK_BUFFER_SIZE_EXTRA=1024 +CONFIG_MODEM_CMUX_WORK_BUFFER_SIZE_EXTRA=2048 # UART configuration for nRF5340 CONFIG_UART_INTERRUPT_DRIVEN=y diff --git a/examples/zephyr/gateway_custom_connect/Kconfig b/examples/zephyr/gateway_custom_connect/Kconfig index 94a9d673..3a359d08 100644 --- a/examples/zephyr/gateway_custom_connect/Kconfig +++ b/examples/zephyr/gateway_custom_connect/Kconfig @@ -15,12 +15,14 @@ config SAMPLE_POUCH_GATEWAY_BT_AUTO_BOND bool default y if BOARD_NRF52_BSIM_NATIVE default y if BOARD_NRF9160DK_NRF52840 + default y if BOARD_THINGY91X_NRF5340_CPUAPP_NS # This option is used only for automated tests config SAMPLE_POUCH_GATEWAY_BT_AUTO_CONFIRM bool default y if BOARD_NRF52_BSIM_NATIVE default y if BOARD_NRF9160DK_NRF52840 + default y if BOARD_THINGY91X_NRF5340_CPUAPP_NS config EXAMPLE_COAP_CLIENT_SYNC_PERIOD_S int "CoAP client sync period (s)" diff --git a/examples/zephyr/gateway_custom_connect/README.md b/examples/zephyr/gateway_custom_connect/README.md index bcd59c39..46752fa3 100644 --- a/examples/zephyr/gateway_custom_connect/README.md +++ b/examples/zephyr/gateway_custom_connect/README.md @@ -53,6 +53,84 @@ mcumgr --conntype serial --connstring $SERIAL_PORT fs upload $KEY_FILE /lfs1/cre where `$SERIAL_PORT` is the serial port for the device, like `/dev/ttyACM0` on Linux, or `COM1` on Windows. +### Provisioning with littlefs binary + +Credentials can also be provisioned by creating a LittleFS binary image +containing the certificate and key files, then flashing it directly to the +storage partition on the device. + +This approach is useful when MCUmgr USB/serial provisioning is not available, +such as on platforms where the UART is used for other purposes (e.g. serial +modem communication on a Thingy91x-based gateway). + +Install the `littlefs_tools` Python package: + +```bash +pip install littlefs_tools +``` + +Create a directory structure for the credentials: + +```bash +mkdir -p littlefs/credentials +``` + +Place your DER-encoded certificate and private key files into the +`littlefs/credentials/` directory: + +``` +littlefs/ +└── credentials + ├── crt.der + └── key.der +``` + +Generate the LittleFS binary image: + +```bash +littlefs create -s littlefs -i image.bin -b 4096 -c 8 +``` + +Convert the binary to Intel HEX format at the appropriate flash offset for the +target platform: + +```bash +arm-zephyr-eabi-objcopy -I binary -O ihex --change-addresses image.bin lfs_storage.hex +``` + +The `` is the flash address of the `storage_partition` +in the device tree. See the platform-specific examples below. + +Flash the HEX file to the device: + +```bash +nrfutil device program \ + --firmware lfs_storage.hex \ + --core application \ + --options chip_erase_mode=ERASE_RANGES_TOUCHED_BY_FIRMWARE,reset=RESET_SYSTEM,verify=VERIFY_READ +``` + +#### Thingy:91 X + +For the Thingy:91 X, the nRF5340 application core has the storage partition +at address `0xF8000`. Use `arm-zephyr-eabi-objcopy` from the Zephyr SDK to +convert the binary: + +```bash +/path/to/zephyr-sdk-0.17.2/arm-zephyr-eabi/bin/arm-zephyr-eabi-objcopy \ + -I binary -O ihex --change-addresses 0xF8000 image.bin lfs_storage.hex +``` + +Ensure the SWD switch (`SW2`) is set to `nRF53`, then flash to the nRF5340 +application core: + +```bash +nrfutil device program \ + --firmware lfs_storage.hex \ + --core application \ + --options chip_erase_mode=ERASE_RANGES_TOUCHED_BY_FIRMWARE,reset=RESET_SYSTEM,verify=VERIFY_READ +``` + ## WiFi Gateway Using the NXP frdm_rw612 By default the frdm_rw612 will build with Ethernet support, but may diff --git a/examples/zephyr/gateway_custom_connect/boards/thingy91x_nrf5340_cpuapp.conf b/examples/zephyr/gateway_custom_connect/boards/thingy91x_nrf5340_cpuapp.conf index b4b13c29..4d96b47c 100644 --- a/examples/zephyr/gateway_custom_connect/boards/thingy91x_nrf5340_cpuapp.conf +++ b/examples/zephyr/gateway_custom_connect/boards/thingy91x_nrf5340_cpuapp.conf @@ -1,3 +1,6 @@ +# Reduce max connected BT devices help with RAM usage +CONFIG_BT_MAX_CONN=8 + # PPP networking over Serial Modem CONFIG_NET_L2_PPP=y CONFIG_NET_L2_PPP_OPTION_DNS_USE=y @@ -15,7 +18,7 @@ CONFIG_MODEM_CELLULAR=y # MTU must accommodate PPP frames (up to 1500 bytes for IP packets) CONFIG_MODEM_CMUX_MTU=1500 CONFIG_MODEM_CELLULAR_UART_BUFFER_SIZES=6000 -CONFIG_MODEM_CMUX_WORK_BUFFER_SIZE_EXTRA=1024 +CONFIG_MODEM_CMUX_WORK_BUFFER_SIZE_EXTRA=2048 # UART configuration for nRF5340 CONFIG_UART_INTERRUPT_DRIVEN=y diff --git a/examples/zephyr/gateway_custom_connect/boards/thingy91x_nrf5340_cpuapp.overlay b/examples/zephyr/gateway_custom_connect/boards/thingy91x_nrf5340_cpuapp.overlay index 30e4a420..e5b6e44a 100644 --- a/examples/zephyr/gateway_custom_connect/boards/thingy91x_nrf5340_cpuapp.overlay +++ b/examples/zephyr/gateway_custom_connect/boards/thingy91x_nrf5340_cpuapp.overlay @@ -13,6 +13,10 @@ */ / { + chosen { + zephyr,code-partition = &slot0_partition; + }; + aliases { modem = &modem; }; @@ -33,6 +37,20 @@ }; }; +/delete-node/ &boot_partition; +/delete-node/ &slot0_partition; +/delete-node/ &slot1_partition; + +&flash0 { + partitions { + slot0_partition: partition@0 { + compatible = "zephyr,mapped-partition"; + label = "image-0"; + reg = <0x00000000 0x000f8000>; + }; + }; +}; + &uart0 { status = "okay"; current-speed = <115200>; diff --git a/examples/zephyr/ncs-serial-modem/boards/thingy91x_nrf9151_ns.conf b/examples/zephyr/ncs-serial-modem/boards/thingy91x_nrf9151_ns.conf new file mode 100644 index 00000000..e25a988e --- /dev/null +++ b/examples/zephyr/ncs-serial-modem/boards/thingy91x_nrf9151_ns.conf @@ -0,0 +1,7 @@ +# Route console and logs to RTT so the nRF9151's two UARTs are free for the +# inter-chip serial-modem link (UART0/UART1 data + flow control pins). +CONFIG_UART_CONSOLE=n +CONFIG_LOG_BACKEND_UART=n +CONFIG_RTT_CONSOLE=y +CONFIG_LOG_BACKEND_RTT=y +CONFIG_USE_SEGGER_RTT=y diff --git a/examples/zephyr/ncs-serial-modem/boards/thingy91x_nrf9151_ns.overlay b/examples/zephyr/ncs-serial-modem/boards/thingy91x_nrf9151_ns.overlay index 451d2b9d..18be7296 100644 --- a/examples/zephyr/ncs-serial-modem/boards/thingy91x_nrf9151_ns.overlay +++ b/examples/zephyr/ncs-serial-modem/boards/thingy91x_nrf9151_ns.overlay @@ -5,11 +5,28 @@ */ / { + rtt0: rtt_chan0 { + compatible = "segger,rtt-uart"; + status = "okay"; + }; + chosen { ncs,sm-uart = &dtr_uart1; + /* + * Route console/shell to RTT. The nRF9151's UART0 and UART1 + * data pins (P0.00/P0.01) are used by the inter-chip + * serial-modem link, so UART0 cannot also drive the console. + */ + zephyr,console = &rtt0; + zephyr,shell-uart = &rtt0; }; }; +/* UART0 is disabled to release P0.00/P0.01 for the modem UART1. */ +&uart0 { + status = "disabled"; +}; + &uart1 { pinctrl-0 = <&uart_vcom0_vcom1_default>; pinctrl-1 = <&uart_vcom0_vcom1_sleep>;