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.


To enable mbed firmware for the FRDM-KL25Z, I found useful notebook written by Tedd OKANO. It's very straightforward.

Setting up to offline tool chain is also very easy as other mbed board. See more detail here:


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

Export the project to Keil uVision4

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.


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.

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


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


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.


Please log in to post comments.