2022-05-11 12:11 PM
I've just bought a STM32G030F6P6 dev board and I'm testing its cababilities.
And one thing I'm having problems with is saving my data to the FLASH.
The first time it writes as espected in the FLASH, but not in the second, HAL_FLASH_Program returns HAL_ERROR.
#include "main.h"
uint32_t Address = 0x0800F800;
uint32_t buffer = 0x12345678;
uint32_t data1 = 0;
uint32_t data2 = 0;
HAL_StatusTypeDef status;
int main(void)
{
HAL_Init();
SystemClock_Config();
data1 = *(__IO uint32_t *)Address;
status = HAL_FLASH_Unlock();
status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, Address, buffer);
status = HAL_FLASH_Lock();
data2 = *(__IO uint32_t *)Address;
while (1)
{
}
}
void SystemClock_Config(void)...
Solved! Go to Solution.
2022-05-11 12:51 PM
>>The first time it writes as expected in the FLASH, but not in the second, HAL_FLASH_Program returns HAL_ERROR
You get ONE write per 64-bit line after an Erase, then you need to move onto the next.
Perhaps advance Address to the point where you read 0xFFFFFFFF, or zero, whatever the erased state is on the G0
2022-05-11 12:37 PM
Looks like you don't erase the Flash before programming, which is the first problem. Also, be careful with data alignment.
2022-05-11 12:51 PM
>>The first time it writes as expected in the FLASH, but not in the second, HAL_FLASH_Program returns HAL_ERROR
You get ONE write per 64-bit line after an Erase, then you need to move onto the next.
Perhaps advance Address to the point where you read 0xFFFFFFFF, or zero, whatever the erased state is on the G0