Recently I found a new RTOS called NuttX and I was pleasantly surprised to see that is a powerful and flexible real time operating system. It can be used for 8 bit MCU to 32 bit MCU in a small footprint and implements the POSIX and ANSI standard. 

I found that NuttX integrates many features like (file system, network, device driver, flash support, graphic support, ...) and I decided to test it on a development board called Nucleo L476RG. The Nucleo L476RG is a interesting board because it's powered by a low power ARM® 32-bit Cortex®-M4 CPU and it has 1 Mb Flash and 128 kB of RAM which allows to be used for many applications. Another advantage is that the Nucleo board has on-board ST-LINK/V2-1 debugger/programmer which allows a confortable debug and programming interface.

More information about the NuttX RTOS can be found at the NuttX website

More information about the Nucleo L476RG board can be found at the ST Nucleo board website

First let's start to configure the development environment. I will use a virtual Linux machine (Ubuntu 16.04.2) to configure and install NuttX. The steps are quite simple, personally I fallow the tutorial on NuttX channel and everything was OK.

However, the steps to configure the development environment are :

  1. Install the Ubuntu 16.04 
  2. sudo apt-get update && sudo apt-get upgrade
  3. apt-get install automake bison build-essential flex gcc-arm-none-eabi gperf git libncurses5-dev libtool libusb-dev libusb-1.0.0-dev 
  4. mkdir ~/nuttxspace
  5. cd ~/nuttxspace
  6. git clone http://repo.or.cz/r/openocd.git
  7. cd ~/nuttxspace/openocd
  8. ./bootstrap
  9. ./configure --enable-internal-jimtcl --enable-maintainer-mode --disable-werror --disable-shared --enable-stlink --enable-jlink --enable-rlink --enable-vslink --enable-ti-icdi --enable-remote-bitbang
  10. make
  11. sudo make install

Now let's compile NuttX for Nucleo L476RG board:

  1. cd ~/nuttxspace/
  2. git clone https://bitbucket.org/nuttx/nuttx
  3. git clone https://bitbucket.org/nuttx/apps
  4. git clone https://bitbucket.org/nuttx/tools
  5. cd tools/kconfig-frontends/
  6. ./configure
  7. make
  8. sudo make install
  9. sudo ldconfig
  10. cd ~/nuttxspace/nuttx/
  11. make distclean
  12. cd tools/
  13. ./configure.sh nucleo-l476rg/nsh
  14. cd ..
  15. make

At the end of the compiled kernel you will find two files: "nuttx.hex" and/or "nuttx.bin" (however the extension of the final binary file can be configured with the "make menuconfig" in the graphic menu).

As everything went well, I hope for everyone, I will flash the "nuttx.bin" file on the board and test if NuttX run correctly. 

Steps to flash code on the board using ST-Link/V2 .

These steps are made only one time:

  1. cd ~/nuttxspace/
  2. cd openocd/contrib/
  3. sudo cp 60-openocd.rules /etc/udev/rules.d/
  4. sudo udevadm trigger

Now, to test the communication with the ST-Link/V2 you must run :

  1. openocd -f interface/stlink-v2.cfg -f target/stm32l4x.cfg

Personally I get an error when I try the commande:

miti@ubuntu:~/nuttxspace/nuttx$ openocd -f interface/stlink-v2.cfg -f target/stm32l4x.cfg
Open On-Chip Debugger 0.10.0+dev-00167-g29cfe9c (2017-07-23-11:57)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 500 kHz
adapter_nsrst_delay: 100
none separate
Info : Unable to match requested speed 500 kHz, using 480 kHz
Info : Unable to match requested speed 500 kHz, using 480 kHz
Info : clock speed 480 kHz
Error: open failed
in procedure 'init'
in procedure 'ocd_bouncer'

In order to avoid this problem I execute :

  1. openocd -f interface/stlink-v2.cfg -c "hla_vid_pid 0x0483 0x374b" -f target/stm32l4x.cfg

If you have something like that, than the communication with the ST-Link/V2 it's correctly established.

miti@ubuntu:~/nuttxspace/nuttx$ openocd -f interface/stlink-v2.cfg -c "hla_vid_pid 0x0483 0x374b" -f target/stm32l4x.cfg
Open On-Chip Debugger 0.10.0+dev-00167-g29cfe9c (2017-07-23-11:57)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 500 kHz
adapter_nsrst_delay: 100
none separate
Info : Unable to match requested speed 500 kHz, using 480 kHz
Info : Unable to match requested speed 500 kHz, using 480 kHz
Info : clock speed 480 kHz
Info : STLINK v2 JTAG v25 API v2 SWIM v13 VID 0x0483 PID 0x374B
Info : using stlink api v2
Info : Target voltage: 3.255570
Info : stm32l4x.cpu: hardware has 6 breakpoints, 4 watchpoints

Now that everything worked, let's flash the "nuttx.bin" file on the board:

  1. openocd -f interface/stlink-v2.cfg -c "hla_vid_pid 0x0483 0x374b" -f target/stm32l4x.cfg -c init -c "reset halt" -c "flash write_image erase nuttx.bin 0x08000000"

Here is the result of the flashing code.

miti@ubuntu:~/nuttxspace/nuttx$ openocd -f interface/stlink-v2.cfg -c "hla_vid_pid 0x0483 0x374b" -f target/stm32l4x.cfg -c init -c "reset halt" -c "flash write_image erase nuttx.bin 0x08000000"
Open On-Chip Debugger 0.10.0+dev-00167-g29cfe9c (2017-07-23-11:57)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 500 kHz
adapter_nsrst_delay: 100
none separate
Info : Unable to match requested speed 500 kHz, using 480 kHz
Info : Unable to match requested speed 500 kHz, using 480 kHz
Info : clock speed 480 kHz
Info : STLINK v2 JTAG v25 API v2 SWIM v13 VID 0x0483 PID 0x374B
Info : using stlink api v2
Info : Target voltage: 3.253997
Info : stm32l4x.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Unable to match requested speed 500 kHz, using 480 kHz
Info : Unable to match requested speed 500 kHz, using 480 kHz
adapter speed: 480 kHz
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08000188 msp: 0x200017bc
auto erase enabled
Info : device id = 0x10076415
Info : flash size = 1024kbytes
target halted due to breakpoint, current mode: Thread
xPSR: 0x61000000 pc: 0x20000050 msp: 0x200017bc
Warn : block write succeeded
wrote 155648 bytes from file nuttx.bin in 8.874666s (17.127 KiB/s)
^C

Note : As you see I had to execute CTRL+C to exit the "openocd" program.

Here is a video that show NuttX running on Nucleo L476RG.

Or check the video on YouTube.

This video show how to change the build-in application using the make menuconfig.

Or check the video on YouTube.

Categories: NuttX

4 Comments

Alan C. Assis · 18/08/2017 at 10:49 am

Hi Mihail,
I’m looking forward for new posts about NuttX !!!

Are you a teacher? If so, It should be share your experience about with your students and ask them to create projects with NuttX.

    CMN_Lab · 18/08/2017 at 5:52 pm

    Hi Alan,

    Unfortunately I only work on this in my free time so it can take a while before I post new articles, anyway I do my best to came out with new articles about NuttX very soon.

    Concerning my profession I’m a Freelancer Embedded System engineer.

    Regards,

felix giffuni · 26/02/2018 at 1:36 pm

Excellent tutorial.Thank you very much.

Felix

    CMN_Lab · 26/02/2018 at 3:00 pm

    You welcome !
    Mihail

Leave a Reply to Alan C. Assis Cancel reply

Your email address will not be published. Required fields are marked *