Some quick notes and tests to start developing with NuttX on STM32F4 Discovery board using an open software stack with GNU/Linux.

Hardware

Software

Running NuttX on STM32F4 Discovery board

Install dependencies:

$ sudo apt-get install \
     gperf libncurses5-dev flex bison \
     curl automake autoconf libtool perl \
     pkg-config minicom build-essential \
     cmake libusb-1.0-0-dev libgtk-3-dev

Follow this documentation to install the toolchain.

Build and install kconfig-frontends package:

$ mkdir ~/sandbox && cd ~/sandbox
$ KF=http://ymorin.is-a-geek.org/download/kconfig-frontends && \
  wget ${KF}/kconfig-frontends-3.12.0.0.tar.xz
$ tar xvf kconfig-frontends-3.12.0.0.tar.xz
$ cd kconfig-frontends-3.12.0.0
$ curl -O \
  http://javiermunhoz.com/blog/content/nuttx/20190715-kconfig-frontends.patch
$ patch -p1 -i 20190715-kconfig-frontends.patch
$ autoreconf -fi
$ ./configure --prefix=/usr
$ make
$ sudo make install

Build NuttX and Apps with the build host platform to Linux:

$ cd ~/sandbox
$ mkdir nx
$ git clone https://bitbucket.org/nuttx/nuttx.git nuttx
$ git clone https://bitbucket.org/nuttx/apps.git apps
$ cd nuttx
$ tools/configure.sh stm32f4discovery/usbnsh
$ make menuconfig
#  Build Setup
#     `--> Build Host Platform (Linux)
$ make

Build ST-Link:

$ cd ~/sandbox
$ git clone https://github.com/texane/stlink
$ cd stlink
$ make release
$ find . -type f -name "st-*" | grep build
./build/Release/st-flash
./build/Release/st-info
./build/Release/src/gdbserver/st-util
$ cd build/Release
$ sudo make install
$ sudo ldconfig

Plug the board and run st-info:

$ sudo st-info
st-info --version
st-info --flash
st-info --sram
st-info --descr
st-info --pagesize
st-info --chipid
st-info --serial
st-info --hla-serial
st-info --probe
$ sudo st-info --version
v1.5.1-30-g84f63d2
$ sudo st-info --flash
0x100000
$ sudo st-info --sram
0x30000
$ sudo st-info --descr
F4 device
$ sudo st-info --pagesize
0x4000
$ sudo st-info --chipid
0x0413
$ sudo st-info --serial
303030303030303030303031
$ sudo st-info --hla-serial
"\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x31"
$ sudo st-info --probe
Found 1 stlink programmers
 serial: 303030303030303030303031
openocd: "\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x31"
  flash: 1048576 (pagesize: 16384)
   sram: 196608
 chipid: 0x0413
  descr: F4 device

Flash NuttX:

$ cd ~/sandbox/nx/nuttx
$ sudo st-flash write nuttx.bin 0x8000000

NSH test with Minicom (115200-8-N-1):

$ sudo minicom -s -c on -D /dev/ttyACMX

Welcome to minicom 2.7.1

OPTIONS: I18n
Compiled on Aug 13 2017, 15:25:34.
Port /dev/ttyACMX, 00:01:02

Press CTRL-A Z for help on special keys


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

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

Builtin Apps:
nsh>

Debugging NuttX on STM32F4 Discovery board

Build with debug symbols (needed for use with a debugger):

$ cd ~/sandbox/nx/nuttx
$ make menuconfig
# Build Setup
#    `--> Debug Options
#            `--> Generate Debug Symbols
$ make
$ cat ~/.gdbinit
target extended-remote :4242
monitor halt
monitor reset
load
break __start
continue

Run st-util:

$ sudo st-util -p 4242
st-util 1.5.1-30-g84f63d2
2019-07-15T00:01:02 INFO usb.c: -- exit_dfu_mode
2019-07-15T00:01:02 INFO common.c: Loading device parameters....
2019-07-15T00:01:02 INFO common.c: Device connected is: F4 device, id 0x10036413
2019-07-15T00:01:02 INFO common.c: SRAM size: 0x30000 bytes (192 KiB),
 Flash: 0x100000 bytes (1024 KiB) in pages of 16384 bytes
2019-07-15T00:01:02 INFO gdb-server.c: Chip ID is 00000413, Core ID is  2ba01477.
2019-07-15T00:01:02 INFO gdb-server.c: Listening at *:4242...

Run the debugger:

$ arm-none-eabi-gdb nuttx
GNU gdb (GNU MCU Eclipse ARM Embedded GCC, 64-bit) 8.3.50.20190509-git
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
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=x86_64-unknown-linux-gnu
 --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from nuttx...
__start () at chip/stm32_start.c:271
271     {
Loading section .text, size 0x11eb9 lma 0x8000000
Loading section .ARM.extab, size 0x240 lma 0x8011ebc
Loading section .ARM.exidx, size 0x12e0 lma 0x80120fc
Loading section .data, size 0x6c lma 0x80133dc
Start address 0x8000188, load size 78917
Transfer rate: 9 KB/sec, 7891 bytes/write.
Breakpoint 1 at 0x8000188: file chip/stm32_start.c, line 271.
Note: automatically using hardware breakpoints for read-only addresses.

Breakpoint 1, __start () at chip/stm32_start.c:271
271     {
(gdb)

References

Comments

comments powered by Disqus

Recent Entries