0
votes

In STM32F030 controller I want to write certain variables on Flash memory. Also, in runtime, those variables may get changed. So, when change in value of variable is detected, I'm erasing flash and again write.

Question : Do I need to do System reset every time the update in variable detected ?

Below is my code.

void FlashWrite(void)
{
    //Channel A
    SlaveHolding_New[0] = SlaveHoldingReg[0];
    if(SlaveHolding_Prev[0]!=SlaveHolding_New[0])
    {
        Flash_Erase();
        Flash_WORD_Write(FLASH_ADD_CH1, SlaveHolding_New[0]);
        Flash_WORD_Write(FLASH_ADD_CH2, SlaveHolding_New[1]);
        Flash_WORD_Write(FLASH_ADD_CH3, SlaveHolding_New[2]);
        Flash_WORD_Write(FLASH_ADD_CH4, SlaveHolding_New[3]);
        SlaveHolding_Prev[0] = SlaveHolding_New[0];
        //HAL_NVIC_SystemReset();
    }
1
No, erasing and writing in the flash memory does not require a system reset. However, we don't know the exact usage of your variables in the code, so it might still be necessary for your application.A.R.C.

1 Answers

2
votes

You need to reset the MCU only when you want to application program to restart.

Updating variables in some flash sector does not require application restart. However, make sure your application gets aware of this update so it reads the new values. If the read operation if performed only on startup, the you need to reset your MCU.