Cannot debug or upload to FRDM_KL27Z board using CMSI-DAP

I’m trying to program my FRDM-KL27Z (Freescale Kinetis FRDM-KL27Z — PlatformIO latest documentation) with platform IO but I’ve not been able to manage.

In case it’s relevant information I’m doing this on a windows virtual machine (windows host & guest).

The board has two USB ports I’m connecting to the one that says OpenSDA and I can see the a F: drive mounting and a COM3 mounting, (I’m passing them to the virtual machine) I have uploaded an example blink program through MCUXpresso so both the board and the USB connection are good.

The board is somewhat old It might just be that:
Board: FRDM-KL27Z
It has a sticker with version information:
700-28303 Rev A
SCH-28303 Rev B
The PCB has a silk marking: 170-28303 Rev B
If I’m reading the serial correctly it was made on 2018

I’m trying to upload code from one of the examples from: GitHub - platformio/platform-freescalekinetis: Freescale Kinetis: development platform for PlatformIO (I’m creating a new porject and selecting the board but copying the main.cpp from the /mbed-rtos-blink-baremetal example).

Here’s the code:

/* mbed Microcontroller Library
 * Copyright (c) 2019 ARM Limited
 * SPDX-License-Identifier: Apache-2.0
 */

#include "mbed.h"

#define WAIT_TIME_MS 5000 
DigitalOut led1(LED1);

int main()
{
    printf("This is the bare metal blinky example running on Mbed OS %d.%d.%d.\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION);

    while (true)
    {
        led1 = !led1;
        thread_sleep_for(WAIT_TIME_MS);
    }
}

And here’s my INI:

[env:frdm_kl27z]
platform = freescalekinetis
board = frdm_kl27z
framework = mbed
debug_tool = cmsis-dap
upload_protocol = cmsis-dap
;upload_port = F: ;whether I specify the port or not it fails.

When I try to upload trhough platform IO I get the following message:

Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [====      ]  35.3% (used 5776 bytes from 16384 bytes)
Flash: [========  ]  78.4% (used 51376 bytes from 65536 bytes)
Building .pio\build\frdm_kl27z\firmware.bin
Configuring upload protocol...
AVAILABLE: blackmagic, cmsis-dap, jlink, mbed
CURRENT: upload_protocol = cmsis-dap
Uploading .pio\build\frdm_kl27z\firmware.bin
WARNING:pyocd.tools.flash_tool:pyocd-flashtool is deprecated; please use the new combined pyocd tool.
WARNING:pyocd.probe.common:STLink and CMSIS-DAPv2 probes are not supported because no libusb library was found.
No connected debug probes
Error: There is no debug probe connected.
*** [upload] Error 1

I found the following thread: Unable To Debug - tool-pyocd ModuleNotFoundError: No module named 'board'

where it recommends to install gdbserver outside of vscode and trying to connect but when I try to execute the following:

C:\Users\win10>pyocd gdbserver -t kl27z4

All I get is this:

C:\Users\win10>pyocd gdbserver -t kl27z4
Waiting for a debug probe to be connected...

And it just hangs there indefinitely.

That thread mention something about installing compatibility for libusb but when I click see libusb installation it always leads me to this link: GitHub - pyocd/pyOCD: Open source Python library for programming and debugging Arm Cortex-M microcontrollers

Did you try debugging - pyocd library cannot find libusb python library - Stack Overflow?

1 Like

I tried that but the problem persists though now it no longer says anything about libusb:

Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [====      ]  35.3% (used 5776 bytes from 16384 bytes)
Flash: [========= ]  94.9% (used 62224 bytes from 65536 bytes)
Building .pio\build\frdm_kl27z\firmware.bin
Configuring upload protocol...
AVAILABLE: blackmagic, cmsis-dap, jlink, mbed
CURRENT: upload_protocol = cmsis-dap
Uploading .pio\build\frdm_kl27z\firmware.bin
WARNING:pyocd.tools.flash_tool:pyocd-flashtool is deprecated; please use the new combined pyocd tool.
No connected debug probes
Error: There is no debug probe connected.
*** [upload] Error 1

trying to connect through cmd still hangs.

I’m starting to have severe doubts whether a frdm_kl27z really does have a CMSIS-DAP debugging probe on-board. Let me check the schematics and documentation for myself.

1 Like

Okay, per FRDM-KL27Z|Freedom Development Platform|Kinetis® MCU | NXP Semiconductors it is supposed to have one.

Open the Windows device manager, set View → Devices by container and scroll all the way down until you see your board. Expand it. What devices are under it?

1 Like

This is all that shows up:
image

Hm after reading through some very confusing things I think you have to reflash the debugger chip on your board from that “OpenSDA” thing to the CMSIS-DAP firmware.

OpenOCD/CMSIS-DAP Debugging with Eclipse and without an IDE | MCU on Eclipse in the section “CMSIS-DAP Debug Firmware” provides instructions for that.

1 Like

That did the trick, thank you kindly.

I download the DAPLink rev0242 from this page: OpenSDA Serial and Debug Adapter | NXP Semiconductors

And that worked, curiously when I tried to install the DAPLink OpenSDA v2.2 Bootloader it just resulted in the board being either partially bricked (aside from the bootloader) or my PC not recognizing the board at all.

Either way the code was uploaded successfully, maybe it’s newer boards that come out of the box with CMIS-DAP?

Uploading now results on the following:

Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [====      ]  35.3% (used 5776 bytes from 16384 bytes)
Flash: [========= ]  94.9% (used 62224 bytes from 65536 bytes)
Configuring upload protocol...
AVAILABLE: blackmagic, cmsis-dap, jlink, mbed
CURRENT: upload_protocol = cmsis-dap
Uploading .pio\build\frdm_kl27z\firmware.bin
WARNING:pyocd.tools.flash_tool:pyocd-flashtool is deprecated; please use the new combined pyocd tool.
INFO:pyocd.board.board:Target type is kl27z4
INFO:pyocd.coresight.dap:DP IDR = 0x0bc11477 (v1 MINDP rev0)
INFO:pyocd.coresight.ap:AHB-AP#0 IDR = 0x04770031 (AHB-AP var3 rev0)
INFO:pyocd.coresight.ap:AP#1 IDR = 0x001c0020 (AP var2 rev0)
INFO:pyocd.target.family.target_kinetis:KL27Z4 not in secure state
INFO:pyocd.coresight.rom_table:AHB-AP#0 Class 0x1 ROM table #0 @ 0xf0002000 (designer=00e part=000)
INFO:pyocd.coresight.rom_table:[0]<f0000000:MTB-M0+ class=9 designer=43b part=932 devtype=31 archid=0a31 devid=0:0:0>
INFO:pyocd.coresight.rom_table:[1]<f0001000:MTBDWT class=9 designer=00e part=000 devtype=04 archid=0000 devid=0:0:0>
INFO:pyocd.coresight.rom_table:[2]<e00ff000:ROM class=1 designer=43b part=4c0>
INFO:pyocd.coresight.rom_table:  AHB-AP#0 Class 0x1 ROM table #1 @ 0xe00ff000 (designer=43b part=4c0)
INFO:pyocd.coresight.rom_table:  [0]<e000e000:SCS-M0+ class=14 designer=43b part=008>
INFO:pyocd.coresight.rom_table:  [1]<e0001000:DWT-M0+ class=14 designer=43b part=00a>
INFO:pyocd.coresight.rom_table:  [2]<e0002000:BPU class=14 designer=43b part=00b>
INFO:pyocd.coresight.cortex_m:CPU core #0 is Cortex-M0+ r0p1
INFO:pyocd.coresight.dwt:2 hardware watchpoints
INFO:pyocd.coresight.fpb:2 hardware breakpoints, 0 literal comparators
[---|---|---|---|---|---|---|---|---|----]
[========================================]
INFO:pyocd.flash.loader:Erased chip, programmed 63488 bytes (62 pages), skipped 0 bytes (0 pages) at 14.75 kB/s
1 Like