NuttX Operating System
NuttX is free open-source RTOS that focuses on standards compliance and small footprint. A basic version of NuttX can be run on low-cost and low-memory microcontrollers (MCUs).
Since NuttX is a POSIX RTOS, you can write an application in a POSIX operating system such as Linux or MacOS and validate it and compile it to run on NuttX without learning a new API.
NuttX also has many parallel subsystems to Linux. Several examples include Virtual File System (VFS), Memory Technology Device (MTD), audio subsystem and USB system with USB composite support. Some of the prime features include:
- Fully pre-emptible
- Naturally scalable
- Highly configurable
- Easily extensible to new processor architectures
- Support for priority inheritance
PolarFire® SoC FPGAs
The flexibility of the Linux Operating System (OS) and the determinism of real-time systems to control hardware are key in safety-critical systems, system control and security applications. Though typical Symmetric Multiprocessing (SMP) implementations offer flexibility, they are not ideal for deterministic performance.
PolarFire SoC FPGAs enable deterministic Asymmetric Multiprocessing (AMP) Linux applications and a multi-core Linux-capable processor compatible with the memory subsystem. This supports a mix of deterministic real-time systems and the Linux OS in a single multi-core central processing unit cluster that can run a real-time application at maximum performance while also running the Linux OS. That is, this solution offers a high-performing system that is not fully deterministic.
NuttX in PolarFire SoC FPGAs
Using AMP mode, we are now able to run NuttX RTOS and Linux together in a PolarFire SoC FPGA, which helps to incorporate the benefits of NuttX and Linux together in one system.
NuttX RTOS is very popular in the aviation drone industry; it also used in a variety of applications, such as smartphones and audio recorders.
The growing demand of PX4 autopilot software for drones and the power efficiency of Microchip’s PolarFire SoC FPGA made implementing a NuttX port on PolarFire SoC FPGA very relevant and necessary.
The Secure Systems Research Center (SSRC) at the Technology Innovation Institute (TII) in Abu Dhabi, UAE, owned and led the integration project. SSRC first subcontracted the base port to Offcode—the Mi-V ecosystem partner providing basic coding services for the project. It was straightforward, thanks to the public RISC-V standards, open-source code, robust hardware, existing toolchains and valuable vendor tools such as the SoftConsole and Libero® SoC design suite. NuttX is well-organized, further boosting the porting task itself.
SSRC furthermore defined the drivers and functionalities required for NuttX to work and tested PX4 functionality and the environment ahead of the NuttX implementation. The Center worked closely with the open-source community to upstream content. SSRC’s engineers are also contributing to the development of the NuttX kernel upstream.
SSRC’s key contributions to the kernel development include:
- RISC-V Sv39 MMU driver
- Configuration option for running NuttX in S-mode
- RISC-V PMP functionality improvements
- Support for CONFIG_BUILD_PROTECTED and CONFIG_BUILD_KERNEL
- RISC-V implementation for address environments and page allocator
- NuttX CONFIG_BUILD_KERNEL corrections for tasks environment initialization, elf loader, Crt0 compilation, and process exit
- Glue logic for SBI integration
The details for the initial port are available at this GitHub community.
Most of the code is located at the following folders:
The assembly file mpfs_head.S, located underneath the arch/risc-v/src/mpfs -directory, contains the starting point for the code execution. Installation of the Machine Trap-Vector Base-Address Register (mtvec) is a primary step there as well. It points to the trap handler for all interrupts and exceptions.
We have a bootloader called Hart Software Systems (HSS). It contains DDR memory training sequences and other hardware block initializations that must be in place before handling any memory accesses. Thus, the HSS was used initially to speed up the porting.
Later, all the required device drivers and functionalities were incorporated into the NuttX as well. As of November 2022, NuttX works also as a bootloader supporting OpenSBI. This means the NuttX based bootloader may start U-boot and Linux on other harts.
Now, the PolarFire Icicle kit has support for the following peripheral drivers for NuttX:
- Serial port
- EMMC/SD (DMA support)
- USB (Composite CDC/ACM and Mass Storage)
- DMA (Memory-to-memory)
In addition to the peripheral drivers, it also features all necessary clock setups, timers, DDR training, OpenSBI support, RPMSG via Inter Hart Communication (IHC) and some other functionalities.
AMP glues the Linux kernel and the NuttX together. This feature is built via the Remote Processor Messaging (RPMSG). If one OS uses, say, the network hardware, another OS cannot conflict by initializing and using the hardware at the same time. What may be done, though, is using the interface via the RPMSG framework. However, messages may be shared between the different operating systems for any reason.
In November 2022, a patch was merged into NuttX that has support for two different NuttX OSs to communicate with the Linux kernel via their own RPMSG paths. Of course, this also required some minor Linux kernel modifications. The tested setup had the following hart setup:
- Hart0: NuttX bootloader
- Hart1: NuttX OS (standalone), uses RPMSG channel 1
- Hart2: NuttX OS (standalone), uses RPMSG channel 2
- Hart3: Linux kernel
- Hart4: Linux kernel
The Linux kernel communicates with both NuttXs on harts 1 and 2. If any real-time vehicle, drone or any time-critical tasks need to be composed, we suggest considering NuttX as an option.
We strongly recommend the NuttX operating system.
Consider whether combining your time-critical layers into NuttX while maintaining a good focus with Linux sounds like a viable option for you.