2021-08-01 08:59 PM
Hello.
I discovered a weird phenomenon that some flash memory of the board that I have is always the last status is 'FLASH_ERROR_PROGRAM'.
The MCU of the board is STM32L152VD.
I download my code that checking the last status of flash memory. (It used ST Periph library.)
The code is as below. Check the last status of flash memory and if the last status is a FLASH_ERROR_PROGRAM then on LED.
void Test()
{
FLASH_Status status = FLASH_GetStatus();
if(status == FLASH_ERROR_PROGRAM) LED::AllOn();
}
Many boards are normal (no FLASH_ERROR_PROGRAM status) but some boards are always FLASH_ERROR_PROGRAM status.
I want to know why 'FLASH_ERROR_PROGRAM' error is fired and how to leave from 'FLASH_ERROR_PROGRAM' status.
Any advice would be much appreciated.
Thanks for reading.
2021-08-02 06:41 AM
It will return FLASH_ERROR_PROGRAM if a variety of different bits are set.
You can read FLASH_SR yourself to determine the exact reason.
It's probably better to figure out why you've gotten into the error state and fix that.
2021-08-02 09:15 AM
Thank you for your answer.
I checked FLASH_SR value. The value was 0x180C.
The problem is that the init status of the flash memory is 0x180C.
in other words, I checked the flash memory status value as soon as starting code as below and the value was 0x180C.
void main()
{
uint32_t status = FLASH->SR; // 0x180C
}
After rebooting the value is always 0x180C.
I tried to initialize FLASH->SR value to 0x00 but still, the value is not changed.
Is it possible that a circuit problem is causing this problem?
Any advice would be much appreciated.
Thank you.
2021-08-02 09:42 AM
Okay, so the OPTVERR (option validity error flag) is set. That means one or more of your option byte settings are invalid. Check those and correct as necessary.
2021-08-02 11:37 PM
I solved this problem thank you.
My solution is as below.
The main point is to set 0x1f0f value to FLASH->SR before erase the flash memory to clear all bits.
The example code is as below.
Thanks.
void Test()
{
FLASH_Unlock();
FLASH_ClearFlag(0x1f0f);
FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
if(FLASH_ErasePage(startAddr+(this->pageSize*i)) == FLASH_COMPLETE)
LED::AllOn();
FLASH_Lock();
}
2021-08-03 06:53 AM
This is the equivalent to putting a piece of tape over your "check engine" light instead of taking it to a mechanic. But at least you won't see the check engine light anymore.