nRF52 Rebooting During flash_erase Operation

Hello,

I’m encountering an issue with my nRF52 device where it reboots during the flash_erase operation. Below is the relevant part of my code and the overlay configuration:

#define FLASH_PARTITION_ID FIXED_PARTITION_ID(storage_partition)

void init_flash(void)
{
    const struct flash_area *flash_area;
    int rc;

    rc = flash_area_open(FLASH_PARTITION_ID, &flash_area);
    if (rc != 0) {
        LOG_ERR("Failed to open flash area (err %d)", rc);
        return;
    }

    flash_dev = flash_area_get_device(flash_area);
    if (!device_is_ready(flash_dev)) {
        LOG_ERR("Flash device not ready");
        return;
    }

    uint8_t write_data[FLASH_TEST_SIZE] = {0xAA, 0xBB, 0xCC, 0xDD}; // Example data
    uint8_t read_data[FLASH_TEST_SIZE];

    LOG_INF("off_add = %lx, size= %d\n", flash_area->fa_off, flash_area->fa_size);

    // Erase the flash area before writing
    __disable_irq();
    rc = flash_erase(flash_dev, flash_area->fa_off, flash_area->fa_size);
    __enable_irq();
    if (rc != 0) {
        LOG_ERR("Flash erase failed (err %d)\n", rc);
        return;
    }

    // Write data to flash
    rc = write_flash(flash_dev, flash_area->fa_off, write_data, sizeof(write_data));
    if (rc != 0) {
        LOG_ERR("Flash write failed (err %d)\n", rc);
        return;
    }

    // Read data from flash
    rc = read_flash(flash_dev, flash_area->fa_off, read_data, sizeof(read_data));
    if (rc != 0) {
        LOG_ERR("Flash read failed (err %d)\n", rc);
        return;
    }

    // Verify the read data
    if (memcmp(write_data, read_data, sizeof(write_data)) == 0) {
        LOG_INF("Flash read/write verification succeeded\n");
    } else {
        LOG_ERR("Flash read/write verification failed\n");
    }
}

overlays config:

&flash0 {
    status = "okay";
    partitions {
        compatible = "fixed-partitions";
        #address-cells = <1>;
        #size-cells = <1>;

        storage1: partition@7a000 {
            label = "storage1";
            reg = <0x7a000 0x06000>; /* 44 KB partition */
        };
    };
};

project config:

CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_NVS=y

The device resets when it reaches the flash_erase function. I’ve tried disabling interrupts around the flash erase operation, but the issue persists. Here are some additional details:

  • The power supply is stable and sufficient.
  • The watchdog timer is disabled during the flash operation.
  • The flash driver configuration seems correct.

Could there be any specific configurations or settings that I might be missing?

Any help or suggestions would be greatly appreciated!

Thanks in advance.

Related