how to read write stm32 flash memory

Solutions on MaxInterview for how to read write stm32 flash memory by the best coders in the world

showing results for - "how to read write stm32 flash memory"
Chiara
30 Nov 2018
1//setup memory
2// Modify Flash Address according to target MCU
3HAL_FLASH_Unlock();
4FLASH_Erase_Sector(11, FLASH_VOLTAGE_RANGE_3);
5HAL_FLASH_Lock();
6
7//write to memory
8HAL_FLASH_Unlock();
9uint8_t rdBuf[5];
10uint8_t wrBuf[5] = {0x11, 0x22, 0x33, 0x44, 0x55};
11
12uint32_t flashAddress = 0x080E0000;
13for(uint32_t i=0; i<5; i++)
14{
15    HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, flashAddress, ((uint8_t *)wrBuf)[i]);
16    flashAddress++;
17}
18HAL_FLASH_Lock();
19
20//read
21flashAddress = 0x080E0000;
22for(uint32_t i=0; i<5; i++)
23{
24    *((uint8_t *)rdBuf + i) = *(uint8_t *)flashAddress;
25    flashAddress++;
26}