py32f0-template icon indicating copy to clipboard operation
py32f0-template copied to clipboard

Can support ST-Link V2 to download PY32F002A

Open Witawat opened this issue 2 years ago • 33 comments

Can support ST-Link V2 to download F200A how to setup on windows ?

Witawat avatar Mar 28 '23 06:03 Witawat

Stlink firmware is locked to stm mcus - so, no. I think some older versions might be unlocked, but i dont know which, or if they'd be compatible.

Daplink programmers are cheap, or you could build one yourself. I found that 'WCHLink' products DON'T work, and also that the raspberry pico pico probe doesn't work either. And my clone jlink doesnt work. But DAPLink works great.

prosper00 avatar Mar 28 '23 14:03 prosper00

Can support ST-Link V2 to download F200A how to setup on windows ?

Yes, but only if you use Keil MDK. This repository is for GNU GCC toolchain(mostly for Linux users) so most of content here might not help.

Keil MDK is a commercial software, you can install their community edition

After Keil MDK is installed, you need to install the DFP pack, which you can download from Puya PY32F0 product page, the download link. Then you can use any of JLink/STLink/DAPLink to flash/debug your PY32F002A.

For more details you can read the manuals in that pack

PY-MCU资料-20221117$ tree
.
├── Application Note
├── Datasheet&Reference_manual
├── Library and Examples
├── pack
│   ├── IAR
│   └── MDK
│       └── Keil
│           ├── Puya.PY32F0xx_DFP.1.1.0.pack
│           └── PY32F0xx_DFP User Manual Rev.1.0.pdf   <--- this
├── PuyaISP
├── PuyaProgrammer
├── PY_LINK用户手册V1.0
│   ├── PY-LINK User Manual Rev.1.0_EN.pdf       <---- and this
│   └── PY-LINK User Manual Rev.1.0.pdf
└── Start Kit用户指南

IOsetting avatar Mar 28 '23 15:03 IOsetting

Stlink firmware is locked to stm mcus - so, no. I think some older versions might be unlocked, but i dont know which, or if they'd be compatible.

Daplink programmers are cheap, or you could build one yourself. I found that 'WCHLink' products DON'T work, and also that the raspberry pico pico probe doesn't work either. And my clone jlink doesnt work. But DAPLink works great.

Have you tried the cheapest JLink OB? It works great too.

IOsetting avatar Mar 28 '23 15:03 IOsetting

These adapters do NOT work (for me). I have not spent much time troubleshooting them though; it may be possible to get them working. 'pyocd list' detects them, at least: https://www.aliexpress.com/item/1005003056314140.html https://www.aliexpress.com/item/1005003059548220.html https://www.aliexpress.com/item/1005004902159370.html

This one DOES work: https://www.aliexpress.com/item/1005004518845326.html

I would note that the one which does work appears to have a genuine STM32 device on it. All the others use WCH chips of varying types.

prosper00 avatar Mar 28 '23 18:03 prosper00

Thanks for the links.

The JLink OB I am using looks like this one,
https://www.aliexpress.us/item/3256803434277250.html

The DAPLink I am using is actually an AIR32F103 board(link) with DAPLink firmware (link), they just released the source code. This is not a genuine STM32, but it works :wink:

IOsetting avatar Mar 29 '23 04:03 IOsetting

there might be something fishy with my setup. I was playing around with some of the non-working probes, and while they all show up when I do a 'pyocd list,' none of them (save for one) work. They all generate varying errors with pyocd, and likewise generate unpredictable results with 'openocd -f cmsis-dap.cfg' The closest to a working probe is this one I built according to https://github.com/wagiminator/CH552-picoDAP - it erases the py32 just fine, but it times out when trying to write a firmware.

In any case, I'm just glad to have one probe that works. Otherwise, I suspect some sort of USB timing issues.

prosper00 avatar Mar 29 '23 22:03 prosper00

I spent some time documenting my results with a handful of different probes (and probe firmwares), and opened an issue with pyOCD.

prosper00 avatar Mar 31 '23 16:03 prosper00

Awesome! Thank you for spending so much time investigating this issue.

IOsetting avatar Apr 01 '23 03:04 IOsetting

Just dropping a quick note:

I couldn't get my J-Link to talk to PY32 chips - this was my first time using a J-Link.

I also ran into some of the issues as noted by @prosper00.

What worked for me:

Use https://github.com/RadioOperator/STM32F103C8T6_CMSIS-DAP_SWO along with a cheap, easily available STM32 BluePill board. This firmware and hardware combination works with pyOCD very well without any problems.

Also, https://daplink.io/ looked promising but it just wouldn't work on the STM32 BluePill board.

I can open a PR to document my working programming setup.

kholia avatar Apr 04 '23 00:04 kholia

I did try a bluepill, with this firmware: https://github.com/devanlai/dap42 - I also flashed it onto an old stlink clone (which, incidentally, make great little usb dev boards cheap). Neither worked with pyocd with any target board. They were able to flash an stm32 target from openocd though. I've been trying to put together a target .cfg file for the py32 and openocd, with (very) limited success so far

prosper00 avatar Apr 04 '23 01:04 prosper00

Yep - https://github.com/devanlai/dap42 didn't work me as well.

https://github.com/RadioOperator/STM32F103C8T6_CMSIS-DAP_SWO works like a champ on the BluePill board.

kholia avatar Apr 04 '23 01:04 kholia

oh yeah - the RadioOperator version works for me in pyocd with the PY32 too. Ironically, I used the dap42 programmer with openocd to flash it to the bluepill...

Tomorrow I'll flash it to an stlink and put it in my bin of dongles.

Makes me really wonder what's up with pyocd, and want to double down on getting openocd up and running. Especially as openocd seems to be about 40 to 50 times faster than pyocd

prosper00 avatar Apr 04 '23 03:04 prosper00

Yep - https://github.com/devanlai/dap42 didn't work me as well.

I have a very hacky pyOCD patch to make dap42 work with PY32. I just ignore some ACK related errors in pyOCD...

kholia avatar Apr 04 '23 03:04 kholia

The JLink OB I am using looks like this one, https://www.aliexpress.us/item/3256803434277250.html

Can confirm - the linked JLinkOB clone works for me. I also bought a genuine JLink Edu. It works too.

prosper00 avatar Apr 24 '23 21:04 prosper00

Something I just discovered: programming works better at 3V3 Vcc. At least some of the probes that weren't working for me actually DO work, but only when running the PY32 at 3.3V. And all probes seem to work with more stability and reliability at 3.3V

prosper00 avatar May 01 '23 19:05 prosper00

Nice detective work :+1:

This may be because the probes themselves are 3V3 devices?

kholia avatar May 02 '23 06:05 kholia

That's is good to know. I rarely run py32 under 5V, so I didn't notice the difference.

IOsetting avatar May 04 '23 16:05 IOsetting

For me picoprobe works out of the box, for both PyOCD and my ugly OpenOCD fork. This is probably the cheapest way to flash and debug puya. My boards are powered from 3,3V though. If you powered your board from 1,8V and used 3,3V probe you violated absolute maximum rating of VCC+0.3V for pins, specified in datasheet.

l0ud avatar May 15 '23 14:05 l0ud

I'd be curious to see your openocd fork. I got as far as trying to create a flash routine in src/flash/nor/ ... never did get it to work. Getting it to connect and debug a running program, yes, but I gave up on trying to get flash working.

In retrospect, yeah, using a 3.3V probe with 3.3V I/O was never going to work well, and probably risked damaging the probe too.

prosper00 avatar May 15 '23 21:05 prosper00

I think i managed to write to the PY32F002 with a CMSIS_DAP made of a CH552. The cheapest CMSIS_DAP i think? imagen

This is the firmware for the CMSIS_DAP based on the CH552: https://github.com/DeqingSun/ch55xduino/tree/ch55xduino/ch55xduino/ch55x/libraries/Generic_Examples/examples/05.USB/CMSIS_DAP

NoNamedCat avatar Jun 07 '23 23:06 NoNamedCat

I flashed the blink a led app but it doesn't flash the led

NoNamedCat avatar Jun 07 '23 23:06 NoNamedCat

Now it's working. My bad... I modify the Make File with the wrong parameters. I can confirm that you can flash the PY32F002 with a CH55x based CMSIS_DAP.

NoNamedCat avatar Jun 09 '23 15:06 NoNamedCat

If anyone is interested on the Design and gerber files to make a simple board for the PY32F002 and a cheap board based on the CH552 I can put the files here.

NoNamedCat avatar Jun 09 '23 15:06 NoNamedCat

If anyone is interested on the Design and gerber files to make a simple board for the PY32F002

I made one here: image

https://www.eevblog.com/forum/microcontrollers/$0-11-py32f002a-m0-24mhz-320kb-actually-324kb-more-peripherals/

deividAlfa avatar Jul 26 '23 20:07 deividAlfa

If anyone is interested on the Design and gerber files to make a simple board for the PY32F002

I made one here: image

https://www.eevblog.com/forum/microcontrollers/$0-11-py32f002a-m0-24mhz-320kb-actually-324kb-more-peripherals/

have all file on github ?

Witawat avatar Sep 25 '23 10:09 Witawat

Are you blind?😄 Files are in the link!

deividAlfa avatar Sep 25 '23 11:09 deividAlfa

Did I understand correctly, this makefile will not work under Windows?

Avtopolet avatar Dec 20 '23 13:12 Avtopolet

Did I understand correctly, this makefile will not work under Windows?

You need something like mingw64 to run make under windows.

IOsetting avatar Dec 21 '23 01:12 IOsetting

Thanks for answer. Im try it. GNU make output: PS C:\PUYA\py32f0-template-main> make
File not found - *.c File not found - *.c File not found - *.c File not found - *.s process_begin: CreateProcess(C:\xpack\xpack-arm-none-eabi-gcc-13.2.1-1.1\bin\arm-none-eabi-gcc, C:/xpack/xpack-arm-none-eabi-gcc-13.2.1-1.1/bin/arm-none-eabi-gcc -dumpversion, ...) failed. 'expr' is not recognized as an internal or external command, operable program or batch file. 'tr' is not recognized as an internal or external command, operable program or batch file. '' was unexpected at this time. make: *** [fullcheck] Error 255

Avtopolet avatar Dec 21 '23 05:12 Avtopolet

Download Arm GCC toolchain from https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads and extract it to /opt,

Then in MSYS2 console

# check version
ls /opt/arm-gnu-toolchain-13.2.Rel1-mingw-w64-i686-arm-none-eabi/bin/arm-none-eabi-gcc
/opt/arm-gnu-toolchain-13.2.Rel1-mingw-w64-i686-arm-none-eabi/bin/arm-none-eabi-gcc --version

arm-none-eabi-gcc.exe (Arm GNU Toolchain 13.2.rel1 (Build arm-13.7)) 13.2.1 20231009
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

# unzip the code
unzip py32f0-template-main.zip
cd py32f0-template-main/

# install nano editor
pacman -S nano

# edit Makefile
nano Makefile

Update the toolchain path in Makefile

##### Toolchains #######
ARM_TOOCHAIN    ?= /opt/arm-gnu-toolchain-13.2.Rel1-mingw-w64-i686-arm-none-eabi/bin

Then make clean and make, the console output

iosetting@a02-NC01 MSYS ~/py32f0-template-main
$ make clean
rm -rf ./Build/*

iosetting@a02-NC01 MSYS ~/py32f0-template-main
$ make
  CC    User/main.c
  CC    User/py32f0xx_hal_msp.c
  CC    User/py32f0xx_it.c
  CC    Libraries/PY32F0xx_HAL_Driver/Src/py32f0xx_hal.c
  CC    Libraries/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_adc.c
  CC    Libraries/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_adc_ex.c
  CC    Libraries/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_comp.c
  CC    Libraries/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_cortex.c
  CC    Libraries/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_crc.c
  CC    Libraries/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_dma.c
  CC    Libraries/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_exti.c
  CC    Libraries/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_flash.c
  CC    Libraries/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_gpio.c
  CC    Libraries/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_i2c.c
  CC    Libraries/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_irda.c
  CC    Libraries/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_iwdg.c
  CC    Libraries/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_led.c
  CC    Libraries/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_lptim.c
  CC    Libraries/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_pwr.c
  CC    Libraries/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc.c
  CC    Libraries/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc_ex.c
  CC    Libraries/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rtc.c
  CC    Libraries/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rtc_ex.c
  CC    Libraries/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_spi.c
  CC    Libraries/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_tim.c
  CC    Libraries/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_tim_ex.c
  CC    Libraries/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_uart.c
  CC    Libraries/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_usart.c
  CC    Libraries/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_wwdg.c
  CC    Libraries/PY32F0xx_HAL_BSP/Src/py32f0xx_bsp_clock.c
  CC    Libraries/PY32F0xx_HAL_BSP/Src/py32f0xx_bsp_led.c
  CC    Libraries/PY32F0xx_HAL_BSP/Src/py32f0xx_bsp_printf.c
  CC    Libraries/CMSIS/Device/PY32F0xx/Source/system_py32f0xx.c
  AS    Libraries/CMSIS/Device/PY32F0xx/Source/gcc/startup_py32f030.s
  LD    Libraries/LDScripts/py32f030x8.ld -> Build/app.elf
Memory region         Used Size  Region Size  %age Used
             RAM:        2280 B         8 KB     27.83%
           FLASH:        7808 B        64 KB     11.91%
  OBJCP BIN     Build/app.bin
  OBJCP HEX     Build/app.hex

iosetting@a02-NC01 MSYS ~/py32f0-template-main

IOsetting avatar Dec 21 '23 07:12 IOsetting