cancel
Showing results for 
Search instead for 
Did you mean: 

Flash RDP activate

RE11
Associate II

Hello everyone, 

I have board and I used STM32G071 MCU on this board. I want to activate RDP Level 1. There is my code: 

 
 
void SysCodeProtection( void )
{
FLASH_OBProgramInitTypeDef pOBInit = {0};
 
HAL_FLASHEx_OBGetConfig( &pOBInit );
 
if ( pOBInit.RDPLevel != OB_RDP_LEVEL_1 )
{
HAL_FLASH_Unlock();
 
HAL_FLASH_OB_Unlock();
 
pOBInit.OptionType = OPTIONBYTE_RDP;
 
pOBInit.RDPLevel = OB_RDP_LEVEL_1;
 
HAL_FLASHEx_OBProgram( &pOBInit );
 
HAL_FLASH_OB_Launch();
 
HAL_FLASH_OB_Lock();
 
HAL_FLASH_Lock();
 
}
 
}
 
I'm programming my MCU on ST-LINK with ST-LINK Utility. But sometimes after I programmed my MCU It's locking or crushing. My power LED is not working on my board and I can't connect my board. I lost many boards after activate RDP If I disable RDP I didn't see any problems. Can anyone help me about it ?
1 ACCEPTED SOLUTION

Accepted Solutions
Diane POMABIA
ST Employee

Hello @RE11 

Try to disable Prefech before programming your OB.

Please refer to my test code :

FLASH_OBProgramInitTypeDef OptionsBytesInit= {0};

HAL_RCC_DeInit();
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
__disable_irq();
__HAL_FLASH_PREFETCH_BUFFER_DISABLE();
/* Unlock Flash Control register and Option Bytes */
HAL_FLASH_Unlock();
HAL_FLASH_OB_Unlock();
HAL_FLASHEx_OBGetConfig(&OptionsBytesInit);


if(OptionsBytesInit.RDPLevel!=OB_RDP_LEVEL_1){
/* First step: Choose option byte type.*/
OptionsBytesInit.OptionType =OPTIONBYTE_RDP;
OptionsBytesInit.RDPLevel = OB_RDP_LEVEL_1;
/* Program Option Bytes */
HAL_FLASHEx_OBProgram(&OptionsBytesInit);
/* Launch Option Bytes Loading */
HAL_FLASH_OB_Launch();

Regards

DianeP

View solution in original post

11 REPLIES 11
Diane POMABIA
ST Employee

Hello @RE11 

Try to disable Prefech before programming your OB.

Please refer to my test code :

FLASH_OBProgramInitTypeDef OptionsBytesInit= {0};

HAL_RCC_DeInit();
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
__disable_irq();
__HAL_FLASH_PREFETCH_BUFFER_DISABLE();
/* Unlock Flash Control register and Option Bytes */
HAL_FLASH_Unlock();
HAL_FLASH_OB_Unlock();
HAL_FLASHEx_OBGetConfig(&OptionsBytesInit);


if(OptionsBytesInit.RDPLevel!=OB_RDP_LEVEL_1){
/* First step: Choose option byte type.*/
OptionsBytesInit.OptionType =OPTIONBYTE_RDP;
OptionsBytesInit.RDPLevel = OB_RDP_LEVEL_1;
/* Program Option Bytes */
HAL_FLASHEx_OBProgram(&OptionsBytesInit);
/* Launch Option Bytes Loading */
HAL_FLASH_OB_Launch();

Regards

DianeP

RE11
Associate II

Hello @Diane POMABIA 

Thanks for reply and your help. I will try it for my boards. I want to ask one more question. My some boards crushed after I upload my code. I can not connect them. There is any way to connect them again ? Can I save my boards ? 

@RE11  At this point, you have lost your board, we suspect that your last code have created OB missmatch that have activated your bootlock.

Regards

Diane

Hi @Diane POMABIA ,

can you please point me to the section of RM where this is documented?

Thanks,

JW

Diane POMABIA
ST Employee

Hi @waclawek.jan 

We are still analysed the issue. An updated will be done on product document (RM or Errata) when we will finish.

Regards

Diane

RE11
Associate II

Hello again @Diane POMABIA 

 

FLASH_OBProgramInitTypeDef OptionsBytesInit = {0};
 
HAL_RCC_DeInit();
 
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
 
__disable_irq();
 
__HAL_FLASH_PREFETCH_BUFFER_DISABLE();
 
/* Unlock Flash Control register and Option Bytes */
HAL_FLASH_Unlock();
 
HAL_FLASH_OB_Unlock();
 
HAL_FLASHEx_OBGetConfig(&OptionsBytesInit);
 
if( OptionsBytesInit.RDPLevel != OB_RDP_LEVEL_1 )
  {
/* First step: Choose option byte type.*/
OptionsBytesInit.OptionType = OPTIONBYTE_RDP;
 
OptionsBytesInit.RDPLevel = OB_RDP_LEVEL_1;
/* Program Option Bytes */
HAL_FLASHEx_OBProgram(&OptionsBytesInit);
 
/* Launch Option Bytes Loading */
HAL_FLASH_OB_Launch();
 
}
 
  HAL_FLASH_OB_Lock();
 
  HAL_FLASH_Lock();
 
  __enable_irq();
 
I tried my board with this code. But my boards still locking I can't connect them again. There is any wrong to lock my boards ? To enable irq or To lock flash can affect my boards ? 

Hi  @RE11 

Is it the same board or new board ?

I tested your code on a part and I do not encounter the same problem. Can you confirm me that you are not using the same sample ? 

Regards

Diane

RE11
Associate II

@Diane POMABIA 

I'm using same boards but this not happening always. I have many boards and they are same. My some boards working well but some of them when I update my code They are not working again. Also I was having F series board too. I didn't experienced it with F series board. But this time I'm using STM32G071 microcontroller and after I enable RDP Level 1 bootlocking this started to happen. After I tried your solution code this didn't fix. Still my some boards not working again. As i said It is not happening always.

Maybe you may try to check state of BOOT_LOCK before trying to set RDP1.

waclawekjan_2-1687523417047.png

 

 

I don't know why would BOOT_LOCK be set, but maybe this is the mechanism through which the chips are "lost".

JW