开源RTOS(实时操作系统):nuttx 编译

发布于:2025-05-17 ⋅ 阅读:(19) ⋅ 点赞:(0)

开源RTOS(实时操作系统):nuttx 编译

手册:Installing — NuttX latest documentation

源码:GitHub - apache/nuttx: Apache NuttX is a mature, real-time embedded operating system (RTOS)

Installing

The first step to get started with NuttX is to install a series of required tools, a toolchain for the architecture you will be working with and, finally, download NuttX source code itself.

Prerequisites

First, install the following set of system dependencies according to your Operating System:

Linux (debian based)Linux (Fedora / RPM based)macOSWindows / WSLWindows/Cygwin

Run the following command to install packages:

$ sudo apt install \
$ bison flex gettext texinfo libncurses5-dev libncursesw5-dev xxd \
$ git gperf automake libtool pkg-config build-essential gperf genromfs \
$ libgmp-dev libmpc-dev libmpfr-dev libisl-dev binutils-dev libelf-dev \
$ libexpat1-dev gcc-multilib g++-multilib picocom u-boot-tools util-linux

KConfig frontend

NuttX configuration system uses KConfig which is exposed via a series of interactive menu-based frontends, part of the kconfig-frontends package. Depending on your OS you may use a precompiled package or you will have to build it from source, which is available in the NuttX tools repository:

Ubuntu 20.04 LTS and laterUbuntu 18.04 LTS and earlierFedoramacOS

$ sudo apt install kconfig-frontends

NuttX also supports kconfiglib by default, which is a Kconfig tool implemented in Python 2/3. Compared with kconfig-frontends, kconfiglib provides NuttX with the possibility of multi-platform support(configure NuttX in Windows native/Visual Studio), and also kconfiglib has a stronger Kconfig syntax check, this will help developers to avoid some Kconfig syntax errors. Install kconfiglib via following command:

sudo apt install python3-kconfiglib

If you are a working on Windows, which also need the support of windows-curses:

pip install windows-curses

Toolchain

To build Apache NuttX you need the appropriate toolchain according to your target platform. Some Operating Systems such as Linux distribute toolchains for various architectures. This is usually an easy choice however you should be aware that in some cases the version offered by your OS may have problems and it may be better to use a widely used build from another source.

The following example shows how to install a toolchain for ARM architecture:

Ubuntu (deb)macOSFrom arm.com

$ sudo apt install gcc-arm-none-eabi binutils-arm-none-eabi

Tip

There are hints on how to get the latest tool chains for most supported architectures in the Apache NuttX CI helper script and Docker container

Todo

Required toolchain should be part of each arch documentation (see relevant issue).

Download NuttX

Apache NuttX is actively developed on GitHub. There are two main repositories, nuttx and apps, where the latter is technically optional (but recommended for complete set of features). If you intend to contribute changes, you need the absolute latest version or you simply prefer to work using git, you should clone these repositories (recommended). Otherwise you can choose to download any stable release archive.

Clone git repositoriesDownload stable release

$ mkdir nuttxspace
$ cd nuttxspace
$ git clone https://github.com/apache/nuttx.git nuttx
$ git clone https://github.com/apache/nuttx-apps apps

The development source code is also available as a compressed archive, should you need it:

$ mkdir nuttxspace
$ cd nuttxspace
$ curl -L https://github.com/apache/nuttx/tarball/master -o nuttx.tar.gz
$ curl -L https://github.com/apache/nuttx-apps/tarball/master -o apps.tar.gz
$ tar zxf nuttx.tar.gz --one-top-level=nuttx --strip-components 1
$ tar zxf apps.tar.gz --one-top-level=apps --strip-components 1

There are also .zip archives available (useful for Windows users): just replace tarball with zipball.

在Windows10的WSL Ubuntu22.04环境下实践安装Nuttx 

首先进入WSL

安装基本库

sudo apt install \
bison flex gettext texinfo libncurses5-dev libncursesw5-dev xxd \
git gperf automake libtool pkg-config build-essential gperf genromfs \
libgmp-dev libmpc-dev libmpfr-dev libisl-dev binutils-dev libelf-dev \
libexpat1-dev gcc-multilib g++-multilib picocom u-boot-tools util-linux

 安装KConfig frontend

sudo apt install kconfig-frontends

安装工具链

sudo apt install gcc-arm-none-eabi binutils-arm-none-eabi

这个占用空间较大,需要2.5G空间

下载源代码

mkdir nuttxspace
cd nuttxspace
git clone https://github.com/apache/nuttx.git nuttx
git clone https://github.com/apache/nuttx-apps apps

如果github抽风,可以使用镜像加速

使用make进行编译

初始化配置

cd nuttx
./tools/configure.sh -L | less

哇塞,这个支持的实在太多了!光esp的就这么多:

  esp32c3-devkit:efuse
  esp32c3-devkit:watchdog
  esp32c3-devkit:pwm
  esp32c3-devkit:gdbstub
  esp32c3-devkit:module
  esp32c3-devkit:watcher
  esp32c3-devkit:wifi
  esp32c3-devkit:romfs
  esp32c3-devkit:tickless
  esp32c3-devkit:coremark
  esp32c3-devkit:sotest
  esp32c3-devkit:bmp180
  esp32c3-devkit:random
  esp32c3-devkit:rtc
  esp32c3-devkit:ble
  esp32c3-devkit:twai
  esp32c3-devkit:ostest
  esp32c3-devkit:usbconsole
  esp32c3-devkit:autopm
  esp32c3-devkit:oneshot
  esp32c3-devkit:pm
  esp32c3-devkit:knsh
  esp32c3-devkit:gpio
  esp32c3-devkit:nvcfgdata
  esp32c3-devkit:sta_softap
  esp32c3-devkit:nsh
  esp32c3-devkit:lvgl
  esp32c3-devkit:timer
  esp32c3-devkit:mcuboot_slot_confirm
  esp32c3-devkit:cxx
  esp32c3-devkit:spiflash
  esp32c3-devkit:crypto
  esp32c3-devkit:uid
  esp32c3-devkit:elf
  esp32c3-devkit:adc
  esp32c3-devkit-rust-1:nsh
  esp32c3-devkit-rust-1:brickmatch
  esp32h2-devkit:i2c
  esp32h2-devkit:efuse
  esp32h2-devkit:watchdog
  esp32h2-devkit:pwm
  esp32h2-devkit:timers
  esp32h2-devkit:tickless
  esp32h2-devkit:i2schar
  esp32h2-devkit:bmp180
  esp32h2-devkit:spi
  esp32h2-devkit:random
  esp32h2-devkit:rtc
  esp32h2-devkit:buttons
  esp32h2-devkit:twai
  esp32h2-devkit:ostest
  esp32h2-devkit:qencoder
  esp32h2-devkit:capture
  esp32h2-devkit:usbconsole
  esp32h2-devkit:motor
  esp32h2-devkit:gpio
  esp32h2-devkit:nsh
  esp32h2-devkit:temperature_sensor
  esp32h2-devkit:rmt
  esp32h2-devkit:spiflash
  esp32h2-devkit:sdm
  esp32h2-devkit:mcuboot_nsh
  esp32h2-devkit:adc
  esp32c3-xiao:wifi
  esp32c3-xiao:ble
  esp32c3-xiao:usbnsh
  esp32c3-xiao:gpio
  esp32c3-xiao:nsh
  esp32c3-generic:i2c
  esp32c3-generic:efuse
  esp32c3-generic:watchdog
  esp32c3-generic:pwm
  esp32c3-generic:timers
  esp32c3-generic:nimble
  esp32c3-generic:wifi
  esp32c3-generic:tickless
  esp32c3-generic:i2schar
  esp32c3-generic:bmp180
  esp32c3-generic:spi
  esp32c3-generic:random
  esp32c3-generic:rtc
  esp32c3-generic:buttons
  esp32c3-generic:ble
  esp32c3-generic:twai
  esp32c3-generic:ostest
  esp32c3-generic:usbconsole
  esp32c3-generic:gpio
  esp32c3-generic:sta_softap
  esp32c3-generic:nsh
  esp32c3-generic:temperature_sensor
  esp32c3-generic:rmt
  esp32c3-generic:spiflash
  esp32c3-generic:sdm
  esp32c3-generic:mcuboot_nsh
  esp32c3-generic:adc
  esp32c6-devkitm:i2c
  esp32c6-devkitm:efuse
  esp32c6-devkitm:watchdog
  esp32c6-devkitm:pwm
  esp32c6-devkitm:timers
  esp32c6-devkitm:wifi
  esp32c6-devkitm:tickless
  esp32c6-devkitm:i2schar
  esp32c6-devkitm:bmp180
  esp32c6-devkitm:spi
  esp32c6-devkitm:random
  esp32c6-devkitm:rtc
  esp32c6-devkitm:buttons
  esp32c6-devkitm:spislv
  esp32c6-devkitm:twai
  esp32c6-devkitm:ostest
  esp32c6-devkitm:usbconsole
  esp32c6-devkitm:gpio
  esp32c6-devkitm:sta_softap
  esp32c6-devkitm:nsh
  esp32c6-devkitm:rmt
  esp32c6-devkitm:spiflash
  esp32c6-devkitm:mcuboot_nsh
  esp32c6-devkitc:i2c
  esp32c6-devkitc:efuse
  esp32c6-devkitc:watchdog
  esp32c6-devkitc:pwm
  esp32c6-devkitc:timers
  esp32c6-devkitc:mpu60x0
  esp32c6-devkitc:wifi
  esp32c6-devkitc:tickless
  esp32c6-devkitc:i2schar
  esp32c6-devkitc:bmp180
  esp32c6-devkitc:spi
  esp32c6-devkitc:random
  esp32c6-devkitc:rtc
  esp32c6-devkitc:buttons
  esp32c6-devkitc:spislv
  esp32c6-devkitc:twai
  esp32c6-devkitc:ostest
  esp32c6-devkitc:qencoder
  esp32c6-devkitc:capture
  esp32c6-devkitc:usbconsole
  esp32c6-devkitc:motor
  esp32c6-devkitc:gpio
  esp32c6-devkitc:sta_softap
  esp32c6-devkitc:nsh
  esp32c6-devkitc:temperature_sensor
  esp32c6-devkitc:rmt
  esp32c6-devkitc:spiflash
  esp32c6-devkitc:sdm
  esp32c6-devkitc:mcuboot_nsh
  esp32c6-devkitc:adc
  esp32c6-xiao:wifi
  esp32c6-xiao:usbnsh
  esp32c6-xiao:gpio
  esp32c6-xiao:nsh
  esp32s3-eye:i2c
  esp32s3-eye:wifi
  esp32s3-eye:usbnsh
  esp32s3-eye:gpio
  esp32s3-eye:nsh
  esp32s3-eye:lcd
  esp32s3-lcd-ev:buttons
  esp32s3-lcd-ev:ws2812
  esp32s3-lcd-ev:audio
  esp32s3-lcd-ev:nsh
  esp32s3-lcd-ev:lcd
  esp32s3-lcd-ev:lvgl
  esp32s3-lhcbit:usbnsh
  esp32s3-korvo-2:rtptools
  esp32s3-korvo-2:sdmmc
  esp32s3-korvo-2:audio
  esp32s3-korvo-2:nsh
  esp32s3-box:lvgl-3
  esp32s3-box:buttons
  esp32s3-box:nsh
  esp32s3-box:touchscreen
  esp32s3-box:lvgl
  esp32s3-devkit:psram_octal
  esp32s3-devkit:i2c
  esp32s3-devkit:watchdog
  esp32s3-devkit:pwm
  esp32s3-devkit:nxlooper
  esp32s3-devkit:usb_device
  esp32s3-devkit:wifi
  esp32s3-devkit:python
  esp32s3-devkit:qemu_toywasm
  esp32s3-devkit:sdmmc
  esp32s3-devkit:tickless
  esp32s3-devkit:psram_quad
  esp32s3-devkit:ksta_softap
  esp32s3-devkit:coremark
  esp32s3-devkit:sotest
  esp32s3-devkit:i2schar
  esp32s3-devkit:spi
  esp32s3-devkit:random
  esp32s3-devkit:smp
  esp32s3-devkit:qemu_openeth
  esp32s3-devkit:rtc
  esp32s3-devkit:buttons
  esp32s3-devkit:ble
  esp32s3-devkit:twai
  esp32s3-devkit:qencoder
  esp32s3-devkit:audio
  esp32s3-devkit:capture
  esp32s3-devkit:txtable
  esp32s3-devkit:usbnsh
  esp32s3-devkit:psram_usrheap
  esp32s3-devkit:oneshot
  esp32s3-devkit:adb
  esp32s3-devkit:pm
  esp32s3-devkit:knsh
  esp32s3-devkit:motor
  esp32s3-devkit:blewifi
  esp32s3-devkit:gpio
  esp32s3-devkit:sta_softap
  esp32s3-devkit:nsh
  esp32s3-devkit:usbmsc
  esp32s3-devkit:qemu_debug
  esp32s3-devkit:temperature_sensor
  esp32s3-devkit:timer
  esp32s3-devkit:rmt
  esp32s3-devkit:eth_lan9250
  esp32s3-devkit:stack
  esp32s3-devkit:cxx
  esp32s3-devkit:spiflash
  esp32s3-devkit:sdm
  esp32s3-devkit:toywasm
  esp32s3-devkit:mcuboot_nsh
  esp32s3-devkit:elf
  esp32s3-devkit:fastboot
  esp32s3-devkit:adc
  esp32s3-xiao:usbnsh
  esp32s3-xiao:combo
  esp32s3-meadow:usbnsh
  esp32s3-meadow:nsh
  lckfb-szpi-esp32s3:pwm
  lckfb-szpi-esp32s3:usb_device
  lckfb-szpi-esp32s3:pca9557
  lckfb-szpi-esp32s3:txtable
  lckfb-szpi-esp32s3:adb
  lckfb-szpi-esp32s3:gpio
  lckfb-szpi-esp32s3:nsh
  lckfb-szpi-esp32s3:psram
  lckfb-szpi-esp32s3:lcd
  lckfb-szpi-esp32s3:lvgl
  lckfb-szpi-esp32s3:fastboot
  esp32-wrover-kit:nx
  esp32-wrover-kit:wifi
  esp32-wrover-kit:leds
  esp32-wrover-kit:lcd1602
  esp32-wrover-kit:bmp180
  esp32-wrover-kit:rtc
  esp32-wrover-kit:buttons
  esp32-wrover-kit:autopm
  esp32-wrover-kit:oneshot
  esp32-wrover-kit:lua
  esp32-wrover-kit:mmcsdspi
  esp32-wrover-kit:gpio
  esp32-wrover-kit:nsh
  esp32-wrover-kit:lvgl
  esp32-devkitc:efuse
  esp32-devkitc:watchdog
  esp32-devkitc:ms5611
  esp32-devkitc:pwm
  esp32-devkitc:nxlooper
  esp32-devkitc:mcuboot_update_agent
  esp32-devkitc:modbus
  esp32-devkitc:softap
  esp32-devkitc:module
  esp32-devkitc:nxdiag
  esp32-devkitc:watcher
  esp32-devkitc:wifi
  esp32-devkitc:tickless
  esp32-devkitc:coremark
  esp32-devkitc:mcp2515
  esp32-devkitc:wifishare
  esp32-devkitc:leds
  esp32-devkitc:sotest
  esp32-devkitc:mqttc
  esp32-devkitc:i2schar
  esp32-devkitc:bmp280
  esp32-devkitc:max6675
  esp32-devkitc:random
  esp32-devkitc:smp
  esp32-devkitc:qemu_openeth
  esp32-devkitc:rtc
  esp32-devkitc:buttons
  esp32-devkitc:wamr_wasi_debug
  esp32-devkitc:ble
  esp32-devkitc:twai
  esp32-devkitc:ostest
  esp32-devkitc:qencoder
  esp32-devkitc:audio
  esp32-devkitc:capture
  esp32-devkitc:dac
  esp32-devkitc:autopm
  esp32-devkitc:snake
  esp32-devkitc:psram_usrheap
  esp32-devkitc:oneshot
  esp32-devkitc:pm
  esp32-devkitc:knsh
  esp32-devkitc:motor
  esp32-devkitc:wifi_smp
  esp32-devkitc:blewifi
  esp32-devkitc:espnow
  esp32-devkitc:sta_softap
  esp32-devkitc:nsh
  esp32-devkitc:psram
  esp32-devkitc:timer
  esp32-devkitc:mcuboot_slot_confirm
  esp32-devkitc:rmt
  esp32-devkitc:cxx
  esp32-devkitc:spiflash
  esp32-devkitc:sdm
  esp32-devkitc:wifinsh
  esp32-devkitc:mcuboot_nsh
  esp32-devkitc:elf
  esp32-devkitc:brickmatch
  esp32-devkitc:adc
  ttgo_lora_esp32:sx127x
  ttgo_lora_esp32:nsh
  ttgo_t_display_esp32:lvgl_fb
  ttgo_t_display_esp32:nsh
  ttgo_t_display_esp32:lvgl_lcd
  esp32-audio-kit:wifi
  esp32-audio-kit:audio
  esp32-audio-kit:nsh
  esp32-pico-kit:nsh
  esp32-2432S028:nsh
  esp32-2432S028:lvgl
  esp32-ethernet-kit:ethernet
  esp32-ethernet-kit:wifi
  esp32-ethernet-kit:rtc
  esp32-ethernet-kit:buttons
  esp32-ethernet-kit:autopm
  esp32-ethernet-kit:oneshot
  esp32-ethernet-kit:nsh
  esp32-sparrow-kit:wifi
  esp32-sparrow-kit:mqttc
  esp32-sparrow-kit:nsh
  esp32-lyrat:nxrecorder
  esp32-lyrat:rtptools
  esp32-lyrat:wifi
  esp32-lyrat:buttons
  esp32-lyrat:audio
  esp32-lyrat:mmcsdspi
  esp32-lyrat:nsh
  esp32s2-kaluga-1:i2c
  esp32s2-kaluga-1:watchdog
  esp32s2-kaluga-1:nxlooper
  esp32s2-kaluga-1:rtc
  esp32s2-kaluga-1:buttons
  esp32s2-kaluga-1:twai
  esp32s2-kaluga-1:audio
  esp32s2-kaluga-1:nsh
  esp32s2-kaluga-1:lvgl_ili9341
  esp32s2-kaluga-1:lvgl_st7789
  esp32s2-saola-1:i2c
  esp32s2-saola-1:watchdog
  esp32s2-saola-1:pwm
  esp32s2-saola-1:nxlooper
  esp32s2-saola-1:wifi
  esp32s2-saola-1:coremark
  esp32s2-saola-1:sotest
  esp32s2-saola-1:i2schar
  esp32s2-saola-1:random
  esp32s2-saola-1:rtc
  esp32s2-saola-1:buttons
  esp32s2-saola-1:twai
  esp32s2-saola-1:ostest
  esp32s2-saola-1:qencoder
  esp32s2-saola-1:audio
  esp32s2-saola-1:oneshot
  esp32s2-saola-1:gpio
  esp32s2-saola-1:sta_softap
  esp32s2-saola-1:nsh
  esp32s2-saola-1:temperature_sensor
  esp32s2-saola-1:timer
  esp32s2-saola-1:rmt
  esp32s2-saola-1:cxx
  esp32s2-saola-1:spiflash
  esp32s2-saola-1:sdm
  esp32s2-saola-1:mcuboot_nsh
  esp32s2-saola-1:adc

列出所有的esp32c3

./tools/configure.sh -L |grep esp32c3
  esp32c3-devkit:efuse
  esp32c3-devkit:watchdog
  esp32c3-devkit:pwm
  esp32c3-devkit:gdbstub
  esp32c3-devkit:module
  esp32c3-devkit:watcher
  esp32c3-devkit:wifi
  esp32c3-devkit:romfs
  esp32c3-devkit:tickless
  esp32c3-devkit:coremark
  esp32c3-devkit:sotest
  esp32c3-devkit:bmp180
  esp32c3-devkit:random
  esp32c3-devkit:rtc
  esp32c3-devkit:ble
  esp32c3-devkit:twai
  esp32c3-devkit:ostest
  esp32c3-devkit:usbconsole
  esp32c3-devkit:autopm
  esp32c3-devkit:oneshot
  esp32c3-devkit:pm
  esp32c3-devkit:knsh
  esp32c3-devkit:gpio
  esp32c3-devkit:nvcfgdata
  esp32c3-devkit:sta_softap
  esp32c3-devkit:nsh
  esp32c3-devkit:lvgl
  esp32c3-devkit:timer
  esp32c3-devkit:mcuboot_slot_confirm
  esp32c3-devkit:cxx
  esp32c3-devkit:spiflash
  esp32c3-devkit:crypto
  esp32c3-devkit:uid
  esp32c3-devkit:elf
  esp32c3-devkit:adc
  esp32c3-devkit-rust-1:nsh
  esp32c3-devkit-rust-1:brickmatch
  esp32c3-xiao:wifi
  esp32c3-xiao:ble
  esp32c3-xiao:usbnsh
  esp32c3-xiao:gpio
  esp32c3-xiao:nsh
  esp32c3-generic:i2c
  esp32c3-generic:efuse
  esp32c3-generic:watchdog
  esp32c3-generic:pwm
  esp32c3-generic:timers
  esp32c3-generic:nimble
  esp32c3-generic:wifi
  esp32c3-generic:tickless
  esp32c3-generic:i2schar
  esp32c3-generic:bmp180
  esp32c3-generic:spi
  esp32c3-generic:random
  esp32c3-generic:rtc
  esp32c3-generic:buttons
  esp32c3-generic:ble
  esp32c3-generic:twai
  esp32c3-generic:ostest
  esp32c3-generic:usbconsole
  esp32c3-generic:gpio
  esp32c3-generic:sta_softap
  esp32c3-generic:nsh
  esp32c3-generic:temperature_sensor
  esp32c3-generic:rmt
  esp32c3-generic:spiflash
  esp32c3-generic:sdm
  esp32c3-generic:mcuboot_nsh
  esp32c3-generic:adc

配置  esp32c3-devkit:nsh

cd nuttx
./tools/configure.sh -l   esp32c3-devkit:nsh

完成显示:

 configuration written to .config

make menuconfig

cd nuttx
make menuconfig

出现菜单界面

对于ammy 也就是Ubuntu 22.04版本,需要加上参数make CONFIG_LIBM=y

在library Routines里加上本地math库的支持:

选择-> Library Routines (库函数) -> Select math library (Math library from NuttX)  -> Math library from NuttX 

设好后,保存退出

make

make

make输出

make
Create version.h
LN: platform/board to /home/skywalk/github/nuttxspace/apps/platform/dummy
Register: dd
Register: dumpstack
Register: nsh
Register: sh
CPP:  /home/skywalk/github/nuttxspace/nuttx/boards/risc-v/esp32c3-legacy/esp32c3-devkit/../common/scripts/esp32c3_rom.ld-> /home/skywalk/github/nuttxspace/nuttx/boards/risc-v/esp32c3-legacy/esp32c3-devkit/../common/scripts/esp32c3_rom.ld.tmCPP:  /home/skywalk/github/nuttxspace/nuttx/boards/risc-v/esp32c3-legacy/esp32c3-devkit/../common/scripts/flat_memory.ld-> /home/skywalk/github/nuttxspace/nuttx/boards/risc-v/esp32c3-legacy/esp32c3-devkit/../common/scripts/flat_memory.ld.tmCPP:  /home/skywalk/github/nuttxspace/nuttx/boards/risc-v/esp32c3-legacy/esp32c3-devkit/../common/scripts/legacy_sections.ld-> /home/skywalk/github/nuttxspace/nuttx/boards/risc-v/esp32c3-legacy/esp32c3-devkit/../common/scripts/legacy_sectioLD: nuttx
Memory region         Used Size  Region Size  %age Used
     iram0_0_seg:        6624 B     321296 B      2.06%
     irom0_0_seg:      107028 B    4194272 B      2.55%
     dram0_0_seg:       13792 B     321296 B      4.29%
     drom0_0_seg:      147892 B    4194272 B      3.53%
         rtc_seg:          0 GB         8 KB      0.00%
CP: nuttx.hex
MKIMAGE: ESP32-C3 binary
esptool.py not found. Please run: 'pip install esptool'
Run make again to create the nuttx.bin image.
make: *** [tools/Unix.mk:559: nuttx] Error 1 

按照提示,安装esptool

pip install esptool

然后再make

输出:

LD: nuttx
Memory region         Used Size  Region Size  %age Used
     iram0_0_seg:        6624 B     321296 B      2.06%
     irom0_0_seg:      107028 B    4194272 B      2.55%
     dram0_0_seg:       13792 B     321296 B      4.29%
     drom0_0_seg:      147892 B    4194272 B      3.53%
         rtc_seg:          0 GB         8 KB      0.00%
CP: nuttx.hex
MKIMAGE: ESP32-C3 binary
esptool.py -c esp32c3 elf2image -fs 4MB -fm dio -ff 40m -o nuttx.bin nuttx
esptool.py v4.8.1
Creating esp32c3 image...
Merged 1 ELF section
Successfully created esp32c3 image.
Generated: nuttx.bin (ESP32-C3 compatible)

使用Cmake

先安装cmake

sudo apt isntall cmake

cd nuttx
cmake -B build -DBOARD_CONFIG=esp32c3-devkit:nsh -GNinja

cmake -B build -DBOARD_CONFIG=esp32c3-devkit:nsh -GNinja

配置管理

cmake --build build -t menuconfig

 cmake失败

烧录

烧录之前安装esptool工具

pip install esptool

使用这条命令:

esptool --chip esp32c3 --port com3 --baud 460800 write_flash -z 0x0  E:\tmp\nuttx.bin

显示:

esptool --chip esp32c3 --port com3 --baud 460800 write_flash -z 0x0  E:\tmp\nuttx.bin
esptool.py v4.8.1
Serial port com3
Connecting...
Failed to get PID of a device on com3, using standard reset sequence.
.
Chip is ESP32-C3 (QFN32) (revision v0.4)
Features: WiFi, BLE
Crystal is 40MHz
MAC: e4:b0:63:22:df:68
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Flash will be erased from 0x00000000 to 0x0002afff...
Compressed 172640 bytes to 81799...
Wrote 172640 bytes (81799 compressed) at 0x00000000 in 2.3 seconds (effective 610.2 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

 也不知道是否成功了...

至少生成了文件:

-rwxr-xr-x  1 skywalk skywalk 2808092 May 17 19:08 nuttx
-rw-r--r--  1 skywalk skywalk  172640 May 17 19:08 nuttx.bin
-rw-r--r--  1 skywalk skywalk  369186 May 17 19:08 nuttx.hex
-rw-r--r--  1 skywalk skywalk      47 May 17 19:08 nuttx.manifest
-rw-r--r--  1 skywalk skywalk 1660487 May 17 19:08 nuttx.map

就先到这里吧! 

调试

编译报错ERROR: riscv64-unknown-elf-gcc failed: 1

make
Create version.h
LN: platform/board to /home/skywalk/github/nuttxspace/apps/platform/dummy
Register: dd
Register: dumpstack
Register: nsh
Register: sh
./stdlib/lib_strtold.c:42:10: fatal error: math.h: No such file or directory
   42 | #include <math.h>
      |          ^~~~~~~~
compilation terminated.
ERROR: riscv64-unknown-elf-gcc failed: 1
       command: riscv64-unknown-elf-gcc -MT bin/lib_strtold.o  -M '-fno-common' '-Wall' '-Wstrict-prototypes' '-Wshadow' '-Wundef' '-Wno-attributes' '-Wno-unknown-pragmas' '-Wno-psabi' '-Os' '-fno-strict-aliasing' '-fno-omit-frame-pointer' '-fno-optimize-sibling-calls' '-ffunction-sections' '-fdata-sections' '-nostdlib' '-g' '-march=rv32imc' '-mabi=ilp32' '-isystem' '/home/skywalk/github/nuttxspace/nuttx/include' '-D__NuttX__' '-DNDEBUG' '-D__KERNEL__' '-Werror=return-type' '-I' '/home/skywalk/github/nuttxspace/nuttx/libs/libc' ./stdlib/lib_strtold.c
make[2]: *** [/home/skywalk/github/nuttxspace/nuttx/tools/Config.mk:232: lib_strtold.ddc] Error 1
make[1]: *** [Makefile:202: .depend] Error 2
make: *** [tools/Unix.mk:660: pass2dep] Error 2

又重新make了一下,报错简化成:

make

CC:  stdlib/lib_strtold.c stdlib/lib_strtold.c:42:10: fatal error: math.h: No such file or directory
   42 | #include <math.h>
      |          ^~~~~~~~
compilation terminated.
make[1]: *** [Makefile:156: bin/lib_strtold.o] Error 1
make: *** [tools/LibTargets.mk:196: libs/libc/libc.a] Error 2

检查math.h 是否存在

find /usr/include -name math.h

find /usr/include -name math.h
/usr/include/newlib/math.h
/usr/include/newlib/c++/10.3.1/math.h
/usr/include/newlib/c++/10.3.1/tr1/math.h
/usr/include/math.h
/usr/include/c++/11/math.h
/usr/include/c++/11/tr1/math.h

检查编译器路径

echo | gcc -E -v -

看到这句

#include <...> search starts here:
 /usr/lib/gcc/x86_64-linux-gnu/11/include
 /usr/local/include
 /usr/include/x86_64-linux-gnu
 /usr/include

证明应该可以看到math.h文件啊!

检查这两项:

7. 检查环境变量

确保环境变量 CC 和 CFLAGS 没有错误配置。例如:

export CC=gcc
export CFLAGS="-I/usr/include"

8. 检查 Makefile 配置

检查 Makefile 中是否有错误的配置,例如缺少 -lm 链接数学库。在 Makefile 中添加以下内容:

LDFLAGS += -lm

问题解决

最终发现,这是已知的问题:`rv-virt:nsh64` can't build with stock gcc-riscv64-unknown-elf on Ubuntu Jammy · Issue #11341 · apache/nuttx 

This is a know issue. Ubuntu release of RISC-V GCC is compiled without math libs. We can do nothing with that, but you can enable NuttX native math libraries support via CONFIG_ LIBM=y and still use RISC-V GCC provided by Ubuntu apt or pick another more mature toolchain

👍1

 直接用命令:

make CONFIG_LIBM=y

哇塞,终于过去了 

cmake -B build -DBOARD_CONFIG=esp32c3-devkit:nsh -GNinja报错

cmake -B build -DBOARD_CONFIG=esp32c3-devkit:nsh -GNinja
CMake Error at CMakeLists.txt:89 (message):
  Kconfig environment depends on kconfiglib, Please install:

    (APT source)
      $ sudo apt install python3-kconfiglib
    or (pip source)
      $ pip install kconfiglib
    or (After Ubuntu 24.04)
      $ pip install kconfiglib --break-system-packages


-- Configuring incomplete, errors occurred!

 放弃cmake

make报错esptool.py not found. Please run: 'pip install esptool'

make
Create version.h
LN: platform/board to /home/skywalk/github/nuttxspace/apps/platform/dummy
Register: dd
Register: dumpstack
Register: nsh
Register: sh
CPP:  /home/skywalk/github/nuttxspace/nuttx/boards/risc-v/esp32c3-legacy/esp32c3-devkit/../common/scripts/esp32c3_rom.ld-> /home/skywalk/github/nuttxspace/nuttx/boards/risc-v/esp32c3-legacy/esp32c3-devkit/../common/scripts/esp32c3_rom.ld.tmCPP:  /home/skywalk/github/nuttxspace/nuttx/boards/risc-v/esp32c3-legacy/esp32c3-devkit/../common/scripts/flat_memory.ld-> /home/skywalk/github/nuttxspace/nuttx/boards/risc-v/esp32c3-legacy/esp32c3-devkit/../common/scripts/flat_memory.ld.tmCPP:  /home/skywalk/github/nuttxspace/nuttx/boards/risc-v/esp32c3-legacy/esp32c3-devkit/../common/scripts/legacy_sections.ld-> /home/skywalk/github/nuttxspace/nuttx/boards/risc-v/esp32c3-legacy/esp32c3-devkit/../common/scripts/legacy_sectioLD: nuttx
Memory region         Used Size  Region Size  %age Used
     iram0_0_seg:        6624 B     321296 B      2.06%
     irom0_0_seg:      107028 B    4194272 B      2.55%
     dram0_0_seg:       13792 B     321296 B      4.29%
     drom0_0_seg:      147892 B    4194272 B      3.53%
         rtc_seg:          0 GB         8 KB      0.00%
CP: nuttx.hex
MKIMAGE: ESP32-C3 binary
esptool.py not found. Please run: 'pip install esptool'
Run make again to create the nuttx.bin image.
make: *** [tools/Unix.mk:559: nuttx] Error 1

按照提示的运行

pip install esptool