2024-01-09 04:44 AM
I have a problem programmatically setting RDP to level 1.
My code is:
OBInit.RDPLevel = OB_RDP_LEVEL_1;
OBInit.OptionType = OPTIONBYTE_RDP;
ret = HAL_FLASH_Unlock();
ret = HAL_FLASH_OB_Unlock();
/* Clear SR register */
CLEAR_BIT(FLASH->SR, FLASH_SR_BSY);
ret = HAL_FLASHEx_OBProgram(&OBInit);
ret = HAL_FLASH_OB_Lock();
ret = HAL_FLASH_Lock();
HAL_Delay(2000);
ret = HAL_FLASH_OB_Launch();
// shouldn't get to this point, as processor will reset
I had to put in the clear pf FLASH->SR, otherwise the "FLASH_WaitForLastOperation" would fail inside "FLASH_OB_RDPConfig". I've no idea why the flash should be busy at this stage.
Whether or not I run this under the debugger, the RDP byte never changes. The last HAL_Delay is to give the flash chance to be written properly before the launch resets the processor.
Solved! Go to Solution.
2024-01-09 06:38 AM
The BSY bit is read-only. Wait for BSY to be low, you can't set it to a value.
You must call HAL_FLASH_OB_Launch before locking option bytes. Locking them prevents access.
Several examples out there for this. Here is one:
2024-01-09 06:38 AM
The BSY bit is read-only. Wait for BSY to be low, you can't set it to a value.
You must call HAL_FLASH_OB_Launch before locking option bytes. Locking them prevents access.
Several examples out there for this. Here is one:
2024-01-09 07:16 AM