Author Topic: PY32F002B locked  (Read 2973 times)

0 Members and 7 Guests are viewing this topic.

Offline Sacodepatatas

  • Regular Contributor
  • *
  • Posts: 203
  • Country: es
Re: PY32F002B locked
« Reply #25 on: July 25, 2026, 08:09:11 am »
Finally, using WCH LINKE as a programmer in ARM mode, in Keil Uvision, I managed to unlock all 6 blocked PY32F002b MCUs. I couldn't do it with the original ST LINK V2 or clone. The secret is to make all connections clearly (GND,VCC,SWD,SWC,NRST) and connect a button between NRST and GND. Then, hold down the button, press LOAD on Keil, and immediately release the button. It's a matter of timing, try several times and don't get discouraged, because it works in case of blockage. :-+

I did also unlock a py32f002bw5 with SWD/SWC turned to GPIO via firmware, with a DAP probe made of a ST-Link V2 clone (the ones that do not work with the STM32CubeProgrammer because of the MCU UUID number) and pyOCD. Plug the probe but don't power the chip (leave Vcc unconnected), just connect GND, SWD, SWC. Run pyOCD mass Erase command. The pyOCD will be waiting for any SWD response... Connect Vcc, and the chip gets erased.
 

Offline ago58Topic starter

  • Contributor
  • Posts: 16
  • Country: it
Re: PY32F002B locked
« Reply #26 on: July 25, 2026, 11:47:27 am »
Finally, using WCH LINKE as a programmer in ARM mode, in Keil Uvision, I managed to unlock all 6 blocked PY32F002b MCUs. I couldn't do it with the original ST LINK V2 or clone. The secret is to make all connections clearly (GND,VCC,SWD,SWC,NRST) and connect a button between NRST and GND. Then, hold down the button, press LOAD on Keil, and immediately release the button. It's a matter of timing, try several times and don't get discouraged, because it works in case of blockage. :-+

The WCH-LinkE has an RST output, which is controlled programmatically. 
And no need to make buttons on NRST. 
Only select the reset mode "pre-reset" or "under-reset".
If this doesn't work in Keil, then using pyOCD it definitely worked. 
JLink OB v2 (f072) also has an RST output, for example.

There is a surprising moment for the PY32F002A(F003,F030) models
- programming on 3 wires - SWD,SWC,GND. 
And there must be a capacitor between Vcc and Gnd. 
Power is obtained through the SWD interface
and pull-up resistors inside the chip.
Since the chip is powered by 1.7V, it works.
In this method, we just get a "reset on power"

For PY32F002B, this method does not work.
I did this without connecting the button and selected
"pre-reset" or "under-reset," to no avail. The button lets you choose the right moment to flash the PY32F002B.
I haven't tried it with pyOCD yet.
Anyway, thanks for the suggestions.
 

Offline ago58Topic starter

  • Contributor
  • Posts: 16
  • Country: it
Re: PY32F002B locked
« Reply #27 on: July 25, 2026, 12:02:15 pm »
Finally, using WCH LINKE as a programmer in ARM mode, in Keil Uvision, I managed to unlock all 6 blocked PY32F002b MCUs. I couldn't do it with the original ST LINK V2 or clone. The secret is to make all connections clearly (GND,VCC,SWD,SWC,NRST) and connect a button between NRST and GND. Then, hold down the button, press LOAD on Keil, and immediately release the button. It's a matter of timing, try several times and don't get discouraged, because it works in case of blockage. :-+

I did also unlock a py32f002bw5 with SWD/SWC turned to GPIO via firmware, with a DAP probe made of a ST-Link V2 clone (the ones that do not work with the STM32CubeProgrammer because of the MCU UUID number) and pyOCD. Plug the probe but don't power the chip (leave Vcc unconnected), just connect GND, SWD, SWC. Run pyOCD mass Erase command. The pyOCD will be waiting for any SWD response... Connect Vcc, and the chip gets erased.
Thanks so much for the suggestion.
I haven't tried pyOCD yet, because I don't have any stuck PY32F002Bs yet. However, if I ever have other stuck MCUs, I'll try the method you suggested. Also, since we're writing about a problem that might affect others, it would be interesting to delve deeper into other aspects of these and other PUYA family MCUs. Clearly, given their very low cost, it wouldn't be worth wasting too much time, but it's not a question of price, but of being more informed. Thanks
 

Offline Xiamatsu

  • Regular Contributor
  • *
  • Posts: 56
  • Country: ru
Re: PY32F002B locked
« Reply #28 on: July 25, 2026, 01:24:16 pm »
I've been studying the PY32 junior models a bit lately.   There are also interesting CW32, N32, HC32  and many other miscellaneous items.

Here are some studies on PY32F002A(F003,F030) and PY32F002B(L020) chips
https://github.com/Xiamatsu/py32f002a_003_030
https://github.com/Xiamatsu/py32f002b
(I apologize that it is not in English.)
I need to add some more recent research data, I haven't updated my github pages for a long time.

I also collect summary data on microcontrollers. 
I am conducting Coremark tests on my own for some controllers,
as well as comparing compilers with different settings.
All this is in a table in the cloud.

https://docs.google.com/spreadsheets/d/1Efv9o9Q0RhQnE3t0KpEYy8XxTBr_Hkxc-rqZPL5IJyA/edit?usp=sharing


PY32F0xx microcontrollers are characterized by very low current consumption, even at high frequencies, as well as at startup.


« Last Edit: July 25, 2026, 01:35:52 pm by Xiamatsu »
 
The following users thanked this post: ago58

Offline ago58Topic starter

  • Contributor
  • Posts: 16
  • Country: it
Re: PY32F002B locked
« Reply #29 on: July 25, 2026, 03:15:34 pm »
I've been studying the PY32 junior models a bit lately.   There are also interesting CW32, N32, HC32  and many other miscellaneous items.

Here are some studies on PY32F002A(F003,F030) and PY32F002B(L020) chips
https://github.com/Xiamatsu/py32f002a_003_030
https://github.com/Xiamatsu/py32f002b
(I apologize that it is not in English.)
I need to add some more recent research data, I haven't updated my github pages for a long time.

I also collect summary data on microcontrollers. 
I am conducting Coremark tests on my own for some controllers,
as well as comparing compilers with different settings.
All this is in a table in the cloud.

https://docs.google.com/spreadsheets/d/1Efv9o9Q0RhQnE3t0KpEYy8XxTBr_Hkxc-rqZPL5IJyA/edit?usp=sharing


PY32F0xx microcontrollers are characterized by very low current consumption, even at high frequencies, as well as at startup.
A thousand thanks.
As soon as possible, with great pleasure, I will take a look at your studies and research.
In fact I think that, despite the time and difficulties encountered in dealing with these mcu, it is worth it because they have, apart from the low price, interesting features.
 

Offline bingo600

  • Super Contributor
  • ***
  • Posts: 2315
  • Country: dk
Re: PY32F002B locked
« Reply #30 on: July 26, 2026, 03:11:32 pm »
Didn't DavidAlpha once say that you could erase the PY32xx , using Puya's Programmer (Windows exe) , even if you had disabled SWD ?
I have no idea if that goes for the B' versions too though.

I can't remember what "Jtag" HW they required.

But i think DA mostly used a Jlink (clone), when playing w. the PY's

/Bingo
« Last Edit: July 26, 2026, 03:14:20 pm by bingo600 »
 
The following users thanked this post: ago58

Offline Xiamatsu

  • Regular Contributor
  • *
  • Posts: 56
  • Country: ru
Re: PY32F002B locked
« Reply #31 on: July 26, 2026, 03:50:21 pm »
Didn't DavidAlpha once say that you could erase the PY32xx , using Puya's Programmer (Windows exe) , even if you had disabled SWD ?
I have no idea if that goes for the B' versions too though.

I can't remember what "Jtag" HW they required.

But i think DA mostly used a Jlink (clone), when playing w. the PY's

/Bingo

PY32F002A ( F003, F030 ) 
>= 20 pin 
have  Boot0  pin
UART   and  PY32CubeProgrammer  and  Boot0='1'
( UART  connect   PA2,3  |  PA9,10  |  PA14,15 )

PY32F002B ( L020 )   no  Bootloader

 
The following users thanked this post: bingo600, ago58

Offline db16122

  • Newbie
  • Posts: 9
  • Country: cn
Re: PY32F002B locked
« Reply #32 on: July 26, 2026, 09:42:17 pm »
22.3. ID codes and locking mechanism
Here are several ID codes inside the MCU. It is recommended that Keil, IAR and other tools use
this ID Code (located at 0x4001 5800 ) locks debugging.
After the chip is powered on, the hardware reads the 0x1FFF 0FF8 address of the flash 's factory
config. byte and loads it into the DBG _IDCODE register.

For the programmer and debugger, do you try PY-LINK and PY programmer? It seems they are official recommended.Not sure for st-link and wch-linke, it is third party tools and could have some problem during MCU development. FYI for selection guideline as below
https://www.puyasemi.com/chanpinxuanxingzhinan.html
 
The following users thanked this post: ago58

Offline Sacodepatatas

  • Regular Contributor
  • *
  • Posts: 203
  • Country: es
Re: PY32F002B locked
« Reply #33 on: July 27, 2026, 01:54:03 am »
Today I've browsing the puya site and downloaded the PY32_GCC_SDE package:

https://www.puyasemi.com/download_path/%E5%B7%A5%E5%85%B7/MCU/PY32_GCC_SDE_V1.0.5.zip

According to the docs, this package offers VSCode integration for all PY32s and it offers optional download and transparent instalation of Python and pyOCD while having the chance of selecting pyOCD, OpenOCD, and Jlink debuggers.

I thought it worths mention.
 
The following users thanked this post: ago58

Offline Xiamatsu

  • Regular Contributor
  • *
  • Posts: 56
  • Country: ru
Re: PY32F002B locked
« Reply #34 on: July 27, 2026, 03:53:16 am »
I have the latest versions of software packages in the cloud.

https://drive.google.com/drive/folders/1_6zKQZTISePGcfjyLglSdTA_UcKs1Hym?usp=drive_link

PY32Studio, an analog of STM32Cube, was recently released.
Also, the new PY32Programmer program stopped supporting JLink,
so I left the old PY32CubeProgrammer program (slightly corrected).
I used PY32_GCC_SDE, it's not bad to start,
but you can additionally install a newer version of GCC and switch EIDE to this version.
I'm trying to do all my examples now for Keil, IAR, VSCode+EIDE

For example, Coremark tests for different MCUs
https://github.com/Xiamatsu/CoreMark_Tests

PY32F002B is low on 3K RAM, 4K is needed for the Coremark test. 
The results in the table are approximate based on a simplified test.
« Last Edit: July 27, 2026, 03:56:17 am by Xiamatsu »
 
The following users thanked this post: ago58

Offline Xiamatsu

  • Regular Contributor
  • *
  • Posts: 56
  • Country: ru
Re: PY32F002B locked
« Reply #35 on: July 27, 2026, 04:18:34 am »
22.3. ID codes and locking mechanism
Here are several ID codes inside the MCU. It is recommended that Keil, IAR and other tools use
this ID Code (located at 0x4001 5800 ) locks debugging.
After the chip is powered on, the hardware reads the 0x1FFF 0FF8 address of the flash 's factory
config. byte and loads it into the DBG _IDCODE register.


Do not read the RM for py32f002b, there are many errors.
Better read RM for PY32L020, it's the same thing, it's the same chip inside.
And all the features of the PY32L020 are in PY32F002B, (48 MHz, deepstop, all Vrefbuf).

for  PY32F002B -
"After the device is powered on, the hardware reads the factory config of the flash. byte's 0x1FFF 01F8
address, loaded into the DBGMCU_IDCODE register."

 
The following users thanked this post: ago58


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

-->