zephyr: Zephyr doesn't boot on STM32F4 (and probably other ARMv7-M cores)

Describe the bug Zephyr can’t boot on STM32F4 after #65071.

To Reproduce Build Zephyr and run on STM32F4

Expected behavior It boots

Impact Very high. Zephyr doesn’t work.

Logs and console output No logs are printed.

Environment (please complete the following information): N/A

Additional context Reverting https://github.com/zephyrproject-rtos/zephyr/commit/f11027df8061932ddf1209f985a67164d140f303 seems to fix the problem.

I compared assembly code and looks like commit above removed cpsie if instruction from arch_switch_to_main_thread(). For me, the following change fixes problem (ARMv7-M only!):

diff --git a/arch/arm/core/cortex_m/thread.c b/arch/arm/core/cortex_m/thread.c
index f9a030675b5..87900df9091 100644
--- a/arch/arm/core/cortex_m/thread.c
+++ b/arch/arm/core/cortex_m/thread.c
@@ -576,6 +576,7 @@ void arch_switch_to_main_thread(struct k_thread *main_thread, char *stack_ptr,
        "mov   r4,  %0\n"       /* force _main to be stored in a register */
        "msr   PSP, %1\n"       /* __set_PSP(stack_ptr) */
 
+       "cpsie if\n"            /* __enable_irq(); __enable_fault_irq() */
        "mov   r0,  #0\n"       /* arch_irq_unlock(0) */
        "ldr   r3, =arch_irq_unlock_outlined\n"
        "blx   r3\n

About this issue

  • Original URL
  • State: closed
  • Created 2 months ago
  • Reactions: 1
  • Comments: 15 (2 by maintainers)

Most upvoted comments

Are you happy closing this issue with the fix that was merged?

In my case, I’m jumping to Zephyr reset vector from another code (chain-loading) with interrupts disabled (cpsid i).

To reproduce issue without chain-loading you can use following code:

void z_arm_reset(void);

void test(void)
{
        __disable_irq();
        z_arm_reset();
}