cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F3 Write in FLASH HAL_FLASH

ACast.5
Associate

Hi!

I'm trying to save values in the FLASH memory, but the values don't are saved. I've implemented erase command in order to preform flash_program command. I'm using a NUCLEO64 - STM32F303RE...

if(HAL_FLASH_Unlock() != HAL_OK)
{
 
    debugPrintln(&huart2, "HAL UNLOCK ERROR");
 
}
 
 
 
FLASH_PageErase(0);
 
 
 
if(HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, (uint32_t) 0x08000000, (uint32_t) 0x01) != HAL_OK)
{
 
    debugPrintln(&huart2, "HAL WRITE ERROR 1");
 
}
 
if(HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, 0x08000004, (uint32_t) 0x00000000) != HAL_OK)
{
 
    debugPrintln(&huart2, "HAL WRITE ERROR 2");
 
}
 
 
 
if(HAL_FLASH_Lock() != HAL_OK)
{
 
    debugPrintln(&huart2, "HAL lOCK ERROR");
 
}
 

After the execution, the maps is next:

0693W00000NpytFQAR.jpg

1 REPLY 1
Petr DAVID
ST Employee

Hello ACast.5,

welcome ST community. I have two questions regarding your code. First is where is your program code stored in the memory that you are writing to the first page of FLASH. And second could you tell me if you get any errors? Regarding erasing and programming flash there is prepared example that is directly prepared for STM32F303RE nucleo board. Please check the STM32F3Cube FW package. The example project could be found under the folder : \STM32Cube_FW_F3_V1.11.3\Projects\STM32F303RE-Nucleo\Examples\FLASH\FLASH_EraseProgram.

With the best regards,

Petr David