Developing for FRDM-KL25Z platform in Linux – Flashing

Posted: Mar 13, 2014 in Tech
Tags: , , , ,

português

Table of contents:

  1. Introduction
  2. Crosstoolchain
  3. Building
  4. Flashing
  5. Debugging

Previously in Building we generated an ELF executable file as the result of building the frdm-kl25z-blink3 application:

user@localhost /tmp/frdm-kl25z-blink3-1.0 $ file frdm_kl25z_blink3 
frdm_kl25z_blink3: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, not stripped

Here we manage to record this file to the board’s flash memory for execution.

Update FRDM-KL25Z board with a CMSIS-DAP firmware

First, extract file CMSIS-DAP.S19 from Keil Application Note 232. This is a firwmare for FRDM-KL25Z that supports the CMSIS-DAP interface to the board’s on-chip debugger.

The following steps must be performed on Windows: Next, enter Bootloader mode in board by holding down the Reset button while plugging in an USB cable to the OpenSDA connector and your computer. (When the D4 led blinks you can release the button as this indicates bootloader mode.) The MSD Bootloader appears in Windows as a removable drive with a volume label of BOOTLOADER. Copy file CMSIS_DAP.s19 into the BOOTLOADER drive, wait for a few seconds and unplug the board.

Back to Gentoo Linux, replug the board and check for usb device with vendor ID 0xc251 and product ID 0xf002:

localhost ~ # lsusb
Bus 001 Device 023: ID c251:f002 Keil Software, Inc. 
...

Create file /etc/udev/rules.d/99-frdm-kl25z-cmsis-dap.rules containing:

SUBSYSTEM=="usb", ATTR{idVendor}=="c251", ATTR{idProduct}=="f002", MODE="0660", GROUP="plugdev"
SUBSYSTEM=="hidraw", ACTION=="add", MODE="0660", GROUP="plugdev"

Unplug and replug the board again, and check that the created hidraw device file belongs to the plugdev group and is group writable:

localhost ~ # ls -l /dev/hidraw*
crw-rw---- 1 root plugdev 252, 0 Mar 10 21:58 /dev/hidraw0
...

This allows the flashing process to be performed by normal users belonging to the plugdev group.

Install OpenOCD with CMSIS-DAP support

For communicating with FRDM-KL25Z on-chip debugger in order to perform flashing, we use OpenOCD. Unfortunately at the moment of this writing the latest available version of OpenOCD from Portage tree (0.7.0-r1) does not support CMSIS-DAP; however I successfully used OpenOCD from openocd.zylin.com for flashing. You may want to grab a snapshot of the latest openocd source tree, unpack, build and install it:

localhost ~/src/openocd # ./configure --enable-cmsis-dap
...
OpenOCD configuration summary
--------------------------------------------------
CMSIS-DAP Compliant Debugger            yes

localhost ~/src/openocd # make
...

localhost ~/src/openocd # make install
...

In a clean Gentoo Linux system the configure phase will likely fail due to missing libraries and softwares; just emerge any required stuff and resume the process as shown above. You should end with a working openocd installation:

localhost ~ # openocd --version
Open On-Chip Debugger 0.8.0-dev-00350-g6c74255 (2014-02-14-16:00)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.sourceforge.net/doc/doxygen/bugs.html

Flash frdm_kl25z_blink3 using OpenOCD

The Makefile in frdm-kl25z-blink3 sources has a target for taking care of flashing:

user@localhost /tmp/frdm-kl25z-blink3-1.0 $ make flash
openocd \
        -c 'interface cmsis-dap' \
        -f ./support/openocd/kl25_init.cfg \
        -f ./support/openocd/kl25_flash.cfg
Open On-Chip Debugger 0.8.0-dev-00350-g6c74255 (2014-02-14-16:00)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.sourceforge.net/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'cmsis-dap'
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: Interface Initialised (SWD)
cortex_m reset_config sysresetreq
adapter speed: 50 kHz
Info : add flash_bank kinetis kl25.flash
#0 : kl25.flash (kinetis) at 0x00000000, size 0x00000000, buswidth 0, chipwidth 0
Info : CMSIS-DAP: FW Version = 1.0
Info : SWCLK/TCK = 0 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1
Info : DAP_SWJ Sequence (reset: 50+ '1' followed by 0)
Info : CMSIS-DAP: Interface ready
Info : clock speed 50 kHz
Info : IDCODE 0x0bc11477
Info : kl25.cpu: hardware has 2 breakpoints, 2 watchpoints
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x00002038 msp: 0x20003000
** Programming Started **
auto erase enabled
Info : Probing flash info for bank 0
Info : Padding image section 0 with 832 bytes
Warn : flash configuration field erased, please reset the device
Warn : Kinetis L Series supports Program Longword execution only.
Info : Kinetis: FLASH Write ...
wrote 11264 bytes from file frdm_kl25z_blink3 in 14.069720s (0.782 KiB/s)
** Programming Finished **
** Verify Started **
verified 10060 bytes in 1.938245s (5.069 KiB/s)
** Verified OK **
** Resetting Target **
shutdown command invoked

If flashing succeeds the application should start automatically and the RGB led should blink repeatedly in a succession of red, green and blue colors.

Next in Debugging we’ll use OpenOCD as a remote server for the GNU debugger, so we can debug the flashed application.


References

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s