Skip to main content
Associate
February 9, 2025
Question

F072 user data option bytes

  • February 9, 2025
  • 1 reply
  • 397 views

ive been trying to use the two option bytes available for the user. but i have not been able to get it to Write to them i code. 

editing the bytes via cubeProgrmmer then reading them with the following:

 

 

uint8_t userByte0 = HAL_FLASHEx_OBGetUserData(OB_DATA_ADDRESS_DATA0);
uint8_t userByte1 = HAL_FLASHEx_OBGetUserData(OB_DATA_ADDRESS_DATA1);

 

 

That works as expected. But trying to write to them does not work. 

 

 

	FLASH_OBProgramInitTypeDef obConfig;

	HAL_FLASHEx_OBGetConfig(&obConfig);

	obConfig.OptionType = OPTIONBYTE_USER; // Specify we are modifying user option bytes
	obConfig.USERType = OB_USER_DATA0; // Select User Data Byte 0
	obConfig.USERConfig = 0x55; // Set the value (change as needed)
	HAL_FLASH_Unlock();
	HAL_FLASH_OB_Unlock();
	HAL_FLASHEx_OBProgram(&obConfig);
	HAL_FLASH_OB_Launch();

 

 

I tired to check the bytes via cubeProgrammer but does not seem to be present.

1 reply

Amel NASRI
Technical Moderator
February 20, 2025

Hi @tje7415 ,

2 recommendations:

  • Verify that HAL_FLASHEx_OBProgram returns HAL_OK to ensure that the programming operation was successful.
  • Ensure that the Flash and Option Bytes are locked at the end: 
HAL_FLASH_OB_Lock();
HAL_FLASH_Lock();

-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.