Tags

, ,

UPDATE (12/28/2015): Erich cleared up my confusion on what ARM processor (cortex-m0+ or cortex-m4) was used in the KL25Z.  From Erich: The KL2x (note the L) has an ARM Cortex M0+, while the K2x is indeed having a M4 core…. this post has been updated to take note of this difference.  Yet again – THANK YOU Erich!

Ron is mentoring us through embedded systems programming on using a Freedom board.  I’m excited about the opportunity to compare/contrast with what I am learning about the nRF51822.

I am using a FRDM-KL25Z board.  

The Goal

The goals of this post include:

  • Installation and verification of OpenOCD with my FRDM-KL25Z board.
  • Setting upEclipse/OpenOCD.
  • Installing the mbed SDK and running test binaries built using the mbed SDK on the FRDM-KL25Z board.

Thanks to Those That Went Before

Paul Ferster

A HUGE thank you to Paul Fertser.  While I am not exactly sure what Paul’s role is in the OpenOCD community, Paul went out of his way helping me debug an OpenOCD install on Ubuntu. We use Ubuntu in Contextual Electronics because it provides a common environment.  I got introduced to Paul after signing up for the OpenOCD mailing list.  I was desperate to figure out why OpenOCD wouldn’t run on my Ubuntu VM.  It couldn’t have been more than two minutes before Paul sent me a reply.  I’m clueless when it comes to *nix commands and had no idea what  was doing with OpenOCD.  It was the holidays, and I wanted to catch up to Ron’s Contextual Electronics videos.  After much debugging, Paul suggested we get the problem figured out on the #openOCD IRC chat channel.  To further show my ignorance, at first I had no idea what he was asking since I’ve used IRC maybe twice and immediately thought of Twitter when he put a # before a word (sad I know 🙂 ).  The problem ultimately turned out to be an old version of OpenOCD.  But it was more confusing than that.  I found three different versions of OpenOCD on the machine!  The Ubuntu version was outdated…and on…and…I learned A LOT about OpenOCD from Paul.  But more importantly, I met someone who kindly helped me, was very gifted in programming and all things *nix and OpenOCD, and was extremely passionate to get the OpenOCD environment “right”.  When I was discussing the experience with Paul, I shared my unhappiness with the amount of time this effort took.  I pointed out that time is the most important currency.  Paul made me rethink my feelings on time – and gave me a glimpse into how time is spent – that when stuff just will not work – that chance opportunity to meet and talk with someone who has an extremely interesting perspective, is super smart, and helpful is very important.  Thank you Paul.

Note: Given the challenges I had with Ubuntu, I moved this project to Mac OS X.  

Erich Styger

Erich Styger for his excellent series of posts on his MCU On Eclipse blog.  Often Erich has written a post on the topic I am trying to learn.  This time I found this post to be very helpful.  Thank you Erich.

Ronald Sousa

Ron teaches embedded systems programming for Contextual Electronics.  I continue to learn A LOT from Ron.  Ron’s post on committing and installing OpenOCD was extremely helpful.  Thank you Ron.

Getting To Know the FRDM-KL25Z

From this page: “The FRDM-KL25Z has been designed by Freescale in collaboration with mbed for prototyping all sorts of devices…and includes a built-in USB Flash programmer.”  From that description, it appears to me like an alternative to an Arduino…a gateway into getting deeper into programming NXP µCU …with a lot of great peripherals, OpenOCD, and mbed support.  BWA-HA-HA!!!!  (As in..You WILL see the value in dropping any other µCU and buying NXP’s SOIC…BWA-HA-HA-HA-HA ).

Details on the FRDM-KL2x series of µCU can be found here.  The User’s Guide gives a nice overview.

Block Diagran

The block diagram:

 

 

From here

Highlights the KL2X’s capabilities.  I’m looking forward to getting to know the µCU better by watching these videos.

Debug Interface

Important for this post is the debug interfaces.  This pdf document (chapter 9 – debugging) pointed out the FRDM-KL25Z implements Arm’s JTAG/SWD debugging support:

 

Like the nRF51822, the FRDM-KL25Z supports Arm’s SWD interface.  YIPPEE!…this means we’ll be able to use OpenOCD software in order to do source line debugging of FRDM-KL25Z code within Eclipse.

mbed

We’ll be using mbed software to develop firmware for the board.  I’ve been curious what mbed is all about.  What I found interesting about the development environment was the focus on a simple online IDE where code is handled within a web browser.  What a clever way to get started!  No messy IDE install.  An easy way to jump start playing with a board.  It seems to me a terrific way to have a starter IDE.

The other option for firmware development is using the mbed SDK.  This is what we’ll need to use in order to use Eclipse as the IDE.

Debugging the FRDM-KL25Z Within Eclipse 

We’ll be using OpenOCD software in order to do source line debugging of FRDM-KL25Z code within Eclipse.

The Eclipse -> OpenOCD debugging path is discussed handily by Erich Styger in  his post “OpenOCD/CMSIS-DAP Debugging with Eclipse and without an IDE”:

 

Lucky for us, the FRDM-KL25Z is supported on the latest stable release of OpenOCD (0.9).  Getting (OpenOCD) debugging working between the FRDM-KL25Z and Eclipse involve the following steps:

Step 1: Firmware

  • Update the firmware on the FRDM-KL25Z.  This was challenging for me because I use a Mac. The mbed boot loader that was loaded on my board when I got it in the mail was version 1.09.  To update firmware from 1.09 to 1.11 (the latest), I had to find a Win 7 machine.  Luckily, I have a machine I’ve kept around for 6 years!  The mbed boot firmware is located here.  Updating the boot loading firmware is confusing because what I found out there is an nbed boot loader and a non-MBed boot loader.  We are using MBed for:
    • USB drag and drop programming
    • USB Virtual COM port for serial terminal
    • CMSIS-DAP interface for programming and debugging from offline tools
    • rich SDK
    I went through the instruction on Arm’s web site.  All seemed to work :-).
     
  • Download the “Hello World!” binary onto the FRDM-KL25Z.  This is incredibly easy to do.  As stated earlier, the FRDM-KL25Z was a joint effort between mbed and Freescale.  So once the firmware was updated, the board shows up as a USB device on my Mac:

It is then just a matter of downloading the HelloWorld_KL25Z.bin file onto the FRDM-KL25Z board.  Go to here for more info.  Luckily, this “just worked” for me :-).  Although I find the continual blinking of the red light to be annoying.

Onto OpenOCD and the mbed SDK….

Step 2: OpenOCD

  • Download and install the OpenOCD binaries from here.  There are directions for the different operating systems.  WHAT A RELIEF to have stable binary distributions of the latest releases.  THANK YOU!! If I had to, I’d build everything myself.  However, it is a time saver having the Eclipse community provide this for us.  I am using OpenOCD v0.9, the most recent stable version as of this date.  Make sure to use at least 0.9!
  • Note: In case there is a need to build OpenOCD from source, this page looked promising.
  • After installing on my Mac, I changed the directory path structure to get rid of the spaces in the “GNU ARM Eclipse” directory name that was created to “GNUARMEclipse”…I find spaces in names can cause unwelcome problems that I wish to deal with.
  • Check the OpenOCD version by opening a terminal and running openocd -v .  This requires a path to the openocd.  I used the default install directory and then changed the GNU ARM Eclipse directory name as noted above, so the command I used was:

$ /Applications/GNUARMEclipse/OpenOCD/0.9.0-201505191004/bin/openocd –version

GNU ARM Eclipse 64-bits Open On-Chip Debugger 0.9.0-00073-gdd34716 (2015-05-19-12:55)

Licensed under GNU GPL v2

For bug reports, read

http://openocd.org/doc/doxygen/bugs.html

  • Check to see if OpenOCD can talk to the FRDM-KL25Z.  OpenOCD uses a configuration file for each board it supports.  Whereas the OpenOCD binary is loaded within the …/bin directory, the configuration files for the boards are located within …/scripts/board .  The configuration file for the FRDM-KL25Z is frdm-kl25z.cfg .  Making sure the board was plugged into a USB port, I ran the following from the command line:

$ /Applications/GNUARMEclipse/OpenOCD/0.9.0-201505191004/bin/openocd -f /Applications/GNUARMEclipse/OpenOCD/0.9.0-201505191004/scripts/board/frdm-kl25z.cfg

GNU ARM Eclipse 64-bits Open On-Chip Debugger 0.9.0-00073-gdd34716 (2015-05-19-12:55)

Licensed under GNU GPL v2

For bug reports, read

http://openocd.org/doc/doxygen/bugs.html

Info : only one transport option; autoselect ‘swd’

srst_only separate srst_gates_jtag srst_open_drain connect_deassert_srst

Info : add flash_bank kinetis kl25.flash

adapter speed: 1000 kHz

srst_only separate srst_nogate srst_open_drain connect_deassert_srst

cortex_m reset_config sysresetreq

Info : CMSIS-DAP: SWD  Supported

Info : CMSIS-DAP: Interface Initialised (SWD)

Info : CMSIS-DAP: FW Version = 1.0

Info : SWCLK/TCK = 0 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1

Info : CMSIS-DAP: Interface ready

Info : clock speed 1000 kHz

Info : SWD IDCODE 0x0bc11477

Info : kl25.cpu: hardware has 2 breakpoints, 2 watchpoints

Info : MDM: Chip is unsecured. Continuing.

OOH…um…YIPPEE!!!  IT WORKED.  (side note – I originally spent way too many hours trying to get this working within Ubuntu..I mean *way* too many hours.  I was going to include details of this painful process.  However, I decided to vent a bit here and press on).
 
…pressing on to using Eclipse + OpenOCD as my IDE of choice….
  • Update Eclipse to know where the OpenOCD binary is located by following the “Update OpenOCD path” steps documented here.
  • Update Eclipse plug-ins for OpenOCD support by follow the steps outlined in “OpenOCD Debugging plug-ins documented here

 

 I already had these installed.  However, I went through the process.  A lot of updates were applied.

 And …finally… the mbed SDK

 Step 3: mbed

My attention at this point turns to what is needed to get an mbed app using the serial port of the FRDM-KL25Z to communicate with a terminal program on my mac through SSH.

The steps I took to install the mbed SDK come from here.

  • Download the mbed project from github: git clone https://github.com/mbedmicro/mbed.git
  • Create a private_settings.py file at the location noted in the web post.  Add the path to the GNU ARM GCC.  I got the path from within an Eclipse project->Properties page->C/C++ Build->Settings  under the Toolchains tab, the Toolchain path.  Mine is /usr/local/gcc-arm-none-eabi-4_9-2015q1/bin
  • I did not have the following python libraries installed on my mac so I ran:
    • sudo easy_install colorama (an overview of colorama can be found here).
    • sudo easy_install jinja2 (overview is here).
    • sudo easy_install pyserial (overview is here).
  • Run the build python script.  Python comes with OS X.  I opened a terminal window in the /Applications/mbed/workspace_tools directory (where build.py is) and ran: 

$ python build.py -m KL25Z -t GCC_ARM 

 

$ python build.py -m KL25Z -t GCC_ARM

Building library CMSIS (KL25Z, GCC_ARM)

Copy: arm_common_tables.h

Copy: arm_const_structs.h

Copy: arm_math.h

Copy: core_ca9.h

Copy: core_ca_mmu.h

Copy: core_caFunc.h

Copy: core_caInstr.h

Copy: core_cm0.h

Copy: core_cm0plus.h

Copy: core_cm3.h

Copy: core_cm4.h

Copy: core_cm4_simd.h

Copy: core_cm7.h

Copy: core_cmFunc.h

Copy: core_cmInstr.h

Copy: core_cmSimd.h

Copy: core_sc000.h

Copy: core_sc300.h

Copy: cmsis.h

Copy: cmsis_nvic.h

Copy: MKL25Z4.h

Copy: system_MKL25Z4.h

Copy: MKL25Z4.ld

Compile: startup_MKL25Z4.S

Compile: cmsis_nvic.c

Compile: system_MKL25Z4.c

Copy: startup_MKL25Z4.o

Copy: cmsis_nvic.o

Copy: system_MKL25Z4.o

Building library MBED (KL25Z, GCC_ARM)

Copy: AnalogIn.h

Copy: AnalogOut.h

Copy: BusIn.h

Copy: BusInOut.h

Copy: BusOut.h

Copy: CallChain.h

Copy: CAN.h

Copy: can_helper.h

Copy: CircularBuffer.h

Copy: CThunk.h

Copy: DigitalIn.h

Copy: DigitalInOut.h

Copy: DigitalOut.h

Copy: DirHandle.h

Copy: Ethernet.h

Copy: FileBase.h

Copy: FileHandle.h

Copy: FileLike.h

Copy: FilePath.h

Copy: FileSystemLike.h

Copy: FunctionPointer.h

Copy: I2C.h

Copy: I2CSlave.h

Copy: InterruptIn.h

Copy: InterruptManager.h

Copy: LocalFileSystem.h

Copy: LowPowerTicker.h

Copy: LowPowerTimeout.h

Copy: LowPowerTimer.h

Copy: mbed.h

Copy: mbed_assert.h

Copy: mbed_debug.h

Copy: mbed_error.h

Copy: mbed_interface.h

Copy: platform.h

Copy: PortIn.h

Copy: PortInOut.h

Copy: PortOut.h

Copy: PwmOut.h

Copy: RawSerial.h

Copy: rtc_time.h

Copy: semihost_api.h

Copy: Serial.h

Copy: SerialBase.h

Copy: SPI.h

Copy: SPISlave.h

Copy: Stream.h

Copy: Ticker.h

Copy: Timeout.h

Copy: Timer.h

Copy: TimerEvent.h

Copy: toolchain.h

Copy: Transaction.h

Copy: wait_api.h

Copy: analogin_api.h

Copy: analogout_api.h

Copy: buffer.h

Copy: can_api.h

Copy: dma_api.h

Copy: ethernet_api.h

Copy: gpio_api.h

Copy: gpio_irq_api.h

Copy: i2c_api.h

Copy: lp_ticker_api.h

Copy: pinmap.h

Copy: port_api.h

Copy: pwmout_api.h

Copy: rtc_api.h

Copy: serial_api.h

Copy: sleep_api.h

Copy: spi_api.h

Copy: ticker_api.h

Copy: us_ticker_api.h

Copy: clk_freqs.h

Copy: gpio_object.h

Copy: objects.h

Copy: PeripheralPins.h

Copy: PortNames.h

Copy: device.h

Copy: PeripheralNames.h

Copy: PinNames.h

Compile: PeripheralPins.c

Compile: gpio_irq_api.c

[Warning] gpio_irq_api.c@86: In function ‘gpio_irq_init’: ‘irq_n’ may be used uninitialized in this function [-Wmaybe-uninitialized]

[Warning] gpio_irq_api.c@100: In function ‘gpio_irq_init’: ‘vector’ may be used uninitialized in this function [-Wmaybe-uninitialized]

[Warning] gpio_irq_api.c@103: In function ‘gpio_irq_init’: ‘ch_base’ may be used uninitialized in this function [-Wmaybe-uninitialized]

Compile: mbed_overrides.c

Compile: serial_api.c

[Warning] serial_api.c@177: In function ‘serial_format’: ‘parity_enable’ may be used uninitialized in this function [-Wmaybe-uninitialized]

[Warning] serial_api.c@177: In function ‘serial_format’: ‘parity_select’ may be used uninitialized in this function [-Wmaybe-uninitialized]

Compile: spi_api.c

[Warning] spi_api.c@55: 22:0: ‘extosc_frequency’ defined but not used [-Wunused-function]

[Warning] spi_api.c@117: 22:0: ‘mcgpllfll_frequency’ defined but not used [-Wunused-function]

Compile: analogin_api.c

[Warning] analogin_api.c@55: 21:0: ‘extosc_frequency’ defined but not used [-Wunused-function]

[Warning] analogin_api.c@117: 21:0: ‘mcgpllfll_frequency’ defined but not used [-Wunused-function]

Compile: analogout_api.c

Compile: gpio_api.c

Compile: i2c_api.c

[Warning] i2c_api.c@55: 21:0: ‘extosc_frequency’ defined but not used [-Wunused-function]

[Warning] i2c_api.c@117: 21:0: ‘mcgpllfll_frequency’ defined but not used [-Wunused-function]

Compile: pinmap.c

Compile: port_api.c

Compile: pwmout_api.c

Compile: rtc_api.c

[Warning] rtc_api.c@117: 18:0: ‘mcgpllfll_frequency’ defined but not used [-Wunused-function]

Compile: sleep.c

[Warning] sleep.c@60: In function ‘deepsleep’: suggest parentheses around comparison in operand of ‘&’ [-Wparentheses]

Compile: us_ticker.c

[Warning] us_ticker.c@117: 19:0: ‘mcgpllfll_frequency’ defined but not used [-Wunused-function]

Compile: BusIn.cpp

Compile: BusInOut.cpp

Compile: BusOut.cpp

Compile: CAN.cpp

Compile: CallChain.cpp

Compile: Ethernet.cpp

Compile: FileBase.cpp

Compile: FileLike.cpp

Compile: FilePath.cpp

Compile: FileSystemLike.cpp

Compile: I2C.cpp

Compile: I2CSlave.cpp

Compile: InterruptIn.cpp

Compile: InterruptManager.cpp

Compile: LocalFileSystem.cpp

Compile: RawSerial.cpp

Compile: SPI.cpp

Compile: SPISlave.cpp

Compile: Serial.cpp

Compile: SerialBase.cpp

Compile: Stream.cpp

Compile: Ticker.cpp

Compile: Timeout.cpp

Compile: Timer.cpp

Compile: TimerEvent.cpp

Compile: assert.c

Compile: board.c

Compile: error.c

Compile: gpio.c

Compile: lp_ticker_api.c

Compile: mbed_interface.c

Compile: pinmap_common.c

Compile: retarget.cpp

Compile: rtc_time.c

Compile: semihost_api.c

Compile: ticker_api.c

Compile: us_ticker_api.c

Compile: wait_api.c

Library: libmbed.a

Copy: mbed_overrides.o

Copy: board.o

Copy: retarget.o

 

Completed in: (4.55)s

 

Build successes:

  * GCC_ARM::KL25Z

 

  • Test by running make.py.  I wanted to echo characters over a serial port, which is the 8th test.  To run this test, I needed to use a SSH application. I could use terminal.  However, I am not well versed in terminal so I downloaded and started to use coolterm.  I found coolterm to be useful so I donated $25.  I appreciate efforts such as these.  
    • after launching CoolTerm, go into options and set the Port to the USB port represented by the FRDM-KL25Z.  The USB port used by the FRDM-KL25Z can be found by starting a terminal session and typing: 

$ ls /dev/tty.*

/dev/tty.Bluetooth-Incoming-Port/dev/tty.usbmodem1452

/dev/tty.Bluetooth-Modem

    • Go into the Terminal settings dialog box and change the Key Emulation to LF and check Local Echo:

 

  • open a Terminal window and run a test.  For example, I opened a terminal window at the folder where the make.py file resides.  I ran test 8 (the echo serial test – you can get a list of the test by running make.py without parameters).  The command I used was: 

python make.py  -m KL25Z -t GCC_ARM -d /Volumes/mbed -s /dev/tty.usbmodem1452 -p 8

YIPPEE!!! Here’s the output in CoolTerm:

 That’s It For Now

The goals for this post were:
  • Installation and verification of OpenOCD with my FRDM-KL25Z board.
  • Setting upEclipse/OpenOCD.
  • Installing the mbed SDK and running test binaries built using the mbed SDK on the FRDM-KL25Z board.

I feel these goals (after many hours of…well… 🙂 ) were met.

My next “unknown” is to step through source code within an OpenOCD debugging session on Eclipse.

 

THANKS for reading this far.  Please find many things to smile about.

Advertisements