Internal Flash Page Erase is not working for nrf 52840 using nrf connect sdk

We have made 2 partition of Internal flash. One is for running Application and Other for storing some configuration. I am trying to erase the page of 2nd partition, and it is not working properly.

2nd partition Id is storage.

flash_area_open(FLASH_AREA_ID(storage), &fa);
flash_area_read(fa,3840,array,256);
flash_area_erase(fa, 3840, 256); //erasing only one page of the storage sector
flash_area_write(fa,3840,array1,256);
Is the above steps are correct?. As I am not able to erase the page properly and working only first time.
  • Hello,

    Could you explain the context a bit more? Which SDK version and Nordic chip are you using?

    You mentioned having two partitions, with one reserved for configuration storage. You should ensure that the partition boundaries are correctly defined in your pm_static.

    Are there any log messages indicating the issue or error? Have you considered using the NVS file system from Zephyr?

    Kind Regards,

    Abhijith

  • SDK Version : 2.6.0

    Chip : NRF52840 DK

    Created Overlay File as Below:

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

            slot0_partition: partition@ba000 {
                label = "image-0";
                reg = <0x000ba000 0x00040000>;
            };

            storage_partition: partition@fa000 {
                label = "storage";
                reg = <0x000fa000 0x00004000>;
            };
           
        };
    };
    Using memory address 0 to 0x000ba000 for some other application. BLE stack using slot0_partition. 
    I am using storage_partiotion to store configuration items and facing issue to erase page.
     
  • Hello,

    Since it is working the first time, I suspect it might be due to incorrect handling of the erase size or misalignment. Please ensure that each erase operation targets a full page (4096 bytes) aligned to the page boundary. You should perform the erase operation on a page-by-page basis. For the nRF52840, it is divided into 256 pages, each 4 kB in size. See product specification page No:22

    Kind Regards,
    Abhijith

  • It means need to erase 4096 bytes completely and can not erase only one page 256bytes at a single execution?

  • Hello,

    In your erase command, flash_area_erase(fa, 3840, 256); only 3.75 KB (3840 bytes) of the storage sector is being erased, which is not a full page. Instead, try erasing a complete page of 4096 bytes (4 KB).

    Kind Regards,
    Abhijith

Related