Skip to main content
JJRR
Associate III
Oct 13, 2020 8:27 AM UTC
Question

STM32L0 - reset after setting RDP

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();
	}

This topic has been closed for replies.

5 replies

TDK
Oct 13, 2020 1:29 PM UTC

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""."
JJRR
JJRRAuthor
Associate III
Oct 13, 2020 1:34 PM UTC

STM32L071

TDK
Oct 13, 2020 2:00 PM UTC
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""."
waclawek.jan
Super User
Oct 14, 2020 2:34 PM UTC

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