Skip to content

Commit

Permalink
Merge pull request #25 from intercreate/example/serial-dfu
Browse files Browse the repository at this point in the history
feat: add serial transport line_length (default 128) and line_bufs (d…
  • Loading branch information
JPHutchins authored May 27, 2024
2 parents 3b2ce63 + c1e783d commit 26a3a2d
Show file tree
Hide file tree
Showing 38 changed files with 46,626 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ source =
smpclient/

[report]
fail_under = 86.0
fail_under = 85.0
show_missing = True
14 changes: 12 additions & 2 deletions dutfirmware/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Activate the environment (in `dutfirmware/`):

Build some FW, for example:
```
west build -b nrf52dk_nrf52832 zephyr/samples/subsys/mgmt/mcumgr/smp_svr -- -DEXTRA_CONF_FILE="overlay-bt.conf;${ENVR_ROOT}/a_smp_dut.conf"
west build -b nrf52dk_nrf52832 zephyr/samples/subsys/mgmt/mcumgr/smp_svr -- -DEXTRA_CONF_FILE="overlay-bt.conf;${ENVR_ROOT}/ble_a_smp_dut.conf"
```

Flash that FW, for example:
Expand All @@ -61,4 +61,14 @@ west flash -d build/nrf52dk_nrf52832 --recover
Or, for USB CDC ACM:
```
west build -b adafruit_feather_nrf52840 zephyr/samples/subsys/mgmt/mcumgr/smp_svr -- -DEXTRA_CONF_FILE="overlay-cdc.conf" -DEXTRA_DTC_OVERLAY_FILE="usb.overlay"
```
```

Fast USB CDC ACM:
```
west build -b nrf52840dk_nrf52840 zephyr/samples/subsys/mgmt/mcumgr/smp_svr -- -DEXTRA_CONF_FILE="overlay-cdc.conf;${ENVR_ROOT}/usb_smp_dut.conf;${ENVR_ROOT}/usb_smp_dut_mtu4096.conf" -DEXTRA_DTC_OVERLAY_FILE="usb.overlay"mp_dut_mtu4096.conf" -DEXTRA_DTC_OVERLAY_FILE="usb.overlay"
```

MCUBoot configuration with SMP USB DFU. USB PID will be 0x000C in bootloader.
```
west build -b nrf52840dk_nrf52840 zephyr/samples/subsys/mgmt/mcumgr/smp_svr -- -DEXTRA_CONF_FILE="overlay-bt.conf;overlay-cdc.conf;${ENVR_ROOT}/usb_a_smp_dut.conf" -DEXTRA_DTC_OVERLAY_FILE="usb.overlay" -Dmcuboot_CONF_FILE="../../../../mcuboot_usb.conf" -Dmcuboot_DTS_FILE="../../../../mcuboot_usb.overlay"
```
File renamed without changes.
File renamed without changes.
63 changes: 63 additions & 0 deletions dutfirmware/mcuboot_usb.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# More RAM
CONFIG_MAIN_STACK_SIZE=20480
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=20480

# Enable flash operations
CONFIG_FLASH=y
CONFIG_NORDIC_QSPI_NOR=n
CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096

# This must be increased to accommodate the bigger images.
CONFIG_BOOT_MAX_IMG_SECTORS=256

# Should be default for Nordic, set anyway
CONFIG_BOOT_PREFER_SWAP_MOVE=y

# Disable console (you could reenable it on a different UART interface)
CONFIG_CONSOLE=n

# Flash footprint savings
CONFIG_ASSERT=n
CONFIG_BOOT_BANNER=n
CONFIG_LOG=n
CONFIG_UART_CONSOLE=n
CONFIG_STDOUT_CONSOLE=n
CONFIG_PRINTK=n
CONFIG_EARLY_CONSOLE=n
CONFIG_SIZE_OPTIMIZATIONS=y

# Bigger MCUBoot partition to fit USB stack, SMP, crypto, etc...
# better to use DTS (or pm_static.yaml)
CONFIG_PM_PARTITION_SIZE_MCUBOOT=0x10800

# Enable SMP USB CDC ACM DFU
CONFIG_MCUBOOT_SERIAL=y
CONFIG_BOOT_MGMT_ECHO=y
CONFIG_BOOT_SERIAL_IMG_GRP_HASH=y
CONFIG_BOOT_SERIAL_IMG_GRP_IMAGE_STATE=y
CONFIG_BOOT_SERIAL_CDC_ACM=y

# Allow upload to the primary slot
CONFIG_MCUBOOT_SERIAL_DIRECT_IMAGE_UPLOAD=y

# Fast USB CDC ACM
# CONFIG_BOOT_MAX_LINE_INPUT_LEN=4096
# CONFIG_BOOT_LINE_BUFS=2
# CONFIG_BOOT_SERIAL_MAX_RECEIVE_SIZE=8192

# Enable USB
CONFIG_USB_DEVICE_STACK=y
CONFIG_SERIAL=y
CONFIG_UART_LINE_CTRL=y
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n

# Serial Recovery
CONFIG_BOOT_SERIAL_NO_APPLICATION=y

# Enter DFU mode on every boot, with timeout
CONFIG_BOOT_SERIAL_WAIT_FOR_DFU=y
# USB must enumerate!
CONFIG_BOOT_SERIAL_WAIT_FOR_DFU_TIMEOUT=2000

# PID 0x000C to make it easy for us to find device in MCUBoot
CONFIG_USB_DEVICE_PID=0x000C
11 changes: 11 additions & 0 deletions dutfirmware/mcuboot_usb.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/ {
chosen {
zephyr,uart-mcumgr = &cdc_acm_uart0;
};
};

&zephyr_udc0 {
cdc_acm_uart0: cdc_acm_uart0 {
compatible = "zephyr,cdc-acm-uart";
};
};
1 change: 1 addition & 0 deletions dutfirmware/usb_a_smp_dut.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_USB_DEVICE_PID=0x000A
1 change: 1 addition & 0 deletions dutfirmware/usb_b_smp_dut.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_USB_DEVICE_PID=0x000B
4 changes: 4 additions & 0 deletions dutfirmware/usb_smp_dut.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# 9.13 KB/s (using defaults)
# CONFIG_UART_MCUMGR_RX_BUF_SIZE=128
# CONFIG_UART_MCUMGR_RX_BUF_COUNT=2
# CONFIG_MCUMGR_TRANSPORT_NETBUF_SIZE=256
4 changes: 4 additions & 0 deletions dutfirmware/usb_smp_dut_1024_1_1024.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# ~31.61 KB/s
CONFIG_UART_MCUMGR_RX_BUF_SIZE=1024
CONFIG_UART_MCUMGR_RX_BUF_COUNT=1
CONFIG_MCUMGR_TRANSPORT_NETBUF_SIZE=1024
4 changes: 4 additions & 0 deletions dutfirmware/usb_smp_dut_512_8_4096.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# ~45.50 KB/s
CONFIG_UART_MCUMGR_RX_BUF_SIZE=512
CONFIG_UART_MCUMGR_RX_BUF_COUNT=8
CONFIG_MCUMGR_TRANSPORT_NETBUF_SIZE=4096
4 changes: 4 additions & 0 deletions dutfirmware/usb_smp_dut_8192_1_8192.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# ~51.19 KB/s
CONFIG_UART_MCUMGR_RX_BUF_SIZE=8192
CONFIG_UART_MCUMGR_RX_BUF_COUNT=1
CONFIG_MCUMGR_TRANSPORT_NETBUF_SIZE=8192
1 change: 1 addition & 0 deletions examples/ble/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ async def main() -> None:
dut_folder: Final = Path(__file__).parent.parent / "duts" / parser.parse_args().board / "ble"
print(f"Using DUT folder: {dut_folder}")
merged_hex_path: Final = dut_folder / "a_smp_dut.merged.hex"
print(f"Using merged.hex: {merged_hex_path}")

print("Flashing the merged.hex...")
assert (
Expand Down
Binary file not shown.
Loading

0 comments on commit 26a3a2d

Please sign in to comment.