cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H7 option byte programming

Mvan .31
Associate II

Hi,

I'm trying to change the boot order of the STM32H745 to gate the M7 core and boot the M4 core.

This works fine in ST-Link utility ofcourse.

Now I'm trying this in code and this seems to not work.

I think the issue is with setting the bit from high to low.

FLASH_OBProgramInitTypeDef OBInit;
HAL_FLASHEx_OBGetConfig(&OBInit);
 
log_info("Usertype: %08x", OBInit.USERType);
 
if (OBInit.USERType & OB_USER_BCM7) {
	log_info("Changing option bytes");
	OBInit.USERType &= ~OB_USER_BCM7;
	if (HAL_FLASH_OB_Unlock() == HAL_OK)
		if (HAL_FLASH_Unlock() == HAL_OK)
			if (HAL_FLASHEx_OBProgram(&OBInit) == HAL_OK)
				if (HAL_FLASH_OB_Launch() == HAL_OK)
					if (HAL_FLASH_OB_Lock() == HAL_OK)
						if (HAL_FLASH_Lock() == HAL_OK)
						{
							log_info("Option bytes changed");
							log_info("Requires rebooting");
							//NVIC_SystemReset();
							return;
						}
	log_info("Failed changing option bytes");

All functions result in HAL_OK but the value doesn't change.

Am I missing something?

Melvin

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

> OBInit.USERType &= ~OB_USER_BCM7;

I think you meant:

> OBInit.USERType = OB_USER_BCM7;

> OBInit.USERConfig = OB_BCM7_DISABLE;

What you posted makes no modification to BOOT_CM7.

Note that disabling the M7 core may make debugging harder, as it's the default access port for SWD.

edit: corrected a few typos

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

2 REPLIES 2
TDK
Guru

> OBInit.USERType &= ~OB_USER_BCM7;

I think you meant:

> OBInit.USERType = OB_USER_BCM7;

> OBInit.USERConfig = OB_BCM7_DISABLE;

What you posted makes no modification to BOOT_CM7.

Note that disabling the M7 core may make debugging harder, as it's the default access port for SWD.

edit: corrected a few typos

If you feel a post has answered your question, please click "Accept as Solution".
Mvan .31
Associate II

Ah yes that solved the issue.

Now I understand the UserType/UserConfig thing.

Yes it seems it makes debugging unusable. I changed the access port to "3 - Cortex-M4" but it still won't connect in STM32CubeIDE.

ST-Link will happily connect though on port 3.