Skip to content

pyOCD flash (load) fails on STM32C031K4 (Custom Target) #1956

@EmreGezer1

Description

@EmreGezer1

Description

pyOCD is unable to flash the STM32C031K4 target via ST-Link V3. Multiple connection errors occur during the flash attempt. STM32CubeProgrammer CLI works as a workaround when using reset=HWrst and --erase all.

Note: pyOCD can read memory successfully (read32 0x08000000 returns the correct stack pointer value), so the issue is specific to the flash/erase operation.

Environment

  • Target: STM32C031K4 (ARM Cortex-M0+), registered as a custom target
  • Debug Probe: ST-Link V3 (STLINK-V3MODS, FW: V3J17M10B6S1)
  • pyOCD version: installed in .venv
  • STM32CubeProgrammer version: v2.22.0
  • Host OS: Windows 10
  • Connection: SWD (SWDCLK, SWDIO, VCC, GND)

Steps to Reproduce

  1. Register the custom target as described in the pyOCD documentation
  2. Run the following command:
.venv\Scripts\python.exe -m pyocd load --target stm32c031k4 --format elf --erase chip --connect under-reset <your_elf_path>

Observed Errors

0002829 E Error probing AP#2: STLink error (22): DP error [discovery]
0002837 E Error probing AP#3: Memory transfer fault (STLink error (17): AP fault) [discovery]
0002842 E Error probing AP#4: Memory transfer fault (STLink error (21): DP fault) [discovery]
0002846 E Error reading AP#1 IDR: Invalid AP address (#1) [discovery]
0002855 C No cores were discovered! [__main__]
Image

Workaround

Flashing via STM32CubeProgrammer CLI works reliably:

STM32_Programmer_CLI --connect port=SWD reset=HWrst --erase all --download <your_elf_path> --verify --go

Memory Read Works

pyOCD can successfully read memory from the target, confirming the custom target registration and SWD connection are correct:

.venv\Scripts\python.exe -m pyocd cmd --target stm32c031k4 --connect under-reset --command "read32 0x08000000"
# output: 08000000:  20001800

The value 20001800 is the initial stack pointer, which is the expected value at address 0x08000000.

target_STM32C031k4.py

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions