Skip to content

Commit

Permalink
arch: arm: cortex-m: enable IRQs before main() in single-thread mode
Browse files Browse the repository at this point in the history
Enable interrupts before switching to main()
in cortex-m builds with single-thread mode
(CONFIG_MULTITHREADING=n).

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
  • Loading branch information
ioannisg committed Sep 29, 2020
1 parent 3aea86e commit 3b89cf1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
8 changes: 8 additions & 0 deletions arch/arm/core/aarch32/thread.c
Expand Up @@ -477,6 +477,14 @@ FUNC_NORETURN void z_arm_switch_to_main_no_multithreading(
"msr PSPLIM, %[_psplim]\n\t"
#endif
"msr PSP, %[_psp]\n\t" /* __set_PSP(psp) */
#if defined(CONFIG_ARMV6_M_ARMV8_M_BASELINE)
"cpsie i\n\t" /* enable_irq() */
#elif defined(CONFIG_ARMV7_M_ARMV8_M_MAINLINE)
"cpsie if\n\t" /* __enable_irq(); __enable_fault_irq() */
"mov r3, #0\n\t"
"msr BASEPRI, r3\n\t" /* __set_BASEPRI(0) */
#endif
"isb\n\t"
"blx %[_main_entry]\n\t" /* main_entry(p1, p2, p3) */
#if defined(CONFIG_ARMV6_M_ARMV8_M_BASELINE)
"cpsid i\n\t" /* disable_irq() */
Expand Down
2 changes: 1 addition & 1 deletion tests/arch/arm/arm_no_multithreading/README.txt
Expand Up @@ -9,7 +9,7 @@ ARM Cortex-M targets. In detail the test verifies that
- PSP points to the main stack
- PSPLIM is set to the main stack base (if applicable)
- FPU state is reset (if applicable)
- Interrupts are disabled when switching to main()
- Interrupts are enabled when switching to main()
- Interrupts may be registerd and serviced

---------------------------------------------------------------------------
Expand Down
7 changes: 3 additions & 4 deletions tests/arch/arm/arm_no_multithreading/src/main.c
Expand Up @@ -52,11 +52,10 @@ void test_main(void)
#endif

int key = arch_irq_lock();
__ASSERT(!arch_irq_unlocked(key),
"IRQs unlocked in main()");
__ASSERT(arch_irq_unlocked(key),
"IRQs locked in main()");

/* Enable interrupts unconditionally */
arch_irq_unlock(0);
arch_irq_unlock(key);

/* Determine an NVIC IRQ line that is not currently in use. */
int i, flag = test_flag;
Expand Down

0 comments on commit 3b89cf1

Please sign in to comment.