cancel
Showing results for 
Search instead for 
Did you mean: 

Disabling readout protection level 1 in stm32F051xx microcontroller

Chidanand
Associate II

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() ;

7 REPLIES 7
Andreas Bolsch
Lead II

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

MM..1
Chief II

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 .

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.

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.

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.

S.Ma
Principal

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

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...