Skip to content

Define atomic macros for C++ project to fix nuttx/spinlock.h compilat… - #19754

Open
teamprof wants to merge 2 commits into
apache:masterfrom
teamprof:master
Open

Define atomic macros for C++ project to fix nuttx/spinlock.h compilat…#19754
teamprof wants to merge 2 commits into
apache:masterfrom
teamprof:master

Conversation

@teamprof

@teamprof teamprof commented Aug 8, 2026

Copy link
Copy Markdown

Issue

Fail to build Pi Pico NuttX C++ project with SMP feature as <nuttx/spinlock.h> is a C header that uses raw macro calls (atomic_cmpxchg_acquire(...)).

Summary

Failed to build a Pi Pico C++ project with SMP enabled due to the missing atomic marcos for nuttx/spinlock.h
Define atomic macros for C++ project to fix nuttx/spinlock.h compilation issue

Impact

Failed to build a Pi Pico (RP2040) C++ project with the SMP feature enabled. Notably, robust SMP support on the RP2040 is a key feature that encourages developers to choose NuttX over other RTOS options.

Testing

Follow the steps on https://github.com/teamprof/arduprof-template/tree/main/pico-nuttx-app to create a C++ project:
git clone --recurse-submodules https://github.com/teamprof/arduprof-template.gif
cd arduprof-template/pico-nuttx-app
ln -s ../src apps/arduprof
cd nuttx
./tools/configure.sh -l ../src/boards/arm/rp2040/raspberrypi-pico/configs/smp
make

Launch a Serial Terminal and connect to Pico's GPIO0/1 at 115200bps
Run "arduprof" under nsh in the terminal

Before

LN: platform/board to /home/teamprof/prj/arduino/arduprof-template/pico-nuttx-app/apps/platform/dummy
Register: arduprof
Register: hello
Register: dd
Register: nsh
Register: sh
Register: taskset
Register: ostest
Register: getprime
Register: smp
CXX: AppContext.cxx In file included from ././../lib/arduprof/src/./os/nuttx/thread/.././MessageQueue.h:29,
from ././../lib/arduprof/src/./os/nuttx/thread/../MessageBus.h:28,
from ././../lib/arduprof/src/./os/nuttx/thread/ThreadBase.h:28,
from ././../lib/arduprof/src/ArduProf.h:77,
from ././ArduProfApp.h:59,
from ./AppContext.h:22,
from AppContext.cxx:21:
/home/teamprof/prj/arduino/arduprof-template/pico-nuttx-app/nuttx/include/nuttx/spinlock.h: In function 'void rspin_lock(rspinlock_t*)':
/home/teamprof/prj/arduino/arduprof-template/pico-nuttx-app/nuttx/include/nuttx/spinlock.h:614:11: error: 'atomic_cmpxchg_acquire' was not declared in this scope
614 | while (!atomic_cmpxchg_acquire((FAR atomic_t )&lock->val,
| ^~~~~~~~~~~~~~~~~~~~~~
/home/teamprof/prj/arduino/arduprof-template/pico-nuttx-app/nuttx/include/nuttx/spinlock.h: In function 'bool rspin_trylock(rspinlock_t
)':
/home/teamprof/prj/arduino/arduprof-template/pico-nuttx-app/nuttx/include/nuttx/spinlock.h:687:10: error: 'atomic_cmpxchg_acquire' was not declared in this scope
687 | return atomic_cmpxchg_acquire((FAR atomic_t )&lock->val,
| ^~~~~~~~~~~~~~~~~~~~~~
/home/teamprof/prj/arduino/arduprof-template/pico-nuttx-app/nuttx/include/nuttx/spinlock.h: In function 'bool rspin_unlock(rspinlock_t
)':
/home/teamprof/prj/arduino/arduprof-template/pico-nuttx-app/nuttx/include/nuttx/spinlock.h:914:7: error: 'atomic_set_release' was not declared in this scope
914 | atomic_set_release((FAR atomic_t )&lock->val, 0);
| ^~~~~~~~~~~~~~~~~~
././../lib/arduprof/src/./os/nuttx/thread/.././MessageQueue.h: In member function 'void nuttxos::MessageQueue::postEvent(void
, const Message&, int)':
././../lib/arduprof/src/./os/nuttx/thread/.././MessageQueue.h:146:51: error: '_lock_pool' was not declared in this scope
146 | irqstate_t flags = spin_lock_irqsave(&_lock_pool);
| ^~~~~~~~~~
././../lib/arduprof/src/./os/nuttx/thread/../MessageBus.h: In member function 'virtual void nuttxos::MessageBus::messageLoop(uint32_t)':
././../lib/arduprof/src/./os/nuttx/thread/../MessageBus.h:78:51: error: '_lock_pool' was not declared in this scope
78 | irqstate_t flags = spin_lock_irqsave(&_lock_pool);
| ^~~~~~~~~~
make[2]: *** [/home/teamprof/prj/arduino/arduprof-template/pico-nuttx-app/apps/Application.mk:268: AppContext.cxx.home.teamprof.prj.arduino.arduprof-template.pico-nuttx-app.src.app.o] Error 1
make[1]: *** [Makefile:54: /home/teamprof/prj/arduino/arduprof-template/pico-nuttx-app/apps/../src/app_all] Error 2
make: *** [tools/LibTargets.mk:248: /home/teamprof/prj/arduino/arduprof-template/pico-nuttx-app/apps/libapps.a] Error 2

After
~/prj/arduino/arduprof-template/pico-nuttx-app/nuttx$ make
CPP: /home/teamprof/prj/arduino/arduprof-template/pico-nuttx-app/nuttx/boards/arm/rp2040/raspberrypi-pico/scripts/raspberrypi-pico-flash.ld-> /home/teamprof/prj/arduino/arduprof-template/pico-nuttx-app/nuttx/boards/arm/rp20LD: nuttx
Memory region Used Size Region Size %age Used
flash: 196 KB 2 MB 9.57%
sram: 14320 B 264 KB 5.30%
Generating: nuttx.uf2
Done.

minicom screenshot of running on Pi Pico
run-pico-smp

acassis
acassis previously approved these changes Aug 8, 2026
@github-actions github-actions Bot added Area: OS Components OS Components issues Size: M The size of the change in this PR is medium labels Aug 8, 2026
@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

arduino-mega2560

  • flash: .text +138 B (+0.2%, 67,622 B / 262,144 B, total: 26% used)

esp32-devkitc

  • ROM: .flash.text -12 B (-0.0%, 124,396 B / 4,194,272 B, total: 3% used)
  • irom0_0_seg: .flash.text -12 B (-0.0%, 88,600 B / 3,342,304 B, total: 3% used)

hifive1-revb

  • flash: .text -56 B (-0.1%, 83,372 B / 4,194,304 B, total: 2% used)
  • sram: .bss +32 B (+0.8%, 3,964 B / 16,384 B, total: 24% used)

mirtoo

  • kseg0_progmem: .text -64 B (-0.1%, 67,476 B / 131,072 B, total: 51% used)

qemu-armv8a

  • Code: .rodata -306 B, .text.nxsched_release_tcb +8 B, .text.nxsig_timedwait +12 B, .text.nxtask_exit +12 B, .text.pthread_start -4 B, .text.uart_writev +28 B, .text.up_initial_state -4 B, .text.user_main -16 B (-0.7%, 316,716 B)
  • Data: .bss.g_idletcb +8 B (+0.0%, 76,977 B)

qemu-intel64

  • Code: .text -1,736 B (-0.0%, 8,657,184 B)
  • Data: .bss +64 B, .rodata -214 B (-0.1%, 120,593 B)

rx65n-rsk2mb

  • ROM: .text +32 B (+0.0%, 87,296 B / 2,097,152 B, total: 4% used)

s698pm-dkit

  • Code: .text +176 B (+0.0%, 363,952 B)

stm32-nucleo-f103rb

  • flash: .text -8 B (-0.0%, 34,016 B / 131,072 B, total: 26% used)

@acassis
acassis requested review from cederom and linguini1 August 9, 2026 16:27
@acassis

acassis commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

@xiaoxiang781216 PTAL

@cederom cederom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you @teamprof :-)

@cederom

cederom commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Also please provide logs in a plaintext form not images..

something
like
this
for
example

@teamprof

Copy link
Copy Markdown
Author

changed to text log, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: OS Components OS Components issues 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.

3 participants