Menu

Microcontroller Runtime System Environment

Rainer Müller FMA

Intro

The runtime system is realized in C++. It consists of the following main components:

  • FreeRTOS in the version 8.1.2 (with some changes)
  • CMSIS-Library from ARM for easy access of Cortex-M specifc features
  • LPCOpenV2.0 from NXP for easy access of the target processor specific features
  • the wrapper classes to FreeRTOS for task operations
  • the plattform independen part of the PEARL runtime system

These resources are structured as:

runtime/
    lpc1768_landtiger  the main entry for the build process for the specific target system
    common/            the plattform independent part of the runtime system
    cortexM/           the plattform specific 3rd party packages
        CMSIS/           the Cortex-M System Interface Software (from ARM)
        LPCOpen/         the processor support library from NXP
    FreeRTOS/          the FreeRTOS specific parts like
        FreeRTOS/        FreeRTOS itself without most of the supplied ports
        PEARL/           the FreeRTOS specific parts of the runtime system

This directory structure enables easy ports to other processors and boards.


Development Hardware

Development board

As development board a NXP LPC1768 based HY-LandTiger board was used:

  • ARM Cortex-M3 100MHz (details)
  • 512KB on-chip Flash
  • 64KB SRAM
  • for the RTC a battery of type CR1225 must be inserted

Documentation

  • LandTiger V2.0 LPC17XX Development Board (link)

Distributors

  • SainSmart (link)
  • HAOYU Electronics (link)
  • Amazon (search for SainSmart)

Development software

A native ArchLinux-system in a VirtualBox-VM with 4GB RAM (due to the use of JVM/Eclipse), 40GB hard disc and the latest VirtualBox extension package for USB 2.0 support for external debugging purposes is used.

Other distributions should work! (e.g. the same distribution as decribed in the linux trunk of OpenPEARL)

This part uses NXP/LPCOpen V2.x, ARM/CMSIS, FreeRTOS and other source libraries. The license agreements are ok to integerate them into the repository.

Required Software for Building

  • from your linux distribution the same tools as for the Linux trunk
    (make, doxygen, graphviz, texlive, perl, lex, yacc, OpenOffice, ...)
  • required write access to system files during development. This may be done with a call of 'make prepare' with root priviledges (/usr/local/lib/libOpenPEARLlpc1768.a, /usr/klocal/lib/ldscripts, /usr/local/lib/OpenPEARLlpc1768_board.o, and my be some more)
  • gcc-toolchain from Lauchpad: (here)
    • Note: regard that not all versions work properly .
      • 5-4-2016q3 and 5-4-2016q2 are known to fail
      • 5-3-2016q1 is known to work
    • download gcc-arm-none-eabi-<xxxx>-linux.tar.bz2 </xxxx>
    • install to (e.g. /usr/local) and setup path variable
      • cd /usr/local && tar xjf gcc-arm-none-eabi-*-yyyymmdd-mac.tar.bz2
      • add export PATH=$PATH:$install_dir/gcc-arm-none-eabi-*/bin in /etc/profile
      • remarks:
        • Path should work after new login
  • Build environment:
    The default build environment is 'make'.
  • Download to the target:
    • install lpc21isp to flash the controller via the serial link (link)
      • apt-package is available in debian
      • else
        • download; unzip; make
        • copy to e.g. /usr/local/bin
    • a standard USB<->RS232 converter may be used.
    • add the device into your udev-rules in order to allow all users to use the device.
    • the 'Makefile' create a prl-handling skript. Setup the flash device in the OpenPEARL configuration
    • connect to tty part to UART0
    • set the jumpers RST and ISP
    • the console outputs are directed to UART0
    • Note:
      • When using minicom you may get trouble since minicom does not release the reset when the jumper RST is set. Remove these jumpers when using minicom at UART0
      • enter the flash mode in this case manually by pressing
        1. RESET+INT0
        2. release RESET
        3. release INT0

Required Software for Debugging as Developer

  • For easier development eclipse may be usefull.
    • eclipse download (not described here)
    • Eclipse CDT (link)
    • create new empty makefile project in your workspace
    • add the folders .../runtime/FreeRTOS_lpc1768, .../runtime/FreeRTOS, .../runtime/common to the project
    • select the makefile in .../runtime/FreeRTOS_lpc1768
    • the Makefile uses the "makefile.conf": set the location of your cross toolchain location
    • NOTE: Be shure to 'safe files' before start a new build
  • Debug Environment: The lpc1768-Landtiger board provides a JTAG-socket as well as a Segger-JLINK-emulation.
    • Zylin Embedded CDT (link) must be added to your eclipse installation via the eclipse update
    • sample setup for debugging via JTAG: see subsection "Open On-Chip Debugger (OpenOCD)"
    • sample setup for debugging via JLINK: see subsection "Debugging with Segger-JLINK-Emulation"
  • Debugging with Segger-JLINK-Emulation

    • download segger jlink tools from link J-Link software/J-Link for Linux
    • install with dpkg -i ./jlink_x.y.deb
    • connect the Landtiger board CN4 to your computer with an usual USB cable
    • make shure that the udev-rules include the segger jlink device (rules are delivered together with the segger download)
      • lsusb must list 'ID 1366:0101 SEGGER J-Link ARM'
    • verify installation from command line: JLinkGDBServer should reply

    ...
    Connecting to J-Link...
    J-Link is connected.
    Firmware: J-Link ARM-OB STM32 compiled Aug 22 2012 19:52:04
    Hardware: V7.00
    Feature(s): RDI,FlashDL,FlashBP,JFlash,GDBFull
    Checking target voltage...
    Target voltage: 3.30 V
    Listening on TCP/IP port 2331
    Connecting to target...
    J-Link found 1 JTAG device, Total IRLen = 4
    JTAG ID: 0x4BA00477 (Cortex-M3)
    Connected to target
    Waiting for GDB connection...

    abort the program with ^C

    • setup jlinkgdbserver as external tool in eclipse

      • new launch configuration
        • Name: e.g. LPC_Landtiger_JLINK
      • Main-tab: Location: /usr/bin/JLinkGDBServer (location depends on your installation)
    • create a debug configuration in eclipse for jlink-debugging

      • RUN/Debug Configurations ...
      • New Launch Configuration
        • Main-Tab:
          • Name: e.g.Landtiger_Flash
          • Project:
        • Debugger-Tab:
          • Debugger: Embedded GDB
          • Stop on startup at main: checked
          • GDG debugger: /root/MentorGraphics/Sourcery_CodeBench_Lite_for_ARM_EABI/bin/arm-none-eabi-gdb
            the path depends on your toolchain and installation location
          • GDB command file: - empty -
        • Commands-Tab:
          • Initialize Commands: - see below - (working, but not optimized, yet)
        • Run commands: - empty -
      • a debug session will download the application to flash and restart the processor.
      • the location of the application is given in the 'Initialize' commads as absolute path (not nice but working)

Initialization commands:

target remote localhost:2331
# stop CPU
monitor reset halt
# wait for 200ms
monitor sleep 200
# write compiled binary file
monitor flash device=lpc1768
monitor interface swd
monitor sleep 200
load
monitor sleep 200
monitor reg r13 = (0x0000)
monitor sleep 200
monitor reg pc=(0x0004)
monitor sleep 200
monitor flash breakpoints = 1
# wait for 200ms
monitor sleep 200
# reset CPU
monitor reset
# wait for 200ms
monitor sleep 200

Open On-Chip Debugger (OpenOCD)

  • Distributors of JTAG probes (incomplete list)

    • Olimex ARM-USB-TINY (link)
    • Amontec JTAGkey-Tiny (link)
  • download and install Open On-Chip Debugger (OpenOCD 0.7.0-3) (link)

Step-1: Configure OpenOCD

# Example: lpc1768.cfg  & Olimex ARM-USB-TINY
#
# JTAG interface (ARM-USB-TINY)
source [find interface/olimex-arm-usb-tiny-h.cfg]
# CPU type
source [find cpu/arm/cortex_m3.tcl]
# CPU variant
source [find target/lpc1768.cfg]
# monitor port (default)
telnet_port 4444
# GDB listener port (default)
gdb_port 3333
# JTAG transmission speed
adapter_khz 500

Next you can start OpenOCD from command line with the corresponding configuration ...

$ openocd -f lpc1768.cfg

Open On-Chip Debugger 0.7.0 (2013-11-25-15:57)    
Licensed under GNU GPL v2
For bug reports, read
http://openocd.sourceforge.net/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'jtag'
adapter_nsrst_delay: 200
jtag_ntrst_delay: 200
adapter speed: 10 kHz
cortex_m3 reset_config vectreset
adapter_nsrst_assert_width: 10
adapter_nsrst_delay: 2
srst_only separate srst_gates_jtag srst_open_drain connect_deassert_srst
adapter speed: 500 kHz
Info : max TCK change to: 30000 kHz
Info : clock speed 500 kHz  
Info : JTAG tap: lpc1768.cpu tap/device found: 0x4ba00477 (mfg: 0x23b, part: 0xba00, ver: 0x4)
Info : lpc1768.cpu: hardware has 6 breakpoints, 4 watchpoints
[...]

If no errors occur OpenOCD can communicate with the development board. Now you can connect via telnet to the OpenOCD monitor port 4444:

$ telnet localhost 4444
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Open On-Chip Debugger
> reset init
JTAG tap: lpc1768.cpu tap/device found: 0x4ba00477 (mfg: 0x23b, part: 0xba00, ver: 0x4)
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x1fff0080 msp: 0x10001ffc
[...]

For other configuration settings or monitor commands you should read the latest OpenOCD manual.

Configuration of Eclipse and OpenOCD

Step-1: External Tool Configuration

To get OpenOCD work together with Eclipse a remote debugging plugin for GDB debugger has to be installed. The Zylin CDT plugin can be installed using the Eclipse Update Manager.

http://opensource.zylin.com/zylincdt

Next you have to configure OpenOCD in the "External Tools" tab (screenshot)

Following settings must be made in the main tab (screenshot):

If you have started the external configuration from Eclipse you should see similar to the following output (screenshot):

Step-2: Debug configuration

Once you have successfully integrated OpenOCD into Eclipse the actual debug configuration (using the Zylin CDT) must be configured (screenshot):

To create a new debug configuration you have to select the main tab, enter a new project name and select the appropriate application (screenshot):

Within the debugger tab you have to select the cross-chain-debugger (e.g. arm-none-eabi-gdb) which you want to use for debugging purposes (screenshot)

At the top of the commands tab (initialize) you have to insert the basic debugger settings. At the bottom (run) the OpenOCD debug monitor settings are made. Monitor commands can be executed with the prefixed command "monitor"

Example settings

# stop CPU
monitor reset halt
# wait for 200ms
monitor sleep 200
# write compiled binary file
monitor flash write_image erase ./FLASH_RUN/main.bin 0x0 bin
# wait for 200ms
monitor sleep 200
# reset CPU
monitor reset
# wait for 200ms
monitor sleep 200
# re-initialize CPU
monitor reset init

With this configuration the compiled project (main.bin) is flashed to MCU and a debug session will be launched (screenshot):


Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.