Hello,
We have a custom board using a nRF5340.
We followed this course implementation for simple serial recovery over UART (and also tried CDC ACM) but as soon as activate CONFIG_BOOTLOADER_MCUBOOT=y our app doesn't load. We deactivate it and it boots up properly. Unfortunately we don't see any logs either via UART or RTT when this flag is on.
Maybe we are missing something about nRF5340 system. We are just hoping to update the app image core for now.
Below is our code.
mcuboot.conf:
CONFIG_SIZE_OPTIMIZATIONS=y CONFIG_SINGLE_APPLICATION_SLOT=y # Enable MCUboot Serial Recovery CONFIG_MCUBOOT_SERIAL=y CONFIG_UART_CONSOLE=n # Enable wait for DFU functionality # CONFIG_BOOT_SERIAL_WAIT_FOR_DFU=y # CONFIG_BOOT_SERIAL_WAIT_FOR_DFU_TIMEOUT=5000
proj.conf:
CONFIG_SOC_NRF5340_CPUAPP_QKAA=y CONFIG_BOARD_NRF7002DK_NRF5340_CPUAPP=y # Enable MPU CONFIG_ARM_MPU=y # Enable hardware stack protection CONFIG_HW_STACK_PROTECTION=y # Enable TrustZone-M CONFIG_ARM_TRUSTZONE_M=y # enable GPIO CONFIG_GPIO=y # Enable uart driver CONFIG_SERIAL=y # enable console CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=n CONFIG_RTT_CONSOLE=y CONFIG_USE_SEGGER_RTT=y CONFIG_STDOUT_CONSOLE=y CONFIG_LOG_MODE_IMMEDIATE=n CONFIG_BOOT_BANNER=y # CONFIG_USB_CDC_ACM_LOG_LEVEL_DBG=y # Kernel settings CONFIG_ENTROPY_GENERATOR=y CONFIG_TEST_RANDOM_GENERATOR=y CONFIG_CRC=y CONFIG_BASE64=y CONFIG_NEWLIB_LIBC=y CONFIG_NEWLIB_LIBC_NANO=n CONFIG_THREAD_NAME=y CONFIG_INIT_STACKS=y # Most of Zephyr allocations use k_alloc, sized with CONFIG_HEAP_MEM_POOL_SIZE. # But there are also calls to libc malloc() etc. which allocate from the libc heap, which is # unused memory (end of .bss to end of SRAM) by default. hostap uses libc heap heavily, and # does not handle failures well (can get stuck in infinite loops). # So override libc malloc with the Zephyr internal implementation, of a preallocated size, and # monitor it at runtime to ensure it does not overflow. # There are still a few allocations remaining on "true" libc stack, about 2.5kB from signal() etc. # which need to be accommodated by leaving some free RAM in the build. CONFIG_COMMON_LIBC_MALLOC=y CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=32768 CONFIG_SYS_HEAP_RUNTIME_STATS=y # Threads CONFIG_MAIN_STACK_SIZE=4096 CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048 CONFIG_NET_TX_STACK_SIZE=4096 CONFIG_NET_RX_STACK_SIZE=4096 # See Pendant.h for how these priorities fit in. CONFIG_NRF700X_BH_WQ_PRIORITY=7 CONFIG_WPA_SUPP_WQ_PRIORITY=9 CONFIG_MAIN_THREAD_PRIORITY=13 # Debugging CONFIG_DEBUG=y # @todo: This could be enabled if debug is off, should help throughput but at a flash cost. # CONFIG_SPEED_OPTIMIZATIONS=y # @todo: Enabling asserts for bringup. This should probably only get enabled for app files, or off. CONFIG_ASSERT=y CONFIG_STACK_SENTINEL=y CONFIG_DEBUG_COREDUMP=n CONFIG_DEBUG_COREDUMP_BACKEND_LOGGING=n CONFIG_DEBUG_COREDUMP_MEMORY_DUMP_MIN=y CONFIG_THREAD_MONITOR=y # Logging CONFIG_LOG=y CONFIG_LOG_BUFFER_SIZE=2048 CONFIG_POSIX_CLOCK=y # shell_uart (through USB) log defaults to 512 byte buffer and silently drops logs beyond that. # Add a larger buffer size and timeout so we minimize dropped messages. CONFIG_SHELL_BACKEND_SERIAL_LOG_MESSAGE_QUEUE_SIZE=4096 CONFIG_SHELL_BACKEND_SERIAL_LOG_MESSAGE_QUEUE_TIMEOUT=500 # Immediate logging and RTT, useful for interactive debugging. # CONFIG_LOG_MODE_IMMEDIATE=y # CONFIG_LOG_BACKEND_RTT=y # CONFIG_LOG_BACKEND_RTT_MODE_DROP=y # CONFIG_USE_SEGGER_RTT=y # Peripherals CONFIG_GPIO=y CONFIG_SPI=y CONFIG_AUDIO=n CONFIG_AUDIO_DMIC=n # Do NOT enable NRFX_PDM here, because we want to use the locally modified file. CONFIG_NRFX_PDM=n CONFIG_NRFX_I2S0=y CONFIG_PWM=y CONFIG_I2C=y CONFIG_SENSOR=y CONFIG_BQ274XX=y # SHELL AND USB CONFIG_SHELL=y CONFIG_SHELL_STACK_SIZE=4096 CONFIG_SHELL_CMDS_RESIZE=n CONFIG_USB_DEVICE_STACK=y CONFIG_USB_CDC_ACM=y CONFIG_USB_DEVICE_PID=0x0110 CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=y CONFIG_UART_INTERRUPT_DRIVEN=y #CONFIG_USB_DEVICE_STACK=y CONFIG_USB_DEVICE_PRODUCT="Limitless Pendant V1" #CONFIG_USB_DEVICE_VID=4440 # NVM using internal flash. CONFIG_FLASH=y CONFIG_FLASH_PAGE_LAYOUT=y CONFIG_FLASH_MAP=y # Disable flash shell, as it has the same name as pendant flash commmands CONFIG_FLASH_SHELL=n CONFIG_NVS=y CONFIG_SETTINGS=y CONFIG_SETTINGS_NVS=y CONFIG_SETTINGS_SHELL=y CONFIG_WIFI_CREDENTIALS=y CONFIG_WIFI_CREDENTIALS_BACKEND_SETTINGS=y CONFIG_WIFI_CREDENTIALS_MAX_ENTRIES=16 CONFIG_WIFI_CREDENTIALS_SHELL=y # WiFi and Networking CONFIG_WIFI=y CONFIG_WIFI_NRF700X=y CONFIG_WPA_SUPP=y CONFIG_NRF700X_AP_MODE=n CONFIG_NRF700X_P2P_MODE=n CONFIG_NRF700X_UTIL=n # @todo: Check whether this has a significant impact on performance/power. Default is enabled. # CONFIG_NRF700X_QSPI_LOW_POWER=n CONFIG_NETWORKING=y CONFIG_NET_L2_ETHERNET=y CONFIG_NET_SOCKETS=y CONFIG_NET_SOCKETS_POSIX_NAMES=y CONFIG_NET_CONTEXT_SNDTIMEO=y CONFIG_NET_CONTEXT_NET_PKT_POOL=y CONFIG_NET_LOG=y CONFIG_NET_IPV4=y # IPv6 hasn't been tested, and likely various things will need to be updated to support it. # Disable until we need it. CONFIG_NET_IPV6=n CONFIG_NET_UDP=y CONFIG_NET_TCP=y CONFIG_NET_DHCPV4=y CONFIG_NET_CONTEXT_SYNC_RECV=y CONFIG_NET_MAX_CONN=4 CONFIG_NET_TC_TX_COUNT=1 CONFIG_NET_IF_UNICAST_IPV4_ADDR_COUNT=1 CONFIG_NET_MAX_CONTEXTS=6 CONFIG_NET_SOCKETS_POLL_MAX=6 CONFIG_POSIX_MAX_FDS=16 CONFIG_NET_MGMT_EVENT_QUEUE_TIMEOUT=5000 CONFIG_NET_CONFIG_SETTINGS=n CONFIG_NET_CONFIG_AUTO_INIT=n CONFIG_WIFI_MGMT_EXT_CONNECTION_TIMEOUT=30 CONFIG_HTTP_CLIENT=y CONFIG_WEBSOCKET_CLIENT=y # The following sections tune the networking stack for memory or performance, and only one section # should be enabled. # The settings come from the NCS v2.6.0 wifi/throughput sample, with the expected performance # listed in the following page: # https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/samples/wifi/throughput/README.html # Memory optimized #CONFIG_HEAP_MEM_POOL_SIZE=80000 #CONFIG_NET_PKT_TX_COUNT=6 #CONFIG_NET_PKT_RX_COUNT=6 #CONFIG_NET_BUF_TX_COUNT=12 #CONFIG_NET_BUF_RX_COUNT=6 #CONFIG_NRF700X_RX_NUM_BUFS=6 #CONFIG_NET_BUF_DATA_SIZE=500 #CONFIG_NRF700X_MAX_TX_AGGREGATION=1 #CONFIG_NRF700X_MAX_TX_TOKENS=5 # IoT devices CONFIG_HEAP_MEM_POOL_SIZE=100000 CONFIG_NET_PKT_TX_COUNT=6 CONFIG_NET_PKT_RX_COUNT=6 CONFIG_NET_BUF_TX_COUNT=12 CONFIG_NET_BUF_RX_COUNT=6 CONFIG_NRF700X_RX_NUM_BUFS=6 CONFIG_NET_BUF_DATA_SIZE=800 CONFIG_NRF700X_MAX_TX_AGGREGATION=1 CONFIG_NRF700X_MAX_TX_TOKENS=5 # High performance # This is unlikely to compile without RAM overflow. #CONFIG_HEAP_MEM_POOL_SIZE=230000 #CONFIG_NET_PKT_TX_COUNT=30 #CONFIG_NET_PKT_RX_COUNT=30 #CONFIG_NET_BUF_TX_COUNT=60 #CONFIG_NET_BUF_RX_COUNT=30 #CONFIG_NRF700X_RX_NUM_BUFS=48 #CONFIG_NET_BUF_DATA_SIZE=1100 #CONFIG_NRF700X_MAX_TX_AGGREGATION=9 #CONFIG_NRF700X_MAX_TX_TOKENS=12 # Enable MCUBoot CONFIG_BOOTLOADER_MCUBOOT=y # Size optimization CONFIG_SIZE_OPTIMIZATIONS=y
pm_static.yml to set mcuboot partition size to fit:
mcuboot: address: 0x0 end_address: 0x10000 placement: before: - mcuboot_primary region: flash_primary size: 0x10000
Our .dts partition layout, although I think Partition Manager overrides this:
&flash0 { partitions { compatible = "fixed-partitions"; #address-cells = <1>; #size-cells = <1>; boot_partition: partition@0 { label = "mcuboot"; reg = <0x00000000 0x00010000>; }; slot0_partition: partition@10000 { label = "image-0"; }; // slot0_ns_partition: partition@50000 { // label = "image-0-nonsecure"; // }; // slot1_partition: partition@80000 { // label = "image-1"; // }; // slot1_ns_partition: partition@c0000 { // label = "image-1-nonsecure"; // }; // scratch_partition: partition@f0000 { // label = "image-scratch"; // reg = <0x000f0000 0xa000>; // }; storage_partition: partition@fc000 { label = "settings"; reg = <0x000fc000 0x0004000>; }; }; };
Our partitions.yml output:
EMPTY_0: address: 0xfe000 end_address: 0x100000 placement: after: - settings_storage region: flash_primary size: 0x2000 app: address: 0x10200 end_address: 0xfc000 region: flash_primary size: 0xebe00 mcuboot: address: 0x0 end_address: 0x10000 placement: before: - mcuboot_primary region: flash_primary size: 0x10000 mcuboot_pad: address: 0x10000 end_address: 0x10200 placement: align: start: 0x4000 before: - mcuboot_primary_app region: flash_primary size: 0x200 mcuboot_primary: address: 0x10000 end_address: 0xfc000 orig_span: &id001 - mcuboot_pad - app region: flash_primary size: 0xec000 span: *id001 mcuboot_primary_app: address: 0x10200 end_address: 0xfc000 orig_span: &id002 - app region: flash_primary size: 0xebe00 span: *id002 otp: address: 0xff8100 end_address: 0xff83fc region: otp size: 0x2fc rpmsg_nrf53_sram: address: 0x20070000 end_address: 0x20080000 placement: before: - end region: sram_primary size: 0x10000 settings_storage: address: 0xfc000 end_address: 0xfe000 placement: align: start: 0x4000 before: - end region: flash_primary size: 0x2000 sram_primary: address: 0x20000000 end_address: 0x20070000 region: sram_primary size: 0x70000