cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H743ZI programming option byte BOOT_ADD0 address to default value (0x08000000) fails

ASá.1
Associate

Hey, I'm using TrueStudio and I'm trying to program BOOT_ADD0 and BOOT_ADD1 by software so I can enable the bootloader and be able to use dfuse to upload new firmware using usb without using the ST-Link Utility to program the option bytes.

So far, when the BOOT_ADD0 is set to 0x0800, I can successfully program the byte to 0x1FF0, however when I upload the binary file with the instruction to program the option byte back to 0x0800, it doesn't work.

Here's a strange detail: When I run the debugger to check the values of the variables, the option bytes are programmed correctly. Then I check if the option bytes were effectively changed recurring to ST-Link utility and it works fine. If I don't run the debugger, the option bytes are not updated.

Here's the code I'm using:

/*INITIALIZE THE OPTION BYTES STRUCTURE AND OPTION BYTES CONFIG*/

FLASH_OBProgramInitTypeDef OBInit;

OBInit.OptionType = OPTIONBYTE_USER;

OBInit.BootConfig = OB_BOOT_ADD_BOTH;   /*!< Specifies if the Boot Address to be

 OBInit.BootAddr0 = value; //* where value= 0x0800000 or 0x1FF00000*//

OBInit.BootAddr1 = 0x1FF00000;

 /* ALLOW ACCESS TO FLASH AND OPTION BYTES SECTOR */

 HAL_FLASH_Unlock();

HAL_FLASH_OB_Unlock();

 FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE, FLASH_BANK_1); //not sure if it's required//

 FLASH_OB_BootAddConfig(OB_BOOT_ADD_BOTH,value,0x1FF00000); 

  

 FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE, FLASH_BANK_1);

 HAL_FLASHEx_OBGetConfig(&OBInit);

 HAL_FLASH_OB_Launch();

FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE, FLASH_BANK_1);

 /* Erase FLASH sectors */

 startSector = 0U; //setor 8

 endSector = 127U; //setor 127

 /* Fill EraseInit structure*/

 FLASH_EraseInitTypeDef EraseInitStruct;

 EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;

 EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3;

 EraseInitStruct.Sector = startSector;

 EraseInitStruct.NbSectors = endSector - startSector + 1;

 FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE, FLASH_BANK_1);

 HAL_FLASHEx_OBGetConfig(&OBInit);

 FLASH_OB_GetBootAdd(&(OBInit.BootAddr0), &(OBInit.BootAddr1));

 HAL_FLASH_OB_Launch();

  HAL_FLASHEx_OBProgram(&OBInit);

 HAL_FLASH_OB_Lock();

 HAL_FLASH_Lock();

//----------------------------------------------------------------------------------------------------------------------//

Resume:

1) truestudio compiles and generates the .bin file value=0x08000000 to program BOOT_ADD0 = 0x0800;

2) I upload the .bin file to the microcontroller and I use ST-Link Utility to check the value of the option bytes.

3) BOOT_ADD0 was not updated to 0x0800. It remains at 0x1FF0 (defined previously)

4) Go back to true studio, run the debugger and the bytes seem to be set successfully.

5) Upload the .bin again without making any changes and St-Link Utility shows that the option bytes were programmed succssfully after running the debugger.

6) when the BOOT_ADD0 is set to 0x800 and I upload the .bin file with the instructions to set it to 0x1FF0 it works fine without the necessity to run the debugger for the code to work.

Does anyone have a clue how can I solve this issue?

1 REPLY 1
ASá.1
Associate

I changed the compiler optimization level to: None and now it works fine.