cancel
Showing results for 
Search instead for 
Did you mean: 

Option byte RDP=1 STM32F0

klaus2
Associate II
Posted on October 25, 2014 at 23:43

I want to set Readprotectionlevel=1. After the initialisation i can't see toggling of GPIO_PIN_7. The function HAL_FLASH_OB_Launch(); causes problems. When commenting out the function HAL_FLASH_OB_Launch() the while(1) loop will be reached. Is there anything wrong setting RDP=1 like this ? I use HAL_DRIVER. I got the same problem with STD_PERIPHERAL_DRIVER. Tools: Keil 4.73, EWARM 7.2, ST-LINKV2

void

MX_Flash_Init(

void

) { FLASH_OBProgramInitTypeDef Optbyte; HAL_FLASHEx_OBGetConfig(&Optbyte);

// read out RDPLvL

if

(Optbyte.RDPLevel ==RESET){

// Lvl 0 = 0, Lvl 1,2 =1

Optbyte.OptionType=OPTIONBYTE_RDP;

// select RDP optionbyte

Optbyte.RDPLevel=OB_RDP_LEVEL_1;

// select RDP level 1

HAL_FLASH_Unlock();

// unlock Flash

HAL_FLASH_OB_Unlock();

// unlock Optionbytes

HAL_FLASHEx_OBProgram(&Optbyte);

// set RDP=1

HAL_FLASH_OB_Launch();

// write OB to Flash and reset

} HAL_FLASH_OB_Lock();

// Lock Optionbytes

HAL_FLASH_Lock();

// lock Flash

}

int

main(

void

) { MX_GPIO_Init(); MX_Flash_Init();

while

(

1

) { GPIOA->ODR^=GPIO_PIN_7; } }

#flash #option-bytes #stm32f0
6 REPLIES 6
John Thorne
Associate II
Posted on March 13, 2015 at 11:20

Did you manage to resolve this issue ?

We had the same problem on an STM32F030R8 design, even running the code on the

STM32F0308-Discovery board. If you haven't already then I think you will find that the HAL_FLASHEx_OBProgram(&Optbyte) call is failing (!=HAL_OK) when it gets to FLASH_OB_RDP_LevelConfig, specifically the WRITE_REG(OB->RDP, ReadProtectLevel) call  - at least that's what we surmised.

It is possible the HAL code is broken here, but I have no evidence of that, apart from this issue.

Keil uVision 5.12.0.0

ArmCC V5.05 (build 41)

stm32f0xx_hal_flash_ex.c V1.0.1 (18-June-2014)

g5428036
Associate II
Posted on June 17, 2015 at 17:20

Do one of you have the solution ?

I have the same issue here,

I agree with the post above : since the launch make a reset of the device.   as long as RDP is not changed we infinitly reset.

but the writed register seems to correspond with the register of the datasheet.

I will post here  more information.

edit: I'm too on

STM32F030R8

Posted on June 17, 2015 at 17:25

And do any of these functions return ERROR or STATUS information that might help you understand the failure?

Do you clear any pending error/status flags from the controller?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
g5428036
Associate II
Posted on June 17, 2015 at 18:09


 HAL_FLASH_Unlock();
HAL_FLASH_OB_Unlock();
FLASH_OBProgramInitTypeDef initFlash;
initFlash.OptionType = OPTIONBYTE_RDP;
initFlash.RDPLevel= OB_RDP_LEVEL_1;
status = HAL_FLASHEx_OBProgram(&initFlash);
if
(status != HAL_OK)
{
if
(status == HAL_ERROR)
{
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_9,GPIO_PIN_SET);
}
if
(status == HAL_BUSY)
{
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_9,GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOB,GPIO_PIN_14,GPIO_PIN_SET);
}
if
(status == HAL_TIMEOUT)
{
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_9,GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOB,GPIO_PIN_14,GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOB,GPIO_PIN_15,GPIO_PIN_SET);
}
while
(1);
}
HAL_FLASH_OB_Launch();
HAL_FLASH_OB_Lock();

I use stm32 cube to generate a project. (only init 3 pin from basic project for feedback) I add just the code above to have a feedback. The result is that we have flash error. ''HAL_ERROR'' thanks for your time :) I'll go further tomorow. regards G.M.
Posted on June 17, 2015 at 19:08

Not a HAL guy, this is an SPL thread covering this

[DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/flash%20readback%20protection&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=891]https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2Fflash%20readback%20protection&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=891

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
g5428036
Associate II
Posted on June 18, 2015 at 10:00

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6q4&d=%2Fa%2F0X0000000bwY%2FWFTXafzMN_W0enGMDf5h5vo7WnkWZZ_KETFMwwTc514&asPdf=false