Skip to main content
Visitor II
September 17, 2017
Question

How to disable read out (RDP) protection?​

  • September 17, 2017
  • 1 reply
  • 1128 views
Posted on September 17, 2017 at 16:11

Hi All,

I am trying to use STM 32 ST-LINK utility to flash my .hex code to STM32L4 microcontroller on my custom board using SWD. I have tried all the modes under Target Settings (Normal, Hot Plug, Connect Under Reset) without any luck. With hot plug selected, I think, I can connect to the microcontroller, it displays ID, flash size etc. but I can not erase chip or write hex code because it displays 'Read out protection is activate'. If I try to open Option Bytes, it gives me error but ends up displaying the window anyway. On the window, read out protection is set to level 1. In this mode I can make changes on the GUI but can not save them, because of the protection, so I am stuck in a never ending loop, I think. Can you please let me know what needs to be done so that I can fix this issue and able to write hex code to my microcontroller using ST-LINK/V2?

Thanks!

Dushyant.

#st-link/v2
    This topic has been closed for replies.

    1 reply

    Graduate
    September 18, 2017
    Posted on September 18, 2017 at 10:49

    I don't know the 'official' way to do this.

    The way I do this is to download some code to RAM which disables readout protection.

    I don't know how you'd specify building a project to download directly into and execute from RAM from your development environment.

    But my code essentially does:

    Old version:

    int main(void) {

    FLASH_Status protector;

    FLASH_OB_Unlock();

    FLASH_OB_WRPConfig(OB_WRP_Sector_All, DISABLE);

    /* protector = */FLASH_OB_RDPConfig(OB_RDP_Level_0);

    protector = FLASH_OB_Launch();

    FLASH_OB_Lock();

    logU(protector);

    logString(' Unlock Complete\n');

    return 0;

    }

    Newer version:

    uint32_t SystemCoreClock;

    int main(void) {

    SystemCoreClock = 16000000;

    HAL_InitTick(TICK_INT_PRIORITY);

    /* Unlock the Flash to enable the flash control register access *************/

    HAL_FLASH_Unlock();

    /* Unlock the Options Bytes *************************************************/

    HAL_FLASH_OB_Unlock();

    HAL_StatusTypeDef rc = FLASH_If_WriteProtectionConfig(OB_WRPSTATE_DISABLE);

    if (rc == HAL_OK) {

    /* Generate System Reset to load the new option byte values ***************/

    HAL_FLASH_OB_Launch();

    /* Lock the Options Bytes *************************************************/

    HAL_FLASH_OB_Lock();

    debug_printf('Successful');

    }

    logString(' Unlock Complete\n');

    return 0;

    }

    Hope this helps,

    Danish

    Visitor II
    September 18, 2017
    Posted on September 18, 2017 at 15:33

    Thanks Danish for the reply,

    no, I don't have a code which can load code to RAM instead of Flash, but I will try yours to fix the issue I am having.

    Is this normal though? to have SWD pins disabled for a microcontroller? I don't know how eval board gets around this problem.

    Thanks,

    Dushyant.

    Visitor II
    September 19, 2017
    Posted on September 19, 2017 at 17:13

    I did not have correct connections made in my custom board, that was the problem. 

    Thanks Danish.