Skip to content

CMake Build Support for arch/arm/rp2040 & Raspberry Pi Pico #16212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

roskuttan
Copy link
Contributor

@roskuttan roskuttan commented Apr 15, 2025

Summary

This change introduces CMake build support for the Raspberry Pi Pico board in Apache NuttX to provide an alternative build system widely used in modern embedded development, enhancing accessibility and maintainability.
The functional part of the code being changed includes the build configuration for the RP2040 architecture and the Raspberry Pi Pico board.
This work is inspired by existing CMake implementations for other boards in the NuttX ecosystem.

Impact

New Feature Added?: YES - Adds CMake build support as an optional build method for the Raspberry Pi Pico.
Impact on User: YES - Users familiar with CMake can adopt this build method, but the existing Make-based system remains unaffected.
Impact on Build: YES - Introduces an alternative build process requiring CMake installation, with potential configuration adjustments (see Testing).
Impact on Hardware: YES - Specific to the Raspberry Pi Pico and RP2040 architecture, with no impact on other hardware.
Impact on Documentation: NO - As there is existing documentation demonstrates the use of cmake in nuttx
Impact on Security: NO - No security implications as this is a build system enhancement.
Impact on Compatibility: YES - Intended to be compatible with existing builds, but current issues prevent full compatibility (see Testing).

Testing

  • Build Host(s): OS (Ubuntu 24.04 on WSL), CPU (x86_64), compiler (arm-none-eabi-gcc), etc.
  • Target(s): arch (ARM), board:config (Raspberry Pi Pico with nsh configuration), etc.
  • Steps to reproduce:
    • Configure the board using cmake -B build -DBOARD_CONFIG=raspberrypi-pico:nsh -GNinja
    • Build using cmake --build build -t clean -j12 && cmake --build build -j12

Testing logs :

roskuttan@SILENT-KILLERED:~/nuttx_pr/nuttx$ cmake --build build -t clean -j12 && cmake --build build -j12
[1/1] Cleaning all built files...
Cleaning... 0 files.
[1029/1041] Building C object boards/CMakeFiles/board.dir/arm/rp2040/common/src/rp2040_common_bringup.c.obj
FAILED: boards/CMakeFiles/board.dir/arm/rp2040/common/src/rp2040_common_bringup.c.obj
/usr/bin/arm-none-eabi-gcc -D__KERNEL__ -D__NuttX__ -I/home/roskuttan/nuttx_pr/nuttx/arch/arm/src/rp2040 -I/home/roskuttan/nuttx_pr/nuttx/arch/arm/src/common -I/home/roskuttan/nuttx_pr/nuttx/arch/arm/src/armv6-m -I/home/roskuttan/nuttx_pr/nuttx/sched -I/home/roskuttan/nuttx_pr/nuttx/boards/arm/rp2040/common/include -isystem /home/roskuttan/nuttx_pr/nuttx/include -isystem /home/roskuttan/nuttx_pr/nuttx/build/include -mcpu=cortex-m0 -mthumb -mfloat-abi=soft --param=min-pagesize=0 -fno-common -Wall -Wshadow -Wundef -nostdlib -Os -fno-strict-aliasing -fomit-frame-pointer -Wa,-mthumb -Wa,-mimplicit-it=always -ffunction-sections -fdata-sections -g -Wno-attributes -Wno-unknown-pragmas -Wstrict-prototypes -Wno-psabi -fdiagnostics-color=always -DNDEBUG -fmacro-prefix-map=/home/roskuttan/nuttx_pr/nuttx= -fmacro-prefix-map=/home/roskuttan/nuttx_pr/nuttx/dummy= -fmacro-prefix-map=/home/roskuttan/nuttx_pr/nuttx/boards/arm/rp2040/raspberrypi-pico= -fmacro-prefix-map=/home/roskuttan/nuttx_pr/nuttx/arch/arm/src/rp2040= @boards/CMakeFiles/board.dir/arm/rp2040/common/src/rp2040_common_bringup.c.obj.rsp -MD -MT boards/CMakeFiles/board.dir/arm/rp2040/common/src/rp2040_common_bringup.c.obj -MF boards/CMakeFiles/board.dir/arm/rp2040/common/src/rp2040_common_bringup.c.obj.d -o boards/CMakeFiles/board.dir/arm/rp2040/common/src/rp2040_common_bringup.c.obj -c /home/roskuttan/nuttx_pr/nuttx/boards/arm/rp2040/common/src/rp2040_common_bringup.c
/home/roskuttan/nuttx_pr/nuttx/boards/arm/rp2040/common/src/rp2040_common_bringup.c:39:10: fatal error: rp2040_pico.h: No such file or directory
   39 | #include "rp2040_pico.h"
      |          ^~~~~~~~~~~~~~~
compilation terminated.
[1030/1041] Building C object boards/CMakeFiles/board.dir/arm/rp2040/common/src/rp2040_uniqueid.c.obj
FAILED: boards/CMakeFiles/board.dir/arm/rp2040/common/src/rp2040_uniqueid.c.obj
/usr/bin/arm-none-eabi-gcc -D__KERNEL__ -D__NuttX__ -I/home/roskuttan/nuttx_pr/nuttx/arch/arm/src/rp2040 -I/home/roskuttan/nuttx_pr/nuttx/arch/arm/src/common -I/home/roskuttan/nuttx_pr/nuttx/arch/arm/src/armv6-m -I/home/roskuttan/nuttx_pr/nuttx/sched -I/home/roskuttan/nuttx_pr/nuttx/boards/arm/rp2040/common/include -isystem /home/roskuttan/nuttx_pr/nuttx/include -isystem /home/roskuttan/nuttx_pr/nuttx/build/include -mcpu=cortex-m0 -mthumb -mfloat-abi=soft --param=min-pagesize=0 -fno-common -Wall -Wshadow -Wundef -nostdlib -Os -fno-strict-aliasing -fomit-frame-pointer -Wa,-mthumb -Wa,-mimplicit-it=always -ffunction-sections -fdata-sections -g -Wno-attributes -Wno-unknown-pragmas -Wstrict-prototypes -Wno-psabi -fdiagnostics-color=always -DNDEBUG -fmacro-prefix-map=/home/roskuttan/nuttx_pr/nuttx= -fmacro-prefix-map=/home/roskuttan/nuttx_pr/nuttx/dummy= -fmacro-prefix-map=/home/roskuttan/nuttx_pr/nuttx/boards/arm/rp2040/raspberrypi-pico= -fmacro-prefix-map=/home/roskuttan/nuttx_pr/nuttx/arch/arm/src/rp2040= @boards/CMakeFiles/board.dir/arm/rp2040/common/src/rp2040_uniqueid.c.obj.rsp -MD -MT boards/CMakeFiles/board.dir/arm/rp2040/common/src/rp2040_uniqueid.c.obj -MF boards/CMakeFiles/board.dir/arm/rp2040/common/src/rp2040_uniqueid.c.obj.d -o boards/CMakeFiles/board.dir/arm/rp2040/common/src/rp2040_uniqueid.c.obj -c /home/roskuttan/nuttx_pr/nuttx/boards/arm/rp2040/common/src/rp2040_uniqueid.c
/home/roskuttan/nuttx_pr/nuttx/boards/arm/rp2040/common/src/rp2040_uniqueid.c:89:27: error: 'CONFIG_BOARDCTL_UNIQUEID_SIZE' undeclared here (not in a function)
   89 | static uint8_t g_uniqueid[CONFIG_BOARDCTL_UNIQUEID_SIZE];
      |                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/roskuttan/nuttx_pr/nuttx/boards/arm/rp2040/common/src/rp2040_uniqueid.c:89:16: warning: 'g_uniqueid' defined but not used [-Wunused-variable]
   89 | static uint8_t g_uniqueid[CONFIG_BOARDCTL_UNIQUEID_SIZE];
      |                ^~~~~~~~~~
[1037/1041] Building C object boards/CMakeFiles/board.dir/arm/rp2040/raspberrypi-pico/src/rp2040_gpio.c.obj
ninja: build stopped: subcommand failed.

@github-actions github-actions bot added Arch: arm Issues related to ARM (32-bit) architecture Board: arm Size: M The size of the change in this PR is medium labels Apr 15, 2025
@nuttxpr
Copy link

nuttxpr commented Apr 15, 2025

[Experimental Bot, please feedback here]

This PR does not fully meet the NuttX requirements yet, specifically in the Testing section. While the PR author has provided details about their build environment and reproduction steps, the build fails. A successful build and accompanying logs demonstrating the functionality are essential before the PR can be considered complete.

Here's a breakdown of what needs to be addressed:

  • Build Errors: The CMake build fails with compilation errors. The logs show:

    • rp2040_pico.h: No such file or directory: This suggests an issue with include paths in the CMake configuration. The build system can't find this required header file.
    • 'CONFIG_BOARDCTL_UNIQUEID_SIZE' undeclared: This indicates a missing configuration option. This macro likely needs to be defined either in the board's defconfig or passed as a CMake option.
  • Missing "Before Change" Logs: The template requests logs from before the change was implemented. These logs are crucial for demonstrating the original behavior and highlighting the improvement introduced by the PR.

  • Incomplete Testing: Even if the build succeeded, the logs don't demonstrate that the CMake build works as intended. The PR needs to show that the resulting binary functions correctly on the target hardware. This might involve output from nsh or other tests demonstrating the board's functionality.

Recommendations for the PR Author:

  1. Fix Build Errors: Address the compilation errors highlighted in the logs. Double-check include directories, macro definitions, and any dependencies required for the Raspberry Pi Pico board.
  2. Provide "Before Change" Logs: Run the existing build system (presumably Make-based) and capture the output. This establishes a baseline for comparison.
  3. Demonstrate Functionality: After fixing the build, show that the CMake-built firmware works. Include logs from the target demonstrating successful initialization and operation. Consider adding a simple test application to exercise the core functionality of the board.
  4. Consider Compatibility Issues: The author mentions compatibility issues preventing full compatibility. These issues need to be explicitly described and, if possible, addressed. If full compatibility isn't achievable yet, explain the limitations and any plans for future improvements.

By addressing these points, the PR will better meet the NuttX requirements and be ready for review.

@roskuttan
Copy link
Contributor Author

I don't see any rp2040_pico.h in the nuttx/boards/arm/rp2040/common/include i think that what causing this error.

roskuttan@SILENT-KILLERED:~/nuttx_pr/nuttx$ cmake --build build -t clean -j12 && cmake --build build -j12
[1/1] Cleaning all built files...
Cleaning... 0 files.
[1027/1039] Building C object boards/CMakeFiles/board.dir/arm/rp2040/common/src/rp2040_common_bringup.c.obj
FAILED: boards/CMakeFiles/board.dir/arm/rp2040/common/src/rp2040_common_bringup.c.obj
/usr/bin/arm-none-eabi-gcc -D__KERNEL__ -D__NuttX__ -I/home/roskuttan/nuttx_pr/nuttx/arch/arm/src/rp2040 -I/home/roskuttan/nuttx_pr/nuttx/arch/arm/src/common -I/home/roskuttan/nuttx_pr/nuttx/arch/arm/src/armv6-m -I/home/roskuttan/nuttx_pr/nuttx/sched -I/home/roskuttan/nuttx_pr/nuttx/boards/arm/rp2040/common/include -isystem /home/roskuttan/nuttx_pr/nuttx/include -isystem /home/roskuttan/nuttx_pr/nuttx/build/include -mcpu=cortex-m0 -mthumb -mfloat-abi=soft --param=min-pagesize=0 -fno-common -Wall -Wshadow -Wundef -nostdlib -Os -fno-strict-aliasing -fomit-frame-pointer -Wa,-mthumb -Wa,-mimplicit-it=always -ffunction-sections -fdata-sections -g -Wno-attributes -Wno-unknown-pragmas -Wstrict-prototypes -Wno-psabi -fdiagnostics-color=always -DNDEBUG -fmacro-prefix-map=/home/roskuttan/nuttx_pr/nuttx= -fmacro-prefix-map=/home/roskuttan/nuttx_pr/nuttx/dummy= -fmacro-prefix-map=/home/roskuttan/nuttx_pr/nuttx/boards/arm/rp2040/raspberrypi-pico= -fmacro-prefix-map=/home/roskuttan/nuttx_pr/nuttx/arch/arm/src/rp2040= @boards/CMakeFiles/board.dir/arm/rp2040/common/src/rp2040_common_bringup.c.obj.rsp -MD -MT boards/CMakeFiles/board.dir/arm/rp2040/common/src/rp2040_common_bringup.c.obj -MF boards/CMakeFiles/board.dir/arm/rp2040/common/src/rp2040_common_bringup.c.obj.d -o boards/CMakeFiles/board.dir/arm/rp2040/common/src/rp2040_common_bringup.c.obj -c /home/roskuttan/nuttx_pr/nuttx/boards/arm/rp2040/common/src/rp2040_common_bringup.c
/home/roskuttan/nuttx_pr/nuttx/boards/arm/rp2040/common/src/rp2040_common_bringup.c:39:10: fatal error: rp2040_pico.h: No such file or directory
   39 | #include "rp2040_pico.h"
      |          ^~~~~~~~~~~~~~~
compilation terminated.
[1036/1039] Linking C static library libs/libc/libc.a
ninja: build stopped: subcommand failed.

@roskuttan roskuttan requested a review from simbit18 April 16, 2025 10:57
@simbit18
Copy link
Contributor

simbit18 commented Apr 16, 2025

@roskuttan Why are your Cmakefiles not aligned with Make.defs?

I created a branch for building rp2040 with CMake seems to work.
(I also commented #include rp2040_pico.h in rp2040_common_bringup.c.)
You also need this fix #16227 (already included in my branch)

master...simbit18:nuttx:simbit18-rp2040

I don't have a Raspberry Pi Pico board so you have to do the tests.

Build CMake
[1113/1114] Linking C executable nuttx
Memory region         Used Size  Region Size  %age Used
           flash:        148 KB         2 MB      7.23%
            sram:        8336 B       264 KB      3.08%
[1114/1114] Generating System.map


Build make
LD: nuttx
Memory region         Used Size  Region Size  %age Used
           flash:        148 KB         2 MB      7.23%
            sram:        8344 B       264 KB      3.09%
PICO_SDK_PATH/picotool must be specified/installed for flash boot

Copy link
Contributor

@simbit18 simbit18 left a comment

Choose a reason for hiding this comment

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

@roskuttan You must take the Make.defs file as a reference.
CMake must be aligned with Make.

e.g. these files
boards/arm/rp2040/common/src/Make.defs
boards/arm/rp2040/common/src/CMakeLists.txt
are not aligned.

The behaviour of CMake must be the same as Make.
Otherwise maintenance becomes a circle of Hell.

This tool nxmake2cmake.py by @raiden00pl can help you speed up the process of converting to CMake.
#9782

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arch: arm Issues related to ARM (32-bit) architecture 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.

4 participants