Skip to content

stm32h7: synchronize cores properly during boot #90668

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

mathieuchopstm
Copy link
Collaborator

On dual-core STM32H7, the Cortex-M4 core is supposed to wait until the Cortex-M7 initializes the system before starting to execute. CM7 should signal this by locking a specific HSEM, which CM4 should poll until locked. However, the logic on the Cortex-M4 side was reading the HSEM_RLR register to obtain semaphore status, which locks the semaphore on read - in turn, this makes the CM4 start directly since it sees that the semaphore is locked (by itself).

Replace raw register read with call to proper LL API, which will read the HSEM_R register instead of HSEM_RLR, to make sure CM4 doesn't begin execution earlier than it should, and update the comments in soc_m4.c and soc_m7.c related to this boot process.

Fixes #86494 - confirmed working on STM32H747I-DISCO by flashing samples/basic/blinky on Cortex-M4 and samples/hello_world on Cortex-M7. With patch, the LED can be seen blinking only if CONFIG_STM32H7_DUAL_CORE=y (and CONFIG_STM32H7_BOOT_M4_AT_INIT=y if the BCM4 option byte is disabled) - without patch, the LED can be seen blinking in all scenarios if the BCM4 option byte is enabled.

First commit tidies stm32_hsem.h - mostly cosmetic changes, but I also removed the seemingly unused CFG_HW_ENTRY_STOP_MODE_MASK_SEMID define. This commit can be dropped if preferred.

Reorder the HSEM semaphore ID definitions to be sorted by ascending value.
The dummy defines are also changed to be sorted in the same order. The
definitions for STM32MP1 are already in an order that follows this order
so they don't need to be changed.

Signed-off-by: Mathieu Choplain <[email protected]>
Copy link
Collaborator

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For commit "soc: st: stm32: hsem: update description for fifth HSEM":
could you also mention in the commit message that you remove definition of macro CFG_HW_ENTRY_STOP_MODE_MASK_SEMID that is not used.

@mathieuchopstm mathieuchopstm force-pushed the stm32h7_dual_core_sync_cores branch from bc8bbb5 to 28440f0 Compare May 27, 2025 14:14
Copy link
Collaborator

@JarmouniA JarmouniA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nits, otherwise looks good!

The fifth HSEM (#define is equal to 4 due to zero-indexing) is used on
STM32H7 to synchronize the two cores. Update the comment above the SEMID
define to reflect this alternate usage. Also remove the associated define
CFG_HW_ENTRY_STOP_MODE_MASK_SEMID, which is unused.

Signed-off-by: Mathieu Choplain <[email protected]>
On dual-core STM32H7, the Cortex-M4 core is supposed to wait until the
Cortex-M7 initializes the system before starting to execute. CM7 should
signal this by locking a specific HSEM, which CM4 should poll until locked.
However, the logic on the Cortex-M4 side was reading the "RLR" register of
HSEM, which *locks the semaphore on read* - in turn, this makes the CM4
start directly since it sees that the semaphore is locked (by itself).

Use proper LL API to read HSEM status - which will read the "R" register
instead - to make sure CM4 doesn't begin execution earlier than it should.

Suggested-by: hglassdyb
Signed-off-by: Mathieu Choplain <[email protected]>
@mathieuchopstm mathieuchopstm force-pushed the stm32h7_dual_core_sync_cores branch from 28440f0 to 0362bab Compare June 4, 2025 08:31
@mathieuchopstm mathieuchopstm requested a review from JarmouniA June 4, 2025 08:32
Copy link

sonarqubecloud bot commented Jun 4, 2025

@kartben kartben merged commit 4282d67 into zephyrproject-rtos:main Jun 10, 2025
26 checks passed
@mathieuchopstm mathieuchopstm deleted the stm32h7_dual_core_sync_cores branch June 10, 2025 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: STM32 ST Micro STM32
Projects
None yet
Development

Successfully merging this pull request may close these issues.

STM32H747: Cortex-M4 core starting without waiting for semaphore
5 participants