Skip to main content
Visitor II
November 14, 2023
Solved

stm32c011 in-application option byte programming

  • November 14, 2023
  • 1 reply
  • 1157 views

Good morning,

I'm trying to program the user option bytes of the STM32C011 using the HAL. The objective of the test is to toggle the BOR bit.

 

 

static HAL_StatusTypeDef testOptionBytes()
{
 FLASH_OBProgramInitTypeDef obInit = {0};
 FLASH_OBProgramInitTypeDef obProgram = {0};
 FLASH_OBProgramInitTypeDef obCmp = {0};
 HAL_StatusTypeDef status = HAL_OK;

 HAL_FLASHEx_OBGetConfig(&obInit);

 status = HAL_FLASH_Unlock();
 assert(status == HAL_OK);
 status = HAL_FLASH_OB_Unlock();
 assert(status == HAL_OK);

 obProgram.OptionType = OPTIONBYTE_USER;
 obProgram.USERType = OB_USER_BOR_EN;
 obProgram.USERConfig = (obInit.USERConfig & OB_USER_BOR_EN) ^ OB_USER_BOR_EN;
 status = HAL_FLASHEx_OBProgram(&obProgram);
 assert(status == HAL_OK);

 HAL_FLASH_OB_Lock();
 HAL_FLASH_Lock();

 HAL_FLASHEx_OBGetConfig(&obCmp);
 assert(obInit.USERConfig != obCmp.USERConfig);

 return status;
}

 

When I step through the HAL code everything looks fine, the FLASH->OPTR register is written with the correct value, but the final assert() always fails.

 

Have I overseen something here?

Thanks in advance, Andreas

This topic has been closed for replies.
Best answer by mƎALLEm

You need to call HAL_FLASH_OB_Launch()  after HAL_FLASHEx_OBProgram()

1 reply

mƎALLEm
mƎALLEmBest answer
Technical Moderator
November 14, 2023

You need to call HAL_FLASH_OB_Launch()  after HAL_FLASHEx_OBProgram()

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.