Month: October 2020

NuttX apps compilation issue

If you decide you create your own NuttX application based on apps/examples/hello you could eventually face this issue:

CC: my_app_main.c
:0:6: error: expected identifier or '(' before numeric constant
:0:6: error: expected identifier or '(' before numeric constant
my_app_main.c:51:5: note: in expansion of macro 'main'
int main(int argc, FAR char *argv[])
make[3]: *** [/home/alan/apps/ my_app_main.home.alan.apps.examples.my_app.o] Error 1

This error happens because your PROGNAME defined inside the Kconfig differs from your application name:

string "Program name"
default "myapp"

If your PROGNAME is myapp then you need to have apps/examples/myapp/myapp_main.c otherwise it will not work. So don’t my_app for your app directory neither my_app_main.c for your main file, it needs to be myapp_main.c

Linking external libraries on NuttX

Some time ago I needed to link with ARM DSP library on NuttX to use FFT feature and I decided to document how I did it and some tricks to reduce the final binary size.

In fact to include a library all you need to do is add it to your board Make.defs. See a simple patch file to stm32f4discovery:

index 59aa60bf6b..5e6845c81c 100644
--- a/boards/arm/stm32/stm32f4discovery/scripts/Make.defs
+++ b/boards/arm/stm32/stm32f4discovery/scripts/Make.defs

+EXTRA_LIBS = "$(TOPDIR)/3rparty/libarmdsp.a"
NXFLATLDFLAGS1 = -r -d -warn-common
NXFLATLDFLAGS2 = $(NXFLATLDFLAGS1) -T$(TOPDIR)/binfmt/libnxflat/gnu-nxflat-pcrel.ld -no-check-sections
LDNXFLATFLAGS = -e main -s 2048

It means you need to create a “3rdpary” directory at root of nuttx/ and put your library there.

But after the compilation you will notice that your nuttx.bin binary will become very big. It happens because the linker will include all the functions from the library.

You can instruct it to include only the needed functions using this parameter with LDFLAGS:

LDFLAGS += --gc-sections

Now your binary will become way smaller

Testing PSRAM support for NuttX on ESP-WROVER-KIT

configsip: 0, SPIWP:0xee
mode:DIO, clock div:2
ho 0 tail 12 room 4
entry 0x40080680
I (30) boot: ESP-IDF v4.2-dev-1883-gb8f5d2e46 2nd stage bootloader
I (30) boot: compile time 17:37:10
I (30) boot: chip revision: 1
I (35) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (42) boot.esp32: SPI Speed : 40MHz
I (46) boot.esp32: SPI Mode : DIO
I (51) boot.esp32: SPI Flash Size : 2MB
I (55) boot: Enabling RNG early entropy source…
I (61) boot: Partition Table:
I (64) boot: ## Label Usage Type ST Offset Length
I (72) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (79) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (87) boot: 2 factory factory app 00 00 00010000 00100000
I (94) boot: End of partition table
I (98) boot_comm: chip revision: 1, min. application chip revision: 0
I (105) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x02eb8 ( 11960) map
I (120) esp_image: segment 1: paddr=0x00012ee0 vaddr=0x3ffbae40 size=0x0006c ( 108) load
I (123) esp_image: segment 2: paddr=0x00012f54 vaddr=0x40080000 size=0x00400 ( 1024) load
I (133) esp_image: segment 3: paddr=0x0001335c vaddr=0x40080400 size=0x01c64 ( 7268) load
I (145) esp_image: segment 4: paddr=0x00014fc8 vaddr=0x00000000 size=0x0b050 ( 45136)
I (169) esp_image: segment 5: paddr=0x00020020 vaddr=0x400d0020 size=0x1a43c (107580) map
I (217) boot: Loaded app from partition at offset 0x10000
I (218) boot: Disabling RNG early entropy source…
NuttShell (NSH) NuttX-9.1.0
nsh> free
total used free largest
Umem: 4477264 15872 4461392 4194288
nsh> ?
help usage: help [-v] []
. cd exec ifconfig mkrd put test usleep
[ cp exit ifdown mh pwd telnetd wget
? cmp false ifup mount rm time xd
arp dirname free kill mv rmdir true
basename dd get ls mw set uname
break df help mb nslookup sleep umount
cat echo hexdump mkdir ps source unset
Builtin Apps:
sh ramtest ping nsh
nsh> ramtest -w 0x3F800000 4194304
RAMTest: Marching ones: 3f800000 4194304
RAMTest: Marching zeroes: 3f800000 4194304
RAMTest: Pattern test: 3f800000 4194304 55555555 aaaaaaaa
RAMTest: Pattern test: 3f800000 4194304 66666666 99999999
RAMTest: Pattern test: 3f800000 4194304 33333333 cccccccc
RAMTest: Address-in-address test: 3f800000 4194304