cancel
Showing results for 
Search instead for 
Did you mean: 

Code does not run when RDP is enabled on STM32L072

RCont.1
Associate II

Hi ST community,

I have a fully functional application on my STM32L072. The problem is when I tried to enable RDP, nothing works anymore.

After flashing the application I tried to connect with ST-Link, the option bytes are set correctly and it is not possible to read the FLASH memory, but the code no longer seems to enter the main.c.

WHAT IS HAPPENING?

Below my code to enable RDP. I call this function immediately after the MX_***_Init modules.

Edit: the main FW is loaded in-app by a bootloader, therefore without using the debugger (through SWD).

static void Enable_RDP(void)
{
    FLASH_OBProgramInitTypeDef obConfig;
    
    // Read opt bytes
    HAL_FLASHEx_OBGetConfig(&obConfig); 
 
    if (obConfig.RDPLevel == OB_RDP_LEVEL_0 || obConfig.BORLevel == OB_BOR_OFF)
    {
        obConfig.OptionType = OPTIONBYTE_RDP | OPTIONBYTE_BOR;
	obConfig.RDPLevel = OB_RDP_LEVEL_1;
	obConfig.BORLevel = OB_BOR_LEVEL4;
 
	// Flash optbyte
	HAL_FLASH_Unlock();
	HAL_FLASH_OB_Unlock();
        HAL_FLASHEx_OBProgram(&obConfig);
	HAL_FLASH_OB_Launch(); // This will cause a system reset
    }
 
    HAL_FLASH_OB_Lock();
    HAL_FLASH_Lock(); 
}

0 REPLIES 0