Skip to content

Compiling NuttX Applications

Drasko DRASKOVIC edited this page Sep 10, 2015 · 16 revisions

Getting the code

Prepare dir

Create one dir to hold NuttX RTOS kernel (called nuttx by convention) and apps (called apps):

mkdir nuttx-top
cd nuttx-top

In the end (when you git clone, as explained in chapters below), you will have a structure like this:

  nuttx-top
      |
 +----+----+
 |         |
nuttx/     apps/

NuttX RTOS

git clone https://bitbucket.org/patacongo/nuttx.git nuttx
cd nuttx
git submodule init
git submodule update
cd ..

Apps

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

Configuring the build

Start by reading README here: https://bitbucket.org/patacongo/nuttx

Install kconfig-frontends

Get them here: http://ymorin.is-a-geek.org/projects/kconfig-frontends

Should be straightforvard ./configure, make, make install procedure, in case of problems consult documentation here: https://bitbucket.org/patacongo/nuttx

configure.sh script

This one is used before the build to do the pre-defined board defconfig. You can see the list of existing board configs in nuttx/configs dir, or here: https://bitbucket.org/nuttx/boards/src

cd tools
./configure.sh stm32f3discovery/nsh

Edit configuration

make menuconfig
  • Under Build Setup, select Linux as a Build Host Platform
  • [For STM32F3 Discovery] Under Application Configuration -> NSH Library -> Console Configuration" select Use a USB serial consoleto useUSB USER` connector (one by the edge of the board) for console.

Build

Make

make -j 16

Build products

drasko@Lenin:~/nuttx/nuttx$ ls | grep nuttx
nuttx
nuttx.bin
nuttx.hex
drasko@Lenin:~/nuttx/nuttx$ file nuttx
nuttx: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, not stripped
drasko@Lenin:~/nuttx/nuttx$ 

Flash

openocd -f ~/openocd/tcl/board/stm32f3discovery.cfg

The in another terminal:

drasko@Lenin:~$ telnet localhost 4444
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Open On-Chip Debugger
> halt
> flash write_image erase /home/drasko/nuttx/nuttx/nuttx
auto erase enabled
target state: halted
target halted due to breakpoint, current mode: Thread 
xPSR: 0x61000000 pc: 0x2000003a msp: 0x20000e98
wrote 57344 bytes from file /home/drasko/nuttx/nuttx/nuttx in 2.567482s (21.811 KiB/s)
> 

or with gdb:

drasko@Lenin:~/nuttx/nuttx$ arm-none-eabi-gdb
GNU gdb (GNU Tools for ARM Embedded Processors) 7.6.0.20140731-cvs
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i686-linux-gnu --target=arm-none-eabi".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
(gdb) target remote localhost:3333
Remote debugging using localhost:3333
0x00000000 in ?? ()
(gdb) load ./nuttx
Loading section .text, size 0xdeed lma 0x8000000
Loading section .ARM.exidx, size 0x8 lma 0x800def0
Loading section .data, size 0x5c lma 0x800def8
Start address 0x8000430, load size 57169
Transfer rate: 21 KB/sec, 9528 bytes/write.
(gdb) 

Specific for STM32F3 Discovery

If seeing errors like this with OpenOcd:

Info : stm32f3x.cpu: hardware has 6 breakpoints, 4 watchpoints
Error: jtag status contains invalid mode value - communication failure
Polling target stm32f3x.cpu failed, GDB will be halted. Polling again in 100ms
Info : Previous state query failed, trying to reconnect
Error: jtag status contains invalid mode value - communication failure
Polling target stm32f3x.cpu failed, GDB will be halted. Polling again in 300ms
Info : Previous state query failed, trying to reconnect
Error: jtag status contains invalid mode value - communication failure

hold the RESET button (black one) while flashing.

Minicom

minicom -D /dev/ttyACM0

Because of CR/LF problem like this: http://stackoverflow.com/questions/7812142/how-to-toggle-cr-lf-in-gnu-screen, use minicom option CTRL+A CTRL+Z:

Add Carriage Ret...U

Example before and after setup:

Welcome to minicom 2.7                                                                                          
                                                                                                                
OPTIONS: I18n                                                                                                   
Compiled on Jan  1 2014, 09:30:18.                                                                              
Port /dev/ttyACM0, 22:59:36                                                                                     
                                                                                                                
Press CTRL-A Z for help on special keys                                                                         
                                                                                                                
                                                                                                                
nsh>                                                                                                            
     nsh>                                                                                                       
          nsh>                                                                                          
nsh> 
nsh>
nsh> 
nsh> ls
/:
 dev/
nsh> ls dev
/dev:
 console
 null
 ttyACM0
 ttyS0
nsh>

Further Reading

Additional Info

Compiling for native Linux target

drasko@Lenin:~/nuttx/nuttx/tools$ ./configure.sh sim/nsh

Using nsh

Executing apps

Conversation from IRC channel #nuttx
====================================

<drasko> nsh> hello
<drasko> nsh: hello: command not found
<patacongo_> try mount -t binfs /bin
<patacongo_> sim/nsh has the binfs enabled any you must do that first
<patacongo_> ls /bin
<patacongo_> echo $PATH

Example of usage:

drasko@Lenin:~/nuttx/nuttx$ ./nuttx

NuttShell (NSH)
nsh> help
help usage:  help [-v] [<cmd>]

  [           df          kill        mh          rmdir       unset       
  ?           echo        losetup     mount       set         usleep      
  break       exec        ls          mv          sh          xd          
  cat         exit        mb          mw          sleep       
  cd          false       mkdir       poweroff    test        
  cp          free        mkfatfs     ps          true        
  cmp         help        mkfifo      pwd         uname       
  dd          hexdump     mkrd        rm          umount      

Builtin Apps:
  hello
nsh> hello
nsh: hello: command not found
nsh> ls
/:
 dev/
 etc/
 tmp/
nsh> mount -t binfs /bin
nsh> ls
/:
 bin/
 dev/
 etc/
 tmp/
nsh> ls bin
/bin:
 hello
nsh> hello
Hello, World!!
nsh> 

More info: http://www.nuttx.org/doku.php?id=wiki:nshhowtos:nshapplications

Exiting

Conversation from IRC channel #nuttx
====================================

<drasko> How do you exit simulator?
<patacongo_> Control C does not work with the simulator because the terminal is in raw mode.
<patacongo_> I usually just do nsh> mw 0
<patacongo_> that will get you out with a memory fault (assuming that address 0 is not readable)
<patacongo_> Otherwise, use some other garbage address

In practice:

nsh> mw 0
Segmentation fault
drasko@Lenin:~/nuttx/nuttx$