2025-05-08 12:02 AM
I am trying to write to the flash memory of the STM32L4S5QIIX microcontroller on the EVAL-ADIN1110EBZ development board. I have also tried similar code on an STM32L4S5VITX microcontroller on a custom circuit board.
Short example code:
uint32_t flash_memory_address = 0x08100000;
uint64_t flash_write_data = 0x12345678;
uint8_t flash_read_data[4]= {0};
HAL_FLASH_Unlock();
FLASH_PageErase(0, FLASH_BANK_2);
HAL_FLASH_Lock();
HAL_FLASH_Unlock();
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
HAL_StatusTypeDef status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD,
flash_memory_address,
flash_write_data);
HAL_FLASH_Lock();
The full code and project files can be found at: https://github.com/landas/stm32l4s5-flash-memory/blob/e8304c3d17e27ee9f27f8a8243ceb7f73ba077bf/Core/Src/main.c#L135
FLASH_PageErase(0, FLASH_BANK_2) operation was completed successfully. This was verified by using STM32CubeProgrammer to write to the flash memory and confirm the changes in the specified memory area.
HAL_FLASH_Program(...) returns the error codes:
I get similar code to work with a NUCLEO-F303RE develpoement board without any errors.
I would appreciate any hints on how to resolve this issue.
Note: I have tried the same code without
HAL_FLASH_Lock(); HAL_FLASH_Unlock();
between erase and program.