cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 read out protection

sanju
Senior

Hello all,

I have developed a code for stm32f103, which works fine.

During code execution, some device configuration data is Read & written into flash (works fine).

But when i enable read out protection, the code doesn't work.

My understanding is that when read out protection is enabled, code is not able to read/write data from flash, in result it doesn't initialize the configuration parameter of device.

i tried to enable to the read out protection by both ways.

......from st-link utility tool

or

......by writing in code itself.

/***************code for read out protection****************/

uint8_t ReadProtectionConfig(uint8_t ProtectionLevel)

{

 uint8_t status = 0;

 FLASH_OBProgramInitTypeDef OB_Init;

 HAL_FLASH_Unlock();

 HAL_FLASH_OB_Unlock();

 OB_Init.OptionType = OPTIONBYTE_RDP;

 if (ProtectionLevel == 0) 

 {

OB_Init.RDPLevel = OB_RDP_LEVEL_0;

 } 

 else if (ProtectionLevel == 1) 

 {

OB_Init.RDPLevel = OB_RDP_LEVEL_1;

 }  

 else 

 {

status = 1;

return status;

 }

 HAL_FLASHEx_OBProgram(&OB_Init);

 HAL_FLASH_OB_Launch();

 HAL_FLASH_OB_Lock();

 HAL_FLASH_Lock();

 return status;

}

in both case read out protection works ok.

Post edited to adhere community guidelines.

please guide me on this.

3 REPLIES 3
Uwe Bonnes
Principal III

Have a look at Read protection in PM0075. Read protection also write protects some first pages. Or use a page granular write protection.

i am using stm32f103cbt7 in my project which has 128KB of flash ( 0x08000000 - 0x0801FFFF) total 128 pages each of 1KB.

my hex file is using memory from (0x08000000 - 0x080052CB)

i am using last page of flash to write some data (0x0801FC00 - 0x0801FC8B)

And using code for implementing read protection (as mentioned in question / first comment).

what can i do now.

@Uwe Bonnes​ 

sanju
Senior

I am very very sorry for the delay for this post.

i was making a very basic error, but now i have solved this.

"When readout protection is enabled, a POR(power on reset) is required after protection enabled."

Before entering in infinite loop, i was calling the ReadProtectionConfig function for enabling protection.

like this

ReadProtectionConfig(1);

while(1)

{

// further application code

}

so it was requiring a POR every time.

so i changed calling of ReadProtectionConfig function to below code.

if(READ_BIT(FLASH->OBR, FLASH_OBR_RDPRT) == 0) // Checking if protection is disabled

{

ReadProtectionConfig(1);

}

else

{

// Do nothing

}

while(1)

{

// further application code

}

now it is working fine because now ReadProtectionConfig function will be called only one time.