Embedded development with open source tools on Windows

Hello World from MinGW

Hello World from MinGW

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.

GCC ARM install location

GCC ARM install location

And add it to your default Windows PATH (to use it without Cygwin or with MinGW):

Add gcc to the Windows path

Add gcc to the Windows path

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.

Windows Command Processor

Windows Command Processor

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

MinGW installation manager

MinGW installation manager

Under “All Packages” select also msys-mintty:

MinGW: install mintty

MinGW: install mintty

Mintty is a really nice terminal emulator for Cygwin and MSYS: http://code.google.com/p/mintty/

MinGW installation manager: apply changes

MinGW installation manager: apply changes

MinGW: installation successful

MinGW: installation successful

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:

mingw-get update

mingw-get update

mingw-get install msys-wget

mingw-get install msys-wget

Now add C:\MinGW\msys\1.0\bin and C:\MinGW\bin to the path:

Add msys to the path

Add msys to the path

Then create a mintty Desktop shortcut:

mintty desktop shortcut

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:

mintty change target

mintty change target

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
Open mintty here

Open mintty here

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.

Hello World from MinGW

Hello World from MinGW

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/

Install Git

Install Git

Add Git to the path

Add Git to the path

Unix line endings

Unix line endings

Git for Windows comes with a nice context menu and GUI tools:

Git context menu

Git context menu

Git GUI

Git GUI

I dunno why but I had to add a new environment variable to have git-gui, gitk in English.

Set environment variable LANG=en

Set environment variable LANG=en

If this is not enough then have a look at http://code.google.com/p/tortoisegit/

Ruby

Install standalone Ruby: http://rubyinstaller.org/

And make sure to add it to the path:

Git GUI

Ruby installation

MC HCK specific instructions

My first MC HCK

My first MC HCK

The MC HCK is a cool little microcontroller development board, have a look here.

Install the dfu-util

http://dfu-util.gnumonks.org/

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".

MC HCK: Windows installation device driver software

MC HCK: Windows installation device driver software

No driver found for MC HCK bootloader

No driver found for MC HCK bootloader

DFU-UTIL: MC HCK found under Windows

DFU-UTIL: MC HCK found under Windows

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.

Zadig tool

Zadig tool

So this is working, now we can compile and flash the blink example.

Programmer’s Notepad

You will get it from http://www.pnotepad.org/.

First enable Explorer integration:

Programmer's Notepad: Explorer integration

Programmer’s Notepad: Explorer integration

And then add make, flash and clean to the tools menu:

Programmer's Notepad: Add tools

Programmer’s Notepad: Add tools

So this is quite easy because MinGW/MSYS is already added to the path.

Programmer's Notepad: Adding make

Programmer’s Notepad: Adding make

It works, even if it says "make": "make": Command not found. And jumping to the line with an error works too:

Programmer's Notepad: Running make

Programmer’s Notepad: Running make

Programmer's Notepad: make, clean, flash

Programmer’s Notepad: make, clean, flash

Programmer's Notepad: flashing successful

Programmer’s Notepad: flashing successful

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:

Cygwin download

Cygwin download

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,....

Cygwin select packages

Cygwin select packages

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.

Cygwin resolving dependencies

Cygwin resolving dependencies

Cygwin install process

Cygwin install process

So this will take quite some time...

Cygwin installation complete

Cygwin installation complete

To install additional Cygwin packages just click on the setup-x86.exe again.

Cygwin terminal

Cygwin terminal

Execute chere -inf -t mintty -s bash -e "Bash prompt here"

Cygwin bash prompt here

Cygwin bash prompt here

Adding additional tools to the path

To add additional tools to your Cygwin path you will have to edit Cygwins .bashrc:

Cygwin editing .bashrc with Notepad++

Cygwin editing .bashrc with Notepad++

Cygwin arm-none-eabi-gcc

Cygwin arm-none-eabi-gcc

MC HCK development

Currently there are still some problems:

Cygwin first MC HCK error

Cygwin first MC HCK error

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:

Cygwin second MC HCK error

Cygwin second MC HCK error

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

SSH

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
wget kernel

wget kernel

Extract the kernel source (this takes some time):

tux@cosmos /c/Users/tux/Desktop/Linux $ tar -xf linux-3.11.4.tar.xz
Extracted kernel

Extracted kernel

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
Oh no! The compiler has crashed...

Oh no! The compiler has crashed...

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