cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F0 read out protection problem

Katarzyna Bartnik
Associate II
Posted on March 30, 2017 at 10:13

Hi,

I would like to use a software read protection on STM32F0. I've made such a function:

PROTECT_STATUS ReadProtectionConfig(uint8_t ProtectionLevel)

{

uint8_t status = OK;

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 if (ProtectionLevel == 2) {

OB_Init.RDPLevel = OB_RDP_LEVEL_2;

} else {

status = RDPLevel_Error;

return status;

}

HAL_FLASHEx_OBProgram(&OB_Init);

HAL_FLASH_OB_Launch();

HAL_FLASH_OB_Lock();

HAL_FLASH_Lock();

return status;

}

but it don't work properly. I mean even if I choose 

OB_RDP_LEVEL_0 it blocks read out of flash memory. It is because the program can't perform the HAL_FLASH_OB_Launch(); function.

My problem is that I don't know why it happens and what should I do to make it better.

Could you help me?

Regards,

Kasia

#stm32f0-read-out-protection #read-out-protection #stm32f072 #stm32f0
3 REPLIES 3
Nesrine M_O
Lead II
Posted on March 30, 2017 at 18:35

Hi

Bartnik.Katarzyna

Please try to start from ready example under the STM32F0 cube firmware package:

STM32Cube_FW_F0_V1.7.0\Projects\STM32091C_EVAL\Examples\FLASH\FLASH_WriteProtection

-Nesrine-

Posted on April 03, 2017 at 08:54

Hi Nesrine M,

This example doesn't pertain to my problem, because it is write protection. I know that it is very similar. I think that a scheme of my program is the same like in the example, but it doesn't work properly.

Regards

Kasia

Artur IWANICKI
ST Employee
Posted on May 15, 2018 at 08:25

Hello Kasia,

I have prepared a simple application using your function. Key point here is to take care to execute protection function only once, thus in my example I am using one of the backup registers which are reset only on power on reset. Just before set protection (even to level0) I am writing there 0xA5A5, then on OB reload when the MCU is reseted I check whether I have not done already modification of the protection and if yes, I am skipping this process. Otherwise I would set protection to level0 continuously.

In main loop I am toggling PC6 pin.

Whole application I have tested on STM#2F072B-Discovery using Atollic True Studio 9.0.1.

I am attaching you main.c file and my .ioc project file for STM32CubeMX.

Could you please test it on your side?

Best Regards,

Artur

________________

Attachments :

RDP0.ioc.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HxXe&d=%2Fa%2F0X0000000b0K%2F0MyA7zBVeGWe.gcH0iosirOZ3gNnNgHiCDrfyInUu3o&asPdf=false

main.c.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hxd7&d=%2Fa%2F0X0000000b0I%2Fl.Q3yLEYU4ljiWBtp6A8x4aM8fobMvRx3E2_WZ7Zln0&asPdf=false