Hello community,
I am trying to develop a custom bluetooth HCI_USB code for the BL5340PA BLE controller board. The Liard Connectivity's(now Ezurio) BL5340PA : https://www.ezurio.com/wireless-modules/bluetooth-modules/bl5340pa-series-long-range-bluetooth-module
These are the following that I want to do in my project:
1. Generate separate binaries for the application core and the network core
2. Enable serial recovery feature so that upon each reset of the device, it goes into recovery mode and a new firmware can be uploaded using mcumgr commands.
To implement the above I have taken reference of the Serial Recovery examples by Hellesvik which is shared on his Github: https://github.com/hellesvik-nordic/samples_for_nrf_connect_sdk/tree/main/bootloader_samples/serial_recovery/mcuboot_serial_recovery_cdc_acm
Based on the examples above I have modified the following files of my project :
Contents of the prj.conf file :
# General Configruation CONFIG_PINCTRL=y ########################################################################## ## HCI_USB Project Configuration -------------------------------------- # --- Sets up the USB interface for HCI control of the BT Carrier Board # -- From default HCI_USB project with few removals due to conflicts CONFIG_STDOUT_CONSOLE=y CONFIG_GPIO=y CONFIG_SERIAL=y CONFIG_UART_INTERRUPT_DRIVEN=y CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n CONFIG_BT=y CONFIG_BT_HCI_RAW=y CONFIG_USB_DEVICE_STACK=y CONFIG_USB_DEVICE_PID=0x000B CONFIG_USB_DEVICE_BLUETOOTH=y CONFIG_USB_DEVICE_BLUETOOTH_VS_H4=n # Workaround: Unable to allocate command buffer when using K_NO_WAIT since # Host number of completed commands does not follow normal flow control. CONFIG_BT_BUF_CMD_TX_COUNT=10 #========================================================================= ########################################################################## ## Additional HCI Features # --- Allows for custom and extra commands to be added if nececssary CONFIG_BT_HCI_VS=y CONFIG_BT_HCI_VS_EVT=y #========================================================================= ########################################################################## ## Data Length and BT Buffers/Counts - CONFIGS Should be mirrored in HCI_RPMSG.conf # This can be edited to 16 for more buffers, if overflows are ocurring CONFIG_BT_BUF_EVT_RX_COUNT=10 CONFIG_BT_HCI_VS=y CONFIG_BT_HCI_VS_EVT=y #Allow data length updates on this device CONFIG_BT_DATA_LEN_UPDATE=y # Size buffers for best functionality with HCI and nrf5340, to allow large data transfers CONFIG_BT_BUF_EVT_RX_SIZE=255 CONFIG_BT_BUF_ACL_RX_SIZE=502 CONFIG_BT_BUF_ACL_TX_SIZE=251 CONFIG_BT_BUF_CMD_TX_SIZE=255 # This can be descresed if necessary, lowest value not tested CONFIG_BT_RX_STACK_SIZE=2048 #========================================================================= ########################################################################## ## Disable unused features # Disabled as it causes unrelated error on boot CONFIG_I2C=n #========================================================================= ##Enable the MCUBoot Bootloader CONFIG_BOOTLOADER_MCUBOOT=y #enable the netcore binary file generation CONFIG_NRF53_UPGRADE_NETWORK_CORE=y CONFIG_ADD_MCUBOOT_MEDIATE_SIM_FLASH_DTS=y #=========================================================================
Since I want to perform serial recovery over cdc_acm I have also added a pm_static.yml file that increases the partition for MCUBOOT to fit the cdc_acm drivers.
The contents of the partition manager yml file are as follows :
mcuboot: address: 0x0 end_address: 0x10000 placement: before: - mcuboot_primary region: flash_primary size: 0x10000
I have also created a child_image folder where I have created a mcuboot.conf file to configure the binary generation for the network core.
The contents of the mcuboot.conf are as follows :
CONFIG_MAIN_STACK_SIZE=10240 # Flash CONFIG_FLASH=y # MCUBoot serial CONFIG_MCUBOOT_SERIAL=y CONFIG_MCUBOOT_SERIAL_DIRECT_IMAGE_UPLOAD=y # Decrease memory footprint CONFIG_CBPRINTF_NANO=y CONFIG_TIMESLICING=n CONFIG_BOOT_BANNER=n CONFIG_CONSOLE=n CONFIG_CONSOLE_HANDLER=n CONFIG_UART_CONSOLE=n CONFIG_RTT_CONSOLE=n CONFIG_USE_SEGGER_RTT=n CONFIG_LOG=n CONFIG_RESET_ON_FATAL_ERROR=n # The following configurations are required to support serial recovery of the # network image CONFIG_PCD_APP=y CONFIG_FLASH_SIMULATOR=y CONFIG_FLASH_SIMULATOR_DOUBLE_WRITES=y CONFIG_FLASH_SIMULATOR_STATS=n CONFIG_BOOT_IMAGE_ACCESS_HOOKS=y CONFIG_NRF53_RECOVERY_NETWORK_CORE=y ################################################## #Configurations to enable Serial Recovery #CONFIG_SIZE_OPTIMIZATIONS=y #CONFIG_SINGLE_APPLICATION_SLOT=y # Enable MCUboot Serial Recovery CONFIG_MCUBOOT_SERIAL=y CONFIG_UART_CONSOLE=n # Point Serial Recovery to CDC_ACM CONFIG_BOOT_SERIAL_CDC_ACM=y # Enable wait for DFU functionality CONFIG_BOOT_SERIAL_WAIT_FOR_DFU=y CONFIG_BOOT_SERIAL_WAIT_FOR_DFU_TIMEOUT=2500
There is also a hci_rpmsg file that is being used to disable the SPI communication with the network core and set the gain to a fixed value because of stability issues while the HCI_USB code works for scanning devices.
Contents of hci_rpmsg file:
################################################################################# # # HCI_RPMSP Child Image Configuration # ################################################################################# #-------------------------------------------------------------------------------- # Enable Pin Control #-------------------------------------------------------------------------------- CONFIG_PINCTRL=y #-------------------------------------------------------------------------------- # Enable SPI #-------------------------------------------------------------------------------- # Disabled for HCI timing conflict CONFIG_SPI=n #-------------------------------------------------------------------------------- # Enable MPSL and FEM #-------------------------------------------------------------------------------- CONFIG_MPSL=y CONFIG_MPSL_FEM=y CONFIG_MPSL_FEM_NRF21540_GPIO=y CONFIG_MPSL_FEM_NRF21540_TX_GAIN_DB=20 CONFIG_BT_CTLR_TX_PWR_ANTENNA=20 # Disable SPI as this causes stopping during operation # Non-recoverable, meaning this device is stuck at the FEM default which should* be the correct gain for +18dBm CONFIG_MPSL_FEM_NRF21540_GPIO_SPI=n #-------------------------------------------------------------------------------- # BT and HCI Configurations/Features #-------------------------------------------------------------------------------- # Allow full data length to enable best speed and communication with S7100 CONFIG_BT_CTLR_DATA_LENGTH_MAX=251 # Limit number of devices connected as with DLE Max it overflows buffer on compile time # This carrier board should not be connected to more than 1 device at a time, this can # be comfortably limited to 2 instead of 4 CONFIG_BT_MAX_CONN=4 # We are operating only on 1M PHY. Limit this to ensure best operation CONFIG_BT_PHY_UPDATE=n # Dynamic Power control is handled differently with the FEM, and SPI is not functional CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL=n # Ensure no nrf5340 default is kept due to the FEM CONFIG_BT_CTLR_TX_PWR_PLUS_3=n #### THe next confiurations, in this section should be mirrored in prj.conf ------------------------ # Default value with the nrf5340 for a workaround explained in prj.conf CONFIG_BT_BUF_CMD_TX_COUNT=10 # This can be edited to 16 for more buffers, if overflows are ocurring CONFIG_BT_BUF_EVT_RX_COUNT=10 # Size buffers for best functionality with HCI and nrf5340, to allow large data transfers CONFIG_BT_BUF_EVT_RX_SIZE=255 CONFIG_BT_BUF_ACL_RX_SIZE=502 CONFIG_BT_BUF_ACL_TX_SIZE=251 CONFIG_BT_BUF_CMD_TX_SIZE=255 # This can be descresed if necessary, lowest value not tested CONFIG_BT_RX_STACK_SIZE=2048 #-------------------------------------------------------------------------------- # Disabel other features #-------------------------------------------------------------------------------- # Disabled as it causes unrelated error on boot CONFIG_I2C=n
While the code compiles successfully when I select the build for nrf5340_dvk_cpuapp but I get an error when I select the board as bl5340pa_dvk_cpuapp. I am utilizing the Zephyr/nrf SDK version 2.4.1 (received from Laird for updated TX power setting rules: GitHub - LairdCP/bl5340pa_manifest: Manifest for the Laird Connectivity fork of the nRF Connect SDK with support for the BL5340PA).
I get the following error while building the code:
FAILED: zephyr/zephyr_pre0.elf zephyr/zephyr_pre0.map : && ccache /home/mutsl04176/ncs/toolchains/7795df4459/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc -gdwarf-4 zephyr/CMakeFiles/zephyr_pre0.dir/misc/empty_file.c.obj -o zephyr/zephyr_pre0.elf -fuse-ld=bfd -T zephyr/linker_zephyr_pre0.cmd -Wl,-Map=/home/mutsl04176/ncs/PA_Firmware/zephyr/samples/bluetooth/ua-ugw-ble-carrier-board/build_1/mcuboot/zephyr/zephyr_pre0.map -Wl,--whole-archive app/libapp.a zephyr/libzephyr.a zephyr/arch/common/libarch__common.a zephyr/arch/arch/arm/core/aarch32/libarch__arm__core__aarch32.a zephyr/arch/arch/arm/core/aarch32/cortex_m/libarch__arm__core__aarch32__cortex_m.a zephyr/arch/arch/arm/core/aarch32/cortex_m/cmse/libarch__arm__core__aarch32__cortex_m__cmse.a zephyr/arch/arch/arm/core/aarch32/mpu/libarch__arm__core__aarch32__mpu.a zephyr/lib/libc/minimal/liblib__libc__minimal.a zephyr/soc/arm/common/cortex_m/libsoc__arm__common__cortex_m.a zephyr/drivers/usb/device/libdrivers__usb__device.a zephyr/drivers/clock_control/libdrivers__clock_control.a zephyr/drivers/flash/libdrivers__flash.a zephyr/drivers/gpio/libdrivers__gpio.a zephyr/drivers/hwinfo/libdrivers__hwinfo.a zephyr/drivers/i2c/libdrivers__i2c.a zephyr/drivers/pinctrl/libdrivers__pinctrl.a zephyr/drivers/serial/libdrivers__serial.a zephyr/drivers/timer/libdrivers__timer.a modules/nrf/lib/fprotect/lib..__nrf__lib__fprotect.a modules/nrf/subsys/pcd/lib..__nrf__subsys__pcd.a modules/nrf/modules/mcuboot/hooks/lib..__nrf__modules__mcuboot__hooks.a modules/nrf/drivers/hw_cc310/lib..__nrf__drivers__hw_cc310.a modules/mcuboot/boot/bootutil/zephyr/libmcuboot_util.a modules/mbedtls/libmodules__mbedtls.a modules/hal_nordic/nrfx/libmodules__hal_nordic__nrfx.a modules/zcbor/libmodules__zcbor.a -Wl,--no-whole-archive zephyr/kernel/libkernel.a zephyr/CMakeFiles/offsets.dir/./arch/arm/core/offsets/offsets.c.obj -L"/home/mutsl04176/ncs/toolchains/7795df4459/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/thumb/v8-m.main/nofp" -L/home/mutsl04176/ncs/PA_Firmware/zephyr/samples/bluetooth/ua-ugw-ble-carrier-board/build_1/mcuboot/zephyr -lgcc zephyr/arch/common/libisr_tables.a -mcpu=cortex-m33 -mthumb -mabi=aapcs -Wl,--gc-sections -Wl,--build-id=none -Wl,--sort-common=descending -Wl,--sort-section=alignment -Wl,-u,_OffsetAbsSyms -Wl,-u,_ConfigAbsSyms -nostdlib -static -Wl,-X -Wl,-N -Wl,--orphan-handling=warn -Wl,-no-pie /home/mutsl04176/ncs/PA_Firmware/nrfxlib/crypto/nrf_cc312_platform/lib/cortex-m33/soft-float/no-interrupts/libnrf_cc312_platform_0.9.17.a && cd /home/mutsl04176/ncs/PA_Firmware/zephyr/samples/bluetooth/ua-ugw-ble-carrier-board/build_1/mcuboot/zephyr && /home/mutsl04176/ncs/toolchains/7795df4459/usr/local/bin/cmake -E echo /home/mutsl04176/ncs/toolchains/7795df4459/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: zephyr/zephyr_pre0.elf section `device_handles' will not fit in region `FLASH' /home/mutsl04176/ncs/toolchains/7795df4459/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: region `FLASH' overflowed by 4200 bytes collect2: error: ld returned 1 exit status ninja: build stopped: subcommand failed. [19/260] Generating include/generated/version.h -- Zephyr version: 3.3.99 (/home/mutsl04176/ncs/PA_Firmware/zephyr), build: 3041adb35158 [229/260] Building C object zephyr/drivers/gpio/CMakeFiles/drivers__gpio.dir/gpio_pca953x.c.obj FAILED: zephyr/drivers/gpio/CMakeFiles/drivers__gpio.dir/gpio_pca953x.c.obj ccache /home/mutsl04176/ncs/toolchains/7795df4459/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc -DKERNEL -DNRF5340_XXAA_APPLICATION -DNRF_SKIP_FICR_NS_COPY_TO_RAM -DUSE_PARTITION_MANAGER=1 -D__PROGRAM_START -D__ZEPHYR_SUPERVISOR__ -D__ZEPHYR__=1 -I../../../../include -Izephyr/include/generated -I../../../../soc/arm/nordic_nrf/nrf53 -I../../../../soc/arm/nordic_nrf/common/. -I../../../../subsys/usb/device -I../../../../subsys/bluetooth -I/home/mutsl04176/ncs/PA_Firmware/nrf/include -I/home/mutsl04176/ncs/PA_Firmware/nrf/tests/include -I/home/mutsl04176/ncs/PA_Firmware/modules/hal/cmsis/CMSIS/Core/Include -I/home/mutsl04176/ncs/PA_Firmware/modules/hal/nordic/nrfx -I/home/mutsl04176/ncs/PA_Firmware/modules/hal/nordic/nrfx/drivers/include -I/home/mutsl04176/ncs/PA_Firmware/modules/hal/nordic/nrfx/mdk -I../../../../modules/hal_nordic/nrfx/. -Imodules/libmetal/libmetal/lib/include -I/home/mutsl04176/ncs/PA_Firmware/modules/lib/open-amp/open-amp/lib/include -I/home/mutsl04176/ncs/PA_Firmware/nrfxlib/softdevice_controller/include -isystem ../../../../lib/libc/minimal/include -isystem /home/mutsl04176/ncs/toolchains/7795df4459/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/include -isystem /home/mutsl04176/ncs/toolchains/7795df4459/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/include-fixed -isystem /home/mutsl04176/ncs/PA_Firmware/nrfxlib/crypto/nrf_cc312_platform/include -fno-strict-aliasing -Os -imacros /home/mutsl04176/ncs/PA_Firmware/zephyr/samples/bluetooth/ua-ugw-ble-carrier-board/build_1/zephyr/include/generated/autoconf.h -ffreestanding -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m33 -mthumb -mabi=aapcs --sysroot=/home/mutsl04176/ncs/toolchains/7795df4459/opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi -imacros /home/mutsl04176/ncs/PA_Firmware/zephyr/include/zephyr/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-pic -fno-pie -fno-asynchronous-unwind-tables -fno-reorder-functions --param=min-pagesize=0 -fno-defer-pop -fmacro-prefix-map=/home/mutsl04176/ncs/PA_Firmware/zephyr/samples/bluetooth/ua-ugw-ble-carrier-board=CMAKE_SOURCE_DIR -fmacro-prefix-map=/home/mutsl04176/ncs/PA_Firmware/zephyr=ZEPHYR_BASE -fmacro-prefix-map=/home/mutsl04176/ncs/PA_Firmware=WEST_TOPDIR -ffunction-sections -fdata-sections -std=c99 -nostdinc -MD -MT zephyr/drivers/gpio/CMakeFiles/drivers__gpio.dir/gpio_pca953x.c.obj -MF zephyr/drivers/gpio/CMakeFiles/drivers__gpio.dir/gpio_pca953x.c.obj.d -o zephyr/drivers/gpio/CMakeFiles/drivers__gpio.dir/gpio_pca953x.c.obj -c /home/mutsl04176/ncs/PA_Firmware/zephyr/drivers/gpio/gpio_pca953x.c In file included from ../../../../include/zephyr/sys/util_macro.h:34, from ../../../../include/zephyr/sys/atomic.h:16, from ../../../../include/zephyr/kernel_includes.h:21, from ../../../../include/zephyr/kernel.h:17, from /home/mutsl04176/ncs/PA_Firmware/zephyr/drivers/gpio/gpio_pca953x.c:13: ../../../../include/zephyr/device.h:84:41: error: '__device_dts_ord_13' undeclared here (not in a function); did you mean '__device_dts_ord_33'? 84 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id) | ^~~~~~~~~ ../../../../include/zephyr/sys/util_internal.h:72:26: note: in definition of macro '__DEBRACKET' 72 | #define __DEBRACKET(...) __VA_ARGS__ | ^~~~~~~~~~~ ../../../../include/zephyr/sys/util_internal.h:64:9: note: in expansion of macro '__GET_ARG2_DEBRACKET' 64 | __GET_ARG2_DEBRACKET(one_or_two_args _if_code, _else_code) | ^~~~~~~~~~~~~~~~~~~~ ../../../../include/zephyr/sys/util_internal.h:59:9: note: in expansion of macro '__COND_CODE' 59 | __COND_CODE(_XXXX##_flag, _if_1_code, _else_code) | ^~~~~~~~~~~ ../../../../include/zephyr/sys/util_macro.h:180:9: note: in expansion of macro 'Z_COND_CODE_1' 180 | Z_COND_CODE_1(_flag, _if_1_code, _else_code) | ^~~~~~~~~~~~~ ../../../../include/zephyr/devicetree.h:3859:9: note: in expansion of macro 'COND_CODE_1' 3859 | COND_CODE_1(DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT), \ | ^~~~~~~~~~~ ../../../../include/zephyr/sys/util_internal.h:69:53: note: in expansion of macro '__DEBRACKET' 69 | #define __GET_ARG2_DEBRACKET(ignore_this, val, ...) __DEBRACKET val | ^~~~~~~~~~~ ../../../../include/zephyr/sys/util_internal.h:64:9: note: in expansion of macro '__GET_ARG2_DEBRACKET' 64 | __GET_ARG2_DEBRACKET(one_or_two_args _if_code, _else_code) | ^~~~~~~~~~~~~~~~~~~~ ../../../../include/zephyr/sys/util_internal.h:59:9: note: in expansion of macro '__COND_CODE' 59 | __COND_CODE(_XXXX##_flag, _if_1_code, _else_code) | ^~~~~~~~~~~ ../../../../include/zephyr/sys/util_macro.h:180:9: note: in expansion of macro 'Z_COND_CODE_1' 180 | Z_COND_CODE_1(_flag, _if_1_code, _else_code) | ^~~~~~~~~~~~~ ../../../../include/zephyr/drivers/i2c.h:119:17: note: in expansion of macro 'COND_CODE_1' 119 | COND_CODE_1(DT_ON_BUS(node_id, i3c), \ | ^~~~~~~~~~~ ../../../../include/zephyr/device.h:210:37: note: in expansion of macro 'DEVICE_NAME_GET' 210 | #define DEVICE_DT_NAME_GET(node_id) DEVICE_NAME_GET(Z_DEVICE_DT_DEV_ID(node_id)) | ^~~~~~~~~~~~~~~ ../../../../include/zephyr/device.h:227:34: note: in expansion of macro 'DEVICE_DT_NAME_GET' 227 | #define DEVICE_DT_GET(node_id) (&DEVICE_DT_NAME_GET(node_id)) | ^~~~~~~~~~~~~~~~~~ ../../../../include/zephyr/drivers/i2c.h:104:16: note: in expansion of macro 'DEVICE_DT_GET' 104 | .bus = DEVICE_DT_GET(DT_BUS(node_id)), \ | ^~~~~~~~~~~~~ ../../../../include/zephyr/drivers/i2c.h:121:30: note: in expansion of macro 'I2C_DT_SPEC_GET_ON_I2C' 121 | (I2C_DT_SPEC_GET_ON_I2C(node_id))) \ | ^~~~~~~~~~~~~~~~~~~~~~ ../../../../include/zephyr/drivers/i2c.h:133:9: note: in expansion of macro 'I2C_DT_SPEC_GET' 133 | I2C_DT_SPEC_GET(DT_DRV_INST(inst)) | ^~~~~~~~~~~~~~~ /home/mutsl04176/ncs/PA_Firmware/zephyr/drivers/gpio/gpio_pca953x.c:465:24: note: in expansion of macro 'I2C_DT_SPEC_INST_GET' 465 | .i2c = I2C_DT_SPEC_INST_GET(n), \ | ^~~~~~~~~~~~~~~~~~~~ zephyr/include/generated/devicetree_generated.h:20111:45: note: in expansion of macro 'GPIO_PCA953X_INIT' 20111 | #define DT_FOREACH_OKAY_INST_ti_tca9538(fn) fn(0) | ^~ ../../../../include/zephyr/sys/util_internal.h:105:36: note: in expansion of macro 'DT_FOREACH_OKAY_INST_ti_tca9538' 105 | #define UTIL_PRIMITIVE_CAT(a, ...) a##__VA_ARGS__ | ^ /home/mutsl04176/ncs/PA_Firmware/zephyr/drivers/gpio/gpio_pca953x.c:488:1: note: in expansion of macro 'DT_INST_FOREACH_STATUS_OKAY' 488 | DT_INST_FOREACH_STATUS_OKAY(GPIO_PCA953X_INIT) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ FAILED: modules/mcuboot/mcuboot_subimage-prefix/src/mcuboot_subimage-stamp/mcuboot_subimage-build mcuboot/zephyr/zephyr.hex mcuboot/zephyr/zephyr.elf cd /home/mutsl04176/ncs/PA_Firmware/zephyr/samples/bluetooth/ua-ugw-ble-carrier-board/build_1/mcuboot && /home/mutsl04176/ncs/toolchains/7795df4459/usr/local/bin/cmake --build . -- ninja: build stopped: subcommand failed.
I can kind of figure it out that it has something to do with the flash partitions not being of correct size in order to accomodate certain sections of the code but I do not have an idea on how to resolve it.
Any help to solve this issue would be of great help!