mbed Blog

Debugging from GDB using pyOCD!

We are pleased to release a python library which allows to drive the Debug Access Port of Cortex-M microcontrollers over CMSIS-DAP!

What can be achieved with pyOCD?

  • Debugging using GDB, as a gdbserver is integrated on the library
  • Writing python applications that can communicate with the CMSIS-DAP and coresight debug interface:
    • read/write memory
    • read/write core registers
    • set breakpoints
    • flash new binary
    • run/stop/step the execution
  • Act as a great reference to show how the CMSIS-DAP protocol works

Currently, the library works on Windows (using pyWinUSB as backend) and on Linux (using pyUSB as backend).

Quick overview

Use python to control your mbed platform

from pyOCD.board import MbedBoard

board = MbedBoard.chooseBoard()

target = board.target
flash = board.flash

target.resume()
target.halt()
print "pc: 0x%X" % target.readCoreRegister("pc")
    pc: 0xA64

target.step()
print "pc: 0x%X" % target.readCoreRegister("pc")
    pc: 0xA30

flash.flashBinary("binaries/l1_lpc1768.bin")

print "pc: 0x%X" % target.readCoreRegister("pc")
    pc: 0x10000000

target.reset()
target.halt()
print "pc: 0x%X" % target.readCoreRegister("pc")
    pc: 0xAAC

board.uninit()

Use GDB to debug your mbed projects

Before using GDB, a .elf file has to be generated with a GCC toolchain.

  • Python code to start a GDB server on port 3333

from pyOCD.gdbserver import GDBServer
from pyOCD.board import MbedBoard

board = MbedBoard.chooseBoard()

# start gdbserver on port 3333
gdb = GDBServer(board, 3333)
  • Debug the target from GDB:

arm-none-eabi-gdb l1_lpc1768.elf

<gdb> target remote localhost:3333
<gdb> load
<gdb> continue

Get Started

All the source code is available on our git repository under workspace_tools/debugger

You can quickly get started with pyOCD by reading the README. It provides all the information that you need to know concerning the dependencies, installation and how to use the library. There are even some sample programs to get started even quicker!

Conclusion

pyOCD provides a simple and efficient solution to debug mbed platforms over CMSIS-DAP.

We expect quite soon the support of all the mbed platforms in OpenOCD as well. There is even a fork of OpenOCD adding CMSIS-DAP support: cmsis-dap support in OpenOCD

Have fun with pyOCD!

Full debugging interface on mbed-enabled platforms!

800

We are pleased to announce we have added CMSIS-DAP support to the mbed HDK firmware for the following targets:

  • mbed NXP LPC1768
  • mbed NXP LPC11U24
  • FRDM-KL25Z

The new firmware upgrade, in addition to a drag n drop flash programming and a virtual serial port interface, provide a CMSIS-DAP interface in order to fully debug your platform for tools that support the CMSIS-DAP protocol.

This, combined with the exporting to toolchain features, means if and when you transition to a full debug toolchain as part of productisation, you don't need to change your hardware to:

  • set breakpoints to stop the program at some event or at a specified instruction to examine the current state
  • step by step execute a program to track the control flow
  • check variables values
  • inspect and modify memory contents

You can now upgrade your board very easily to support full CMSIS-DAP debug. Just select your board and follow the instructions:

Whilst the Online IDE doesn't support a debugger, here is an example of using this new feature with uVision MDK:

In this post, I would like to explain in more detail how CMSIS-DAP works.

What is CMSIS-DAP?

CMSIS-DAP provides a standardized way to access the Coresight Debug Access Port (DAP) of an ARM Cortex microcontroller via USB. CMSIS-DAP is generally implemented as an on-board interface chip, providing direct USB connection from a development board to a debugger running on a host computer on one side, and over JTAG (Joint Test Action Group) or SWD (Serial Wire Debug) to the target device to access the Coresight DAP on the other.

Why the need for CMSIS-DAP?

Before the CMSIS-DAP standard, a lot of USB wigglers implemented their own protocols. With this configuration, the host debugger has to be aware of these different protocols and has to implement all of them, which produces a lot of fragmentation and re-inventing the wheel. At the same time, the protocols were usually defined at the JTAG level, meaning they are slow. CMSIS-DAP provides a standardised interface for debuggers that is defined at the Coresight DAP level, allowing for a standard interface and fast driverless implementations.

How CMSIS-DAP can be integrated?

The CMSIS-DAP firmware has been implemented as part of the mbed HDK. In addition to the existing Mass Storage and the Virtual Serial port interfaces, a new HID endpoint is used to establish a CMSIS-DAP communication with a debugger. We chose to use a HID communication as HID drivers are built-in in all Operating Systems, there is no need for a specific driver to be installed on the host computer.

/media/uploads/samux/cmsis-dap-6.png

This means all mbed-enabled boards now have CMSIS-DAP built in (even ones already sold via a firmware upgrade), and if you implement the mbed HDK as part of your own development board or product, CMSIS-DAP will be freely available on that too!

Overview of the CMSIS-DAP standard

Packets are exchanged between the host debugger and the Interface Chip. Basically, the host sends a command and the debug unit sends the response of the command.

Different types of commands can be issued by the host:

  • General Commands: request information and control the debug unit. Also used to connect/disconnect the debug unit.
  • Common SWD/JTAG commands: used for instance to set the clock speed
  • SWD specific commands: configure the parameters for SWD mode
  • JTAG specific commands: configure the JTAG device chain
  • Transfer Commands: read/write CoreSight registers. These commands are independent of the transport (SWD or JTAG)

Example: Read memory over CMSIS-DAP

Let's say that a debugger needs to read the value at a specific location in memory. The following commands have to be sent by the host:

  • Transfer Command: write the CSW register (Control/Status Word Register). This will configure the transfer (32bits/16bits/8bits transfer)
  • Transfer Command: write the TAR register (Transfer Address Register) with the address of the memory location
  • Transfer Command: read the DRW register (Data Read/Write register) to read the value at the location specified earlier

Use CMSIS-DAP to debug your projects

To use it, you just need to update the firmware on your board (don't worry, it is easily upgraded and reverted) and connect with a CMSIS-DAP compliant toolchain. We've been using MDK as one of our test toolchains which has CMSIS-DAP support in it publicly from MDK uVision 4.60. To find out more about enabling your board with CMSIS-DAP, installing Keil MDK and debugging your first applications, please see the following page:

We'll be announcing more supported toolchains and scripts as they become available!

USBHost library now in Beta!

We are pleased to release a new library: USBHost!

/media/uploads/samux/_scaled_usb_host_app_board.jpg

About the USBHost library

A USBHost library has been developed in order to communicate with USB devices. Currently, the library supports:

  • USB mice
  • USB keyboards
  • Mass storage devices
  • Virtual serial port devices

In addition to the drivers already implemented, the USBHost stack provides some cool features of USB such as:

  • Hub auto-detection
    • You can use exactly the same code if you are using a hub to connect a usb device to an mbed
  • Plug n Play support
    • You can detect when a device is attached and detached to and from the usb bus

Where to get started?

Hardware details and helloWorld examples are provided in order to get started quickly with the USBHost library:

Community contribution

It would be great if the USBHost stack development involves several developers. There is plenty of work to be done such as:

  • core modification by adding support of isochronous transfer
  • develop drivers on top of the USBHost stack:
    • Bluetooth class
    • Webcam class
    • ...

Any contribution from the mbed community would be greatly appreciated!

Have fun with USBHost!

mbed Application Board on sale!

The mbed application board is now available!

http://mbed.org/media/uploads/chris/mab-top.jpg http://mbed.org/media/uploads/chris/mab-bottom.jpg

The first stockists to go live are (alphabetically!):

For those not yet familiar with the application board, here is a quote from the Sparkfun description:

Sparkfun wrote:

This credit-card sized breakout board makes it easy to plug in to a whole bunch of peripherals. Simply pop an LPC1768 mbed module into the socket and you've got access to a 128x32 graphic lcd, 5-way joystick, accelerometer, temperature sensor and more! There are headers on either side of the mbed module socket as well so you can jumper off to breadboards and other off-board components.

It will be great for software development and experiments, and running fixed labs and workshops.

The board has a load of examples that you can use straight out the box, and no doubt more will be shared as the boards work their way out there.

See the application board cookbook page for more details!

New $12.95 mbed-enabled Freescale board!

We're very pleased to announce the new mbed-enabled Freescale FRDM-KL25Z board!

FRDM-KL25Z is now mbed-enabled

We've been working with Freescale on the development of their new range of ultra-low-cost boards, and from today you can upgrade them for free to be mbed-enabled and get free access to the mbed online compiler and development platform.

It is great to be able to welcome Freescale to the mbed project!

About the FRDM-KL25Z board

The FRDM-KL25Z Freescale Freedom development board uses the Kinetis L series of MCUs, the industry’s first microcontrollers built on the ARM® Cortex™-M0+ core. The board is based on the KL25Z128VLK, a tiny KL2 family device that runs at 48 MHz, has 128 KB of flash, a full-speed USB controller and various analog and digital peripherals. The FRDM-KL25Z hardware is form-factor compatible with the Arduino™ R3 pin layout, so it'll work with lots of existing shield designs. The board includes some bonus features of an RGB LED, a 3-axis digital accelerometer and a capacitive touch slider.

Freescale FRDM-KL25Z supported in the mbed platform!

We've been working with Freescale to add support in the mbed SDK, HDK and Online Tools for the KL25Z, so now you can use the FRDM-KL25Z board with the mbed development platform for free!

We'll be introducing additional mbed-enabled development platforms from Freescale (and others) in 2013.

Get yours now!

You can get the FRDM-KL25Z development platform from Farnell/Newark/Element14 for a suggested resale price of $12.95 (USD):

For more information on the board, see:

If you are new to mbed, why not explore why you should base your next project on the mbed platform: