Skip to main content
Associate II
June 22, 2026
Solved

Set the bor threshold for stm32u575

  • June 22, 2026
  • 3 replies
  • 89 views

  When I was developing the stm32u575, I needed to set the threshold for the bor (power-on reset). I wanted the device to reset when the voltage was below a certain level. While configuring the bor threshold for the stm32u575, I followed the configuration process of the stm32f405, but it didn't work. The program got stuck at HAL_FLASH_OB_Unlock(). Why did this happen? What was the problem?

	FLASH_OBProgramInitTypeDef OBInit;
HAL_FLASHEx_OBGetConfig(&OBInit);

OBInit.USERType = OB_USER_BOR_LEV;
OBInit.USERConfig = OB_BOR_LEVEL_1;
HAL_FLASH_OB_Unlock();
HAL_FLASHEx_OBProgram(&OBInit);
HAL_FLASH_OB_Launch();
HAL_FLASH_OB_Lock();

 

Best answer by 杜明恢

The function prototype is as follows. When the program executed WRITE_REG(FLASH->OPTKEYR, FLASH_OPTKEY1), HardFault_Handler interrupt was triggered.At this moment, R13(SP) = 0x200BFF40, R14(LR) = 0xFFFFFFA8, R15(PC) = 0x08008250。I have identified the cause. The ICACHE needs to be disabled.

HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void)
{
if (READ_BIT(FLASH->NSCR, FLASH_NSCR_OPTLOCK) != 0U)
{
/* Authorizes the Option Byte register programming */
WRITE_REG(FLASH->OPTKEYR, FLASH_OPTKEY1);
WRITE_REG(FLASH->OPTKEYR, FLASH_OPTKEY2);

/* Verify that the Option Bytes are unlocked */
if (READ_BIT(FLASH->NSCR, FLASH_NSCR_OPTLOCK) != 0U)
{
return HAL_ERROR;
}
}

return HAL_OK;
}

 

3 replies

ST Technical Moderator
June 22, 2026

Hello ​@杜明恢 

Could you please check the return value of HAL_FLASH_OB_Unlock() first?
It would be useful to update the code so that every HAL function return status is verified.

On STM32U575, the option-byte programming flow is not identical to STM32F405, so reusing the same sequence may lead to issues. If the code appears to stop at HAL_FLASH_OB_Unlock(), the first thing to confirm is whether the function is actually returning HAL_OK, or whether it is returning an error.

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Saket_Om
杜明恢AuthorBest answer
Associate II
June 23, 2026

The function prototype is as follows. When the program executed WRITE_REG(FLASH->OPTKEYR, FLASH_OPTKEY1), HardFault_Handler interrupt was triggered.At this moment, R13(SP) = 0x200BFF40, R14(LR) = 0xFFFFFFA8, R15(PC) = 0x08008250。I have identified the cause. The ICACHE needs to be disabled.

HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void)
{
if (READ_BIT(FLASH->NSCR, FLASH_NSCR_OPTLOCK) != 0U)
{
/* Authorizes the Option Byte register programming */
WRITE_REG(FLASH->OPTKEYR, FLASH_OPTKEY1);
WRITE_REG(FLASH->OPTKEYR, FLASH_OPTKEY2);

/* Verify that the Option Bytes are unlocked */
if (READ_BIT(FLASH->NSCR, FLASH_NSCR_OPTLOCK) != 0U)
{
return HAL_ERROR;
}
}

return HAL_OK;
}

 

ST Technical Moderator
June 22, 2026

Hello ​@杜明恢 
Add to what ​@Saket_Om said, I should mention that you can modify BOR level using STM32CubeProgrammer
just connect the product and select the wanted BOR level
looks like an easier way

BR
Gyessine

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question.