Using STM32 FLASH memory
I am learning on using the STM32L431CC FLASH memory to store data after the microcontroller loses power. From compiling through Keil, I get:
Program Size: Code=34316 RO-data=1228 RW-data=364 ZI-data=1908
From the above, Is it correct that only 35Kbytes of FLASH are being used?
FLASH/ROM = Code + RO-data = 34316 + 1228 = 35544 bytes
Since the STM32L431CC uses Pages instead of Sectors for its FLASH, this is the code that I used to write into its FLASH memory:
HAL_FLASH_Unlock();
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGSERR);
HAL_FLASHEx_Erase(&lFlashPage, &PageErrorStatus);
HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, 0x0803F800, *pData1);
HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, 0x0803F800 + 0x08, *pData2);
HAL_FLASH_Lock();And the FLASH configuration that I used:
FLASH_EraseInitTypeDef lFlashPage;
lFlashPage.TypeErase = FLASH_TYPEERASE_PAGES;
lFlashPage.Banks = FLASH_BANK_1;
lFlashPage.Page = 127;
lFlashPage.NbPages = 1;If the whole program only uses 35Kbytes of FLASH memory, does that also mean that the program only used FLASH Page 0 up to FLASH Page 17 (total of 36KBytes with 2KByte per page), and that it is safe to use FLASH page 127? The FLASH rewriting should not mess up the program itself would it? I should also note that I have not tried changing the Scatter File in Keil and don't know if I have to if the program won't touch Page 127 at all.
I also have a question regarding erasing the FLASH page. Would calling the function:
HAL_FLASHEx_Erase(&lFlashPage, &PageErrorStatus);erase FLASH page 127 into all 0xFFFFFFFF? I did notice that at startup, if I did not write anything to FLASH, the data stored in the memory are 0xFFFFFFFF per block.
Any help would be appreciated. Thank you!