2019-03-05 05:09 AM
my mcu is STM32F103RGT7.
I want to set RDP level to 1 in firmware.
Error occurs in HAL_FLASH_OB_Launch().
Please tell me what to do.
The following sources have been used:
HAL_FLASHEx_OBGetConfig(&OptionsBytesStruct);
if( OptionsBytesStruct.RDPLevel != OB_RDP_LEVEL_1 )
{
/* Unlocks the option bytes block access */
HAL_FLASH_Unlock();
HAL_FLASH_OB_Unlock();
OptionsBytesStruct.RDPLevel = OB_RDP_LEVEL_1;
OptionsBytesStruct.OptionType = OPTIONBYTE_RDP;
if( HAL_FLASHEx_OBProgram(&OptionsBytesStruct) != HAL_OK )
{
DEBUG_PRINTF("RDP_WRITE Error\r\n");
/* Error occurred while options bytes programming. **********************/
while( 1 );
}
/* Launch the option byte loading */
HAL_FLASH_OB_Launch();
/* Locks the option bytes block access */
HAL_FLASH_OB_Lock();
HAL_FLASH_Lock();
}
2021-03-14 03:03 AM
Hello.
I apologize for the google translation.
Digging into
HAL_FLASH_OB_Launch (); // !!!!!! write OB to Flash and reset !!!!!
it will become visible
/ **
\ brief System Reset
\ details Initiates a system reset request to reset the MCU.
* /
__NO_RETURN __STATIC_INLINE void __NVIC_SystemReset (void)
{
__DSB (); / * Ensure all outstanding memory accesses included
buffered write are completed before reset * /
SCB-> AIRCR = (uint32_t) ((0x5FAUL << SCB_AIRCR_VECTKEY_Pos) |
(SCB-> AIRCR & SCB_AIRCR_PRIGROUP_Msk) |
SCB_AIRCR_SYSRESETREQ_Msk); / * Keep priority group unchanged * /
__DSB (); / * Ensure completion of memory access * /
for (;;) / * wait until reset * /
{
__NOP ();
}
}
I think it is clear that the system deliberately hangs waiting for a reset.