After run the command to upload firmware to chip PY32F002AA15M6TU
pyocd load app.hex -t PY32F002Ax5I got the error
0004908 C STLink error (22): DP error [__main__]But if you try to read firmware, it works fine
pyocd> savemem 0x08000000 20480 py32f002.binBTW pyOCD and ST-Link V2 work well with the PY32F003xx series.
The solution is to use CMSIS-DAP based programmer instead of ST-Link V2, but instead of buying a new one you can use STM32 Blue Pill board without adding any extra components, just upload the firmware https://github.com/RadioOperator/STM32F103C8T6_CMSIS-DAP_SWO/blob/master/build/F103-DAP-SWO-CDC-BLUEPILL-SWD_PB8PB9.hex from the repository https://github.com/RadioOperator/STM32F103C8T6_CMSIS-DAP_SWO and connect 2 wires.
After flashing Blue Pill, connect Blue Pill to your computer and connect PY32F002xx target as described below
| STM32 Blue Pull | PY32F002xx |
|---|---|
| PB8 | SWCLK (PA14) |
| PB9 | SWDIO (PA13) |

The original source of the image is http://reblag.dk/stm32
After running the command you will see a new device CMSIS-DAP by ARM CMSIS-DAP
pyocd listNow you can use a new Blue Pill based programmer to programm PY32F002 chips with pyOCD.