Write data in custom flash section
Hi,
I'm working on stm32l496 and I try to write data to a custom flash section, in the .ld file I put new sector :
/* Memories definition */
MEMORY
{
[...]
FLASH (rx) : ORIGIN = 0x08003800, LENGTH = 0x07B800
config(rx) : ORIGIN = 0x0807F000, LENGTH = 2K
common(rxw) : ORIGIN = 0x0807F800, LENGTH = 2K
}
[...]
PROVIDE(_config_page_start = ORIGIN(config));
PROVIDE(_common_page_start = ORIGIN(common));
I set it like this to flash config or common page without touch my program section.
I have no difficulty to read data from this pages. But when I use `HAL_FLASH_Program()` function to write data in 'common' section, I have an error.
After reseach the error may be due to ASSERT checking if the address is whitin the flash range.
This is my code :
error_e mcu_flash_program_data(uint32_t start_addr, const void *data, size_t size) {
HAL_StatusTypeDef hal_ret = HAL_OK;
const uint64_t *ptr = data;
for (size_t i = 0; i < size; i += sizeof(uint64_t)) {
hal_ret = HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, start_addr + i, *ptr);
if (hal_ret != HAL_OK) {
return (ERR_HAL);
}
}
return (ERR_OK);
}
error_e mcu_flash_write_page(my_own_struct_s data) {
void* ptr = &data;// the data to store
uin32_t addr_val = 0x0807F800;
size_t size = sizeof(data);
if (HAL_FLASH_Unlock() == HAL_OK) {
err = mcu_flash_program_data(addr_val, data_ptr, size);
HAL_FLASH_Lock(); // it always returns HAL_OK
}If I replace `addr_val` by 0x0807e000 (by example) there is no problem.
Is there a way to write correctly in this part of the memory ?
Thanks !
