June 2, 2013

GCC ARM Embedded + Eclipse on Kinetis with JLink

I have been writing my own start-up and a linker command file for K60 Tower board. Unfortunately, I am still having an unidentified problem with OSJTAG, I  had decided to use jlink with eclipse. I don't use yagarto tool chain, decided to go with GCC ARM embedded.
 There's been many resources on the internet, I'll post which helped me to set it correctly.

Getting Started with the ARM GCC Compiler on Windows PART 1 [thehackerworkshop.com]
Guide how to set eclipse development (GCC ARM, make, eclipse). This guide (Part 1 plus part 2) is more detailed than the original one published on emb4fun.

You can skip few steps in PART 2, right to the Step 5 if you are not using the ST discovery board. This is the most important one, once you set everything, add files, you should be able to compile and link your project files.

This is a highlight what you should look for:
  • C/C++ Build - External builder , build command - make (or set PATH correctly)
  • C/C++ Build - Discovery options - set arm-none-eabi-
  • In linker options inside Tool Settings - there's a flag where you type a path to a linker command file (an example : -T ./../Sources/PK60N512_flash.ld)
  • In compiler options inside Tool Settings - there's other flags option where you type at least these two flags -mcpu=cortex-m4 -mthumb (same should apply for assembler flags)

The last step before debugging, is to set gdb commands inside a created debug configuration (click 2x on the GDB hardware debugging to create a new one). This are taken from the example shared on yagarto webpage, targeted for K40. They are valid for jlink.

These are initialization commands:
target remote localhost:2331
monitor flash device = MK60DN512xxx10
monitor flash download = 1
monitor flash breakpoints = 1
monitor clrbp
monitor endian little
monitor speed 1000
monitor reset
monitor sleep 100
monitor speed auto
monitor writeu32 0xE000ED08 = 0x00000000

These are run commands:
monitor reg r13 = (0x00000000)
monitor reg pc = (0x00000004)
break main

I did not want to repeat what you can find online, but if there's anything unclear, not able to debug your application using jlink on any Tower from Kinetis line, let me know and I can expand this into a small tutorial ;)

I am planning to publish a small gcc application for some tower boards, or perhaps all, depends on how much time I'll have these days ;) Because when you look into code what CodeWarrior generates with gcc, you marvel how much lines that code contains, most of it are unnecessary.

Update June 9th: a demo app for TWRK60N512 is published.