This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Use a fixed starting address for flash fds

Im am running a nrf528322 board with the s332 softdevice using sdk14.2.

I have implemented flash storage in my program according to the nordic flash_fds example.
This works fine.
We need to externally program some parameters in flash using nrfjprog. When I debug the flash code I see that sometimes the start address where the data is stored changes.

How can I best adjust my code to set a fixed flash start address? And how do I best determine where to start writing?

Parents
  • Hi,

     

    FDS is designed to use the upper part of the flash (and go downwards), and if there's a bootloader present (set in UICR), it will start below that address instead.

    This is calculated in fds.c::flash_end_addr():

    static uint32_t flash_end_addr(void)
    {
        uint32_t const bootloader_addr = NRF_UICR->NRFFW[0];
        uint32_t const page_sz         = NRF_FICR->CODEPAGESIZE;
    #ifndef NRF52810_XXAA
        uint32_t const code_sz         = NRF_FICR->CODESIZE;
    #else
        // Number of flash pages, necessary to emulate the NRF52810 on NRF52832.
        uint32_t const code_sz         = 48;
    #endif
    
        return (bootloader_addr != 0xFFFFFFFF) ? bootloader_addr : (code_sz * page_sz);
    }

     

    Note that if you're going to initialize fds manually, you'll need to match the amount of pages it uses as well. If the configuration states 3 flash pages, you need to add the proper tags on the upper 3 pages (2 x data, 1 x swap).

     

    Best regards,

    Håkon

Reply
  • Hi,

     

    FDS is designed to use the upper part of the flash (and go downwards), and if there's a bootloader present (set in UICR), it will start below that address instead.

    This is calculated in fds.c::flash_end_addr():

    static uint32_t flash_end_addr(void)
    {
        uint32_t const bootloader_addr = NRF_UICR->NRFFW[0];
        uint32_t const page_sz         = NRF_FICR->CODEPAGESIZE;
    #ifndef NRF52810_XXAA
        uint32_t const code_sz         = NRF_FICR->CODESIZE;
    #else
        // Number of flash pages, necessary to emulate the NRF52810 on NRF52832.
        uint32_t const code_sz         = 48;
    #endif
    
        return (bootloader_addr != 0xFFFFFFFF) ? bootloader_addr : (code_sz * page_sz);
    }

     

    Note that if you're going to initialize fds manually, you'll need to match the amount of pages it uses as well. If the configuration states 3 flash pages, you need to add the proper tags on the upper 3 pages (2 x data, 1 x swap).

     

    Best regards,

    Håkon

Children
No Data
Related