Cortex Cross Development Environment

I’ve been using ARM processors with C/C++ for more than a decade for nearly all of my embedded development.  I’ve usually used Em::Blocks on Windows platforms which works nicely but doesn’t fully work on linux, doesn’t support integrated version control, and hides some details that I want to have control over.

I’m working on some new projects using Cortex M3 and M4 processors and wanted to explore the available tools.  My favorite IDE is still NetBeans.  Netbeans was meant for Java, but has a C/C++ plugin and is fairly easy to configure for gcc cross-compilation using gnu tools for arm (linux/mac/windows).  I’d really like to get the environment working both on windows and linux since I routinely use both.  This post details the linux setup:

1) Download and install the GNU tools for ARM in /usr/local/gcc-arm-none-eabi-…:

cd /usr/local
sudo tar xjf ~dalbert/Downloads/gcc-arm-none-eabi-*.bz2

Add the tools to the search path (add the following to ~/.bashrc):


2) Install the C++ plugin for Netbeans and configure NetBeans to use add the new arm cross-compilation toolchain:

Tools->Options->C/C++->Add the configure the base directory (e.g. /usr/local/gcc-arm-none-eabi-4_9-2014q4/bin) and the c, c++, assembler, and debugger programs to arm-none-eabi-gcc, arm-none-eabi-g++, arm-none-eabi-as, arm-none-eabi-gdb.  I add the cross tools as GNU_ARM

3) Install the GDB Server plugin for Netbeans.  This allows you to attach NetBeans debugger to the remote target using the configured gdb debugger (arm-none-eabi-gdb per the above step).  To debug, Debug->Attach Debugger, choose debugger type as “gdbserver”, choose target as “remote:4242”, and set the project to your project.

4) For hardware assisted debugging, the STMlinkv2 software works with the STLink USB JTAG/SWD debug hardware ($30 from Digikey and included free with any ST Discovery board; I like this one that costs $10 at Digikey); documentation is here.

Install texane stmlinkv2 (for linux, install the packages required to build stmlinkv2: autotools autoconf autogen libusb-1.0.0 and maybe libusb-1.0.0-dev, intltool) see here and here for more info.  Windows binaries are here.  Included is st-flash for flashing the processors, st-info, st-term, and st-util: a GDB server.  For Windows, just unzip the folder to a convenient location and run st-util.  For linux, after installing the dependencies (listed above), build STMLinkV2 and install it (installs in /usr/local/bin):

sudo make install

Grant permissions for the tools (e.g. st-util) to access the USB ST-Link V2 hardware:

sudo install -m 644 49-stlinkv2.rules /etc/udev/rules.d/49-stlinkv2.rules
sudo udevadm control –reload-rules

More info on permissions for st-util

5) Download sample code and create a project for one of the examples.  I keep my NetBeans projects in my home directory in a NetBeansProjects directory:

File->New Project->C/C++ Project with Existing Sources->~/NetBeansProjects/kkstm32_base-master/example/32l_lcd
Set the Tool Collection to GNU_ARM and select Automatic configuration mode then press finish.
Note: the STM32 library in the downloaded example code I’ve linked to contains an error in core_cm3.c that must be fixed (add the ‘&’ in front of result r); see diffs below:

dalbert@mypc ~/NetBeansProjects/kkstm32_base-master/libs_stm/inc/core_support $ diff core_cm3.c.orig core_cm3.c
<    __ASM volatile (“strexb %0, %2, [%1]” : “=r” (result) : “r” (addr), “r” (value) );

>    __ASM volatile (“strexb %0, %2, [%1]” : “=&r” (result) : “r” (addr), “r” (value) );
<    __ASM volatile (“strexh %0, %2, [%1]” : “=r” (result) : “r” (addr), “r” (value) );

>    __ASM volatile (“strexh %0, %2, [%1]” : “=&r” (result) : “r” (addr), “r” (value) );

cd kkstm32_base-master/libs_stm/build
make     (to build the STM32 peripheral library)
cd kkstm32_base-master/example/32l_lcd
make     (to build the example code – builds lcd.elf, lcd.bin)

6) Build and load one of the examples built above into your STM32L Discovery eval board using the CLI first to confirm that everything is working:

st-flash write lcd.bin 0x8000000
test the other nifty st tools: st-info, st-term, st-util

7) Test debug interface from CLI:

st-util   (runs gdb-server which listens on localhost:4242)
arm-none-eabi-gdb -q lcd.elf
(gdb) target remote localhost:4242

8) Optionally install openocd (gdb server compatible) and test it for debugging:

sudo apt-get install openocd       (installs to /usr/share/openocd)
openocd –version
sudo openocd -f /usr/share/openocd/scripts/interface/stlink-v2.cfg -f /usr/share/openocd/scripts/target/stm32lx_stlink.cfg
in another window: telnet localhost 4444

9) Import one of the example projects into NetBeans and test operation in the IDE!

File->New Project->C/C++->C/C++ Project with Existing Sources
Choose source folder and GNU_ARM tool collection
Select Automatic Configuration Mode
Right click the project->Properties->Build->Make->Build Result = build/ch.elf

Make sure the Makefile is compiling the project with debugging enabled (-g)

Other links related to setting up a gnu/arm cross development environment:

  •   (wiki for the stlink tools)
  •  (detailed discussion of stlink tools)
  •  (very detailed article on eclipse, openocd, and a wide range of cross tools)
  • LibOpenCM3
  •   (STM32 peripheral library)

Next steps: