cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L0 - reset after setting RDP

JJRR
Senior

Dear,

I am setting RDP to level 1 in my application, After setting it I call System reset HAL_NVIC_SystemReset();

After reset I am expecting the MCU is locked, but it seems I read in code the MCU is still in level 0 so the procedure of setting RDP to level 1 is repeating. Only power disconnect locks the processor to level 1.

Any solution?

Best regards, Jan.

        HAL_FLASHEx_OBGetConfig(&flashTemp);
	if(OB_RDP_LEVEL_0 == flashTemp.RDPLevel)
	{
		HAL_FLASH_OB_Unlock();
		HAL_FLASHEx_OBGetConfig(&pOBInit);
		pOBInit.RDPLevel = 0xBB;
		pOBInit.WRPState = OB_WRPSTATE_ENABLE;
		HAL_FLASHEx_OBProgram(&pOBInit);
		HAL_FLASH_OB_Lock();
		HAL_NVIC_SystemReset();
	}

5 REPLIES 5
TDK
Guru

What chip?

Look at the code:

https://github.com/STMicroelectronics/STM32CubeL0/blob/58c3ec5bb16e3475309da63f64d62efb2782594d/Drivers/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_flash_ex.c#L327

You need to add:

pOBInit.OptionType = OPTIONBYTE_RDP | OPTIONBYTE_WRP;

if you want to set those options.

If you feel a post has answered your question, please click "Accept as Solution".

STM32L071

Thanks, I didn't see it initially. I edited my post after asking. See the new answer.
If you feel a post has answered your question, please click "Accept as Solution".

Hi @Community member​ ,

Did you added the line suggested by @TDK​ ? Does it work this time?

If yes, please mark his reply as Best answer (click on "Select as Best").

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Funny how problems occur in pairs -- somewhat related.

You might probably need to reload the option bytes after programming, see Reloading Option bytes by software subchapter in RM.

JW