Compiling and Installing the NuttX on Bambino 200E board
This tutorial is using Ubuntu 16.04 LTS, but you can adapt it to other distros.
Pre-requesites
First, install a few packages we'll need :
sudo apt-get install automake bison build-essential flex gperf git libncurses5-dev libtool libusb-dev libusb-1.0.0-dev
Work folder
Now create a workspace directory:
mkdir -p ~/nuttxspace cd ~/nuttxspace
Toolchain installation
Then we need to install the ARM GCC Toolchain.
For this you use the repositories : We want a version >= gcc version 6.3.1 20170620
From the repositories
Simply do :
sudo apt-get install gcc-arm-none-eabi
Cloning NuttX
Clone the NuttX repositories:
git clone https://bitbucket.org/nuttx/nuttx git clone https://bitbucket.org/nuttx/apps git clone https://bitbucket.org/nuttx/tools
Compiling Kconfig
Enter inside tools/kconfig-frontends/ to compile it:
cd tools/kconfig-frontends/ ./bootstrap ./configure make sudo make install
If all happened as expected you installed the kconfig inside /usr/local/bin.
Compiling NuttX
Now we can compile the NuttX for Bambino board:
cd ~/nuttxspace/nuttx/tools ./configure.sh bambino-200e/nsh cd .. make
When the compilation finishes it will create a the nuttx.bin that needs to be flashed in the Bambino board.
Flashing to the board
Here is a list of different methods you can use to flash the board, mostly depending on the hardware available to you :
Using a STLink-v2 with OpenOCD
Note: You will need to use the OpenOCD version 0.10 or newer from repository. OpenOCD 0.9 from Ubuntu repository doesn't work.
In order to flash the firmware (nuttx.bin) inside the board using a ST-Link v2, you need to connect the JTAG/SWD programmer in the J5 connector of the board.
This is the command to use to flash nuttx.bin inside the board:
sudo openocd -f interface/stlink-v2.cfg -f target/lpc4350.cfg -c init -c "reset halt" -c "flash write_image erase nuttx.bin 0x14000000"
Note we are using “lpc4350.cfg”, it is because openocd doesn't have the “lpc4330.cfg”, but it works fine with LPC4330.
Just connect the USB/Serial board to Slot/Connector 5 and use some serial console terminal like “minicom” configured to 115200 8n1 to get access to NuttX prompt.
Using JLink with OpenOCD
Note: You will need to use the OpenOCD version 0.10 or newer from repository. OpenOCD 0.9 from Ubuntu repository doesn't work.
To use JLink programmer to flash the Bambino board you need edit the jlink.cfg to use the SWD instead of JTAG:
$ sudo vi /usr/local/share/openocd/scripts/interface/jlink.cfg
Then add this line at end of file:
transport select swd
Now you can use the same command line that was used with STLink-V2 programmer:
$ sudo openocd -f interface/jlink.cfg -f target/lpc4350.cfg -c init -c "reset halt" -c "flash write_image erase nuttx.bin 0x14000000"
If this command doesn't work for you, try it instead:
$ sudo openocd -f interface/jlink.cfg -f board/lpc4350_spifi_generic.cfg -c init -c "reset halt" -c "flash write_image erase nuttx.bin 0x14000000"
We should see this message:
Open On-Chip Debugger 0.10.0-dev-00371-g81631e4 (2016-09-26-12:35) Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html swd adapter speed: 500 kHz cortex_m reset_config vectreset Info : No device selected, using first device. Info : J-Link ARM V8 compiled Nov 28 2014 13:44:46 Info : Hardware version: 8.00 Info : VTarget = 3.313 V Info : clock speed 500 kHz Info : SWD DPIDR 0x2ba01477 Info : lpc4350.m4: hardware has 6 breakpoints, 4 watchpoints Warn : Only resetting the Cortex-M core, use a reset-init event handler to reset any peripherals or configure hardware srst support. lpc4350.m4: target state: halted target halted due to debug-request, current mode: Thread xPSR: 0x01000000 pc: 0x10402c40 msp: 0x10087ff0 auto erase enabled Info : Found flash device 'win w25q64cv' (ID 0x001740ef) wrote 131072 bytes from file nuttx.bin in 5.381125s (23.787 KiB/s)
Using lpc21isp
Based on this guide.
The lpc21isp application communicates with the LPC43xx via its UART0 peripheral.
By default the board is configured so that the LPC43xx response is to start running the code which has previously been loaded into the internal FLASH of the device.
You need to use a special reset sequence to get the LPC43xx to run the built-in ISP boot loader instead.
To enter ISP mode we just need to:
- Press and hold down the ISP button.
- Press and release the RESET button.
- Release the ISP button.
This is the same as the procedure for flashing the v1 bootloader.
Once the device is running the ISP boot loader, lpc21isp can be used to load new firmware into the internal FLASH of the device.
First, install lpc21isp :
sudo apt-get install lpc21isp
Then, we need to get the “make” command to produce a .hex file ( which it doesn't by default ), do :
make menuconfig
Then go to Build Setup, then Binary Output Format, then select Intel HEX binary format ( with the space bar ), then select Save, and finally exit.
Finally, build the firmware again :
make
And now it should have produced a nuttx.hex file
Finally, we can flash the firmware to the board :
lpc21isp nuttx.hex /dev/ttyUSB0 115200 12000
- You will need to change /dev/ttyUSB0 to match the device name for the FTDI USB device on your machine.
- The baud rate of 115200 appears to be the highest rate that can be used by the LPC43xx when it is running in ISP mode where it uses the internal 12MHz IRC clock source.
Using J-link
Based on this guide.
The first step to working with the J-Link debugger is to install the necessary software from SEGGER.
- Install the Software & documentation pack software appropriate for your operating system
Two programs are involved in using GDB to debug via the J-Link hardware debugger.
One is a TCP/IP based debug server provided by SEGGER in the Software & documentation pack and the other is arm-none-eabi-gdb.
They are each started as below:
JLinkGDBServer -device LPC4330_M4 -endian little -if JTAG -speed 10000 -localhostonly arm-none-eabi-gdb -ex "set target-charset ASCII" -ex "set print pretty on" -ex "target remote :2331" -ex "set mem inaccessible-by-default off" nuttx
- JLinkGDBServer connects to the J-Link hardware pod via the provided USB cable. The command line options it is given let it know that we are debugging a LPC43xx device (specifically the M4 core), the device is setup as little endian, using JTAG as the debug protocol instead of SWD, the JTAG protocol should run at 10MHz, and only allow GDB processes from the same machine to connect (reduces the security risk of remote connections to the debug stub).
- arm-none-eabi-gdb connects to JLinkGDBServer via a TCP/IP socket on port 2331. It can then be used in a fashion similar to how MRI has been used to debug Smoothie firmware in the past.
It is possible to use GDB and the JLinkGDBServer to upload code into the LPC4330 via JTAG. I see upload speeds of >1MiB/sec when using this method.
From within GDB, you can issue the following commands to upload the binary contents of the specified .elf file into the microcontroller and start it executing again from a clean reset.
Ctrl+C load monitor reset continue
Using LPCScrypt
First off download the User Guide PDF here.
In particular, read section 3.2 and 3.3 about what needs to be installed before LPCScrypt can run.
Here is a brief summary of what is required for Ubuntu platforms:
- LPCScrypt installs 32-bit binaries so 64-bit Ubuntu installs will need additional 32-bit library support:
- Ubuntu 13.04 of earlier:
sudo apt-get install linux32 ia32-libs
- Ubuntu 13.10 and later:
sudo apt-get install libc6:i386 libusb-dev:i386 uuid-dev:i386 libgtk2.0-0:i386 gtk2-engines-murrine:i386
- It can be nice to have the USB based serial ports exposed by the LPCScrypt second stage boot loader accessible from user mode:
sudo scripts/install_udev_rules
Then, download LPCScript from here and install it.
You then need to enter bootloader mode :
- Press and hold down the ISP button.
- Press and release the RESET button.
- Release the ISP button.
This is the same as the procedure for flashing the v1 bootloader.
You can then use LPCScrypt to flash your firmware :
./scripts/boot_lpcscrypt ./bin/lpcscrypt program +c /path/to/nuttx/nuttx.bin BankA ./bin/lpcscrypt resetCore
Alternatively this has been known to work :
sleep 1 ./bin/lpcscrypt -d /dev/ttyACM0 program +c LPC4330_M4/Smoothie2.bin SPIFI sleep 1 ./bin/lpcscrypt -d /dev/ttyACM0 resetCore
Verifying NuttX Initialization
You flashed the nuttx.bin firmware inside Bambino 200E board, now you can see the NuttX initialization over serial.
Just connect the USB/Serial board to Gadgeteer Slot 5 (label: “KU X”) and use some serial console terminal like “minicom” with the USB/Serial device file detected by Linux (use dmesg to see it, normall will be /dev/ttyUSB0) and configure it to 115200 8n1 to get access to NuttX prompt.
Press the “RESET” button near USB1 connector and you will see the NuttX initialization:
NuttShell (NSH) nsh>
Type “help” or “?” to see the available commands:
nsh> ? help usage: help [[-v|]] [[<cmd>|]] [ cmp false mkdir rm true ? dirname free mh rmdir uname basename dd help mount set umount break df hexdump mv sh unset cat echo kill mw sleep usleep cd exec ls ps test xd cp exit mb pwd time Builtin Apps: nsh>
Testing Ethernet
You can test Ethernet on Bambino board using these steps:
cd ~/nuttxspace/nuttx/tools ./configure.sh bambino-200e/netnsh cd .. make
Flash the nuttx.bin firmware as explained before and use an ethernet cable to connect your board to your router. Look in the router Status page the IP it defined to Bambino board, then execute from your Linux machine:
telnet 192.168.0.14
Supposing 192.168.0.14 was the IP address your router attributed to Bambino board, replace it with the correct IP.
Testing USB
You can test USB on Bambino board using these steps:
cd ~/nuttxspace/nuttx/tools ./configure.sh bambino-200e/usbnsh cd .. make
Flash the nuttx.bin firmware as explained before and connect a USB cable on USB0 port and to your PC.
Reset the board, you will see in the “dmesg” of Linux that it created the USB/Serial device as ttyACM0. Configure the minicom to use /dev/ttyACM0 115200 8N1.
Press Enter three times in the minicom to start the NuttX Shell.
Testing SD Card
TODO