Define atomic macros for C++ project to fix nuttx/spinlock.h compilat… - #19754
Open
teamprof wants to merge 2 commits into
Open
Define atomic macros for C++ project to fix nuttx/spinlock.h compilat…#19754teamprof wants to merge 2 commits into
teamprof wants to merge 2 commits into
Conversation
acassis
previously approved these changes
Aug 8, 2026
|
Contributor
|
@xiaoxiang781216 PTAL |
cederom
requested changes
Aug 9, 2026
cederom
left a comment
Contributor
There was a problem hiding this comment.
Thank you @teamprof :-)
- Please fix the git commit according to https://nuttx.apache.org/docs/latest/contributing/guide.html#commit-requirements.
- Please fix minor code forma issue reported by ci/checkpatch (see https://nuttx.apache.org/docs/latest/contributing/coding_style.html).
- PR description does not seem to cover use case in NuttX, please update (specifically description + testing section).
Contributor
|
Also please provide logs in a plaintext form not images.. |
Author
|
changed to text log, thanks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
