Can debug with mbed OS 5.15. STLink error (22): DP error

I am using:

  • Mbed Studio 1.3.1
  • Mbed OS 5.15
  • Windows 10
  • Nucelo-F767ZI

I am able to debug the “mbed-os-example-blinky-baremetal-5” example program just fine, but trying to debug my program yields “STLink error (22): DP error”.
What does this error mean and how do I fix it?

Here is my code:

#include "mbed.h"

#define WAIT_TIME 100

static Serial serial(PD_1, PD_0, 115200); // UART4

AnalogIn analogInputs[NUM_ANALOG_INPUTS]
    = { AnalogIn(PA_0), AnalogIn(PA_3), AnalogIn(PA_6), AnalogIn(PB_1), AnalogIn(PC_0), AnalogIn(PC_2),
        AnalogIn(PC_3), AnalogIn(PC_5), AnalogIn(PF_3), AnalogIn(PF_4), AnalogIn(PF_5), AnalogIn(PF_6), AnalogIn(PF_7) };

DigitalIn digitalInputs[NUM_DIGITAL_INPUTS]
    = { DigitalIn(PC_10), DigitalIn(PC_11), DigitalIn(PC_12), DigitalIn(PC_13), DigitalIn(PD_2), DigitalIn(PD_3),
        DigitalIn(PD_4), DigitalIn(PD_5), DigitalIn(PD_6), DigitalIn(PD_7), DigitalIn(PE_1), DigitalIn(PE_3), DigitalIn(PB_4),
        DigitalIn(PB_5), DigitalIn(PB_6), DigitalIn(PB_8), DigitalIn(PB_9), DigitalIn(PB_10), DigitalIn(PC_7), DigitalIn(PC_9),
        DigitalIn(PD_11), DigitalIn(PD_12), DigitalIn(PD_13), DigitalIn(PE_10), DigitalIn(PE_12), DigitalIn(PE_13),
        DigitalIn(PE_14), DigitalIn(PE_15), DigitalIn(PF_12), DigitalIn(PF_13), DigitalIn(PG_14) };

DigitalOut digitalOutputs[NUM_DIGITAL_OUTPUTS]
    = { DigitalOut(PA_13), DigitalOut(PA_14), DigitalOut(PA_15) };

// This is a bit field for digital inputs.  Currently, we need to sample 34 digital inputs
uint32_t digitalInValues = 0;

Timer timer;

int main()
    serial.printf("\nStart test\n");

    // Set pulldowns on digital pins
    for(uint8_t i = 0; i < NUM_DIGITAL_INPUTS; i++)

    float analogInValues[NUM_ANALOG_INPUTS];


        for(uint8_t i = 0; i < NUM_ANALOG_INPUTS; i++)
            serial.printf("%.3f,", analogInputs[i].read());

        for(uint8_t i = 0; i < NUM_DIGITAL_OUTPUTS; i++)
            // TODO: Test code.  Not sure how we will need to drive these digital outputs
            digitalOutputs[i] = 1;

        digitalInValues = 0;
        for (uint8_t i = 0; i < NUM_DIGITAL_INPUTS; i++)
            int digitalInput = digitalInputs[i];
            digitalInValues |= digitalInput << i;

        // Print digital inputs, packed into a 32 bit bitfield.  Only print the right 31 bits and always print leading zeros.
        serial.printf("%u,", digitalInValues);
        float timestamp =;
        serial.printf("%.4f\n",; // print time from boot in seconds


The following error log is repeated many times in the debug console. Also, it leaves my system in a state where my CPU usage is high with Python being the culprit.

0018257:ERROR:gdbserver:Unhandled exception in handle_message: STLink error (22): DP error
Traceback (most recent call last):
  File "c:\Users\nhopkins\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\gdbserver\", line 381, in handle_message
    reply = handler()
  File "c:\Users\nhopkins\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\gdbserver\", line 817, in get_registers
    return self.create_rsp_packet(self.target_facade.get_register_context())
  File "c:\Users\nhopkins\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\gdbserver\", line 69, in get_register_context
    vals = self._context.read_core_registers_raw(reg_num_list)
  File "c:\Users\nhopkins\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\debug\", line 48, in read_core_registers_raw
    return self._regcache.read_core_registers_raw(reg_list)
  File "c:\Users\nhopkins\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\cache\", line 100, in read_core_registers_raw
  File "c:\Users\nhopkins\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\cache\", line 77, in _check_cache
    if self._core.is_running():
  File "c:\Users\nhopkins\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\coresight\", line 1013, in is_running
    return self.get_state() == Target.State.RUNNING
  File "c:\Users\nhopkins\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\coresight\", line 982, in get_state
    dhcsr = self.read_memory(CortexM.DHCSR)
  File "c:\Users\nhopkins\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\coresight\", line 646, in read_memory
    result = self.ap.read_memory(addr, transfer_size, now)
  File "c:\Users\nhopkins\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\probe\", line 255, in read_memory
    result = conversion.byte_list_to_u32le_list(self._link.read_mem32(addr, 4, self._apsel))[0]
  File "c:\Users\nhopkins\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\probe\stlink\", line 387, in read_mem32
    return self._read_mem(addr, size, Commands.JTAG_READMEM_32BIT, self.MAXIMUM_TRANSFER_SIZE, apsel)
  File "c:\Users\nhopkins\AppData\Local\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\probe\stlink\", line 347, in _read_mem
    raise self._ERROR_CLASSES[status](error_message)
pyocd.core.exceptions.TransferError: STLink error (22): DP error


Could you try after removing digitalOutputs pins ?


Thank you for the suggestion! I commented them out and I can debug, now!

Can you tell me why we can’t use the digital outputs and / or what STLink error (22) is?


I need to find some place to document this better.

You can check Reference Manual for STM32F767 / SWJ debug port pins paragraph.
Some pins are used for the STLink/JTAG connection, so you can use them in “normal” mode, but not in “debug” mode.

In mbed-os, you can check PinNames.h file for each target, I only named these pins as SYS_xxx, but no check are done after, it is up to user to know if debug mode is allowed or not.



Thank you. Just what I was looking for!