This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit f1714ad9e7a42c3831e1d1928ba25bdfa7c85e4d Author: Kerogit <[email protected]> AuthorDate: Tue Oct 13 00:41:40 2026 +0200 arch/avr/src/avr/excptmacros.h: reorder stack pointer write According to their documentation, older AVR chips do not handle stack pointer write in any special way. The newer chips (DA/DB family) on the other hand disable interrupts in hardware when stack pointer low byte is written, making sure that the program has time to also write stack pointer high byte. NuttX already assigns the stack pointer with interrupts disabled but there is no reason to not do the write as intended. The change is only in effect for the newer family and does not affect the older chips. (Compiled binary is identical.) Signed-off-by: Kerogit <[email protected]> --- arch/avr/src/avr/excptmacros.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/arch/avr/src/avr/excptmacros.h b/arch/avr/src/avr/excptmacros.h index d0973e175c5..b99ef194329 100644 --- a/arch/avr/src/avr/excptmacros.h +++ b/arch/avr/src/avr/excptmacros.h @@ -489,10 +489,29 @@ /* Fetch and set the new stack pointer */ +#ifdef CONFIG_ARCH_CHIP_AVRDX + /* AVR128DA28/32/48/64 datasheet rev C, section 6.4.4 + * Write to SPL automatically disables interrupts for up to four + * instructions or until next I/O memory write, whichever comes first. + * + * This should run with interrupts disabled but let's order the write + * as intended. + */ + + ld r25, x+ /* Fetch stack pointer (post-incrementing) */ + ld r24, x+ + out _SFR_IO_ADDR(SPL), r24 /* (SPL first) */ + out _SFR_IO_ADDR(SPH), r25 +#else + /* According to the datasheet of ATmega1284, the older chips do not care + * about ordering of writes. Old code kept unchanged. + */ + ld r25, x+ /* Fetch stack pointer (post-incrementing) */ out _SFR_IO_ADDR(SPH), r25 /* (SPH then SPL) */ ld r24, x+ out _SFR_IO_ADDR(SPL), r24 +#endif /* Fetch the return address and save it at the bottom of the new stack so * that we can iret to switch contexts. The new stack is now:
