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

fstorage in chosen area

Hello, I'd like to store a large amount of data in flash and in a chosen area. As a start, I've chosen the area starting from 0x77000 and ending at 0x78000 Iv'e written this

const tGlobalData romData  __attribute__((at(0x77000))) __attribute__((used));
static void fs_evt_handler(fs_evt_t const * const evt, fs_ret_t result);
FS_REGISTER_CFG(fs_config_t my_fs_config) =
    {
        .callback  = fs_evt_handler,    // Function for event callbacks.
        .num_pages = 4,                 // Number of physical flash pages required.
        .priority  = 0xFE,               // Priority for flash usage.
        .p_start_addr = (uint32_t*)0x77000,
        .p_end_addr = (uint32_t*)0x78000
    };
    
static void fs_evt_handler(fs_evt_t const * const evt, fs_ret_t result)
{
    switch(evt->id)
    {
        case FS_EVT_STORE:
            if(result == FS_SUCCESS){
            }
            break;

        case FS_EVT_ERASE:
            // Handle erase event
            break;

        default:
            //Do nothing
            break;
    }
}

void initROM()
{
  //fs_ret_t ret = fs_init();
}

void saveROM()
{
  volatile fs_ret_t fs_ret;
  fs_ret= fs_erase(&my_fs_config,(uint32_t*)&romData,4,NULL);
  fs_ret= fs_store(&my_fs_config,(uint32_t*)&romData,(uint32_t*)&globalData,(sizeof(tGlobalData)+1)/4,NULL);
}

void readROM()
{
  memcpy(&globalData,&romData,sizeof(tGlobalData));
}

the erase operation fails. After debug, the start address at config is 0x7D000, so that &romData is out of range. The arear is welle allocated by the linker, so I should miss something.

Parents Reply Children
  • Hello, I've comment fs_init during tries, I just forgot to uncomment before posting the code. In the example you gave, you don't control the destination address of the stored data. It's somewhere in the ROM area reserved for peer manager data and some other. I need more space, and as I have a bootloader too, I need to precisely control the ROM address of the stored data.

  • Yes, I mentioned, I modified the code and can set the start address. It worked. Code I used:

    	FS_REGISTER_CFG(fs_config_t fs_config) =
    	{
    		  .callback  = fs_evt_handler, // Function for event callbacks.
    			.num_pages = NUM_PAGES,      // Number of physical flash pages required.
    			.priority  = 0xFE,            // Priority for flash usage.
            .p_start_addr = (uint32_t*)0x57000,
            .p_end_addr = (uint32_t*)0x58000
    	};
    
Related