cancel
Showing results for 
Search instead for 
Did you mean: 

Setting Brown-Out Threshold in Option bits

AHass.1
Associate II

Hi,

for my application, I need to set my BOR threshold to about 2.5 V in my STM32L476RG. My understanding is that the preconfigured threshold is at level 4, which is 2.8 V (see RM0351 Rev 7, page 111).

What is a good strategy for setting the BOR_LEV bits with the HAL (ver. 1.7.0)? I tried to set them with following code, but after that, the L476 does not work anymore.

Also I don't really understand how these registers are organised. First of all, why are there two registers, that are basically the same:

  1. "User and read protection option bytes" with default value of 0xFFEF F8AA at address 0x1FFF7800 (RM0351 Rev 7, on page 111) and
  2. "Flash option register (FLASH_OPTR)" with default value 0xXXXX XXXX at address offset 0x20 (RM0351 Rev 7, on page 131)?

HAL_StatusTypeDef set_BOR_threshold(void)
{
	FLASH_OBProgramInitTypeDef FLASH_Handle;
 
	FLASH_Handle.USERConfig = OB_BOR_LEVEL_0;
 
	if (HAL_FLASH_OB_Unlock() != HAL_OK)
	{
		return HAL_ERROR;
	}
 
 
	if (HAL_FLASHEx_OBProgram(&FLASH_Handle) != HAL_OK)
	{
		return HAL_ERROR;
	}
 
 
	return HAL_OK;
}

In order for my code to work on first launch, I also would like to use OBL_LAUNCH.

Is there any way on how to achieve that with the HAL 1.7.0? Do I need to write all bits of this register?

Thank you very much in advance for any tips and hints.

1 REPLY 1
TDK
Guru

You should be able to adapt the example:

https://github.com/STMicroelectronics/STM32CubeL4/blob/d023c0d560ace11509f9b761c8913a9e48fcf194/Projects/STM32L476G-EVAL/Examples/FLASH/FLASH_WriteProtection/Src/main.c

You need to set the OptionType parameter so it knows which option byte you're changing.

> I need to set my BOR threshold to about 2.5 V in my STM32L476RG.

> FLASH_Handle.USERConfig = OB_BOR_LEVEL_0;

OB_BOR_LEVEL_0 is 1.8V, OB_BOR_LEVEL_3 is 2.5V.

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