Using NuttX as library once again

If you follow this blog you know that I already show how to use NuttX as a library to avoid compiling it all the time using the build system. But unfortunately I did it more than 3 years ago and NuttX changed a lot since that time.

So, let’s to start configuring the STM32F429IDISCOVERY board.

Create the nuttxspace directory and clone the nuttx and apps:

$ mkdir ~/nuttxspace
$ cd ~/nuttxspace
$ git clone nuttx
$ git clone apps

Configure the NuttX to the STM32F429IDISCOVERY board and ‘nsh’ profile:

$ cd ~/nuttxspace
$ cd nuttx
$ make distclean
$ ./tools/ stm32f429i-disco:nsh
$ make menuconfig

Select HELLO application and use USER_ENTRYPOINT = hello_main

Exit menuconfig and run:

$ make export

If everything worked fine it should have created a nuttx-export file:

$ ls -l nuttx-export*
-rw-rw-r-- 1 alan alan 4396597 Jun 28 09:49

Now create your hello world directory and copy this export file to there

$ mkdir ~/hello
$ cp ~/hello
$ cd ~/hello
$ unzip
$ cd nuttx-export-9.0.0

Finally create your hello.c file:

#include <stdio.h>

int hello_main(void)
        printf("Hello World from my App!\n");
        return 0;

Compile it:

$ arm-none-eabi-gcc -c -fno-builtin -Wall -Wstrict-prototypes -Wshadow -Wundef -g -mcpu=cortex-m4 -mthumb -mfloat-abi=soft -I. -isystem ./include   -pipe -I "./include" -I "./arch/chip" hello.c -o  hello.o

We just need to link again all libs to generate our nuttx ELF:

$ arm-none-eabi-ld --entry=__start -nostartfiles -nodefaultlibs -T./scripts/ld.script -L./libs hello.o -o nuttx.elf --start-group -lc -larch -lbinfmt -lboard -lboards -ldrivers -lfs -lmm -lsched -lxx "/usr/lib/gcc/arm-none-eabi/9.2.1/thumb/v7e-m/nofp/libgcc.a" --end-group

Finally convert the ELF to BIN to flash into the board:

$ arm-none-eabi-objcopy -S -O binary nuttx.elf nuttx.bin

Time to flash it:

$ sudo openocd -f interface/stlink-v2.cfg -f target/stm32f4x.cfg -c init -c "reset halt" -c "flash write_image erase nuttx.bin 0x08000000"

Open the minicom and reset the board, you should see:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s