Skip to main content
Chidanand
Associate II
July 8, 2020
Question

Disabling readout protection level 1 in stm32F051xx microcontroller

  • July 8, 2020
  • 7 replies
  • 1898 views

Hi,

I'm trying to protect my code from being able to read by others.So I chose readout protection level-1,I could make it read protected and I'm not able disable it by using readout protection level-0,I have to disable it using ST link utility.But I want to disable readout protection using code itself.Please can someone correct me where I went wrong?

Thank you.

Enable readout protection level 1:

FLASH_Unlock() ;

if(!(FLASH_OB_GetRDP())

{

FLASH_OB_Unlock() ;

state = FLASH_OB_RDPConfig(OB_RDP_Level_1) ;

if(state == FLASH_COMPLETE)

FLASH_OB_Launch();

FLASH_OB_Lock() ;

}

FLASH_Lock() ;

Disable readout protection level 1:

FLASH_Unlock() ;

if((FLASH_OB_GetRDP())

{

FLASH_OB_Unlock() ;

state = FLASH_OB_RDPConfig(OB_RDP_Level_0) ;

if(state == FLASH_COMPLETE)

FLASH_OB_Launch();

FLASH_OB_Lock() ;

}

FLASH_Lock() ;

This topic has been closed for replies.

7 replies

Andreas Bolsch
Lead III
July 8, 2020

Erm, that's a rather strange idea ... Changing RDP to level 0 causes a mass erase of flash. Is that really your intention?

Chidanand
ChidanandAuthor
Associate II
July 9, 2020

Thanks for the quick reply.

My intention is to being able to enable and disable the readout protection level 1.Enabling part is working,but disabling part is not working(which is working through ST-Link Utility).After executing disabling logic also it says readout protection is still enabled.

Are disabling steps correct ?

Thank you.

Andreas Bolsch
Lead III
July 11, 2020

It simply doesn't make any sense to disable the readout protection in your code.

Read the RM carefully regarding the implication of the various RDP levels.

MM..1
Super User
July 8, 2020

Level 1 protect flash against debug SWD interface , but you can upgrade or owerwrite flash with bootloader or other type code.

Switch back to level 0 equal erase flash, maybe can do with code run from ram .

Chidanand
ChidanandAuthor
Associate II
July 9, 2020

Thanks for the quick reply.

My intention is to being able to enable and disable the readout protection level 1.Enabling part is working,but disabling part is not working(which is working through ST-Link Utility).After executing disabling logic also it says readout protection is still enabled.

Are disabling steps correct ?

Thank you.

MM..1
Super User
July 12, 2020

I cant say your code is ok or not. But in fact when you build and run this code from flash then on moment execution instruction to change level to 0 MCU internaly erase full flash and next instructions in your code after this dont exist..

I write that maybe when you move this code to RAM and run here maybe work, but RDP is protection then i mean your idea is bad. I dont have more reply...

S.Ma
Principal
July 12, 2020

Is the stlink doing a flash erase, switch level 0, rewrite flash? Then your sw won't have a backdoor.