cancel
Showing results for 
Search instead for 
Did you mean: 

I am trying to clear the IWDG_STDBY bit set in flash so I can enter standby mode without the watchdog timer waking up the MCU.

CFlec
Associate II

I am using an STM32f746zg and this is what I have been trying:

HAL_FLASH_Unlock();

CLEAR_BIT(FLASH->OPTCR, FLASH_OPTCR_IWDG_STDBY);

HAL_FLASH_Lock();

But it doesn't seem to actually modify the bit. What is the proper procedure to clear this bit in flash?

Thanks in advance!!

Charles

6 REPLIES 6
TDK
Guru

Changing option bytes requires you to unlock them, modify them, then activate them by writing to OPTSTRT.

Unlocking flash is different from unlocking option bytes.

Example:

https://github.com/STMicroelectronics/STM32CubeF7/blob/c7c5ec99c7482ea8bcdbf0a869c930af4547088f/Projects/STM32756G_EVAL/Examples/FLASH/FLASH_WriteProtection/Src/main.c

Disabling IWDG requires a chip restart as well, so this scheme won't quite work as is.

If you feel a post has answered your question, please click "Accept as Solution".
CFlec
Associate II

So I've gotten it to clear the bits properly, but they don't seem to persist on reset. I've been resetting by just allowing the watchdog timer to runout, is there a better way to reset?

Thanks again!!

Charles

TDK
Guru

I can't see what you're doing. Show the code you're using or follow a working example.

If you feel a post has answered your question, please click "Accept as Solution".
CFlec
Associate II

On startup I am trying to check if those bits are cleared, if they aren't I clear them and then force a watchdog reset. Here is my code:

// Check if the watchdog pause on sleep bits are set. If they aren't, set them and reset.

    HAL_FLASH_OB_Unlock();

    HAL_FLASH_Unlock();

    // Read the bits.

    if (FLASH->OPTCR & 0xC0000000)

    {

        printf("Sleep bits are not set.\r\n");

        

        // Clear the bits.

        CLEAR_BIT(FLASH->OPTCR, FLASH_OPTCR_IWDG_STOP);

        CLEAR_BIT(FLASH->OPTCR, FLASH_OPTCR_IWDG_STDBY);

        

        // Lock flash.

        HAL_FLASH_OB_Lock();

        HAL_FLASH_Lock();

        // Force a watchdog reset.

        while(1);

    }

It looks like the bits get cleared when I clear them, and then I force a reset as is required for those bits. After the reset the bits seem to get set again, though, so I think I am missing a step.

Thanks!!

Charles

TDK
Guru

You need to call HAL_FLASH_OB_Launch after changing the option bytes and before locking them in order to apply the changes and to reset the chip.

Again, look at what the example code does:

https://github.com/STMicroelectronics/STM32CubeF7/blob/c7c5ec99c7482ea8bcdbf0a869c930af4547088f/Projects/STM32756G_EVAL/Examples/FLASH/FLASH_WriteProtection/Src/main.c#L133

If you feel a post has answered your question, please click "Accept as Solution".
CFlec
Associate II

Ah, I was calling that after I locked, so it wasn't working. Looks good now, thanks for the help!!

Thanks,

Charles