2021-07-01 02:09 PM
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
2021-07-01 02:16 PM
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:
Disabling IWDG requires a chip restart as well, so this scheme won't quite work as is.
2021-07-06 11:04 AM
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
2021-07-06 11:07 AM
I can't see what you're doing. Show the code you're using or follow a working example.
2021-07-06 11:10 AM
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
2021-07-06 11:31 AM
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:
2021-07-06 11:35 AM
Ah, I was calling that after I locked, so it wasn't working. Looks good now, thanks for the help!!
Thanks,
Charles