Apache NuttX RTOS on Spresense

ソニーのApache NuttX RTOSコードの最新版をSpresenseマイクロコントローラ上で試してみて下さい。皆さんのApache NuttX RTOSコミュニティへの参加をお待ちしています。

Get started

Build instructions for Apache NuttX

Below you can find step-by-step guides on to how to build Apache NuttX for Sony Spresense boards.

You will also find instructions for how to prepare your environment and download all necessary tools .

Preparing the code

This guide assumes you run Ubuntu (we used Ubuntu 20.04 LTS ), but it should work in a similar way on any Linux-based system. The instructions will guide you through each step, starting with how to prepare your environment and install all necessary tools to downloading and configuring the code, before you can finally build Apache NuttX images for Spresense board and flash them on your device.

  1. Prerequisites

Run the following command to install packages:

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

NOTE: Apache 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.

2. 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 better to use a widely used build from another source.

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

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

3. 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 with changes, you need to have the absolute latest version. If you simply prefer to work using git, it is recommended that you clone these repositories:

<pre>mkdir nuttx
cd nuttx
git clone https://github.com/apache/incubator-nuttx.git nuttx
git clone https://github.com/apache/incubator-nuttx-apps apps

Compiling

Now that we’ve installed Apache NuttX prerequisites and downloaded the source code, we are ready to compile the source code into an executable binary file that can be run on the embedded board.

  1. Initialize Configuration

The first step is to initialize Apache NuttX configuration for a given board, based from a pre-existing configuration. To list all supported configurations you can do:

cd nuttx
./tools/configure.sh -L |  grep spresense

The output is in the format :. You will see that there are various configurations but in general nsh configuration is a good starting point since it enables booting into the interactive command line NuttShell (NSH).

To choose a configuration, you pass the : option to configure.sh and indicate your host platform, such as:

cd nuttx
./tools/configure.sh -l spresense:nsh

The -l tells use that we’re on Linux (macOS and Windows builds are possible). Use the -h argument to see all available options.

2. Customizing the features(optional)

Apache NuttX is very configurable: nearly all features can be configured in or out of the system. This makes it possible to compile a build tailored for your hardware and application.

The Apache NuttX configuration system uses Linux’s kconfig system which includes various frontends that allow you to modify configuration easily. Usually, the menuconfig frontend is used, which is a console based menu system (more info here).

cd nuttx/
make menuconfig

3. Build NuttX

We can now build NuttX. To do so, you can simply run:

cd nuttx/
make -j$(nproc)

The build will complete by generating the binary outputs inside nuttx directory. Typically this includes the nuttx ELF file (suitable for debugging using gdb) and a spresense.spk file that can be flashed to the board.

To clean the build, you can do:

make clean

Running

In order to finally run Apache NuttX on your board, you first have to flash the Apache NuttX binary on the Spresense board.

1. Flashing

The board is flashed by using flash_writer.py which is already provided in the Apache NuttX tools folder.

To flash the binary to your board, connect the USB cable and type:

cd nuttx/
./tools/flash_writer.py -s -c /dev/ttyUSB0 -d -b 1152000 -n nuttx.spk

2. Access NuttShell

Once you flash your board, it will reset and offer a prompt over the serial console. With the Spresense board, you can simply open the terminal program of your choice where you will see the nsh> prompt (press enter if you don’t see anything):

picocom -b 115200 /dev/ttyUSB0

NOTE

In case the error “Command 'picocom' not found, but can be installed with:” appears, the picom package can be installed with the following command:

apt install picocom