Enabling RDP on STM32F7 MCU

I am trying to enable RDP Level 1 on an STM32F767VI MCU using the following code:

void SetRDP()
{
// Enables RDP level 1 on STM32F7 MCUs
#ifdef STM32F7
    printf("RDP Set Start\r\n");
    HAL_StatusTypeDef status;

    status = HAL_FLASH_OB_Unlock();
    if(status){
        printf("Flash OB Unlock Error\r\n");
        return;
    }

    FLASH_OBProgramInitTypeDef OBConfig;
    HAL_FLASHEx_OBGetConfig(&OBConfig);
    OBConfig.RDPLevel = OB_RDP_LEVEL_1;

    status = HAL_FLASHEx_OBProgram(&OBConfig);
    if(status){
        printf("FlashEx OB Program Error\r\n");
        return;
    }

    status = HAL_FLASH_OB_Lock();
    if(status){
        printf("Flash OB Lock Error\r\n");
        return;
    }

    printf("RDP Success\r\n");
#endif
}

The code follows all the way through to “RDP Success”, but checking with an STLink still lets me look at the flash and tells me that the RDP is still on level 0. What am I doing wrong?

Found my issue, you have to call HAL_FLASH_OB_Launch() after the program. Which then led me to wonder why it would not run the program at all once the RDP is set to level one. Turns out with a debugger attached (STLINK-V3MODS in my case), it will not run anything. Once I unplugged the debugger it ran fine. So problem solved!

1 Like