home Home library_books Notes style Projects photos Photos Table Of Contents Plain Nuttx Menuconfig Nuttx Apps Eclipse + Nuttx Px4 Firmware Eclipse Debugging Bootloader Further Reading Nuttx Px4 Related Articles HobbyKing Quanum V2 Pro Goggles Asguard AIO BlHeli ESCs Flashing Kiss 24a ESCs with DSHOT firmware via BetaFlight Passthrough MultiRotor Setup Checklist HMDVR and Eachine ProDVR FPV Video Recorder Nuttx and Px4 Development Getting Started Guide Nt 48

Lets start by building and flashing plain old nuttx, without Px4

Plain Nuttx

Im using the STM32F746 Nucleo-144 board pinmap

Install deps (Mac OS):

brew install gperf stlink

Make a nuttx top level dir

mkdir ~/src/embedded/nuttx
cd ~/src/embedded/nuttx

Nuttx depends on kconfig-frontend, so lets build and install it

git clone https://bitbucket.org/nuttx/tools
pushd tools/kconfig-frontends
# https://github.com/PX4/NuttX/tree/master/misc/tools
# appy this diff: https://github.com/PX4/NuttX/blob/master/misc/tools/kconfig-macos.diff
./configure --disable-shared --enable-static --disable-gconf --disable-qconf --disable-nconf --disable-utils
sudo make
sudo make install
popd

Clone the nuttx example apps

git clone https://bitbucket.org/nuttx/apps.git

Clone nuttx and cd into the directory

git clone https://bitbucket.org/nuttx/nuttx.git
cd nuttx

Note that target documentation is in the target folder's readme.txt file

# clean any previous builds
make distclean
# pick a target board and app, then configure
# look in configs/ for board info
tools/configure.sh configs/nucleo-144/f746-nsh
# menuconfig, note run this in bash. zsh does not like it at all
# i'm using bash explicitly since it seems to break with by default zsh
bash -c 'make menuconfig'
# build it
make

Then flash it with an st-link

st-flash write nuttx.bin 0x8000000

Using the st-link's built in serial port, we can connect to nsh with:

screen /dev/tty.usbmodemFD133 115200 8N1

Reconfigure the UART config when using a jlink, to run nsh on a different uart. With JLinkExe:

make distclean
# pick a target board and app, then configure
# look in configs/ for board info
tools/configure.sh configs/nucleo-144/f746-nsh
# menuconfig, note run this in bash. zsh does not like it at all
# i'm using bash explicitly since it seems to break with by default zsh
bash -c 'make menuconfig'
# build it
make

Then flash it with JLinkExe

si 1
speed 4000
device STM32F746ZG
r
h
loadbin nuttx.bin, 0x8000000
exit

Or create a file like flash.jtag with the contents above and run:

JLinkExe flash.jtag

Configure with menuconfig

make menuconfig

Configure any settings specified in configs/stm32f429i-disco/README.txt for the example you're running.

Nuttx Apps

Here's a great guide on adding an app: https://acassis.wordpress.com/2013/06/09/how-to-put-your-application-to-be-called-from-nuttx-terminal/

Eclipse + Nuttx

Here's a great setup guide for compiling nuttx with Eclipse: http://paregov.net/17-manuals/nuttx/20-building-nuttx-in-eclipse-ubuntu

Just note the comment #2 by Galin Hristov:

In case some of the apps will be build (not only the OS) it is better to select the parent folder in step 3 (instead of “nuttx”). This way also apps code will be visible and indexed by Eclipse.

|- nuttx-code - Select this folder ...
| |-- nuttx - …. instead of this folder.
| |-- apps

Then in the project properties in "C/C++ Build" page for Build Location "${workspace_loc:/nuttx-code/nuttx}/" must be selected instead of "${workspace_loc:/nuttx-code}/"

And set the debug configuration application to nuttx/nuttx the nuttx file in the nuttx folder is an .elf file, even though it doesnt have the extension

Px4

Once you understand the basics of building nuttx, we can move onto the more complicated Px4 build.

Note that when checking out the project to a specific tag, be sure to reset submodules with:

git submodule foreach --recursive git reset --hard

Firmware

The Px4 firmware uses nuttx as a middleware

Show all build info with the VERBOSE=1 environment variable

When porting, make a new target with VERBOSE=1 make px4-omnibus-nxt_default

When making nuttx changes, rm -rf build/[target name] before making again to ensure the existing build config is updated

Install the Bootloader first, then build the new target with the upload command specified:

VERBOSE=1 make px4-omnibus-nxt_default upload

Eclipse Debugging

To debug with Eclipse, in the Firmware folder:

mv eclipse.cproject .cproject
mv eclipse.project .project

Then open Eclipse and right click on the project explorer, choose import -> existing -> [pick the px4/firmware directory] -> ok

Add a new build target by right clicking on the Build targets icon

Bootloader

The Px4 bootloader is based on libopencm3

All that is needed to port to a new board is: https://gist.github.com/nathantsoi/b24232791d3ec9390a51fab141c7a4bb

To build, run make omnibusnxt_bl

And to flash:

st-flash write build_omnibusnxt_bl/omnibusnxt_bl.bin 0x8000000

The status LED will flash once successfully uploaded to the flight controller

Further Reading

Nuttx

Main documentation page: http://nuttx.org/doku.php?id=documentation

Getting Started Guide (README.txt): https://bitbucket.org/nuttx/nuttx/src/master/README.txt

STM32F4 Discovery board info: http://nuttx.org/doku.php?id=wiki:getting-started:stm32f4discovery_unix

"Blue Pill"/Maple Mini/Stm32f1 Dev board info: https://acassis.wordpress.com/2016/06/12/running-nuttx-on-a-less-than-u2-00-board/

How to compile an external application out of tree: http://nuttx.org/doku.php?id=wiki:nshhowtos:external-applications

Porting guide has a good overview of the RTOS: http://www.nuttx.org/Documentation/NuttxPortingGuide.html

A great tutorial on compiling nuttx and writing a simple application: http://www.zilogic.com/blog/tutorial-nuttx-hello.html

Nuttx driver development: https://acassis.wordpress.com/2013/06/11/how-to-create-a-driver-for-nuttx/

A set of great tutorials for Nuttx development on the stm32 minimum board: https://www.youtube.com/channel/UC0QciIlcUnjJkL5yJJBmluw

Building nuttx from scratch: http://reclonelabs.com/building-nuttx-in-ubuntu-from-scratch/

Nuttx gitbook: https://phreakuencies.gitlab.io/nuttx_book/

Px4

Porting Guide: https://github.com/PX4/Devguide/blob/master/en/debug/porting-guide.md

App development: https://dev.px4.io/en/tutorials/tutorial_hello_sky.html

Driver using the I2C bus: https://dev.px4.io/en/sensor_bus/i2c.html

STM32 F4 discovery board development: https://pixhawk.org/modules/stm32f4discovery

Hope this was helpful. If so, feel free to checkout my YouTube channel, get updates when a new article is posted by following on Feedly and read the the other guides at nathan.vertile.com/blog