I'm developing for a custom board that has an nRF52832 and an FM25W04 external flash. My application uses nRF Connect SDK v2.9.2. I have a debug build that doesn't use a bootloader, and a release build that uses MCUboot as the bootloader. I've set up my partitions so that the bootloader, primary image, and scratch slots are on internal flash and the secondary image slot is on external flash.
The issue I am seeing is that flashing my release build onto one of my custom boards will occasionally brick the device. This is not a true brick however, because if I flash a debug build onto the bricked board the app will run fine, but then if I reflash the release build the board will brick again. Flashing an identical release build onto an identical custom board will usually not brick the second board.
I am having a difficult time debugging this problem and was hoping to get some advice on how to move forward. I believe this could be due to an issue with how I've configured my external flash chip via devicetree and/or Kconfig, or possibly an issue with how I've setup my partitions to place the secondary image slot on external flash. I'm providing some relevant snippets from files below, please let me know if any additional context is needed.
pinctrl.dtsi:
&pinctrl {
spi2_default: spi2_default {
group1 {
psels = <NRF_PSEL(SPIM_MISO, 0, 19)>;
bias-pull-up;
};
group2 {
psels = <NRF_PSEL(SPIM_MOSI, 0, 18)>,
<NRF_PSEL(SPIM_SCK, 0, 17)>;
};
};
spi2_sleep: spi2_sleep {
group1 {
psels = <NRF_PSEL(SPIM_MISO, 0, 19)>,
<NRF_PSEL(SPIM_MOSI, 0, 18)>,
<NRF_PSEL(SPIM_SCK, 0, 17)>;
low-power-enable;
};
};
};
.dts:
/ {
chosen {
zephyr,flash = &flash0;
zephyr,code-partition = &slot0_partition;
nordic,pm-ext-flash = &fm25w04;
};
};
&flash0 {
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
boot_partition: partition@0 {
label = "mcuboot";
reg = <0x00000000 0xC000>;
};
slot0_partition: partition@C000 {
label = "image-0";
reg = <0x0000C000 0x58000>;
};
scratch_partition: partition@64000 {
label = "image-scratch";
reg = <0x00064000 0x1000>;
};
};
};
&spi2 {
compatible = "nordic,nrf-spi";
status="okay";
pinctrl-0 = <&spi2_default>;
pinctrl-1 = <&spi2_sleep>;
pinctrl-names = "default", "sleep";
cs-gpios = <&gpio0 20 GPIO_ACTIVE_LOW>;
fm25w04: fm25w04@0 {
compatible = "jedec,spi-nor";
reg = <0>;
spi-max-frequency = <8000000>;
jedec-id = [a1 28 13];
size = <4194304>;
has-dpd;
t-enter-dpd = <3000>;
t-exit-dpd = <3000>;
};
};
&fm25w04 {
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
slot1_partition: partition@0 {
label = "image-1";
reg = <0x00000000 0x58000>;
};
config_partition: partition@58000 {
label = "config";
reg = <0x00058000 0x6000>;
};
record_partition: partition@5E000 {
label = "record";
reg = <0x0005E000 0x10000>;
};
nvs_storage: partition@6E000 {
label = "nvs_storage";
reg = <0x0006E000 0x6000>;
};
};
};
pm_static.yml:
mcuboot: address: 0x00000000 size: 0xC000 mcuboot_primary: address: 0x0000C000 size: 0x58000 span: [mcuboot_pad, mcuboot_primary_app] mcuboot_pad: address: 0x0000C000 size: 0x200 mcuboot_primary_app: address: 0x0000C200 size: 0x57E00 span: [app] mcuboot_scratch: address: 0x00064000 size: 0x1000 flash_guard: address: 0x00065000 size: 0x1B000 external_flash: device: fm25w04 region: external_flash address: 0x00000 size: 0x80000 span: [mcuboot_secondary, config, record, nvs_storage] mcuboot_secondary: region: external_flash address: 0x00000000 size: 0x58000 config: region: external_flash address: 0x00058000 size: 0x6000 record: region: external_flash address: 0x0005E000 size: 0x10000 nvs_storage: region: external_flash address: 0x0006E000 size: 0x6000
child_image/mcuboot.overlay:
&spi2 {
compatible = "nordic,nrf-spi";
status="okay";
pinctrl-0 = <&spi2_default>;
pinctrl-1 = <&spi2_sleep>;
pinctrl-names = "default", "sleep";
cs-gpios = <&gpio0 20 GPIO_ACTIVE_LOW>;
fm25w04: fm25w04@0 {
compatible = "jedec,spi-nor";
reg = <0>;
spi-max-frequency = <8000000>;
jedec-id = [a1 28 13];
size = <4194304>;
has-dpd;
t-enter-dpd = <3000>;
t-exit-dpd = <3000>;
};
};
/ {
chosen {
nordic,pm-ext-flash = &fm25w04;
};
};
child_image/mcuboot/prj.conf:
CONFIG_GPIO=y CONFIG_SPI=y CONFIG_SPI_NOR=y CONFIG_SPI_NOR_SFDP_RUNTIME=y CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096 CONFIG_NORDIC_QSPI_NOR=n CONFIG_MULTITHREADING=y CONFIG_FLASH=y CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=y CONFIG_PM_OVERRIDE_EXTERNAL_DRIVER_CHECK=y CONFIG_BOOT_MAX_IMG_SECTORS=128 CONFIG_BOOT_SWAP_USING_SCRATCH=y CONFIG_WATCHDOG=y CONFIG_BOOT_WATCHDOG_FEED=y