pyOCD flash (load) fails on STM32C031K4 (Custom Target)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.5k
- Forks
- 560
- Avg merge
- 1h 41m
- Merged PRs (30d)
- 3
Description
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
- Register the custom target as described in the pyOCD documentation
- 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__]
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the attached target_STM32C031K4.py and the custom-target guidance in the pyOCD documentation. Reproduce the failure with the documented pyocd load command, then compare it with the successful read32 command and the STM32CubeProgrammer workaround. Done means the custom target can be erased and flashed through pyOCD without the discovery or transfer errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100