Embedded development with open source tools on Windows
Overview
- Get a proper editor
- Install the GCC ARM Embedded toolchain
- Installing MinGW and MSYS
- Build a simple Hello World program with gcc
- Git version control system
- Ruby
- Python
- MC HCK specific instructions
- Programmer’s Notepad
- Cygwin
- OpenOCD and GDB
- Working with embedded Linux systems
- What’s next
- References/Further Reading
Get a proper editor
You probably want to install Notepad++ http://notepad-plus-plus.org/ or Programmer’s Notepad: http://www.pnotepad.org/.
Install the GCC ARM Embedded toolchain
GNU Tools for ARM Embedded Processors: https://launchpad.net/gcc-arm-embedded
Download the Windows installer from https://launchpad.net/gcc-arm-embedded/+download, for example:
And install it clicking everywhere next but choose a path without spaces, like C:\tools\gcc-arm-4.7-2013q3.
And add it to your default Windows PATH (to use it without Cygwin or with MinGW):
If you open the “Windows Command Processor” you should already be able to execute arm-none-eabi-gcc but this terminal is really ugly and the make command is missing.
Installing MinGW and MSYS
MinGW/MSYS: http://www.mingw.org/
Download the latest mingw-get-setup.exe: https://sourceforge.net/projects/mingw/files/latest/download
And follow http://www.mingw.org/wiki/Getting_Started
Under “All Packages” select also msys-mintty:
Mintty is a really nice terminal emulator for Cygwin and MSYS: http://code.google.com/p/mintty/
Its also a good idea to install msys-vim, msys-openssh, msys-patch, msys-rsync, msys-wget. You can either click the “MinGW Installer” shortcut on the desktop of use mingw-get:
Now add C:\MinGW\msys\1.0\bin and C:\MinGW\bin to the path:
Then create a mintty Desktop shortcut:
Then right click on the shortcut and change the target to C:\MinGW\msys\1.0\bin\mintty.exe /bin/bash -l to get a nice login shell that sources all the usual startup scripts:
And to get a “Open mintty here” context menu entry when clicking on a folder paste the following text in a file named mintty.reg and double click it:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\mintty]
@="Open mintty here"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\mintty\command]
@="C:\\MinGW\\msys\\1.0\\bin\\mintty.exe /bin/env CHERE=%L /bin/bash -l"
And edit C:\MinGW\msys\1.0\etc\profile and change the line that says:
cd "$HOME"
to:
if [ -z "$CHERE" ]; then
cd "$HOME"
else
cd "$CHERE"
fi
Another trick to open a normal command window: http://www.sevenforums.com/tutorials/27778-open-command-window-here.html
Build a simple Hello World program with gcc
Open a mintty window, you can use the shortcut from above to open the terminal within a specific directory, or just use cd to navigate.
Vim behaves somehow differently as expected from Linux but works for basic editing.
Git version control system
Install Git for Windows (sometimes also called msysgit): http://msysgit.github.io/
Git for Windows comes with a nice context menu and GUI tools:
I dunno why but I had to add a new environment variable to have git-gui, gitk in English.
If this is not enough then have a look at http://code.google.com/p/tortoisegit/
MC HCK specific instructions

My first MC HCK
The MC HCK is a cool little microcontroller development board, have a look here.
Install the dfu-util
You can download it from http://dfu-util.gnumonks.org/releases/:
Then extract the folder somewhere, for example: C:\tools\dfu-util-0.7-binaries\win32-mingw32 and add this directory to the path.
My PATH variable has now the following contents:
C:\Ruby200\bin;C:\tools\gcc-arm-4.7-2013q3\bin;C:\MinGW\msys\1.0\bin;C:\MinGW\bin;C:\tools\dfu-util-0.7-binaries\win32-mingw32
If you have done everything correctly you should be able to execute the dfu-util and if you have also connected your MC HCK and pressed the push button then the output of dfu-util --list should contain Found DFU: [2323:0001] devnum=0, cfg=1, intf=0, alt=0, name="UNDEFINED".
dfu-util uses libusb to access USB devices, and this version of libusb uses WinUSB (a Microsoft Windows system driver installed by default in Microsoft Vista and later versions). The USB device to be accessed must therefore be registered with the WinUSB driver. This can easily be done with the zadig tool from https://sourceforge.net/projects/libwdi/files/zadig/
Plug in your device, run zadig.exe, select your device in the left field and select WinUSB in the right field. You can now access your device from any WinUSB or libusb based programs.
So this is working, now we can compile and flash the blink example.
Compile and flash the blink example
First get the MC HCK source code:
tux@cosmos /c/Users/tux/Desktop/MCHCK $ git clone https://github.com/mchck/mchck.git
To be able to compile our programs we need to fix a Ruby script under mchck/toolchain/scripts. To run Ruby scripts in Windows we need to remove the env from the shebang, e.g. replace #!/usr/bin/env ruby in mchck/toolchain/scripts/real-ld with #!/usr/bin/ruby.
tux@cosmos /c/Users/tux/Desktop/MCHCK $ sed -i 's/env ruby/ruby/g' mchck/toolchain/scripts/real-ld
Now we can connect our MC HCK, press the push button and run make flash:
Now you can edit the blink program and change for example the blinking frequency to make sure that you are really flashing a new program.
tux@cosmos mchck/examples/blink $ sed -i 's/500/100/g' blink.c
tux@cosmos mchck/examples/blink $ cat blink.c
#include <mchck.h>
static struct timeout_ctx t;
static void
blink(void *data)
{
onboard_led(ONBOARD_LED_TOGGLE);
timeout_add(&t, 100, blink, NULL);
}
int
main(void)
{
timeout_init();
/* blink will also setup a timer to itself */
blink(NULL);
sys_yield_for_frogs();
}
Debugging the MC HCK
TODO
Programmer’s Notepad
You will get it from http://www.pnotepad.org/.
First enable Explorer integration:
And then add make, flash and clean to the tools menu:
So this is quite easy because MinGW/MSYS is already added to the path.
It works, even if it says "make": "make": Command not found. And jumping to the line with an error works too:
Cygwin
Another possibility to use Linux tools under Windows is Cygwin.
Lets start with downloading Cygwin from http://www.cygwin.com/ and following the installation instructions http://cygwin.com/install.html.
It is probably a good idea to use the x68 version, even on 64-bit Windows:
Just click on the exe and follow the generic installation steps until you reach the “Select Packages” dialogue. Then select chere, ruby, gcc, gcc-g++, gdb, binutils, make, cmake, automake, patch, git, gitk, git-gui, subversion, python, vim, vim-common, nano, wget, curl, sed, zip, unzip, xinit, screen, xterm, openssh, rsync,....
You don’t need all of them at the moment. These are some commonly used programs under Linux. You can install additional packages later too.
So this will take quite some time...
To install additional Cygwin packages just click on the setup-x86.exe again.
Execute chere -inf -t mintty -s bash -e "Bash prompt here"
Adding additional tools to the path
To add additional tools to your Cygwin path you will have to edit Cygwins .bashrc:
MC HCK development
Currently there are still some problems:
tux@cosmos /cygdrive/c/Users/tux/Desktop/MCHCK/mchck/examples/blink $ make
arm-none-eabi-gcc -MM -I../../toolchain//include -I../../toolchain//lib -std=gnu11 -I../../toolchain//CMSIS/Include -I. -include ../../toolchain//include/mchck_internal.h -MT mchck-lib-startup_k20.d -MT mchck-lib-startup_k20.o -MP -MF mchck-lib-startup_k20.d ../../toolchain//lib/mchck/startup_k20.c
...
arm-none-eabi-gcc -fplan9-extensions -ggdb3 -Os -Wall -Wno-main -mcpu=cortex-m4 -msoft-float -mthumb -ffunction-sections -fdata-sections -fno-builtin -fstrict-volatile-bitfields -flto -fno-use-linker-plugin -I../../toolchain//include -I../../toolchain//lib -std=gnu11 -I../../toolchain//CMSIS/Include -I. -include ../../toolchain//include/mchck_internal.h -c -o mchck-lib-system.o ../../toolchain//lib/mchck/system.c
arm-none-eabi-gcc -fplan9-extensions -ggdb3 -Os -Wall -Wno-main -mcpu=cortex-m4 -msoft-float -mthumb -ffunction-sections -fdata-sections -fno-builtin -fstrict-volatile-bitfields -flto -fno-use-linker-plugin -I../../toolchain//include -I../../toolchain//lib -std=gnu11 -I../../toolchain//CMSIS/Include -I. -include ../../toolchain//include/mchck_internal.h -c -o mchck-lib-timeout.o ../../toolchain//lib/mchck/timeout.c
arm-none-eabi-gcc -E -o blink.ld-template -P -CC -I../../toolchain//ld -I. -DTARGET_LDSCRIPT='"MK20DX32VLF5.ld"' -DMEMCFG_LDSCRIPT='"app.ld"' ../../toolchain//ld/link.ld.S
arm-none-eabi-gcc -o blink.elf -fplan9-extensions -ggdb3 -Os -Wall -Wno-main -mcpu=cortex-m4 -msoft-float -mthumb -ffunction-sections -fdata-sections -fno-builtin -fstrict-volatile-bitfields -flto -fno-use-linker-plugin -Wl,--gc-sections -fwhole-program -T blink.ld-template -nostartfiles -Wl,-Map=blink.map -Wl,-output-linker-script=blink.ld blink.o mchck-lib-builtins.o mchck-lib-gpio.o mchck-lib-onboard-led.o mchck-lib-pin.o mchck-lib-startup_k20.o mchck-lib-system.o mchck-lib-timeout.o
/cygdrive/c/Users/tux/Desktop/MCHCK/mchck/toolchain/scripts/pack-sections.rb:34:in `block in parse': undefined method `flags=' for nil:NilClass (NoMethodError)
from /cygdrive/c/Users/tux/Desktop/MCHCK/mchck/toolchain/scripts/pack-sections.rb:25:in `each'
from /cygdrive/c/Users/tux/Desktop/MCHCK/mchck/toolchain/scripts/pack-sections.rb:25:in `parse'
from /cygdrive/c/Users/tux/Desktop/MCHCK/mchck/toolchain/scripts/pack-sections.rb:19:in `block in initialize'
from /cygdrive/c/Users/tux/Desktop/MCHCK/mchck/toolchain/scripts/pack-sections.rb:18:in `each'
from /cygdrive/c/Users/tux/Desktop/MCHCK/mchck/toolchain/scripts/pack-sections.rb:18:in `initialize'
from ../../toolchain//scripts/real-ld:72:in `new'
from ../../toolchain//scripts/real-ld:72:in `<main>'
collect2.exe: error: ld returned 1 exit status
../../toolchain/mchck.mk:150: recipe for target `blink.elf' failed
make: *** [blink.elf] Error 1
tux@cosmos /cygdrive/c/Users/tux/Desktop/MCHCK/mchck/examples/blink $
The first error can be fixed by changing .split("\n").each do |l| to .split(/\r?\n/).each do |l| in mchck/toolchain/scripts/pack-sections.rb.
But the next error is a bit more complicated:
tux@cosmos /cygdrive/c/Users/tux/Desktop/MCHCK/mchck/examples/blink $ make
arm-none-eabi-gcc -MM -I../../toolchain//include -I../../toolchain//lib -std=gnu11 -I../../toolchain//CMSIS/Include -I. -include ../../toolchain//include/mchck_internal.h -MT mchck-lib-startup_k20.d -MT mchck-lib-startup_k20.o -MP -MF mchck-lib-startup_k20.d ../../toolchain//lib/mchck/startup_k20.c
...
arm-none-eabi-gcc -E -o blink.ld-template -P -CC -I../../toolchain//ld -I. -DTARGET_LDSCRIPT='"MK20DX32VLF5.ld"' -DMEMCFG_LDSCRIPT='"app.ld"' ../../toolchain//ld/link.ld.S
arm-none-eabi-gcc -o blink.elf -fplan9-extensions -ggdb3 -Os -Wall -Wno-main -mcpu=cortex-m4 -msoft-float -mthumb -ffunction-sections -fdata-sections -fno-builtin -fstrict-volatile-bitfields -flto -fno-use-linker-plugin -Wl,--gc-sections -fwhole-program -T blink.ld-template -nostartfiles -Wl,-Map=blink.map -Wl,-output-linker-script=blink.ld blink.o mchck-lib-builtins.o mchck-lib-gpio.o mchck-lib-onboard-led.o mchck-lib-pin.o mchck-lib-startup_k20.o mchck-lib-system.o mchck-lib-timeout.o
C:\tools\gcc-arm-4.7-2013q3\bin\arm-none-eabi-ld.exe: cannot open map file /tmp/mchck-real-ld-20131010-2804-1mz4kzp.map: No such file or directory
collect2.exe: error: ld returned 1 exit status
../../toolchain/mchck.mk:150: recipe for target `blink.elf' failed
make: *** [blink.elf] Error 1
tux@cosmos /cygdrive/c/Users/tux/Desktop/MCHCK/mchck/examples/blink $
C:\tools\... is a default Windows path and /tmp/mchck/... is a Cygwin path.
Working with embedded Linux systems
Linux kernel building instructions
Get the kernel source:
tux@cosmos /c/Users/tux/Desktop/Linux $ wget --no-check-certificate https://www.kernel.org/pub/linux/kernel/v3.0/linux-3.11.4.tar.xz
Extract the kernel source (this takes some time):
tux@cosmos /c/Users/tux/Desktop/Linux $ tar -xf linux-3.11.4.tar.xz
It has probably extracted everything correctly (except a wrong time stamp) even if it says tar: Exiting with failure status due to previous errors.
Now configure and compile the kernel, a full guide for the OLinuXino is located here: Building a kernel 3.x for the iMX233-OLinuXino.
tux@cosmos /c/Users/tux/Desktop/Linux $ cd linux-3.11.4
tux@cosmos /c/Users/tux/Desktop/Linux/linux-3.11.4 $ make ARCH=arm CROSS_COMPILE=arm-none-eabi- mxs_defconfig
To be continued...
What’s next
- Integrate MinGW/Cygwin into your editor of choice
- Create batch files for your projects to automatically compile or flash something