Skip to content

boards/arm/stm32*/: Align ARM STM32 idle stack#18569

Open
pbarada wants to merge 1 commit intoapache:masterfrom
pbarada:test/unaligned-idlestack
Open

boards/arm/stm32*/: Align ARM STM32 idle stack#18569
pbarada wants to merge 1 commit intoapache:masterfrom
pbarada:test/unaligned-idlestack

Conversation

@pbarada
Copy link
Contributor

@pbarada pbarada commented Mar 20, 2026

This patch fixes [BUG #18558] for STM32 variants by aligning _ebss symbol(used as base of idle stack) in linker files to 8-byte boundary to conform to AAPCS-32. This PR does not address all possible ARM cases where idles tack does not align to AAPCS-32.

Summary

Currently STM32 builds use _ebss symbol (located at end of .bss linker section) as the base address of the idle stack, but _ebss is not aligned to AAPCS-32 required 8-byte boundary. Normally this isn't an issue but vararg processing by GCC forcibly aligns accesses of long long on 8-byte boundaries causing remaining varargs to be misaligned. Depending on stack content this bug can cause an exception.

While adding code to remove the "Missing logic" warning in stm32_irq.c:152 I ran into a bus fault exception while calling syslog() from stm32_dumpnvic during startup(which uses the idle stack) on a nucleo-stm32h743zi2 board(based on stm32h7). This was also observed on nucleo-f446re(stm32) and nuclio-f767zi(stm32f7) when configured to have an unaligned idle stack.

The fix is to force _ebss alignment to an 8-byte boundary in the linker files.

Impact

If _ebss is not aligned on an 8-byte boundary then any varag processing in the idle task (e.g. syslog message with timestamps) can cause an exception. This issue I believe potentially affects a vast majority of 32-bit ARM ports(arm64 looks to use a separate properly aligned section for the idle stack).

Testing

Build Host:

OS: Ubuntu 24.04.4 LTS
Compiler: arm-none-eabi-gcc 13.2.1

Target:

Architecture: ARM (STM32H7x3ZIx)
Board: Nucleo-h743zi2
Configuration: Default nucleo-h743zi2:jumbo 

Architecture: ARM (STM32F767ZITx)
Board: Nucleo-f767zi
Configuration: Default nucleo-h767zi:nsh

Architecture: ARM (STM32F446RETx)
Board: Nucleo-f446re
Configuration: Default nucleo-f446re:nsh 

in 'make menuconfig' enable ARCH_IRQPRIO, DEBUG_FEATURES, DEBUG_IRQ, DEBUG_IRQ_INFO, then built/booted(log for nucleo-h743zi2 shown) to have syslog messages called from idle task:

NuttShell (NSH) NuttX-12.12.0
nsh> uname -a
NuttX  12.12.0 43c15b3ddb-dirty Mar 20 2026 10:47:30 arm nucleo-h743zi2
nsh> dmesg
[    0.000000] [  INFO] Idle_Task: stm32_dumpnvic: NVIC (initial, irq=179):
[    0.000000] [  INFO] Idle_Task: stm32_dumpnvic:   INTCTRL:    00000000 VECTAB:  08000000
[    0.000000] [  INFO] Idle_Task: stm32_dumpnvic:   IRQ ENABLE: 00000000 00000000 00000000
[    0.000000] [  INFO] Idle_Task: stm32_dumpnvic:   SYSH_PRIO:  00808080 70000000 80800080
[    0.000000] [  INFO] Idle_Task: stm32_dumpnvic:   IRQ PRIO:   80808080 80808080 80808080 80808080
[    0.000000] [  INFO] Idle_Task: stm32_dumpnvic:               80808080 80808080 80808080 80nsh>


Repeated on nucleo-f767zi and nucleo-f446re.

This patch fixes [BUG apache#18558] for stm32 by aligning _ebss symbol(used
as base of idle stack) in linker files to 8-byte boundary to conform
to AAPCS-32.

Signed-off-by: Peter Barada <peter.barada@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Board: arm Size: M The size of the change in this PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants