Using mbed-KL25Z MTB (Micro Trace Buffer)

Freescale FRDM-KL25Z is a first Cortex-M0+ processor in mbed platform. The firmware also support CMSIS-DAP which has powerful debug capably, so I used off-line compiler and debugger with this device.

Preparation

To enable mbed firmware for the FRDM-KL25Z, I found useful notebook written by Tedd OKANO. It's very straightforward.
http://mbed.org/users/okano/notebook/mbed-kl25z/

Setting up to offline tool chain is also very easy as other mbed board. See more detail here:
http://mbed.org/users/MACRUM/notebook/uvision4_debug/

Warning

Please use latest MDK-ARM Lite v4.70 or later (free evaluation version). Example project in v4.60 had a problem about MTB settings and didn't work properly.

Build and debug by offline tools

Build project targeting to the Freescale KL25Z
/media/uploads/MACRUM/target_select.png

Export the project to Keil uVision4
/media/uploads/MACRUM/export.png

Download/extract a zip file and launch uVision4 by double click the project file.

Setting for MTB

Memory map

Memory map of KL25Z is described below.

Information

Flash: 128kB
0x00000000 - 0x0001FFFF

RAM: 16kB
0x1FFFF000 - 0x20002FFF

RAM area mapping is a bit tricky, but it is not an issue.

You can see RAM area memory map in a scatter description file for KL25Z which is exported for offline tool.

  ; 8_byte_aligned(48 vect * 4 bytes) =  8_byte_aligned(0xC0) = 0xC0
  ; 0x4000 - 0xC0 = 0x3F40
  RW_IRAM1 0x1FFFF0C0 0x3F40 {
   .ANY (+RW +ZI)
  }

Top 0xC0 bytes is not available. It seems to be assigned to vector table remapping area when interrupt enabled libraries are used such as Ticker class.

MTB can be used to map trace buffer in internal RAM area on chip. Start address (Buffer Position) of the MTB has to be aligned by multiple number of the buffer size.

By exploring contents of vector table using debugger, initial stack pointer of KL25Z is fixed at 0x20003000 address (end of RAM) regardless RW_IRAM1 region setting in the scatter description file.

By above conditions, configuration of memory usage for MTB is something like below:

RAM: 16kB
  0x1FFFF000 - 0x1FFFF0BF ; vector table area
  0x1FFFF0C0 - 0x20000FFF ; DATA area for user program
  0x20001000 - 0x20001FFF ; Buffer area for MTB (4kB)
  0x20002000 - 0x20002FFF ; Stack area

Modify RW_IRAM1 region in the scatter file.

  RW_IRAM1 0x1FFFF0C0 0x1F40 {
   .ANY (+RW +ZI)
  }

MTB setting

Setting for MTB can be done by defining debug command using Initialization file.

http://www.keil.com/support/man/docs/uv4/uv4_dg_debug.htm http://www.keil.com/support/man/docs/uv4/uv4_debug_functions.htm

We will refer example project for Freescale FRDM-KL25Z. Copy following file into your project directory.

{install}\ARM\Boards\Freescale\FRDM-KL25Z\Blinky_MTB\DBG_MTB.ini

Add this .ini file in the Initilization File field of Debug setting.

/media/uploads/MACRUM/mtb_config.png

Press Edit button to modify. You can use nice GUI to set the value by clicking Configuration Wizard tab in the bottom of text window. /media/uploads/MACRUM/mtb_config_1.png

This configuration will be executed when debug session is launched as a debug function. Please do not forget to save this file by ctrl+S.

Disyapy trace view

Start debug session and you can view MTB trace data from menu [View] - [Trace] - [Trace Data]. /media/uploads/MACRUM/mtb_view.png

Enjoy, debugging.


Report

Please login to post comments.