cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H setting security bit fails

Bart_
Associate II

I am trying to set the SECURITY bit on a STM32H7B3ZITX using STM32CubeProgrammer (v2.10.0). But it fails, see attached screenshot. 

I also tried setting the bit using the firmware. This does not produce any errors, but the bit is still not set. Following code is used for that:

 FLASH_OBProgramInitTypeDef sFlashOptionBytes;
(void) HAL_FLASHEx_OBGetConfig(&sFlashOptionBytes);

/* Set the security bit if needed */
/* ------------------------------ */
if ((sFlashOptionBytes.USERConfig & FLASH_OPTSR_SECURITY) == RESET)
{
sFlashOptionBytes.Banks = FLASH_BANK_1;
sFlashOptionBytes.OptionType = OPTIONBYTE_USER;
sFlashOptionBytes.USERType = OB_USER_SECURITY;
sFlashOptionBytes.USERConfig = OB_SECURITY_ENABLE;

if (HAL_FLASHEx_OBProgram(&sFlashOptionBytes) == HAL_OK)
{
printf("Security bit set.\n");
HAL_FLASH_OB_Launch();
}
else
{
printf("Cannot set the security bit - ERROR\n");
}
}
 
I see the message "Security bit set.", but checking with STMCubeProgrammer shows the bit is not set. 

Has anyone any ideas what can be wrong?
 
 
3 REPLIES 3
Issamos
Lead II

Hello @Bart_ 

This post may help you to verify your code.

Best regards.

II

Thank you @Issamos, the code looks identical to my code. I Think I copied it from the same place.
Also setting the bit using the CubeProgrammer fails, so maybe I am missing some kind of precondition.

Bart_
Associate II

I have now tested with multiple boards. We have boards with different batches of the STM32H7 chip (same version but different production dates). Some chips report bootloader version 0x92 (see attached image), this are also the chips where setting the SECURITY bit fails. 

All other boards that report bootloader version 0x91 work properly.