$0.11 PY32F002A: Cortex-M0+ MCU, actually a PY32F030! 32/4KB, 48MHz, PLL, DMA... - Page 1
Forum section: electronics / general

author: DavidAlfa
author_rank: Super Contributor
timestamp: July 01, 2023, 10:52:02 am
content: To avoid bloating my HK32F030M thread, I'll be posting the PY32F002A bits here.Links:Puya gitee repo: Docs, libs, software...Puya Google Drive folder: English reference manuals, datasheets, application notes, PuyaISP...IOSetting's repo containing py32 template and libs.MCU-Flash-Tools. Python-based ISP bootloader tool for WCH and PY32 mcus, removing the dependency of Puya-ISP.Tested so far:- Bootloader. Pulling PB6 (BOOT0) high before power-on (Or resetting afterwards) enters the embedded bootloader, just like in STM32.Connect RX/TX to PA2/PA3, open Puya ISP, everything works.Thread showing PuyaISP:https://www.elektroda.pl/rtvforum/topic3951956.html- STM32 CubeIDE: The patch works, I was able to program & debug using JLink.CubeIDE Patch: Adds support for several devices, including PY32, HK32... Everything works except CubeMX, you must use your own libs and initialization. Debugging and CMSIS SVD peripheral view work too.PY32 folderwith docs and CubeIDE PY32F030 sample project. Patch must be applied before attempting to open this project, otherwise CubeIDE will crash.Jlink doesn't support this chip yet so you must manually add it. Place IOSetting'sPY32 folderfollowingthis instructions:Edit: Jlink added support for PY32. If you're using a ST-Link converted to Jlink you'll get the "Not a ST device" error, keep reading for the fix.QuoteAlternatively, you can convert a ST-Link into JLinkEDU, but it will block any attempts to use non-ST devices.The solution is to edit the XML file and change the vendor to ST (ChipInfo Vendor="ST").But if the device already exists in Jlink software, then you must change the device name, for example "_py32f002af15p6".Then set this device name under Jlink configuration.DO NOT do this for commercial purposes. Most people can't afford $100 programmers to just blink some leds or learn by their own.So far this chip seems to contain the same die as the PY32F030x6, with the same 4/32KB. PLL, DMA, 2nd UART & SPI...More info:https://www.elektroda.com/rtvforum/topic3946116.htmlTested so far:- 32KB flash- 4KB RAM- PLL (48MHz)- 2xSPI, 2xUSART- DMAAfter setting RDP1, I could no longer program or erase it with J-Link, I had to use PUYA ISP, setting BOOT=1 to enter the serial bootloader and running "Clear chip".Edit: Fix PCB:- Missing GND trace for CH340E !!- CH340E RTS/DTR not working as expected, removed them.- Fix BOOT0 button, pull pin high instead low.QuoteRest are common parts easily sourced anywhere, 0402 resistors / capacitors, pin headers, 25xx/24xx memories...The board doesn't need to be fully populated. Actually just the LDO and few caps and you'll have a working board.You can add the rest of functionalities depending on your needs.I also extracted the factory bootloader located at 0x1FFF0000, just in case anyone wants to tinker with it in Ghidra/IDA.

author: DavidAlfa
author_rank: Super Contributor
timestamp: July 01, 2023, 12:26:33 pm
content: The USART2 is definitely there!I'm toggling the pin AF before transmitting, PA2 AF1=TX1, AF4=TX2.Edit:Confirmed the PLL is also present and works, the system boosts to 48MHz.Overclockability beyond this point is weak, not reaching even 64MHz without crashing.Could It be the reason it's being sold as a 24MHz part? Perhabs.As stated in the Elektroda thread, the HSI TRIM value is not restored on system reset, so be careful (PLL has no issues here).Edit2: Also DMA works. This chip has an amazing value for the cost!Edit3: I forgot to attach a picture showing the component references...

author: prosper
author_rank: Regular Contributor
timestamp: July 02, 2023, 02:47:09 am
content: i played with iosetting's environment and its examples, and can confirm that the 002 can be treated as an 030. pll, dma, flash, and sram were tested and work for me.

author: DavidAlfa
author_rank: Super Contributor
timestamp: July 11, 2023, 06:44:28 pm
content: I finished adding CubeIDE support for all PY32F0xx devices.Updated the CubeIDE patch and added a PY323F030 sample project in the main message.IOSetting's LL libraty worked great after setting the project up.

author: iMo
author_rank: Super Contributor
timestamp: July 21, 2023, 11:12:46 am
content: Does the IDE support double precision floating point math on this device?

author: brucehoult
author_rank: Super Contributor
timestamp: July 21, 2023, 11:16:07 am
content: Quote from: iMo on July 21, 2023, 11:12:46 amIt would be very strange if it didn't. Using the compiler's runtime library software emulation, of course. Which might eat half of your flash.

author: iMo
author_rank: Super Contributor
timestamp: July 21, 2023, 11:22:33 am
content: Yep, would be great to test it somehow, how it fits.64kB flash would be handier, however..PS: the + - * / sqrt would be ok for most cases (ie while messing with 6-7digits DMM values).

author: iMo
author_rank: Super Contributor
timestamp: July 21, 2023, 11:52:03 am
content: Like this test for example:Code:// Double precision math TEST by iMo and AI#include <stdio.h>#include <stdlib.h>#include <stdint.h>#include <math.h>#define NUM_SAMPLES 100double calculate_mean(double* data, int n) {double sum = 0.0;for (int i = 0; i < n; i++) {sum += data;}return sum / n;}double calculate_standard_deviation(double* data, int n, double mean) {double variance = 0.0;for (int i = 0; i < n; i++) {variance += (data - mean)*(data - mean);}variance /= n;return sqrt(variance);}int main() {// Seed the random number generator//srand(time(NULL));double random_numbers;// The rand() function computes a new pseudo-random number in the interval 0 to RAND_MAX// #define RAND_MAX 0x3fffffff// Generate 100 random double fp numbers between 9.99999 and 10.0for (int i = 0; i < NUM_SAMPLES; i++) {random_numbers = 9.99999 + ((double)rand() / RAND_MAX) * (10.0 - 9.99999);}// Calculate the mean of the 100 samplesdouble mean = calculate_mean(random_numbers, NUM_SAMPLES);// Calculate the standard deviation of the 100 samplesdouble std_deviation = calculate_standard_deviation(random_numbers, NUM_SAMPLES, mean);//printf("Sample Mean: %lld\n", (long long)(mean*1e15));//printf("Sample Standard Deviation: %lld\n", (long long)(std_deviation*1e15));printf("Sample Mean: %d\n", (int)(mean*1e8));printf("Sample Standard Deviation: %d\n", (int)(std_deviation*1e14));return 0;}Sample Mean: 999999533Sample Standard Deviation: 293668347//Sample Mean: 9.999999533124507//Sample Standard Deviation: 0.000000293668347

author: brucehoult
author_rank: Super Contributor
timestamp: July 21, 2023, 12:04:46 pm
content: Now you're including not only DP calculation, but also printf that supports DP FP. That's another thing again.

author: iMo
author_rank: Super Contributor
timestamp: July 21, 2023, 12:24:50 pm
content: ok fixed abovePS: alternative int32 print, such we can see something printed out, what is the "test" is how it fits into the flash of these CM0 gadgets..Code:printf("Sample Mean: %d\n", (int)(mean*1e8));printf("Sample Standard Deviation: %d\n", (int)(std_deviation*1e14));Sample Mean: 999999533Sample Standard Deviation: 293668347

author: DavidAlfa
author_rank: Super Contributor
timestamp: July 21, 2023, 04:16:48 pm
content: It's ARM and GCC, not a strange architecture with propietary compiler, so of course it supports that.

author: iMo
author_rank: Super Contributor
timestamp: July 21, 2023, 05:07:24 pm
content: And how does it fit inside? Provided you already work with the gcc and the chip - could you cut and paste the source above, build it and look at the flash mem used, plz?

author: DavidAlfa
author_rank: Super Contributor
timestamp: July 21, 2023, 08:34:48 pm
content: Quote from: iMo on July 21, 2023, 11:52:03 amYou know this is a pretty terrible example for a small MCU, where you normally would try to avoid printf etc at all costsBut anyways, compiled with -Os. Without your code, flash usage is 508 Bytes, of which 192 are the ISR vectors.

author: iMo
author_rank: Super Contributor
timestamp: July 22, 2023, 11:47:20 am
content: I've installed new Cube and built my example for an STM32F030R8 with the HAL there -> 17.3kB flash. Lot of HAL stuff re system config and UART. You've done it with LL thus you've saved precious ~4kB..

author: DavidAlfa
author_rank: Super Contributor
timestamp: July 23, 2023, 03:25:19 am
content: I did with LL, but using PY32 lib, not CubeMX.Also there was no system initialization (Clock, etc), just the main() with your code.Some HAL functions can get really heavy, I remember seeing 1KB used by the oscillator/clock initialization alone!

author: iMo
author_rank: Super Contributor
timestamp: July 23, 2023, 06:05:39 am
content: 1020bytes oscRCC, pretty heavy, indeed..

author: DavidAlfa
author_rank: Super Contributor
timestamp: July 23, 2023, 07:34:23 am
content: Plus the aeabi routines, also used by that function.If you tweak so it only handles the default speed instead all combinations, it'll get a lot smaller.Or use LL for the clock, it might improve.

author: iMo
author_rank: Super Contributor
timestamp: July 23, 2023, 11:34:55 am
content: I've patched the latest Cube with your above patches. Now - does it allow to see the PY/HK chips in the mcu type selector? Or how do you use the patches actually?? I am happy to use them with the Cube's HAL at this stage.

author: DavidAlfa
author_rank: Super Contributor
timestamp: July 23, 2023, 02:22:36 pm
content: Yes, check the new picture I added to the 1st message.But anyways you will likely want to use the libs, check the 1st message again with the py32 folder.

author: danymogh
author_rank: Regular Contributor
timestamp: August 05, 2023, 04:37:59 pm
content: which programmer are you using to connect to the PY32?I have a st link v2 which i converted to DAP link but neither KEIL nor puya programmer don't detect it.in the vendor pack there are 2 manuals regarding this PY-LINK programmer which seems to be a modified Jlink but I found no resources or a place to buy it.in the manual, It just selects DAP-link to connect to the MCU so I suppose any DAP link would be ok, however, it seems that's not the case.so which clone programmers are you using to connect to it? would the Jlink OB work?

author: DavidAlfa
author_rank: Super Contributor
timestamp: August 05, 2023, 04:57:13 pm
content: More important, what software are you using? The programmer is just the interface!I'm using patched CubeIDE (But anything able to use Jlink will work).For DIY /Learing you can convert a STLINK into JLINK, though you'll need custom JLinkDevices to fake them as ST parts.Not hard, please use ethically.Alternatively, if you are only programming (Not debugging), then simply use a serial converter and Puya ISP!

author: danymogh
author_rank: Regular Contributor
timestamp: August 06, 2023, 06:56:02 am
content: Thanks for the tip.I ended up finding this repohttps://github.com/RadioOperator/STM32F103C8T6_CMSIS-DAP_SWOand will turn one of my bluepills to CMSIS-DAP and will test it.Is there any program that supports the Puya programmer software? where is the Py-link available ?

author: DavidAlfa
author_rank: Super Contributor
timestamp: August 06, 2023, 07:21:58 am
content: Puya ISP is the software itself. Connect the serial converter to Rx/Tx, set boot=1, that's all it takes.I have no idea what to use for PyLink.

author: danymogh
author_rank: Regular Contributor
timestamp: August 06, 2023, 12:39:37 pm
content: I finally managed to get it working.I first used a USB TTL as you described and connected to it by Puya ISP. I had to pull up Boot0 pin.The software is a bit tricky. I had to reset the VDD after every program or chip cleared. (I'm not using DTR or RST).Also if you attempt to readout a read-protected chip it automatically clears the chip!Then I converted a Bluepill to a CMISIS-DAP and managed to get it to work with KEIL. the standard SWD, SWCK, VDD, GND, and Reset.I can now use the debug features. however, It doesn't work with Puya Programmer.Is there any way to set the option bytes with CMSIS-DAP?

author: DavidAlfa
author_rank: Super Contributor
timestamp: August 06, 2023, 03:02:41 pm
content: Tricky? Couldn't be easier!Mcu info doesn't clear the chip automatically, just shows it's protected.Download code does... exactly that!It will reset automatically on erasing/programming, if you permanently pull boot high, it'll enter bootloader again.(So if you plan to do multiple operations, leave boot high all the time)If you want it to execute the program automatically without releasing boot0, tick "Use GO command".

author: danymogh
author_rank: Regular Contributor
timestamp: August 06, 2023, 04:07:10 pm
content: Very strange , I have the same config but mine automatically erases the chip after attempting to read the data.I noticed in your first post you mentioned to programed the RDP using Jlink and then had to use puya isp to reset it.How did you set RDP using Jlink? is it possible to program optionbyes using Jlink or cmsis dap ?

author: DavidAlfa
author_rank: Super Contributor
timestamp: August 06, 2023, 04:36:34 pm
content: I said I had set RDP, not that I used Jlink for that. In fact I did it with code:Code:FLASH_OBProgramInitTypeDef pOBInit;LL_FLASH_OBGetConfig(&pOBInit);if(pOBInit.RDPLevel != OB_RDP_LEVEL_1){pOBInit.OptionType = OPTIONBYTE_RDP;pOBInit.RDPLevel = OB_RDP_LEVEL_1;LL_FLASH_Unlock();LL_FLASH_OB_Unlock();LL_FLASH_OBProgram(&pOBInit);LL_FLASH_OB_Lock();LL_FLASH_Lock();LL_FLASH_OB_Launch();}If you want a quick program for testing, here's one.It loops USART1 (PA2, PA3), all you send is TX'ed back using DMA (115200 baud).Also there're 3 leds: PA0, PB0, PB1 (Meant to be a RGB led), connect them to VDD trough a resistor (The mcu pulls low to lit it).Just like the schematics in the 1st post, as I'm using that board.

author: DavidAlfa
author_rank: Super Contributor
timestamp: August 06, 2023, 05:18:49 pm
content: I tried, and it can be set while programming by modifying the linker script:Code:MEMORY{RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 4KFLASH (rx) : ORIGIN = 0x08000000, LENGTH = 32KRDP (r): ORIGIN = 0x1FFF0E80, LENGTH = 4}/* Define output sections */SECTIONS{.rdp :{KEEP(*(.rdp))/* .rdp section */KEEP(*(.rdp*))} >RDPThen defining the value:Code:// RDP 0__attribute__((section(".rdp"))) const uint32_t rdp = 0x4155beaa;//RDP 1__attribute__((section(".rdp"))) const uint32_t rdp = 0x41aabe55;But be careful, setting BOOT1 will make BOOT0 unable from entering the bootloader (boot0 & boot1 high boots from ram instead).Better simply to not touch RDP unless you really want to protect it (For production, etc).Interestingly, after setting RDP1 this way, PUYA ISP doesn't complain for readout protection, it still reads the MCU, though it's all 0xFF.Also, the default value stated in the RM seems wrong, it says it's 0x0155BEAA but should be 0x4155BEAA.(The upper 16 bits are the lower 16 bits, inverted).The 2nd byte (0xBE) byte defines the behaviour of nRST, BOOT1 (Not available as pin), BOR, IWDG, WWDG...Read the referece manual to find out what these bits mean, section "Flash option byte".Also, Puya ISP won't work properly if you set RDP like this, it crashes when opening the hex file.Don't enable bin generation, it will fill the gap between the end of the flash (0x8008000) and the start of RDP(0x1FFF0E80), making a giant file of 383MB.

author: prosper
author_rank: Regular Contributor
timestamp: August 08, 2023, 03:49:39 am
content: you should be able to write opt from within your application, or, attach GDB to it (with the DAP and pyocd) and write the bytes manually(gdb) set *((unsigned int *) 0x1FFF0E80) = <value>you could include a gdb one or two liner in your makefile.

author: DavidAlfa
author_rank: Super Contributor
timestamp: August 17, 2023, 12:15:42 pm
content: So I'm having a really weird situation.Edit:I set everything to fit 100% to the official PY32F002A specs, leaving the code to the very minimum...Now it only uses Systick and Timer1.Timer1 capture triggers in any falling edge, sets "new_capture" variable when detected and stops itself.Systick isr monitors this variable, sets a led indicating a new capture was received and restarts the capture timer.It also toggles a second led indicating the system is working.Systick isr has the highest priority, so no other IRQ can execute over it except HardFault.It all works as expected, no matter the optimization level.When I set RDP1, it will randomly freeze when toggling the input capture signal, killing everything.I made a checkum of the entire flash before and after locking, printing it through serial, it matched.This also happens if I set RDP using PuyaISP.I only know it's not a HardFault, as it has a routine that quickly flashes the led.I can trigger it by accessing unimplemented memory, but it's not being called when this strange fault happens.I even filled all the empty NVIC entries in case it was triggering some undocumented vector... nope.I can attach the debugger, as RDP is set I can only see the cpu registers, the PC can be read so I have a slight idea of what's going on.The debugger halts when toggling the capture input, so clearly there's some exception happening.Quote

author: danymogh
author_rank: Regular Contributor
timestamp: August 18, 2023, 12:17:55 pm
content: your PC = 0xFFFFFFFEthat's an invalid address. if this happens only when RDP is set then it might have to do with flash protection options.have you read Table 4-8 from the English reference manual?Edit : try to apply the RDP protection from outside the code. (from PuyaISP) see if that changes anything.

author: DavidAlfa
author_rank: Super Contributor
timestamp: August 18, 2023, 12:28:09 pm
content: Quote from: danymogh on August 18, 2023, 12:17:55 pmI know!Quote from: danymogh on August 18, 2023, 12:17:55 pmI forgot to mention that. Yes, it also happens. Thats's what made me think of a real hardware issue.It's not the flash, as I said I checksumed the entire 32K, before and after locking and the result matched.Also I could write to the flash in the code after setting RDP.The executed code is always the same...I attached the binary just in case you want to try, RDP disabled.MCU:PY32F002AF15P6TUSystem LED: PB1, active lowCCP LED: PB0, active lowCCP input: PA1, falling edge, internal pullup.Oscillator: Internal 24MHZ HSILeds are active-low, connected to VDD, the mcu pin pull it low when active.Nothing else is required. Just poke the CCP input and see the CCP led doing stuff.If RDP is enabled, it will randomly stall.Without RDP it can run for hours.

author: DavidAlfa
author_rank: Super Contributor
timestamp: August 18, 2023, 12:52:22 pm
content: Made it so the led blinks for only 1ms when a falling edge is detected.Led duration is not very accurate, as it can happen right after a systick IRQ, so it might remain enabled anywhere between 1 and 2ms.Not the problem here!100Hz CCP signal, when RDP off it runs forever.With RDP on, it crashed after 2 seconds or so.The system only crashes when toggling the ccp input, otherwise it will run fine.Time for crashing is random, sometimes it happens in 100ms, others in 3 seconds.

author: bingo600
author_rank: Super Contributor
timestamp: August 18, 2023, 03:39:59 pm
content: @DavidATM i just have two F002 devel boards, same mcu as you.I can't really test, will loose my "chip"I'm quite sure you wrote that only the puya programmer could clear the read protection.And the puya programmer s Win-only, i'm linux only.Hope someone else can help out./Bingo

author: DavidAlfa
author_rank: Super Contributor
timestamp: August 18, 2023, 04:27:51 pm
content: Might it work in Wine? I tried but it's not recognizing the serial ports...Edit: It's only happening if more than one interrupt is enabled.Seems like some sort of stack corruption? One interrupt happens over other one, then the it restores a wrong or corrupted context?If I disable systick it won't happen. But this will also happen if any other interrupt is running.It can't get any simpler than this!Code:#include "main.h"volatile uint8_t new_capture;/*--------------------------------------------------*/void system_init(void){LL_RCC_HSI_SetCalibFreq(LL_RCC_HSICALIBRATION_24MHz);while (LL_RCC_HSI_IsReady() != 1);LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA | LL_IOP_GRP1_PERIPH_GPIOB | LL_IOP_GRP1_PERIPH_GPIOF);LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_TIM1);WritePin(RED,1);WritePin(BLUE,1);LL_GPIO_Init(CCP_Port, &(LL_GPIO_InitTypeDef){ CCP_Pin, LL_GPIO_MODE_ALTERNATE, LL_GPIO_SPEED_FREQ_VERY_HIGH, LL_GPIO_OUTPUT_PUSHPULL, LL_GPIO_PULL_NO, CCP_AF });LL_GPIO_Init(RED_Port, &(LL_GPIO_InitTypeDef){ RED_Pin, LL_GPIO_MODE_OUTPUT, LL_GPIO_SPEED_FREQ_VERY_HIGH, LL_GPIO_OUTPUT_PUSHPULL });LL_GPIO_Init(BLUE_Port, &(LL_GPIO_InitTypeDef){ BLUE_Pin, LL_GPIO_MODE_OUTPUT, LL_GPIO_SPEED_FREQ_VERY_HIGH, LL_GPIO_OUTPUT_PUSHPULL });LL_TIM_Init(CCP_TIM, &(LL_TIM_InitTypeDef){ 23, LL_TIM_COUNTERDIRECTION_UP, 65535, LL_TIM_CLOCKDIVISION_DIV1, 0}); // 1MHz clock, 65ms overflowLL_TIM_IC_Init(CCP_TIM, CCP_CH, &(LL_TIM_IC_InitTypeDef){ LL_TIM_IC_POLARITY_FALLING, LL_TIM_ACTIVEINPUT_DIRECTTI, LL_TIM_ICPSC_DIV1, 4 }); // Falling edgeLL_TIM_EnableCounter(CCP_TIM);NVIC_SetPriority(TIM1_CC_IRQn, 1);NVIC_EnableIRQ(TIM1_CC_IRQn);SysTick_Config(24000); // 24MHz cpu clock, 1ms period.}/*--------------------------------------------------*/void capture_start(void){LL_TIM_ClearFlag_CC4(CCP_TIM);LL_TIM_EnableIT_CC4(CCP_TIM);}/*--------------------------------------------------*/int main(void){uint32_t red=0, blue=0;system_init();capture_start();while(1){/*-------------*/ // Handle red ledif(new_capture){ // Turn on the red LED for some time when a capture is received.new_capture=0;red=100; // Load led countercapture_start(); // Start a new capture}else if(red && !--red) // Decrease led counter until 0WritePin(RED,1); // Led expired, turn off/*-------------*/ // Handle blue ledif (!blue || !--blue ) // Generate small pulses in the blue led as heartbeat signal{bool b = ReadPin(BLUE);WritePin(BLUE,!b);blue = b ? 1000 : 1100000;}/*-------------*/}}/*--------------------------------------------------*/void systick_isr(void){asm("nop"); // Do nothing}/*--------------------------------------------------*/void capture_isr(void){LL_TIM_SetCounter(CCP_TIM, 0); // Reset timer counterif(LL_TIM_IsActiveFlag_CC4(CCP_TIM)) // Capture flag active{LL_TIM_IC_GetCaptureCH4(CCP_TIM); // Capture CCP valueLL_TIM_DisableIT_CC4(CCP_TIM); // Disable CC interruptLL_TIM_ClearFlag_CC4(CCP_TIM); // Clear flagWritePin(RED,0); // Turn led onnew_capture=1; // Set flag}}

author: bingo600
author_rank: Super Contributor
timestamp: August 18, 2023, 07:48:34 pm
content: Quote from: DavidAlfa on August 18, 2023, 04:27:51 pmAnd still only when RDP is enabled ??/Bingo

author: DavidAlfa
author_rank: Super Contributor
timestamp: August 18, 2023, 07:53:16 pm
content: Yes! That's why I started this. Otherwise I would think it was my fault.The code should not be affected in any way by RDP!I left it with RDP off, receiving 200Hz pulses from the generator for more than an hour, no problem!Same file, programmed setting RDP in PuyaISP - crashes in 1-2 seconds.How is that?!So anything planned to be sold and RDP-protected - back to stm32 LOL.I knew something had to happen at some point

author: danymogh
author_rank: Regular Contributor
timestamp: August 19, 2023, 07:20:11 am
content: That's a big problem if it really is a problem on the chip level.AFAIK they buy or implement the cortex M0+ core as is on the chip and only add peripherals. what you described is on the core level which means the core is faulty somehow?I think it needs a little more digging.

author: DavidAlfa
author_rank: Super Contributor
timestamp: August 19, 2023, 09:27:03 am
content: I sent a mail to Puya, I don't expect getting any solution3 but who knows.Meanwhile this will be my own fix:https://a.aliexpress.com/_Eu8sh0B

author: man_anyone
author_rank: Newbie
timestamp: August 21, 2023, 10:12:19 am
content: Did you test the hk32f030 to see if it has the same problem? Maybe there's a common thing that all Chinese MCUs cheap out on that leads to this problemMaybe we can get help from hangshun too if their MCU has the same problem

author: PCB.Wiz
author_rank: Super Contributor
timestamp: August 21, 2023, 10:22:34 am
content: Or other PUYA MCU, do they have the same issue?

author: DavidAlfa
author_rank: Super Contributor
timestamp: August 21, 2023, 11:11:58 am
content: The HK only had a small issue, requiring power cycling after programming. Yeah this same project is working in the HK, in fact I've sold a few.I tried migrating to the PY32 as it's a better mcu overall while less than half the price, but didn't go as planned.

author: man_anyone
author_rank: Newbie
timestamp: August 21, 2023, 03:47:51 pm
content: What about trying other puya MCUs? Also try other units maybe this one is defective

author: DavidAlfa
author_rank: Super Contributor
timestamp: August 21, 2023, 05:49:30 pm
content: I tried 3 chips, all had the same behaviour.So I tried moving the interrupt vector table to the SRAM as @bingo600 suggested.The issue is gone! Working now!Created a PR atIOSetting's repo.However this is not optimal, anyone could dump the flash by overwriting the sram, for example placing custom code in the systick ISR or changing the vector addresses.After that, you can place up to 4KB of code... you can do anything with so many space!

author: bingo600
author_rank: Super Contributor
timestamp: August 21, 2023, 06:52:18 pm
content: Longshot ... but it worked out@DavidThank you for the PR/Bingo

author: DavidAlfa
author_rank: Super Contributor
timestamp: August 21, 2023, 06:56:26 pm
content: Yeah but it's not ok... leaves the system poorly protected!

author: bingo600
author_rank: Super Contributor
timestamp: August 21, 2023, 07:09:00 pm
content: Quote from: DavidAlfa on August 21, 2023, 05:49:30 pmCan you (a debugger) still write to the ram if it's protected , or do you mean "buffer overflow" attack ??

author: DavidAlfa
author_rank: Super Contributor
timestamp: August 21, 2023, 08:04:27 pm
content: Yeah, a debugger has complete access to the ram.Systick vector is now placed at 0x2000003C:You could halt the system, load a program into 0x20001000, made to dump the flash through the serial port, and write that address to systick vector.When the IRQ triggers, game over!At least I can mitigate this by disabling SWD port and setting the nRST config bit.The reset pin function becoems completely disabled, even when shorting the reset pin before power is applied, it no longer works.Then I have a special unlock procedure in the code that resets the RDP, this completely erases the mcu so it can be accesed again.nBOOT1 config bit switches between bootloader mode ad system ram booting. Not sure what would be the safest!Let me guess.. Burn the pin down!

author: prosper
author_rank: Regular Contributor
timestamp: August 22, 2023, 06:23:53 pm
content: I don't understand the vulnerability. If you have debug, can't you *already* modify SRAM, and then point the program counter wherever you want to execute arbitrary code?

author: DavidAlfa
author_rank: Super Contributor
timestamp: August 22, 2023, 07:11:36 pm
content: I guess you could also write to VTOR with the debugger, yeah!Well, if possible at all, nRST=OFF, BOR=ON, SWD=OFF and BOOT1=OFF should give plenty of headaches to the attackers.

author: DavidAlfa
author_rank: Super Contributor
timestamp: August 24, 2023, 06:12:44 pm
content: So these are are my locking / unlocking routines:Code:// Call with lock=1 to set RDP1, also disabling RESET pin and bootloader// Call with lock=0 to disable, though if already locked it will erase everything, nothing can be done about it.void rdp_set(bool lock){FLASH_OBProgramInitTypeDef pOBInit;LL_FLASH_OBGetConfig(&pOBInit);bool lock_state = (pOBInit.RDPLevel == OB_RDP_LEVEL_1);if(lock_state != lock) // current state not same as requested{pOBInit.OptionType = OPTIONBYTE_RDP | OPTIONBYTE_USER; // Update user and RDP bitspOBInit.RDPLevel = lock ? OB_RDP_LEVEL_1 : OB_RDP_LEVEL_0; // Set RDP modeif(lock){pOBInit.USERConfig = OB_RESET_MODE_GPIO | \ // Disable Reset function, enable BOROB_BOR_ENABLE | OB_BOR_LEVEL_3p1_3p2 | \ // Enable BOR to 3.2VOB_IWDG_SW | OB_WWDG_SW | \ // Disable HW watchdog enforcementOB_BOOT1_SRAM; // When BOOT1=SRAM, BOOT0=1 boots from SRAM instead the bootloader}else{pOBInit.USERConfig = OB_RESET_MODE_RESET | \ // Disable Reset function, enable BOROB_BOR_DISABLE | OB_BOR_LEVEL_3p1_3p2 | \ // Disable BOR, set default levelOB_IWDG_SW | OB_WWDG_SW | \ // Disable HW watchdog enforcementOB_BOOT1_SYSTEM; // When BOOT1=SYSTEM, BOOT0=1 boots the bootloader}LL_FLASH_Unlock(); // Unlock FlashLL_FLASH_OB_Unlock(); // Unlock OBLL_FLASH_OBProgram(&pOBInit); // Program config. Going RDP1->RDP0 instantly wipes the entire system, but still need a cycling the power to reload the RDP config.LL_FLASH_OB_Launch(); // Force OB reload (This normally restarts the system)NVIC_SystemReset(); // Just in case}}

author: DavidAlfa
author_rank: Super Contributor
timestamp: August 24, 2023, 07:35:37 pm
content: Bingo600, as you asked in PM, here's a very simple example showing how to lock and unlock RDP.PB0 = button to GND.PB1 = RED led ( To indicate lock)PB3 = GREEN led (Activity and unlocked indicator)LEDS are active low - Connect between VCC and the mcu pin through a 470R-1K resistor.Simply flash it - RED will be steady on, GREEN blinking as "I'm alive".Press button - GREEN will be steady on, RED off. MCU will be wiped, cycle power to update RDP security, Jlink will be able to program it again.Just in case, I'm only setting RDP1 in this test, not disabling nRST or BOOT0, at $0.11 it's cheap but better to not brick any! (I'm using the "full" mode myself, works perfect).

author: bingo600
author_rank: Super Contributor
timestamp: August 24, 2023, 08:11:23 pm
content: Thanx DavidI'll see if i can do a test in the weekend.What pin should i apply the 9KHz signal to ??Ahh .. This guy doesn't seem to have the timer stuff ...Well i'll give it a shot this weekend ...I'll have to setup Cube .... According to your instructions...I'm (ATM) more of a "makefile guy"Do you use "just" CubeMX , or also CubeIDE ?I don't even think i have CubeIDE downloaded./Bingo

author: DavidAlfa
author_rank: Super Contributor
timestamp: August 24, 2023, 08:37:28 pm
content: I use the IDE as only that - IDE.Provides editor, compiler and debugger all in one - that's why I patched it.CubeMX is for ST products, I don't have interest in it, the M0+ is pretty easy to setup using low level libs, that's what I use.Yeah sorry I forgot! Will make it tomorrow.For now just test that the unlocking works, it should!It's not speed dependand, I crashed it with only few Hz, 100Hz would do it very quick.Seems something related to the capture edge happening at precise wrong moment.Normally this would read a IR signal with NEC protocol, the fastest pulse is 500-600us, this would crash it in the first remote button press (Doing fine now).But as I say just anything at CCP crashed it with RDP set.Maybe a sync bug, I don't know.Anyways, it's fine now!

author: bingo600
author_rank: Super Contributor
timestamp: August 25, 2023, 12:01:09 pm
content: WellI'm postponing the 1GBCubeIDE install for now ....I "whipped up" a makefile instead ...Btw .. It expect the "Arm GCC bin" directory to be on the pathI also included the BIN & HEX it created ... Mine is 2.4K with -oSMade by : gcc-arm-none-eabi-8-2018-q4-majorCode:LDBuild/main.elfMemory region Used Size Region Size %age UsedRAM: 336 B 4 KB 8.20%FLASH: 2360 B 32 KB 7.20%RDP: 0 GB 4 B 0.00%OBJCP BINBuild/main.binOBJCP HEXBuild/main.hexmade by : arm-gnu-toolchain-12.3.rel1-x86_64-arm-none-eabiCode:LDBuild/main.elf/home/cfo/arm/arm-gcc/arm-gnu-toolchain-12.3.rel1-x86_64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/12.3.1/../../../../arm-none-eabi/bin/ld: warning: Build/main.elf has a LOAD segment with RWX permissionsMemory region Used Size Region Size %age UsedRAM: 336 B 4 KB 8.20%FLASH: 2420 B 32 KB 7.39%RDP: 0 GB 4 B 0.00%OBJCP BINBuild/main.binOBJCP HEXBuild/main.hexI would have expected 12 to produce less code than 8q4Well ...Made by: arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabiCode:LDBuild/main.elfMemory region Used Size Region Size %age UsedRAM: 336 B 4 KB 8.20%FLASH: 2408 B 32 KB 7.35%RDP: 0 GB 4 B 0.00%OBJCP BINBuild/main.binOBJCP HEXBuild/main.hexMade by: gcc-arm-none-eabi-10-2020-q4-majorCode:LDBuild/main.elfMemory region Used Size Region Size %age UsedRAM: 336 B 4 KB 8.20%FLASH: 2336 B 32 KB 7.13%RDP: 0 GB 4 B 0.00%OBJCP BINBuild/main.binOBJCP HEXBuild/main.hexMade by: gcc-arm-none-eabi-9-2019-q4-majorCode:LDBuild/main.elfMemory region Used Size Region Size %age UsedRAM: 336 B 4 KB 8.20%FLASH: 2344 B 32 KB 7.15%RDP: 0 GB 4 B 0.00%OBJCP BINBuild/main.binOBJCP HEXBuild/main.hex/Bingo

author: DavidAlfa
author_rank: Super Contributor
timestamp: August 25, 2023, 01:34:43 pm
content: Ahh 1GB.. it's 2023 not 1999!Yeah yu don't really need the IDE for anything, but you'll have to write the makefile then, I prefer it to be done automatically

author: bingo600
author_rank: Super Contributor
timestamp: August 25, 2023, 01:55:52 pm
content: Quote from: DavidAlfa on August 25, 2023, 01:34:43 pmI even think CubeIDE can export a Makefile orBtw: I'm quite sure the STM Doc said i needed 15G disk.I might install it anyways ... Later ...

author: DavidAlfa
author_rank: Super Contributor
timestamp: August 25, 2023, 09:59:30 pm
content: So here's the CCP test.I attached two versions of the binary, one placing irq vectors in flash, other placing them in sram (Which should never fail).Usage is pretty simple:- Any falling edge at CCP pin pulses the green led for 1-2ms (Not precise as CCP input it's not synced with systick).- If there's no CCP activity for >1 second, the green led starts pulsing at 1Hz pulse to show it's alive.- Pressing the button will toggle RDP, blinking the red led if setting RDP1 or the green led for RDP0.- It'll keep blinking until you release the button + 1 second.- Doing RDP1->RDP0 wipes the system, needs power cycling to update the RDP security.- The red led turns ON if RDP1 is set.With FLASH vectors and RDP1, at some point you'll notice the system completely dies when toggling the CCP input.For your PY32F003 chips: Use the same pin names (PA1, PA5, PB0, PB1), not the pin numbers!

author: bingo600
author_rank: Super Contributor
timestamp: August 26, 2023, 04:30:12 am
content: Thanx DavidWill solder a PY32F003F18P6TU on a breakout board today.And might solder a PY32F002AW15S6TU on a board too (SOP-16 should be "easy")Just for fun i added some arm-gcc compile results of the RDP program to the post above.I am now using the arm-gcc 10 , as the default. What version do yo use ??This is what gcc-arm-none-eabi-10-2020-q4-major results in with the CCP programCode:LDBuild/main.elfMemory region Used Size Region Size %age UsedRAM: 208 B 4 KB 5.08%FLASH: 2764 B 32640 B 8.47%SETTINGS: 0 GB 128 B 0.00%OBJCP BINBuild/main.binOBJCP HEXBuild/main.hex/Bingo

author: DavidAlfa
author_rank: Super Contributor
timestamp: August 26, 2023, 04:55:23 am
content: ST's GCC version is a bit more optimized, I always had slighly lower usage with it.The good part is you can call it externally just like any other gcc compiler.

author: bingo600
author_rank: Super Contributor
timestamp: August 26, 2023, 05:42:22 am
content: Oh ...I have modified both examples RDP + CCP to use PA7 for BTN , and PB0 for Red / PB1 for Green.My PY32F002AW15S6TU (SOP16) doesn't have PA5, and if you'd not commected out the "lock code" my SOP16 MCU would have been locked forever.RDPCode://Buttons#define BTN_Port GPIOA#define BTN_Pin LL_GPIO_PIN_7// LEDs#define RED_Port GPIOB#define RED_Pin LL_GPIO_PIN_0#define GREEN_Port GPIOB#define GREEN_Pin LL_GPIO_PIN_1CCPCode:// CCP pin#define CCP_Port GPIOA#define CCP_Pin LL_GPIO_PIN_1#define CCP_AF LL_GPIO_AF13_TIM1#define CCP_TIM TIM1#define CCP_CH LL_TIM_CHANNEL_CH4// Buttons#define BTN_Port GPIOA#define BTN_Pin LL_GPIO_PIN_7// LEDs#define RED_Port GPIOB#define RED_Pin LL_GPIO_PIN_0#define GREEN_Port GPIOB#define GREEN_Pin LL_GPIO_PIN_1// SWD interface#define SWC_Port GPIOA#define SWC_Pin LL_GPIO_PIN_14#define SWD_Port GPIOA#define SWD_Pin LL_GPIO_PIN_13/Bingo

author: bingo600
author_rank: Super Contributor
timestamp: August 26, 2023, 08:20:43 am
content: I just tried the RDP on a PY32F002AW15S6TU (SOP-16)Changed leds to active high.It given an error during programming (pyOCD - DAP)Code:$ make flashpyocd erase -t py32f030x6 --chip --config ./Misc/pyocd.yaml0000872 I Erasing chip... 0001113 I Chip erase complete pyocd load ./Build/main.hex -t py32f030x6 --config ./Misc/pyocd.yaml0000874 I Loading /home/cfo/1-Arm/py32f0/git/David/PY32F030_test-cfo/Build/main.hex [==================================================] 100%0002048 I Erased 4096 bytes (1 sector), programmed 2432 bytes (19 pages), skipped 0 bytes (0 pages) at 2.03 kB/s 0002058 E Error during board uninit: But i suppose it's okunint prob involve Reset , that has just been deactivated ....Hmm RDP just sets RDP (Flas lock) ...My "Dual led" toggles between RED & Orange (Orange = Red + Green)When i GND PA7 , LED gets GreenOhh ... And i have to Power reset to get swd to work againWell ... I didn't have DAP reset connected , so the programmer couldn't reset it.Connected DAP Reset to MCUCode:$ make flashpyocd erase -t py32f030x6 --chip --config ./Misc/pyocd.yaml0000806 I Erasing chip... 0001051 I Chip erase complete pyocd load ./Build/main.hex -t py32f030x6 --config ./Misc/pyocd.yaml0000824 I Loading /home/cfo/1-Arm/py32f0/git/David/PY32F030_test-cfo/Build/main.hex [==================================================] 100%0001969 I Erased 4096 bytes (1 sector), programmed 2432 bytes (19 pages), skipped 0 bytes (0 pages) at 2.09 kB/s 0001975 E Error during board uninit: 0001977 E Probe error during disconnect: Now 2 errors during programmingStill can't program (after PA7 Clear of RDP)Code:$ make flashpyocd erase -t py32f002ax5 --chip --config ./Misc/pyocd.yaml0000843 I Erasing chip... 0001076 C target was not halted as expected after calling flash algorithm routine (IPSR=3) POR Reset works./Bingo

author: bingo600
author_rank: Super Contributor
timestamp: August 26, 2023, 08:48:45 am
content: I just tried the CCP on a PY32F002AW15S6TU (SOP-16)Wo. any external pulse , it blinks briefly green (continuously).That one behaves a bit strange , when PA7 is GND'edWhen i GND PA7 it blinks RED Continuously.When i remove PA7 (GND) , it lights mostly RED , short pulses of green (i think)I can't erase ....If i connect PA7 again , it blinks green , when i remove PA7 , it lights steady green.I can erase program chip.Seems like it needs to times PA7 to GNDYepp ... 2 x PA7 GND works (permanent Green) , and unlocks.I can erase/reflash.Program CCP - POR Reset (No external pulse) (flow)Green constantly blinks briefly.PA7 GND , Red blinks , then becomes "almost steady" , short green blinks alco i thinkAnother PA7 GND , it blinks Green , and then steady Green.After POR i can reflash.Edit: Remember i have nothing connected to CCP pin .... Maybe it sees some noise (the brief green pulses)/Bingo

author: bingo600
author_rank: Super Contributor
timestamp: August 26, 2023, 09:09:10 am
content: Now to whip up a 9KHz signal ..... Using my other py32F002 (TSSOP20) board.I'll have to do a bit of DS studying ....

author: DavidAlfa
author_rank: Super Contributor
timestamp: August 26, 2023, 12:54:59 pm
content: 100Hz is enough! Or a simple push button, it'll crash really easily.It's not behaving strangely, that's how it's supposed to work.Activate the button (PA7), sets rdp1, reboots and turns the red led on.Now you can't erase as it seems the device pack programming algorithm is bugged.This didn't happen in the HKL32F030M, I clearly got a warning about it, advicing to erase the device.Activate the button again and rdp1 is cleared, wiping the system and enabling the green led.Same about the green led behaviour.Have you read anything where I posted the test?About PyOCD, I can't help. I tried using it but cmsis pack didn't work nor it was found anywhere, though it was clearly installed.Attached same fw with button in PA7, both flash and sram vectors versions.

author: DavidAlfa
author_rank: Super Contributor
timestamp: August 26, 2023, 01:40:23 pm
content: Gotta love chinese stuff.I disassembled the FLM in ghidra, look at the blank checking function!- Is it blank?- Looks at the sky while puffing on a cigar - Sure bro!

author: bingo600
author_rank: Super Contributor
timestamp: August 26, 2023, 02:14:01 pm
content: I did do a "quick read" of your description of the CCP test program.But apparently not close enough.What i described was my experience , in no way any critisism.Re: poOCD ... You need to put the pyocd yaml in the "main directory" , or use the --pack to point at the packThe pack is in IOsettings Misc dir , so is the yaml fileUse 'pyocd list --targets' to see available targets.Code:pyocd list --targets --pack Misc/Puya.PY32F0xx_DFP.1.1.3.pack | grep -i py32py32f002ax5 Puya PY32F002Ax5 PY32F0 Series, PY32F002 packpy32f002x5 Puya PY32F002x5 PY32F0 Series, PY32F002 packpy32f003x4 Puya PY32F003x4 PY32F0 Series, PY32F003 packpy32f003x6 Puya PY32F003x6 PY32F0 Series, PY32F003 packpy32f003x8 Puya PY32F003x8 PY32F0 Series, PY32F003 packpy32f030x3 Puya PY32F030x3 PY32F0 Series, PY32F030 packpy32f030x4 Puya PY32F030x4 PY32F0 Series, PY32F030 packpy32f030x6 Puya PY32F030x6 PY32F0 Series, PY32F030 packpy32f030x7 Puya PY32F030x7 PY32F0 Series, PY32F030 packpy32f030x8 Puya PY32F030x8 PY32F0 Series, PY32F030 packpy32f072xb Puya PY32F072xB PY32F0 Series, PY32F072 packStill working on modifying your CCP program from input capture to output compare w. pin toggle - 9KHz - Thats my learning task for now .... As mentioned i'm quite green with ARM ie. STM/PY.I have never used AF pins before , and have quite some issue figuring out why you did select : LL_GPIO_AF_13And not ie. LL_GPIO_AF_1.Is the AF just a "Pin rerouting Matrix" , where you could have chosen any that has tim1 in the name ??#define LL_GPIO_AF2_TIM1 LL_GPIO_AF_2 /*!< TIM1 Alternate Function mapping */I don't understand the logic , and the PY RM has a Matric that doesn't help (me) much.Re: Black checkI suppose FLM = Flash loader module.Is that in the chip or some of the bin (elf) used for Jlink or ?/Bingo

author: DavidAlfa
author_rank: Super Contributor
timestamp: August 26, 2023, 02:28:56 pm
content: The AF pins are better described in the Datasheet.You have a simple table showing how each AF source connects the physical pins to the different peripherals.AF13 connects PA1 to TIM1_CH4.AF1 would connect it to USART1_CTS!LL_GPIO_AF13 and LL_GPIO_AF_13_TIM1 is the same thing, it's just a way for you to easily see wat are you interfacing to.Does LL_GPIO_AF2 say anything to you? Not to me! I'd need to open the datasheet and look it out.LL_GPIO_AF_13_TIM1 makes it a bit easier. I would even have used LL_GPIO_AF_13_TIM1_CH4.

author: bingo600
author_rank: Super Contributor
timestamp: August 26, 2023, 02:58:52 pm
content: Thanx for the hint with the AF in the DS.Btw do you exclusively look at the F030 documentation for the F002 ?Re DAPLINKI use an Air32F103 with both the (top/bottom) 5 Pins soldered at the end. ... Think you have some of themUse V1 hexfile... V2 doesn't workhttps://www.eevblog.com/forum/microcontrollers/air105-air32f103-new-chinese-arm-chips/msg5014411/#msg5014411Quote/Bingo

author: DavidAlfa
author_rank: Super Contributor
timestamp: August 26, 2023, 03:34:34 pm
content: Yeah I normally use the 030 docs. The 002 and 003 docs have the same thing, just cutting down some features.I do check the "official" specs in case something doesn't work, like in this RDP problem, I removed all non officlal 002A features to make sure it wasn't my fault for using them, but surprise, no change!

author: bingo600
author_rank: Super Contributor
timestamp: August 26, 2023, 06:02:25 pm
content: I got something kludged together to generate ~9KHz pulses on PA1Used your CCP as baseCode:/*--------------------------------------------------*/void system_init(void){LL_RCC_HSI_SetCalibFreq(LL_RCC_HSICALIBRATION_24MHz);while (LL_RCC_HSI_IsReady() != 1);LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA | LL_IOP_GRP1_PERIPH_GPIOB | LL_IOP_GRP1_PERIPH_GPIOF);LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_TIM1);// LL_GPIO_Init(SWC_Port, &(LL_GPIO_InitTypeDef){ SWC_Pin, LL_GPIO_MODE_ANALOG }); // Disable SWD interface access// LL_GPIO_Init( SWD_Port, &(LL_GPIO_InitTypeDef){ SWD_Pin, LL_GPIO_MODE_ANALOG });LL_GPIO_Init(CCP_Port, &(LL_GPIO_InitTypeDef){ CCP_Pin, LL_GPIO_MODE_ALTERNATE, LL_GPIO_SPEED_FREQ_VERY_HIGH, LL_GPIO_OUTPUT_PUSHPULL, LL_GPIO_PULL_NO, CCP_AF });LL_GPIO_Init(RED_Port, &(LL_GPIO_InitTypeDef){ RED_Pin, LL_GPIO_MODE_OUTPUT, LL_GPIO_SPEED_FREQ_VERY_HIGH, LL_GPIO_OUTPUT_PUSHPULL, LL_GPIO_PULL_NO });LL_GPIO_Init(GREEN_Port, &(LL_GPIO_InitTypeDef){ GREEN_Pin, LL_GPIO_MODE_OUTPUT, LL_GPIO_SPEED_FREQ_VERY_HIGH, LL_GPIO_OUTPUT_PUSHPULL, LL_GPIO_PULL_NO });LL_GPIO_Init(BTN_Port, &(LL_GPIO_InitTypeDef){ BTN_Pin, LL_GPIO_MODE_INPUT, 0, 0, LL_GPIO_PULL_UP });//https://community.st.com/t5/stm32-mcu-products/setting-the-timer-tim1-in-stm32f407/td-p/395256//LL_TIM_Init(CCP_TIM, &(LL_TIM_InitTypeDef){ 23, LL_TIM_COUNTERDIRECTION_UP, 65535, LL_TIM_CLOCKDIVISION_DIV1, 0}); // 1MHz clock, 65ms overflowLL_TIM_Init(CCP_TIM, &(LL_TIM_InitTypeDef){ 11, LL_TIM_COUNTERDIRECTION_UP, 111, LL_TIM_CLOCKDIVISION_DIV1, 0}); // 1MHz clock, 65ms overflow//LL_TIM_IC_Init(CCP_TIM, CCP_CH, &(LL_TIM_IC_InitTypeDef){ LL_TIM_IC_POLARITY_FALLING, LL_TIM_ACTIVEINPUT_DIRECTTI, LL_TIM_ICPSC_DIV1, 4 }); // Falling edgeLL_TIM_OC_Init(CCP_TIM, CCP_CH, &(LL_TIM_OC_InitTypeDef){ LL_TIM_OCMODE_TOGGLE, LL_TIM_OCSTATE_ENABLE, LL_TIM_OCSTATE_ENABLE, 111,LL_TIM_OCPOLARITY_HIGH, LL_TIM_OCPOLARITY_HIGH, LL_TIM_OCIDLESTATE_LOW, LL_TIM_OCIDLESTATE_LOW }); // Falling edge// Generates 8.97 KHz pulsesLL_TIM_EnableCounter(CCP_TIM);LL_TIM_CC_EnableChannel(CCP_TIM, CCP_CH);LL_TIM_EnableAllOutputs(CCP_TIM);NVIC_SetPriority(TIM1_CC_IRQn, 1);//NVIC_EnableIRQ(TIM1_CC_IRQn);SysTick_Config(24000); // 24MHz cpu clock, 1ms period.}But it seems like it's the below LL_TIM_Init that controls the Pulse duration24M/12/111 ~18KHz ==> 9KHz ToggledCode:LL_TIM_Init(CCP_TIM, &(LL_TIM_InitTypeDef){ 11, LL_TIM_COUNTERDIRECTION_UP, 111, LL_TIM_CLOCKDIVISION_DIV1, 0}); // 1MHz clock, 65ms overflowWhar does the 111 in this one (LL_TIM_OC_Init) do then ?Code:LL_TIM_OC_Init(CCP_TIM, CCP_CH, &(LL_TIM_OC_InitTypeDef){ LL_TIM_OCMODE_TOGGLE, LL_TIM_OCSTATE_ENABLE, LL_TIM_OCSTATE_ENABLE, 111,LL_TIM_OCPOLARITY_HIGH, LL_TIM_OCPOLARITY_HIGH, LL_TIM_OCIDLESTATE_LOW, LL_TIM_OCIDLESTATE_LOW }); // Falling edgeI would have expected that one :Code:uint32_t CompareValue; /*!< Specifies the Compare value to be loaded into the Capture Compare Register.This parameter can be a number between Min_Data=0x0000 and Max_Data=0xFFFF.To control the "compare" ...Will try tomorrow, with the 9KHz from my F002 dev board as pulse source.Ps:Thank you for your examples & guidance/Bingo

author: DavidAlfa
author_rank: Super Contributor
timestamp: August 26, 2023, 06:18:19 pm
content: What are you taking about? CCP doesn't generate pulses, it captures edges and triggers an interrupt.You're using in your own way (OCP) for no reason, beyond the scope of this issue.Please don't do that. If we're talking about apples don't come saying you got orangesOCP is triggered internally, won't cause any issue. The issue with CCP seems caused by external, unsynced signal.That's not what I wrote! First 11 is the prescaler, timer freq. is 24MHz/(prescaler+1). The second is the overflow value, so the timer resets at timer freq / (overflow+1).Quote from: bingo600 on August 26, 2023, 06:02:25 pmIn that example you made: 24MHz/(11+1) = 2MHz clock, timer overflows at 2MHz/(111+1) = 17.857KHz.Quote from: bingo600 on August 26, 2023, 06:02:25 pmIt's the CompareValue:QuoteWhat are you tring to do? Why the fixation of generating 9KHz for no reason?Quote from: DavidAlfa on August 26, 2023, 12:54:59 pm

author: bingo600
author_rank: Super Contributor
timestamp: August 26, 2023, 06:31:33 pm
content: I'm talking about my need for generate pulses for the capture port on the PY32 running your CCP program.So i modified your CCP program a bit to do OCP instead of ICP, for the PY32 i use as pulse generator.I'm not going to modify your CCP program on the DUT, just use it as base for a pulse generator for pulsing the DUT.

author: DavidAlfa
author_rank: Super Contributor
timestamp: August 26, 2023, 06:43:40 pm
content: Just use a simple push button LOL, I will repeat again, no need for any KHz signal.Connect a button, press it few times, it will crash after few presses if RDP is set.

author: bingo600
author_rank: Super Contributor
timestamp: August 26, 2023, 06:54:42 pm
content: I'm not sure where i got the 9KHz fromBut as i'm also using this as a PY32/STM + pyOCD/DAP-Programmer learningproject, i wanted to try OCP as pulse source.I'll modify the pulse source to 200Hz

author: DavidAlfa
author_rank: Super Contributor
timestamp: August 26, 2023, 07:23:10 pm
content: This will easily generate the signal you're asking for in PA1:Code:#define PERIOD_US 10000 // 10ms PWM signal (100Hz). Will work with any value between 2 and 65535int main(void){LL_RCC_HSI_Enable();LL_RCC_HSI_SetCalibFreq(LL_RCC_HSICALIBRATION_24MHz);while (LL_RCC_HSI_IsReady() != 1);LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA | LL_IOP_GRP1_PERIPH_GPIOB | LL_IOP_GRP1_PERIPH_GPIOF);LL_APB1_GRP2_EnableClock( LL_APB1_GRP2_PERIPH_TIM1);LL_GPIO_Init(GPIOA, &(LL_GPIO_InitTypeDef){ LL_GPIO_PIN_1, LL_GPIO_MODE_ALTERNATE, LL_GPIO_SPEED_FREQ_VERY_HIGH, LL_GPIO_OUTPUT_PUSHPULL, LL_GPIO_PULL_NO, LL_GPIO_AF13_TIM1 });LL_TIM_Init(TIM1, &(LL_TIM_InitTypeDef){ 23, LL_TIM_COUNTERDIRECTION_UP, PERIOD_US-1, LL_TIM_CLOCKDIVISION_DIV1, 0}); // 1MHz input clockLL_TIM_OC_Init(TIM1, LL_TIM_CHANNEL_CH4, &(LL_TIM_OC_InitTypeDef){ LL_TIM_OCMODE_PWM1, LL_TIM_OCSTATE_ENABLE, LL_TIM_OCSTATE_DISABLE, 0,LL_TIM_OCPOLARITY_HIGH, LL_TIM_OCPOLARITY_HIGH, LL_TIM_OCIDLESTATE_LOW, LL_TIM_OCIDLESTATE_LOW });LL_TIM_OC_SetCompareCH4(TIM1, PERIOD_US/2);LL_TIM_EnableCounter(TIM1);LL_TIM_EnableAllOutputs(TIM1);while (1){}}

author: bingo600
author_rank: Super Contributor
timestamp: August 27, 2023, 06:04:45 am
content: Quote from: DavidAlfa on August 26, 2023, 07:23:10 pmThanx DavidI just checkked w. a scope , and yep ... 100Hz 50% duty.One question though ...Why : LL_TIM_OCMODE_PWM1 , and not LL_TIM_OCMODE_TOGGLE ?I'm now going to read your description of the CCP program again , and do the tests on the F002 (SOP-16) , and later on the F003.Should i recompile for the F003 using your CCP sources , or just use your PA7 binary for both ??/Bingo

author: bingo600
author_rank: Super Contributor
timestamp: August 27, 2023, 06:44:29 am
content: Testing my own compile of the CCP (No source touched , besides setting PA7 as button pin)That didn't take long of the F002 SOP-16, w. the 100Hz pulses.1: Turn on DUT w 100Hz pulses activeLED is constantly green (pulses received)2: GND PA7 to enable RDP , RED blinksThen LED is constantly orange (Red + Green) ... For a few seconds , and then turns Red.Maybe 2..3 sec.I tried again after a POR , maybe 3..4 sec this timeAnd a 3'rd POR , this time it lasted 10+ seconds.Had to remove the 100Hz pulses, in order to reliably GND PA7 for RDP unlockNow testing with your build : symlinked it to main.bin -> PY32F030_CCP_test_VECT_FLASH_PA7.bin , to use the "make flash"Behaves the same as above .....Trying the VECT_SRAM now w 100Hz pulsesLooking goodAfter 7 minutes , the led is still "Orange" (Red + Green)So the PY32F002AW15S6TU (SOP-16) has the same "quirk" as the PY32F002AF15P6TU (SSOP-20)Now on to the PY32F003F18P6TU (SSOP-20)/Bingo

author: bingo600
author_rank: Super Contributor
timestamp: August 27, 2023, 07:44:43 am
content: Now testing w. the : PY32F003F18P6TUStill building for a F030 , and the pyOCD (DAP) device is still : PYOCD_DEVICE ?= py32f002ax5 ... Wonder if i should change that to a py32f003x8 - Does the 64K x8 use different flash pages ?I'll have to use my own build of the CCP program , as the F003 is rather "skimpy" on PortB pins , and doesn't have PB0/PB1 for the leds.I have chosen to use PA2 (Red) / PA3 (Green) , and still use PA1 for Capture & PA7 for "Button"Just ran a simple "blinky" on the F003 w PA2/PA3 working as expected.Hmmm ....Loaded my CCP (Only led pins changed) - I expect it to be VECT_FLASH per default , as i haven't uncommentedCode:/************************* Miscellaneous Configuration ************************//*!< Uncomment the following line if you need to relocate your vector Table inInternal SRAM. *///#define VECT_TAB_SRAM#define VECT_TAB_OFFSET 0x00 /*!< Vector Table base offset field.This value must be a multiple of 0x100. */1: Programmed & started w. 100Hz connected to PA1Led was constant green2: Connected PA7 to GNDRED blinking + the permanently RED3: Did a POR of the F003 - 100Hz still connectedLED Constaly "Orange" after 10+ minutes.Seems like it's "Hardfaulting" when RDP is set ,but after a POR it seems to run wo any issues.Nope ... Now it doesn't react to PA7 , and LED still "Orange after" 100KHz signal is removed.Had to connect PA7 to GND before POR , in order to get it to not "hardfault" immediately , now i could reset the RDP by toggling PA7Will build SRAM version & testSRAM vers build (from linker map)Code:.ram_vector 0x0000000020000000 0xc0*(.ram_vector).ram_vector 0x0000000020000000 0xc0 ./Build/Driver/CMSIS/Device/PY32F0xx/Source/system_py32f0xx.oSeems like SRAM works ...Modified hardfault , to turn green offCode:/*** @brief This function handles Hard fault interrupt.*/void HardFault_Handler(void){WritePin(GREEN,0); // Set led OFFwhile (1){for(volatile uint32_t i=0;i<50000;i++);TogglePin(RED);}}And tried FLASH Vectors again ...Took very short time before led was RED.Trying SRAM again w RDP.Seems to work fine , i'll let it run for 10+ minutesAfter 17minutes , still going strong , and responding to PA7.So the F003 has the same issue as the F002And the workaround is the same ... To move Vectors to SRAM/Bingo

author: bingo600
author_rank: Super Contributor
timestamp: August 27, 2023, 08:51:17 am
content: @DavidBtw:Did you see that SDK protection stuff in F002 RM , or F030 RM (pg. 37)It mentions something about Read protection with RDP = 0I'm not sure i understand it fully right now ...But it seems like one can protect the memory in 2K pages/Bingo

author: DavidAlfa
author_rank: Super Contributor
timestamp: August 27, 2023, 08:59:43 am
content: Just as I thought, thanks for testing!Why pwm instead ocp? Because I already had some code made that way!The final result would be almost the same, just toggling the output on each overflow instead at the middle.But PWM adds more flexibility, allowing variable duty cycle.I updated the fix atIOsetting's repo.Should be a pretty solid patch now.Yeah I read the SDK thing. It's disabled by default:Code:Production value: 0xFF0000FF28:24 Complemented SDK_END[4:0]20:16 Complemented SDK_STRT[4:0]12:8 SDK_END[4:0] SDK area end address, each corresponding STEP is 2 kbytes4:0 SDK_STRT[4:0] SDK area start address, each corresponding STEP is 2 kbytesQuoteBut the default values (0x00FF) will do: SDKR_END = 0x00, SDKR_STRT = 0x1FThus SDK protection is disabled:Quote

author: bingo600
author_rank: Super Contributor
timestamp: August 27, 2023, 12:22:30 pm
content: Quote from: DavidAlfa on August 27, 2023, 08:59:43 amThnxEven tough i liked the vectors in flash as default ... When not using RDPWell i can just define the : FORBID_VECT_TAB_MIGRATION - If no RDP is neededQuote from: DavidAlfa on August 27, 2023, 08:59:43 amI was "brainstorming internally"If it was possible to protect the code via SDK bits , and then not needing the RDP.But i could easily have misunderstood something here ... It just seemed that Debugger reads would be disabled on a SDK protected page , even if RDP was 0/Bingo

author: DavidAlfa
author_rank: Super Contributor
timestamp: August 27, 2023, 01:09:42 pm
content: Quote from: bingo600 on August 27, 2023, 12:22:30 pmYeah but the code has no way of knowing if you're setting RDP or not.So I think using SRAM vectors by default is better, otherwise anyone setting RDP may get a nasty surprise, squeezing his brain thinking it's a code problem.... Until many hours later, he might find this issue.Uses 192 bytes, 6% of system RAM, not terrible, and remember you have +1KB for free so it would actually be 4.7%.Setting flash vectors back is plain easy by adding that flag in the makefile or insystem_py32f0xx.c.Quote from: bingo600 on August 27, 2023, 12:22:30 pmSomething like this? Subtitles : "How does this SDK thing work?" in polite Danish.

author: bingo600
author_rank: Super Contributor
timestamp: August 27, 2023, 02:51:13 pm
content: A bit more calm, than the YT guy ..Sport coaches & Chef's apparently think they get "Better performance" if they yell ...Btw: Just cloned your repos, to get the Vector stuff/Bingo

author: DavidAlfa
author_rank: Super Contributor
timestamp: August 28, 2023, 03:54:07 pm
content: It's merged now, so I'll be deleting mine!

author: yjmwxwx
author_rank: Newbie
timestamp: August 29, 2023, 02:27:25 am
content: Battery Internal Resistance Tester PY32F002AF15P6TU48MHZ，DMA，PLLhttps://hackaday.io/project/192563-py32f002a-mcu-battery-internal-resistance-testercommon-positive digital tube (electronics)

author: yjmwxwx
author_rank: Newbie
timestamp: August 29, 2023, 02:43:12 am
content: I'm using JLINK OB.Copy Devices to the JLINK installation directory and copy the contents of py32.xml to JLinkDevices.xml.

author: true
author_rank: Frequent Contributor
timestamp: September 01, 2023, 05:32:30 am
content: First, I currently have PY32F002A programming and debugging successfully with a CMSIS-DAP debugger in VSCode with PlatformIO. This is without any custom platform, and no framework - basically a bare metal project. It uses pyOCD but the dependency is managed by PlatformIO. It's pretty much just load and go. No hacks are needed.The only problem I am having right now is the peripheral register window not working correctly while debugging. Basically, neither reading nor writing values works. I can use pyOCD to read peripheral registers manually and that works, but the peripheral pane just isn't working. Don't know if it's a new platformio bug or not - someone else has a similar issue with an STM32 part and the issue is very recent.Second, PUYA released PY32F002Bparts. They have slightly different specifications vs 002A, such as 24K flash. The chinese version of the website has a newer datasheet/code download than the english site with 002B code, but no datasheets or reference manual. The datasheet is available on LCSC but is Chinese-only. I would imagine these are actually less capable / smaller die parts. Who knows if the 002A parts will dry up?

author: DavidAlfa
author_rank: Super Contributor
timestamp: September 01, 2023, 06:03:00 am
content: Are you modifying these registers halting the core first, right ?

author: bingo600
author_rank: Super Contributor
timestamp: September 01, 2023, 01:08:26 pm
content: Quote from: true on September 01, 2023, 05:32:30 amI'm out .....I won't touch platformIO .. Even with a 10 feet pole.I really don't like the concept/Bingo

author: DavidAlfa
author_rank: Super Contributor
timestamp: September 01, 2023, 02:58:18 pm
content: Neither I. Really, try CubeiDE + devices patch and Jlink.

author: true
author_rank: Frequent Contributor
timestamp: September 02, 2023, 01:40:09 am
content: Of course the core is stopped when checking peripherals in the peripheral pane. There is a specific error message, but I did not expect support for that here so did not post it. As I said, I can manually read peripheral registers just fine, or write to them using the debug console. It's just the peripheral pane that's busted. Again I am not asking for help here, just that I have that problem to solve before I release stuff for it. Once it's working I'll post a link to a bare minimum viable platformio PY32F project.To continue on the pio tangent, I don't like how much platformio forces some things for platforms (just one example: can't specify a config for pyocd in nxplpc platform) and limits expansion of unsupported or parts without becoming a developer for them, making patches, or doing a bunch of hacky shit with fairly middling and incomplete documentation. But for most of the many supported platforms, it just works. What's wrong with the concept of "just open a project and everything is installed local to platformio as needed and just works, on windows or linux and possibly mac?" While I use many vendor IDEs, for some platforms they just don't exist (ahem... this one), are vendor packages for proprietary ones, or suck. I ported STM8L15x + fixed SDCC to PlatformIO and it's by far the best experience I have had programming and debugging for that platform. For supported target platforms, it basically just works, and gives you options (vs vendor IDEs where if you don't like what they provide, you'll usually have to hack shit). For unsupported ARM cores, it's pretty easy to hack in bare metal support with existing structures. To each their own. Not really sure what the point of your comment was, expressing your hate based on ignorance because you don't like the "concept;" this is just another option. If you don't that I got it to work, you can ignore it.But try getting people hacking on firmware who don't have a bunch of experience. The less friction, the better. This is a goal of many of my devices. I'd rather just tell them for a PY32 device to "install vscode, install platformio extension, open project and build, and it works" and have that be only ~300MB total download at a convention than "try a bunch of hacky shit with some vendor IDE that is a 1GB download behind an account login." (ok, ideally it'd be even smaller download, but that's hard to do and have people still be comfortable while also making sure the codebase remains maintainable)The other options here are a stolen (or real, but look at the post history) debugger and a version-specific hacked IDE. Which I have also used and it works well. Or a proprietary IDE using vendor packs.Quote from: DavidAlfaThat doesn't solve my core problem. And besides, I already have used this (for HK32 anyway) and have spoken with you about it.Back on topic:Re PY32F specifically, I have two products, one using 002A-TSSOP20 and another 003-SOP16 that I'll be hacking on code for over the next few weeks. The peripheral set reminds me a lot of other Chinese domestic MCUs, and it was near effortless to get it going, so I imagine this will work just fine. I do like that the pinout for debugging makes way more sense than the HK32, lol.

author: DavidAlfa
author_rank: Super Contributor
timestamp: September 02, 2023, 02:10:10 am
content: Doesn't solve your core problem? I can write to any core/peripheral register just fine there...

author: true
author_rank: Frequent Contributor
timestamp: September 03, 2023, 02:54:21 am
content: Quote from: DavidAlfa on September 02, 2023, 02:10:10 amCorrect. Peripheral pane not working right now isnotmy core problem. Something else is, which I also described. Getting a development environment working with this MCU that is both smaller and doesn't involve modifying a vendor IDE or modifying anything really solves my problem better. I can program and debug just fine this way, and for an end user / programmer getting the source, does not require any special instructions or modified software. I can work on the periph pane issue later. Was not asking for help for it. I only mentioned thatthat's the only thing that isn't working right now otherwise I'd post detailsand for some reason it got taken as a shit solution or something.Quote from: DavidAlfa on September 02, 2023, 02:10:10 amWhat is "there?" Using PY32 on pio+pyOCD? Or do you mean with STM32CubeIDE? I already know it works on the latter and implied as such. If you mean the former, please describe how / post your platformio.ini?I really don't know how "everything works except peripheral pane not working" got taken as "everything you do is shit, your choice is shit, and it must be refuted." This isn't a competition. Why the hate? I don't understand it. I only described that I have this working another way. Instead of "cool" or not saying anything, there's just hate and pushback. Why hate over it? Can things only be done your way here?

author: true
author_rank: Frequent Contributor
timestamp: September 03, 2023, 02:59:45 am
content: Exactly. huh?I'll talk elsewhere about my progress with this.

author: DavidAlfa
author_rank: Super Contributor
timestamp: September 03, 2023, 11:41:11 am
content: So did you went back to earth from whatever you took yesterday?Competition? Hate?, "everything you do is shit"?I simply said: I use THIS, and it works for me. That's all.I'm NOT using Plattformio (Neither I like it, I find it messy, that's a personal preference), so I CAN'T help with that.Now, where did anyone said you were a f** piece of sh** or X method was better?

author: DavidAlfa
author_rank: Super Contributor
timestamp: September 06, 2023, 01:10:34 pm
content: It was a *** mess to set it up, but I got it working in Eclipse.1 - Install Eclipse for C/C++ Embedded.2 - Install python 3 from windows store.3 - Install pyocd withpip3 install pyocd4 - DownloadxPack gcc, extract it somewhere, ex.c:\xpack\xpack-arm-none-eabi-gcc-10.3.1-2.3.5 - DownloadxPack build tools, extract t it somewhere, ex.c:\xpack\xpack-windows-build-tools-4.4.1-1.6 - Eclipse->Window->Preferences->MCU->Global Arm Toolchains Paths->Default toolchain: xPack GNU Arm Embedded GCCToolchain folder:C:\xpack\xpack-arm-none-eabi-gcc-10.3.1-2.3\bin.Global Build Tools Path:C:\xpack\xpack-windows-build-tools-4.4.1-1\bin.7 - Eclipse->Help->Marketplace, install EmbSysRegView plugin, close the IDE.8 - PlacePuya.PY32F0xx_DFP.1.1.0.packinC:\Users\user_name\AppData\Roaming\CMSIS-Packs.9 - Temporary rename the file from .pack to .zip, extract the SVD files somewhere, then rename it to .pack again.10 - Go toC:\Users\user_name\.p2\pool\plugins\org.eclipse.cdt.embsysregview.data_0.2.6.r191\data\SVD(CMSIS)Create the folder "Puya". Place the SVD files file inside it, change the extension to xml.9 - Open Eclipse->Window->Preferences->C/C++->Debug->Embsys Register View-> Architecture:SVD, Vendor:Puya, Chip: py32f030xx (The svd name).10 - Eclipse->New->C/C++ Project->C Managed build->Empty project, Arm Cross GCC->Should use the toolchain be set earlier->Finish11 - Right click on project->C/C++ Build-> External BuilderBehaviour-> Enable parallel buildSettings->Target Processor->cortexm0-plus.Settings->Optimization->Other optimization flags:-Wl,--cref -Wl,--gc-sections -static --specs=nano.specs -mfloat-abi=soft -mthumb -Wl,--start-group -lc -lm -Wl,--end-group(Apply this to both Debug and Release profiles). This saves a lot of space, it's what CubeIDE uses.12 - Eclipse->Window->Preferences->MCU->Global pyOCD PathExecutable:pyocd.exeFolder:C:\Users\user_name\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.xxx\LocalCache\local-packages\Python3xx\Scripts13 - Click on the Debug button->Debug configurations->Create New GDB PyOCD -> Debugger tabClick override target:py32f030x6Other options:--pack=C:\Users\user_name\AppData\Roaming\CMSIS-Packs\Puya.PY32F0xx_DFP.1.1.0.packLinker script is set in Project properties->C/C++ Build->Settings->GNU Arm Cross Linker->GeneralIt's common to have a startup file in asm, Eclipse only takes assembler files with .S extension, must be uppercase!Debugging and programmign works, but EmbSys won't show the register data by default, you must first enable each by double-clicking on the reg name, it'll become green, now you can write and read to it.Attached a simple project.

author: DavidAlfa
author_rank: Super Contributor
timestamp: September 06, 2023, 01:16:35 pm
content: And forget unlocking RDP with pyOCD either.I've tried with J-Link, ST-Link and DAP-LINK, they all do the same:Quote

author: man_anyone
author_rank: Newbie
timestamp: September 06, 2023, 10:37:25 pm
content: Quote from: true on September 03, 2023, 02:54:21 amI appreciate what you're doing, I really doI've never wanted to use the vendor IDEs and you can see that I've asked David Alfa about the possibility of adding support for this MCU to PlatformIO in a previous post, so I'm really glad that you're adding support for itBut you need to calm down man, like reallyThey just said they don't know how to help, they didn't say that PlatformIO is objectively bad or anything, they were just expressing their opinionQuote from: true on September 03, 2023, 02:59:45 amI'm really interested, so I would be glad if you told me where you're goingAlso thanks David for going out of your comfort zone to help us here

author: DavidAlfa
author_rank: Super Contributor
timestamp: September 25, 2023, 08:21:27 pm
content: Quote from: bingo600 on August 18, 2023, 03:39:59 pmEdited the first post.There's a new tool,MCU-Flash-Tools, python-based, which can program PY32 using the embedded bootloader, just like Puya ISP, so you can now use it under linux.

author: Bikkel
author_rank: Newbie
timestamp: October 02, 2023, 12:26:49 pm
content: Do you think it is possible to jump from your user code to this bootloader and start using the onboard bootloader without going through the sequence were you have to power up with the boot pin pulled high ?

author: DavidAlfa
author_rank: Super Contributor
timestamp: October 02, 2023, 01:36:24 pm
content: Should be posssible. Based on gbm's answer here:https://community.st.com/t5/stm32-mcus/how-to-jump-to-system-bootloader-from-application-code-on-stm32/ta-p/49424I got it working with this code:Code:void JumpToBootloader(void){typedef struct {uint32_t Initial_SP;void (*Reset_Handler)(void);}boot_vectable_t;boot_vectable_t * BOOTVTAB = (boot_vectable_t *) 0x1FFF0000; // PY32 system bootloader base address;__disable_irq(); // Disable all interruptsif(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_HSISYS) // If not using HSI clock source, set default HSI 8M clock.{LL_RCC_HSI_Enable();while(LL_RCC_HSI_IsReady() != 1);LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_HSISYS);while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_HSISYS);LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);LL_RCC_PLL_Disable(); // Disable PLL}RCC->AHBENR = 0x300; // Disable all peripherals except FLASH and SRAMRCC->APBENR1 = 0;RCC->APBENR2 = 0;RCC->IOPRSTR = 0xFFFFFFFF; // Reset all portsRCC->AHBRSTR = 0xFFFFFFFF; // Reset all peripheralsRCC->APBRSTR1 = 0xFFFFFFFF;RCC->APBRSTR2 = 0xFFFFFFFF;RCC->IOPRSTR = 0; // Release resetsRCC->AHBRSTR = 0;RCC->APBRSTR1 = 0;RCC->APBRSTR2 = 0;SysTick->CTRL = 0; // Disable Systick timerNVIC->ICER=0xFFFFFFFF; // Clear Interrupt Enable & Interrupt Pending RegistersNVIC->ICPR=0xFFFFFFFF;__enable_irq(); // Re-enable all interrupts__set_MSP(BOOTVTAB->Initial_SP); // Set the MSPBOOTVTAB->Reset_Handler(); // Jump to bootloader}It probably can be optimized by removing unnecessary code, but it's a small function anyways (Uses 168 Bytes of flash).All the LL calls are basically reg read/write/modify macros or very small inline functions.Puya ISP finds the mcu in the instant I push the button:Code:int main(void){system_init();while (1){led_blink();if(!ReadPin(BUTTON))JumpToBootloader();}}Code:Send 0x7F...Receive 0x79Send 0x7F...Receive 0x1FVersion:1.0PID：0x0440Read UID 128Bytes at 0x1FFF0E00.00: 31 34 50 41 03 32 36 38 2A 64 E7 00 78 93 05 5610: FF FF 30 01 BA 78 BA 65 FF FF FF 9A FF FF FF 0A20: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF30: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF40: E8 10 00 00 E8 30 00 00 0A 51 00 00 E9 72 00 0050: E2 92 00 00 B7 03 00 00 69 04 00 00 FF FF FF FF60: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF70: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FFFLASH：32 KB, SRAM：4 KBOPTR: 0xB0AA SDKR: 0x001F WRPR: 0xFFFF

author: true
author_rank: Frequent Contributor
timestamp: October 12, 2023, 10:03:22 am
content: Quote from: man_anyone on September 06, 2023, 10:37:25 pmWhat I wrote is that I got it working. A progress report. For some reason "this one thing isn't working" is the only thing that was understood, and perhaps taken both as begging for help and an opportunity to hate on an IDE / platform. I never asked for help nor did I want help. The response was just "your choice sucks" and "use what was made before, it works." Has nothing to do with the progress report.Really I was more interested in discussing the PY32F002B and if anyone did anything with it yet...Since you're interested, if you don't mind waiting, I'll post the platformio conf file once I get done with a convention early November. This way I can make sure the config is repeatable and not specific to my setup. Shouldn't require doing any hacky stuff - just make a new project, use the config and PUYA .pack file. If you want it sooner let me know.

author: IOsetting
author_rank: Regular Contributor
timestamp: October 13, 2023, 02:47:08 am
content: I just noticed that Puya has created their account on Giteehttps://gitee.com/puya-semiconductorand released quite a lot tools and softwarehttps://gitee.com/puya-semiconductor/tools-and-softwareA good sign that they are making their software things public and officially supporting GCC

author: DavidAlfa
author_rank: Super Contributor
timestamp: October 13, 2023, 05:14:55 pm
content: Including notes for the bootloader protocol

author: DavidAlfa
author_rank: Super Contributor
timestamp: October 30, 2023, 03:36:51 pm
content: Long story short, I noticed setting RDP1 disables nRST!My fault, I was clearly disabling it in the config bits when setting RDP!Had two weeks, 11h/day thanks to stupid sales/management people, was time for a planned order and they didn't had bought the parts yet, so then it was again our mission to save their as$es.I had already given it all and struggled with this simple task.

author: Pixie dust
author_rank: Contributor
timestamp: November 19, 2023, 07:30:17 am
content: I checked out the ADC onboard the PY32F003. The converter is quite accurate (jitter of 1 count only). However there is one flaw: If a pin is configured in input mode (not analog) and the voltage of such pin goes beyond the rails (either on the ground side or VDD side) the ADC results of other (analog) pins are messed up. And this while the VDD stays perfectly constant. So the ADC does not strictly convert in the range 0...VDD.In designs were the onboard protection diodes are used to clamp an input pin this can be a problem.

author: DavidAlfa
author_rank: Super Contributor
timestamp: November 19, 2023, 08:14:16 am
content: Yeah this is a pretty common issue in plenty of mcus.Relying on the pin clamping diodes is always a bad idea when using analog peripherals and must be thoroughly tested.Of course the adc works in the 0...VDD range, the problem comes from the clamping diodes, clamping to VDD+0.6V, those extra 0.6V are causing the behaviour.If the current consumption is low, even 10K could cause VDD to rise slightly.You can also play with the pulldown resistors, so they make a voltage divider.I recall they were about 40-50K, so if interfacing 5V, a 22-33K input resistor will do it.

author: IOsetting
author_rank: Regular Contributor
timestamp: November 29, 2023, 12:22:35 pm
content: A newly reported bug:When IWDG is enabled, if RTC or LPTIM interrupt is triggered(to feed the dog) at the same time when MCU is entering stop mode, there is a possibility that the dog feeding fails and then MCU will reset.(Source:https://www.cnblogs.com/liwen01/p/17850148.html)In PY32F002B, using option byte IWDG_STOP may avoid this bug. when IWDG_STOP is set, watchdog stops counting in stop mode.

author: antst
author_rank: Newbie
timestamp: December 01, 2023, 02:36:08 pm
content: Quote from: true on October 12, 2023, 10:03:22 amKindly reminding!I just got dev boards and going to start hacking around it. Would be nice to avoid some work with setting up platformi

author: bingo600
author_rank: Super Contributor
timestamp: December 10, 2023, 09:17:01 am
content: Seems line Puya has gotten their "Device packs" in the "Official" DAP repos.Install with:pyocd pack update - It will "barf a bit" but completepyocd pack install PY32pyocd pack find PY32Code:Part Vendor Pack Version Installed------------------------------------------------------------------PY32F002Ax5 Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F002Bx5 Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F003x4 Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F003x6 Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F003x7 Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F003x8 Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F030x4 Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F030x6 Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F030x7 Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F030x8 Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F031x4 Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F031x6 Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F031x7 Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F031x8 Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F040Cx6 Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F040Cx8 Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F040Cx9 Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F040CxB Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F040x6 Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F040x8 Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F040x9 Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F040xB Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F071Cx6 Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F071Cx8 Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F071Cx9 Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F071CxB Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F071x6 Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F071x8 Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F071x9 Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F071xB Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F072Cx6 Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F072Cx8 Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F072Cx9 Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F072CxB Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F072x6 Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F072x8 Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F072x9 Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F072xB Puya Puya.PY32F0xx_DFP 1.2.0 TruePY32F303x8 Puya Puya.PY32F3xx_DFP 1.0.0 TruePY32F303xB Puya Puya.PY32F3xx_DFP 1.0.0 TruePY32F303xC Puya Puya.PY32F3xx_DFP 1.0.0 TruePY32F403xB Puya Puya.PY32F4xx_DFP 1.0.0 TruePY32F403xC Puya Puya.PY32F4xx_DFP 1.0.0 TruePY32F403xD Puya Puya.PY32F4xx_DFP 1.0.0 TruePY32L020x5 Puya Puya.PY32L0xx_DFP 1.0.0 TruePY32M010x5 Puya Puya.PY32Mxxx_DFP 1.0.0 TruePY32M030x8 Puya Puya.PY32Mxxx_DFP 1.0.0 TruePY32M070xB Puya Puya.PY32Mxxx_DFP 1.0.0 True1.2.0 Pack is herehttps://www.puyasemi.com/uploadfiles/Puya.PY32F0xx_DFP.1.2.0.pack/Bingo

author: bingo600
author_rank: Super Contributor
timestamp: December 11, 2023, 02:05:51 pm
content: Quote from: DavidAlfa on September 06, 2023, 01:10:34 pm@DavidI decided to "Fine tune" my PY32 ... And install an IDE to do debugging.I tried theCube IDEw. Jlink - I have a Chinese Jlink-OB.Works a few times (Run to breakpoint) ... But after setting a breakpoint, and "resuming" a few times GDB/Segger/IDE crashes , saying it has run out of breakpoints.I don't think my OB has Flash BP's licensed.But i only have the BP at main , and the "other BP" active ...I then installed Eclipse Embedded (w. Embsys) , and is using my AirF103 DAP-Link probe.I'm having quite some debug issues here ...PyOCD is flashing "fine" (text show in red) ... Well it says flashing 3200 bytes , and the bin fills 3417 bytesThe breakpoints seem to work , but the MCU isn't blinking the led ....Crazy enough BP's work, and show the "loop" variable.If i "just" press "Run" - the led isn't blinking too.If i move the project to "makefile" , and still use dap-link to programThe led is blinkingI'm in "deep do..do" here ...Any hints would be much appreciated.PC is x64 Mint 21.02Attached Eclipse Project./Bingo

author: DavidAlfa
author_rank: Super Contributor
timestamp: December 11, 2023, 02:36:59 pm
content: My experience with pyOCD wasn't pretty good... it was a PITA to set up the CMSIS packs, Eclipse and all that, but I remember it working.After making the Eclipse guide few posts back (Did it for a 100% legal alternative), I never used it again.I'm running STLINK converted into JLink-OB with no problem else than the daily annoying warning.You can only set 2 or 3 breakpoints, if you add more you'll have to delete or disable others.Plus ensure to remove "Halt at main" in the debug launch options, as it will use another breakpoint.I have no problem whatsoever with breakpoints, just remember they're finite!BTW, these puyas have started to get more expensive, 2-4 cents more in small quantities!

author: bingo600
author_rank: Super Contributor
timestamp: December 11, 2023, 04:36:58 pm
content: I got Eclipse to compile & flashI seem to have an issue with the clock initCode:#if 0BSP_RCC_HSI_PLL48MConfig();SysTick_Config(480000);#elseLL_RCC_HSI_SetCalibFreq(LL_RCC_HSICALIBRATION_24MHz);while (LL_RCC_HSI_IsReady() != 1);SysTick_Config(24000); // 24MHz cpu clock, 1ms period.#endifIf i set it at 48M , it runs super slowIf i use the 24M , it runs as expected ...Hmmm .....Isn't there a zero to much in that 48M systick ?

author: DavidAlfa
author_rank: Super Contributor
timestamp: December 11, 2023, 04:47:22 pm
content: Yep, 480.000 will make a 10ms tick period (100Hz), 10 times slower.Change to 48.000, fixed!

author: bingo600
author_rank: Super Contributor
timestamp: December 11, 2023, 05:03:57 pm
content: Quote from: DavidAlfa on December 11, 2023, 02:36:59 pmInteresting ....Is it "just" connect a China "USB-Stick" lookalike ST-Link , and then "convert" it ...And it isn't locked to "Just ST MCU's" ?Any hints ... ?Ohh ... I suppose t has to be a F103 ST-link or ??Some of the clones uses a F101 i think ...Quote from: DavidAlfa on December 11, 2023, 02:36:59 pmThat's the strange thing ...I have "The main breakpoint" , and ONE other breakpoint.I just press ""Run" , and it breaks at the LED togleI press Run gain ... It worksAfter 4..6 "Run's" it crashes with "No more breakponts"But i never set any more ....I'll try to remove the break at mainQuote from: DavidAlfa on December 11, 2023, 02:36:59 pmThat's quite a lot , when you think about they were 11centIt got 100 of each ... F003 & F002a15 in 20-ssop , and F002a15 in 16tsopI just got Eclipse debug to behave .....I had to give it a SVD file , in order to see the periph. registers

author: DavidAlfa
author_rank: Super Contributor
timestamp: December 11, 2023, 05:45:08 pm
content: Quote from: bingo600 on December 11, 2023, 05:03:57 pmIt's a stlink v2 clone, but the full one (White plastic housing), thenreflashed to OB.Quote from: bingo600 on December 11, 2023, 05:03:57 pm"Yes", but read 1st post.Quote from: bingo600 on December 11, 2023, 05:03:57 pmAFAIK it only needs to be a CB (128K) part, but genuine stm32, not apm32, etc.Quote from: bingo600 on December 11, 2023, 05:03:57 pmEdit: I can set up to 4 breakpoints just fine!More than that and I get the window asking to buy a license for unlimited flash breakpoints.If you have a spare stm32f103 BluePill send me a PM, I have a binary you can try out.

author: bingo600
author_rank: Super Contributor
timestamp: December 11, 2023, 06:15:23 pm
content: Quote from: DavidAlfa on December 11, 2023, 05:45:08 pmI suppose that's what bites me ....Quote from: DavidAlfa on December 11, 2023, 05:45:08 pmNeat ....I suppose the "Unlimited flash BP" is the "Dongle" reprogramming the flash , and inserts BP's thereI haven't tried more than 2 BP's (Main + an extra)But i suppose i don't need the BP at main ...If that frees up a BP . that i can use for a "Line", and then have the other for stepping. That would be fine for me.But right now Eclipse + pyocd seems to behave quite ok .../BingoPs: Thanx for the assistancePps: Did you see the picts i inserted above ...

author: DavidAlfa
author_rank: Super Contributor
timestamp: December 11, 2023, 06:19:07 pm
content: I see you anwered to my previous message before editing, please re-read.Yeah I saw your picture...Quote from: bingo600 on December 11, 2023, 05:03:57 pmDid you follow all the stepshere?Though I used an external pack file, as it wasn't included in pyOCD back then.Maybe the breakpoint issue is a DAP or PyOCD thing? I'm not using that...Try Jlink just in case?

author: bingo600
author_rank: Super Contributor
timestamp: December 11, 2023, 06:42:01 pm
content: Quote from: DavidAlfa on December 11, 2023, 06:19:07 pmI did follow your "Guide quite a lot" ... It helped great.But remember i'm on linux, there could be differences ....The BP issue i have was with CubeIDE + JlinkOBSo far ...It seems like Eclipse + pyOCD + DAP-debugger runs quite nice ....Btw: I tried to upgrade 1.13 CubeIDE "online" to 1.14 ... It broke .... PROB DON'T do that ...I ended up deleting 1.13 , and reinstallAnd DL + Install 1.14 instead of upgrade They can coexist , in different dir's ... (Had to do the Java mod etc ... Again) , but you described it nicelyI'm glad i got my 2TB NVMEEdit:I think i just "killed" a PY002 tsop-16 ...During my "fight" with Eclipse , i loaded the "RDP test program" you made.And the CLI-DAP flasher - Gave an error and Couldn't verify ...But the program isn't running either (no led blink) , so i can't disable RDP.Maybe it's time to try that "linux" puya-programmer ....Is it via seria interface l, that you "remove the RDP" on windows ??Well it was 11cent ... The tsop to DIP adapter was more expensive/Bingo

author: DavidAlfa
author_rank: Super Contributor
timestamp: December 11, 2023, 06:52:36 pm
content: Quote from: bingo600 on December 11, 2023, 06:42:01 pmI never tested this. Only Jlink in CubeIDE.Quote from: bingo600 on December 11, 2023, 06:42:01 pmCubeIDE always broke for me when updating. I just delete everything and install from zero.Keep in mind you'll have to manually patch that new IDE version (Just follow the included instructions).Pasting the zip contents will likely break something, as the included plugins will be newer.I kept 1.2.1 because of the stupid login thing. It's not just annoying, also screwed up my STM32 soldering FW automated building script.So feeeck it

author: bingo600
author_rank: Super Contributor
timestamp: December 12, 2023, 07:49:50 pm
content: Seems like my PY32F002AW15S (TSOP-16) is "gone"Somehow it went bannanas during programming of Davids RDP-Test program.Now there's no led blink or .....Well i looked at the new PuyaISP python program, to unprotect the device.In order to activate the serial bootloader you need to pull Boot0 "high" ....Wellon a TSOP-16 there's no PF4/Boot0 pinWonder how they will utilize serial bootloader on that one wo. a Boot0 pin?Big loss 11cThe TSOP to DIP adapter was more ...Lesson learned ... Use a TSSOP-20 for playing around with RDP.But then again ... A bit strange the < 20 pin , doesn't seem to be able to use the serial boot loader/Bingo

author: DavidAlfa
author_rank: Super Contributor
timestamp: December 12, 2023, 10:18:50 pm
content: But my test allowed RDP to be erased in software by pressing a button ?Quote from: DavidAlfa on August 24, 2023, 07:35:37 pmQuote from: bingo600 on December 12, 2023, 07:49:50 pmI don't think you can.BTW why the SO-16 package? The TSSOP20 is cheaper, has more pins while being ~30% smaller, and it's not hard to solder either!In fact, it's the only package with BOOT0...

author: bingo600
author_rank: Super Contributor
timestamp: December 13, 2023, 04:54:44 am
content: Quote from: DavidAlfa on December 12, 2023, 10:18:50 pmWell i have both ....But also wanted one that was easy solderable, for a friend ....From now on , i'll use the TSSOP-20 for playing around./Bingo

author: DavidAlfa
author_rank: Super Contributor
timestamp: December 13, 2023, 02:43:00 pm
content: Still, why can't it be erased by the button? Did you modify it?Anyways, I can't think on a worse example to play with, make a mistake and it'll be gone!Just play with a led like the rest of the world

author: bingo600
author_rank: Super Contributor
timestamp: December 13, 2023, 05:04:08 pm
content: Quote from: DavidAlfa on December 13, 2023, 02:43:00 pmYupp - The SO16 needed other pinsQuote from: DavidAlfa on December 13, 2023, 02:43:00 pmBut- I misred the "Pin1 - dot" on the package , when jumpering the "Button pin" & ledsMagic ... Leds blinking - Program running & It's revived from the deadI'mo now 11c richer ... And think i'll just play w leds/Bingo

author: DavidAlfa
author_rank: Super Contributor
timestamp: December 13, 2023, 05:55:09 pm
content: You can now tell the wife you'll have food for Christmas!

author: eliocor
author_rank: Unknown
timestamp: January 08, 2024, 02:44:28 am
content: because the PY32F002A micro is the same as a PY32F030,except for the pinout, I have prepared a small document (extracted from the datasheets) which can be of some help when you are planning to use the 002A using all the "enhancements" of the 030.I hope it can be of some use...

author: Pixie dust
author_rank: Contributor
timestamp: February 13, 2024, 01:47:21 pm
content: During a test on a PY32F003 current was fed via the onboard protection diodes into the bulk capacitors placed on the output of a 5V regulator powering a py32F003. As more current was pushed in than drawn by the processor the voltage started to rise to about 8V. I thought this was the end of that microcontroller but to my surprise nothing broke and the processor still runs fine. I thought this is quite remarkable and makes me think that these PYFxxx controllers have quite robust IO pins.

author: pappkopp
author_rank: Contributor
timestamp: February 18, 2024, 09:45:04 pm
content: For the 8 pin (SOP8) PY32F002AL15S6TU, how would i flash this device? using J-link, USART RX/TX and PA14 ?This model does not have a boot0 mode, only reset/nrst button?

author: DavidAlfa
author_rank: Super Contributor
timestamp: February 18, 2024, 10:03:29 pm
content: Jlink, dap...

author: pappkopp
author_rank: Contributor
timestamp: February 28, 2024, 07:42:58 pm
content: I'm trying to connect to the 8 pin (SOP8) PY32F002AL15S6TU via PuyaISP, but i cant really get it working, how should i enter the bootloader? I have tried pulling pin 6 (PA2/PF2-NRST) both high and low while power-cycling the MCU, but PuyaISP wont connect,Is pulling NRST high the correct method to enter the bootloader? This package does not have a dedicated BOOT0 pin,I have the option to try J-Link, does Puya have some tool to upload or read the mcu info via this? I have tried PuyaProgrammer but it can't find the USB device to use for SWD, For the J-link i'm using a nucleo board i have converted to J-link, but i belive Puya has its own programmer but it should be compatible ?

author: DavidAlfa
author_rank: Super Contributor
timestamp: February 28, 2024, 10:44:49 pm
content: You already asked ths and were answered:Quote from: DavidAlfa on February 18, 2024, 10:03:29 pmNo bootloader possible without Boot0, you need a programmer or buy a different package which has Boot0.Read the thread, that matter has already been talked.

author: IOsetting
author_rank: Regular Contributor
timestamp: February 29, 2024, 01:45:44 am
content: Quote from: pappkopp on February 28, 2024, 07:42:58 pmJ-Link has its own software, which can be downloaded fromhttps://www.segger.com/downloads/jlink/

author: John Celo
author_rank: Regular Contributor
timestamp: March 13, 2024, 05:17:24 pm
content: I'm reading this thread and trying to piece together on how to programm the SOP8/SOP16 versions of the PY32F002 (those don't have the boot0 pin available)I don't have any dedicated programming device at the moment, and up to this point I have only programmed dev-boards that can be flashed via USB port (like arduino nano with it's onboard CH340 usb-to-serial chip and similar)Which programming device should I get to program SOP8/SOP16 versions of those chips?I've seen JLink mentioned, and on the first glance those cost 1000 euro or more.For example, STM32 chips seem to have cheap ST-Link V2 programmers available on ali and else where.Similarly, WCH CH32V003 chips have cheap WCH-LinkE on ali.Are there any affordable beginner options to program SOP8/SOP16 versions of these chips?

author: prosper
author_rank: Regular Contributor
timestamp: March 13, 2024, 05:26:24 pm
content: you might already have parts on hand to build a daplink.seehttps://github.com/IOsetting/py32f0-template/issues/6for a discussion on probes. most DAP probes work, if only at 3.3V

author: bingo600
author_rank: Super Contributor
timestamp: March 13, 2024, 08:07:27 pm
content: Quote from: John Celo on March 13, 2024, 05:17:24 pmA Jlink-OB or a Dap-Link from Ali will do ....They're like $5 .. $81:I've used this daplinkhttps://www.aliexpress.com/item/1005005303809188.html2:And this Jlink-OBhttps://www.aliexpress.com/item/1005003620592002.html3:And this diy daplinkhttps://www.aliexpress.com/item/1005004635091721.htmlhttps://www.eevblog.com/forum/microcontrollers/$0-11-py32f002a-m0-24mhz-320kb-actually-324kb-more-peripherals/msg5029996/#msg5029996I'd prob get : One of #1 , and one of #2

author: prosper
author_rank: Regular Contributor
timestamp: March 13, 2024, 08:18:41 pm
content: this also works (same AIR32 as previous poster, just a smaller form factor):https://www.aliexpress.com/item/1005005966658428.html

author: DavidAlfa
author_rank: Super Contributor
timestamp: March 13, 2024, 08:59:11 pm
content: Puya has modded OpenOCD adding support por their chips:https://gitee.com/puya-semiconductor/tools-and-software/blob/master/PY32_GCC/openocd-0.12.0.zipExample cfg file forthis DAP:Code:source [find interface/cmsis-dap.cfg]source [find target/py32f030.cfg]cmsis_dap_backend hidtransport select "swd"set CLOCK_FREQ 1000reset_config noneset CONNECT_UNDER_RESET 0set CORE_RESET 0Unfortunately CubeIDE complains about non genuine device. Haven't looked over it.

author: prosper
author_rank: Regular Contributor
timestamp: March 13, 2024, 09:05:31 pm
content: I saw that. Unfortunately, it's windows-only and doesn't provide the source, so it's not useful for me.probe-rs does support the py32, though, so that's my go-to OCD

author: John Celo
author_rank: Regular Contributor
timestamp: March 14, 2024, 05:32:42 pm
content: Thank you for advice!Sop8 version has following pins:1. VCC2. PA4/PA103. PA34. PA14-SWC/PB35. PA13-SWD6. PA2/PF2-NRST7. PA18. GNDThe pins that have to be connected when programming are (5) SWC (6) SWD and (1) VCC (2) GND, correct?Can SWC/SWD pins be shared and reused for different purposes?And if the pins can be reused/shared, how does the device know that is being flashed instead of being used as in normal operation?Is there some sort of special startup sequence?

author: prosper
author_rank: Regular Contributor
timestamp: March 14, 2024, 06:22:46 pm
content: I generally reserve SWC and SWD for debugging only, and don't re-assign them. It's easy enough to use a TSSOP-20 or something with more pins if IO is that tight.If you do want to re-assign them, it'd be wise to implement a boot delay in your code before doing so, so that you have a moment when you can flash it on bootup before the SWD interface becomes unavailable to you. Otherwise, you'd essentially get a one-time-programmable device (which is not necessarily a problem if you're a manufacturer, but is less than ideal for a hobbyist)Also be aware that in some cases, the 'multiplexing' is just the way the die is bonded - i.e. they just short together the points to the same pin. So you might have trouble if you try to drive PA14 high and PB3 low at the same time. Not sure if this is the case with the py32 or not, you'd need to carefully examine the datasheet (or experiment) and make your own inferences.

author: DavidAlfa
author_rank: Super Contributor
timestamp: March 14, 2024, 07:07:59 pm
content: If you reasign swd pins, then you must also connect nRST to enter programming mode, otherwise it'll be impossible.

author: DavidAlfa
author_rank: Super Contributor
timestamp: March 14, 2024, 11:33:47 pm
content: I was able to run puya OpenOCD under CubeIDE.- Replace bin/dlls in plugins\com.st.stm32cube.ide.mcu.externaltools.openocd.win32_xxx\tools\bin.- Add script files to plugins\com.st.stm32cube.ide.mcu.debug.openocd_xxx\resources\openocd\st_scriptsBut the IDE had other genuine checks I missed out in the previous patch, so it didn't work.I analyzed com.st.stm32cube.ide.mcu.debug.launch_xxx.jar and found a better aproach to entirely bypasss the checks.Now it works great either with Jlink or openocd+stlink.Updated the 1.12.1 patch, also added the patching guide so anyone can do it for any IDE version.

author: John Celo
author_rank: Regular Contributor
timestamp: March 15, 2024, 08:55:45 am
content: It's all very confusing, for example PY32F002BW15S sop16 B version of the chip doesn't even seem to have NRST pin. (or is it a bug in the datasheet?)How does writing to the flash memory of the device gets started/initiated when connected just to VCC/GND/SWC/SWD pins?From what I could understand from reading the reference manual is:1. Once powered on device resets pin functions to their default state2. Since the SOP14/16 devices don't have a BOOT0 pin, CPU fetches top-of-stack value from 0x0000 00000and starts executing code from 0x0000 0004 from the main flash memory (20kbytes)3. Now in code, functions of GPIO pins will be set via Alternate Function Registers called GPIOx_AFRH and GPIOx_AFRL and accessed via peripheral registers (those are memory mapped in linear address space (32bit, 4gb))For PF2-NRST pin specifically, their function is set through so called "Option bytes"Option bytes (128bytes, one page of flash memory) are stored in flash memory.Is that correct?

author: IOsetting
author_rank: Regular Contributor
timestamp: March 15, 2024, 10:00:52 am
content: Quote from: John Celo on March 15, 2024, 08:55:45 amPIN13 is NRST, multiplexed with PC0, PA7EN datasheet v0.3 is not the latest, please refer to the pin map inCN datasheet v0.9, page 17Quote from: John Celo on March 15, 2024, 08:55:45 amSWD transfer doesn't need a reset

author: trimarco232
author_rank: Newbie
timestamp: March 21, 2024, 10:37:22 am
content: Hi , there is something maybe new at aliexpress : TW32F003https://fr.aliexpress.com/item/1005006207267714.htmlit is showed as a CH32V003 equivalent , but it is ARM , so rather a new PY32 ?some thoughts ?

author: bingo600
author_rank: Super Contributor
timestamp: March 21, 2024, 02:08:33 pm
content: Quote from: trimarco232 on March 21, 2024, 10:37:22 amDon't ....I think i have 3 of these , but : Absolutely no DOC is to be found ..../Bingo

author: prosper
author_rank: Regular Contributor
timestamp: March 21, 2024, 03:34:52 pm
content: looks like it's a 'tianwen51' product, possibly the same as the mm32f003?https://www.micros.com.pl/mediaserver/UIMM32f003tw_0001.pdfSome stuff comes up on a web search, likehttp://www.haohaodada.com/new/Arduino_example.php?href=TW32F003...can probably say that it's *not* a py32, at least. I'd avoid it until/unless a datasheet and code examples from the vendor (as well as toolchain support) is provided

author: DavidAlfa
author_rank: Super Contributor
timestamp: March 21, 2024, 04:47:52 pm
content: 16K Flash, 2K SRAM, definitely not PY, just cheap low spec chinese CM0+ MCU not worth any mentioning.

author: trimarco232
author_rank: Newbie
timestamp: March 21, 2024, 05:20:44 pm
content: they say 64 and 8kbbut agree with you , as 32 and 4kb are enough

author: DavidAlfa
author_rank: Super Contributor
timestamp: March 21, 2024, 07:42:59 pm
content: I don't think it has 64K by any means, other twen32 listings show 16/2KI guess it's a very opportune "mistake".

author: IOsetting
author_rank: Regular Contributor
timestamp: March 22, 2024, 02:16:49 am
content: Quote from: trimarco232 on March 21, 2024, 10:37:22 amI'm not sure if it's a PY32 OEM or not, as I can't find its datasheet anywhere.The company seems to be a training agency, so this chip is definitely rebranded from some other known chips. If you have the board with you, you can try to program it using PyISP or JLink, if this works, then it might be a PY32.

author: trimarco232
author_rank: Newbie
timestamp: March 22, 2024, 08:41:42 am
content: pinout of the board is the same as PY32I have ordered few , we will see (I also hope arduino for PY32 will work)

author: bingo600
author_rank: Super Contributor
timestamp: March 22, 2024, 09:29:15 am
content: Quote from: trimarco232 on March 22, 2024, 08:41:42 amI can't remember 100% , but i have a feeling that there's an issue with the way the board led is connected , if when programming that twenBe aware if you have issues.

author: IOsetting
author_rank: Regular Contributor
timestamp: March 22, 2024, 01:55:56 pm
content: Well, I managed to get the datasheet from their Taobao customer service. It looks quite similar to PY32F030.

author: DavidAlfa
author_rank: Super Contributor
timestamp: March 22, 2024, 04:25:44 pm
content: That one does indeed look the same as the py32f002, 20/3K...Anyways, were's the deal? Probably won't be any cheaper than puya?Try reading the DBG_MCU ID register.Ask the seller for the reference manual, not just the datasheet, which is pretty useless alone.

author: trimarco232
author_rank: Newbie
timestamp: March 22, 2024, 09:43:48 pm
content: I was looking for a PY32 on a smart little board , and didn't find something similar from Puya ...

author: DavidAlfa
author_rank: Super Contributor
timestamp: March 22, 2024, 11:05:32 pm
content: https://www.aliexpress.com/item/1005005698577482.htmlYou can replace it with the cheaper PY32F002B, which has a compatible pinout (The PY32F002Ais not compatible).

author: Sacodepatatas
author_rank: Regular Contributor
timestamp: March 30, 2024, 05:32:51 pm
content: Quote from: DavidAlfa on July 01, 2023, 10:52:02 amThese two links are broken 😔.

author: DavidAlfa
author_rank: Super Contributor
timestamp: March 30, 2024, 08:46:35 pm
content: Yeah, Puya changed the website, it's much better now.Everything is in the product page:https://www.puyasemi.com/mcu_weichuliqi.html

author: John Celo
author_rank: Regular Contributor
timestamp: April 03, 2024, 05:44:55 pm
content: Quote from: bingo600 on March 13, 2024, 08:07:27 pmSo this JLink-OB thing has arrived in the mail.It shows missing drivers in the device manager.Where do I get drivers for it?How do I use it? Any documentation or anything?The baidu link doesn't work (the one I received has FMD mcu on it).

author: bingo600
author_rank: Super Contributor
timestamp: April 04, 2024, 08:24:02 am
content: Quote from: John Celo on April 03, 2024, 05:44:55 pmI suppose you're talking Windows hereI'm on linux , so not much experience with win.I would expect you can find something on segger.com (Jlink manuf)

author: John Celo
author_rank: Regular Contributor
timestamp: April 09, 2024, 01:14:35 am
content: Got blink sketch to work, used WeActStudio DAP-Link. (for a py32 chip without a boot pin)Used Keil uVision v5 IDE (it has support packages for various devices, including py32). Keil is german subsidy of ARM that makes software tools, including IDEs. For some reason couldn't get it to flash from uVision though.So used pyOCD to flash the .hex file instead. pyOCD is python API and command line tools for flashing/erasing/debugging ARM Cortex microcontrollers.Ideally would like to flash/debug right from the uVision, but will figure that out another day...For beginner this stuff's pretty tough, so much ambigious, confusing terminology where most sources never bother to explain any of it... plus, you aren't even sure initially if dap-link is not defective, if my solder job wasn't sloppy and if the blinksketch itself is correct(you have to enable perhiphery clock or it wont work!)

author: John Celo
author_rank: Regular Contributor
timestamp: April 11, 2024, 02:46:17 pm
content: I'm getting this exact error when trying to flash it via uVision5 and a DAPLink.Code:Erase Failed!Cannot access Memory (@ 0xe000edf0, Read, Acc Size: 4 Byte)Error: Flash Download failed - "Cortex-M0+"All the settings in uVision5 are exactly like in their manual! This is sop8 version of PY32F002! (PY32F002AL15S6TU)It flashes perfectly via:Code:pyocd flash -t PY32F002Ax5 Project.hexBut doesn't in uVision!I've no idea what i'm doing wrong. I would like to debug the device within uVision, so I'd love to get this to work!I've seen a post of somebody with the exact same problem on a chinese forum (with no answer how to solve it).

author: John Celo
author_rank: Regular Contributor
timestamp: April 13, 2024, 03:36:50 pm
content: Quote from: John Celo on April 11, 2024, 02:46:17 pmGreat news! Flashing and debugging works in uVision5 with J-Link OB clone thingie! (not sure why it doesn't work with daplink)!(for beginners out there: J-Link OB thing also works nicely for stm32 arm chips in uVision, so this is definitely handy tool to have!Keil uVision seems to be particularly popular in China and lots of chinese chips come with uVision project files/examples!)

author: prosper
author_rank: Regular Contributor
timestamp: April 13, 2024, 10:12:31 pm
content: that doesn't surprise me. in my experience, the py32 is really picky about which probes it'll work with. some flash ok but are unstable for debugging, some work ok with pyocd, but not probers or vice versa... its a mixed bag.

author: Sacodepatatas
author_rank: Regular Contributor
timestamp: April 21, 2024, 03:08:41 pm
content: Has anybody noticed any funcional difference between the PY32F002BF15P and the PY32L020F15P apart from the specified max speed? I would like to know if these two chips are both interchangeable.

author: DavidAlfa
author_rank: Super Contributor
timestamp: April 21, 2024, 06:56:33 pm
content: I guess you'll have to buy a few and find yourself!

author: Sacodepatatas
author_rank: Regular Contributor
timestamp: April 21, 2024, 09:39:23 pm
content: Quote from: DavidAlfa on April 21, 2024, 06:56:33 pmI guess so, and i purchased several PY32F002BF from LCSC, that i expect receiving next week. But the PY32L020F seems to be unbtainable from outside China.The most I can do is treating the F002BF as it was the L020F and see what happens.

author: IOsetting
author_rank: Regular Contributor
timestamp: April 22, 2024, 02:50:02 am
content: Quote from: Sacodepatatas on April 21, 2024, 03:08:41 pmWhat I know about PY32L020 is that it has an extra "deep stop" mode while PY32F002B only has "stop" mode.If you don't need the low power feature, they are the same.BTW, PY32F002BF15P can also run in 48MHz, add a "#define RCC_HSI48M_SUPPORT" in CMSIS/Device/PY32F0xx/Include/py32f002bx5.h will enable it.

author: DavidAlfa
author_rank: Super Contributor
timestamp: April 22, 2024, 08:40:44 am
content: Are you sure the "Super Deep sleep" isn't also included with the 030?If so, then it likely to also be present in the 002.

author: IOsetting
author_rank: Regular Contributor
timestamp: April 22, 2024, 10:26:52 am
content: No, 002a/003/030 has no "Super Deep Sleep".002b/L020 is a different core (the option bytes are different from those of 002a/003/030).I doubt 002b also supports "Super Deep Sleep" but I didn't test it.

author: John_doe
author_rank: Regular Contributor
timestamp: April 22, 2024, 04:38:21 pm
content: Hi, another newbie/amateur here, hopefully you still have some patience for one of thoseI'd like some help writing to the flash of the PY32F002AL15S6TU (That is, the SOP-8 package).After reading this thread and finding out that only the TSSOP-20 package supports ISP, I tried first with my PY32F002AF15P6TU (TSSOP-20) using Arduino as my IDE and writing to the PY32F002AF15P6TU directly from Arduino using a USB->TTL adapter with BOOT0 pulled high and everything worked well on the first try (yes, I was also surprised) - Got some LEDs blinking and some buzzers beeping and was happy.But now I want to return to my original goal of flashing the SOP-8 version. The thing is, I haven't touched a traditional IDE since collage (more than 3 decades ago) and I really don't want to start installing and then messing with CubeIDE, Keil, Eclipse, Python stuff, or any other heavy software that requires fiddling with definitions, settings and configuration files. Is there a simple solution like a standalone software such as PuyaISP in the the sense of just running an EXE (I'm on Windows) and writing? Or better yet, writing directly from the Arduino IDE ?I'll emphasize that IDON'Tneed debugging at all, just programming the flash with the hex file that I get from the Arduino IDE.Another thing is the hardware (programmer). I just bought the DAPLINK and J-Link OB that you guys recommended from AliExpress:https://www.aliexpress.com/item/1005003620126365.htmlhttps://www.aliexpress.com/item/1005005179354439.htmlBut it'll take about a month for them to arrive and I don't want to wait. I'd like to ask your expert help with how I can use what I have now, which is:1. One ST-Link v2 clone. specifically this one:https://www.aliexpress.com/item/33045347900.htmlI looked 'under the hood' and it has a APM32F103CBT6 MCU, if it matters.2. A WCH-LinkE, specifically this one:https://www.aliexpress.com/item/1005005269690018.html3. Many Arduino compatible STM32F103 boards (bluepills, blackpills, redpills, Etc.) as well as other Arduino dev boards (ESP32, RP2040, ATMEGA 328p, Etc.)4. Many USB->TTL converters of all kinds.So, any ideas? What programmer (if any) I need in order to write this firmware to a bluepill / blackpill? Will my ST-Link v2 clone work?https://github.com/RadioOperator/STM32F103C8T6_CMSIS-DAP_SWO

author: bingo600
author_rank: Super Contributor
timestamp: April 22, 2024, 05:16:07 pm
content: Quote from: John_doe on April 22, 2024, 04:38:21 pmYour ST_link should be able to program a "Bluepill" with the above firmware.I'd suggest you program the "remap hex" from here :https://github.com/RadioOperator/STM32F103C8T6_CMSIS-DAP_SWO/tree/master/buildThen the picts on the above site seem to match your new cmsis-dap bluepill board.Unless you're a Linux user.I can't help with "how to do it" ...This post might come in handy, when needing the PY devicepacks for pyocdhttps://www.eevblog.com/forum/microcontrollers/$0-11-py32f002a-m0-24mhz-320kb-actually-324kb-more-peripherals/msg5213643/#msg5213643/Bingo

author: Sacodepatatas
author_rank: Regular Contributor
timestamp: April 22, 2024, 10:23:59 pm
content: Quote from: IOsetting on April 22, 2024, 02:50:02 amVery informative. Thank you so much.

author: John Celo
author_rank: Regular Contributor
timestamp: April 23, 2024, 01:34:10 am
content: Quote from: John_doe on April 22, 2024, 04:38:21 pmI'm an absolutest newbie/amateur, and I did get SOP-8 flashing, used J-Link OB (with keil uvision) and CMSIS/DAP-link (via pyOCD which is a command line flasher, it's not hard to use at all!).That being said, SOP-8 is pain in the ass to work with, you functionally have 3 pins left (VCC/GND/SWC/SWD/NRST) if you don't remap SWC/SWD/NRST - and I dont think it's worth bothering with that. SOP-16 is just a better fit for a beginner, since you can hook up uart and have some extra printfs diagnostics messages ON TOP of debugger. I also use uart to send commands from my computer to the chip.Frankly, if you want Arduino as an IDE, I'd suggest to stick with tssop-20 package, it takes as much space as SOP-8 anyway and costs the same.I did go the absolute opposite route - I do want a debugger and prefer an IDE, so I use keil uVision (but might move to another IDE).This sop16 chip is my first step outside of Arduino environment.So far I've got multiple ADCs working in continuous mode, uart and i2c is also working (although i2c is a bit finicky) using provided high-level HAL (as far as I can tell it's similar to hal used by stm32), I do intend to move to lower level HAL as I find them easier to reason about with reference sheet in hand.These chips are kind of slow, so if you sample multiple ADCs at total sample rate of 400kHz, and it runs at 24mHz, you only get ~60 cyclesto work for every sample! If you have some external timing sensitive signals that trigger an interrupt, those can easily take 16 cycles or more if you account for storing/restoring registers state, etc! (I have to time this!)I've yet to try the "hidden" PY32F002A features like DMA and clocking it to 48mhz (is this hard to do?).

author: John_doe
author_rank: Regular Contributor
timestamp: April 23, 2024, 03:17:19 am
content: Quote from: bingo600 on April 22, 2024, 05:16:07 pmThanks Bingo, I was able to write the "remap" firmware to the blue pill with 'STM32 ST-LINK utility'.I also had success writing to the SOP-8 chip with OpenOCD. I will write a summery of what I did in a new message.Quote from: John Celo on April 23, 2024, 01:34:10 amThank you, but I already managed to write to the chip with OpenOCD, and a good thing I did, becauseI HATE Pythonwith a vengeance!Quote from: John Celo on April 23, 2024, 01:34:10 amWait, only 3 pins? Does that mean that if I use the SWC/SWD pins in my Arduino sketch, I won't be able to write to the chip againQuote from: John Celo on April 23, 2024, 01:34:10 amNo idea, but I would also like to know how to do that. Maybe you just select PY32F030 as your target chip when writing?

author: John Celo
author_rank: Regular Contributor
timestamp: April 23, 2024, 04:21:33 am
content: Quote from: John_doe on April 23, 2024, 03:17:19 amThe chip is gone if you reassign both SWC/SWD and NRST.If you have SWC/SWD reassigned, but NRST is still available, you can still flash the chip if you pull NRST low (which forces the SWC/SWD pins to get reassigned to defaults).What I mean by saying "3 pins" is - that during development, you will probably want to have SWC/SWD connected all the time as you iterate and work on your design & code.If you reassign SWC/SWD you'll have to have some way to share those programming wires with whatever peripherals you want there and have some way to connect/reconnect those - not to interfere with flashing, as well as have to hold NRST while programming.It just seems like a hassle for no real benefit? Price is the same, and package is roughly the same size as tssop20.I bought a few py32 sop8 chips myself, and retrospectively that was a mistake, with so few pins there's not much I can use them for.

author: John_doe
author_rank: Regular Contributor
timestamp: April 23, 2024, 04:36:39 am
content: I'm writing a summery of what I did to program these PY32F002A chips. Maybe it'll help some other n00b to save some time:1. I installed PY32Duino for the Arduino IDE. I just followed the instructions here (used Google to translate the site to English):https://arduino.py32.org/2. Wrote a simple test sketch and compiled it. To upload it to the TSSOP-20 version, I just connected a USB to TTL module (costs less than $1 on AliExpress) and uploaded from the Arduino GUI. Instructions on how to connect the module to the chip can be found here:https://github.com/wagiminator/MCU-Flash-Tools?tab=readme-ov-file#puyaisp3. To write to the chip packages that do not have a BOOT0 pin, a programmer was needed, I didn't have a suitable one, such as these that were recommended in this thread:https://www.aliexpress.com/item/1005003620126365.htmlhttps://www.aliexpress.com/item/1005005179354439.htmlSo I used an ST-Link v2 clone to write this firmware to an STM32F103 "Blue Pill":https://github.com/RadioOperator/STM32F103C8T6_CMSIS-DAP_SWO/blob/master/build/F103-DAP-SWO-CDC-BLUEPILL-SWD_REMAP.hexTo do that I used STM32 ST-LINK utility from this link:https://www.st.com/en/development-tools/stsw-link004.htmlI had to hold the reset button while pressing Target>Connect . Connections from ST-Link to blue pill are 3.3v->3.3V ; GND ->GND ; SWCLK->SWCLK ; SWDIO->SWDIO.4. After I had a working CMSIS-DAP, I took the compiled Arduino hex file (if you don't know where to find it, google it) and used OpenOCD. To do that I downloaded the OpenOCD package that already includes the PY32 support files from the PUYA gitee:https://gitee.com/puya-semiconductor/tools-and-software/blob/master/PY32_GCC/openocd-0.12.0.zip(Thanks IOsetting and DavidAlfa for the link)I had to modify the "openocd_run.bat" file to include the ".\bin" folder:Code:.\bin\openocd.exe -s ./scripts -f ./scripts/interface/cmsis-dap.cfg -f ./scripts/target/py32f002x.cfg5. Had to enable Telnet for my Windows 10 (google it if you don't know how) from the control panel.6. To connect the blue pill CMSIS-DAP to the IC, I connected the USB of it to my PC and from the blue pill to the PY32F002A the connections are: 3.3V->VCC ; GND->GND ; SWCLK->SWC ; SWDIO->SWD. For the SOP-8 Package, the pins are 1 ; 8 ; 4 ; 5, respectively.7. To use OpenOCD, I ran the batch file and in a new command prompt window I entered:Code:telnet localhost 4444And then the following commands:Code:reset haltflash write_image erase c:/myfolder/myfile.hexNotice the forward slash in the path to hex file. The command will fail if a Backslash is used.

author: prosper
author_rank: Regular Contributor
timestamp: April 24, 2024, 03:55:11 pm
content: Thanks for the write up. I was excited about openocd for the PY32.... but there's (still) no source and no linux version. Ah well.Also may be worth noting: beyond openocd and pyocd, there's also probe-rs which supports the py32. Probe-rs has similar capabilities to openocd and pyocd, but has a much nicer CLI than openocd (more like pyocd). It's also pretty quick (not being python). The only real downside that I've found is that its GDB stub is pretty limited (you can't 'load,' for example), so its not as good as a debug server. [though it does have a vscode extension which supports the microsoft DAP protocol directly, if vscode is your thang]

author: John_doe
author_rank: Regular Contributor
timestamp: April 25, 2024, 04:35:24 am
content: Quote from: John Celo on April 23, 2024, 04:21:33 amThanks for the useful tip! I tried it, that is, pinMode() for both the SWD and SWC pins and indeed couldn't connect to the chip anymore. Holding NRST low (and releasing it after the command "reset halt") worked like a charm!Quote from: prosper on April 24, 2024, 03:55:11 pmWait, so the PY32 support of openOCD is built into the executable? I didn't know that... I thought that if you download the official Linux version and add the *.cfg files to it from the gitee archive it'll work.Quote from: prosper on April 24, 2024, 03:55:11 pmThanks, right now I got myself busy with something else but when I'll return to the PY32F002A project I'll be sure to try probe-rs.

author: prosper
author_rank: Regular Contributor
timestamp: April 28, 2024, 06:44:41 pm
content: QuoteThat's right. You need the configs, but they just specify which functions to use. The functions themselves are in the binary.

author: IOsetting
author_rank: Regular Contributor
timestamp: April 29, 2024, 05:11:57 pm
content: Quote from: IOsetting on April 22, 2024, 10:26:52 amit's very likely that 002B is an equivalent of L020, I just run the Deep Stop example on a TSSOP20 PY32F002b, the current consumption is much lower than the Stop mode ( 0.6 uA vs 1.6 uA).

author: ataradov
author_rank: Super Contributor
timestamp: April 29, 2024, 06:45:16 pm
content: FYI, I just added PY32F002A to my programming toolhttps://github.com/ataradov/edbg. It works with any CMSIS-DAP debugger and is just a simple standalone executable with no dependencies. Binaries for Windows/Linux/Mac are available.I'm happy to add other parts, but nowhere I can find IDCODE values for them. They are not documented anywhere. So, if you have other devices and need support, run the tool, it will report the ID for the unsupported device.BTW, 002B does not officially document code read protection. There is no RDP field and all text about read protection is removed. No idea what this is all about, seems rather strange.

author: DavidAlfa
author_rank: Super Contributor
timestamp: April 29, 2024, 09:11:50 pm
content: Very nice toolAFAIK the 002B is the same thing, just a different pinout, making the higher end 030 a direct swap.

author: John_doe
author_rank: Regular Contributor
timestamp: April 30, 2024, 12:39:03 am
content: Quote from: prosper on April 28, 2024, 06:44:41 pmThank you for clarifying.Quote from: ataradov on April 29, 2024, 06:45:16 pmPhenomenal! Just tried EDBG and it works like a charm (see attachment). This is much more convenient than OpenOCD for me. Hopefully the guys on this forum will help you with the missing ID codes.

author: IOsetting
author_rank: Regular Contributor
timestamp: April 30, 2024, 12:56:37 am
content: Quote from: ataradov on April 29, 2024, 06:45:16 pmI checked this with their tech, FLASH_SDKR in option bytes can be used for read protection. They gave a short videohttps://v.douyin.com/i2R2Ecd7/(in Chinese) to demonstrate this feature. They use an offline programmer to write the option bytes.

author: Sacodepatatas
author_rank: Regular Contributor
timestamp: April 30, 2024, 12:09:05 pm
content: Quote from: IOsetting on April 29, 2024, 05:11:57 pmIn fact, I checked this header file of the LL driver in your repo...https://github.com/IOsetting/py32f0-template/blob/main/Libraries/PY32F002B_LL_Driver/Inc/py32f002b_ll_pwr.hAnd i found an interesting paragraph...QuoteSo if you define PWR_DEEPSTOP_SUPPORT in the code, you can use the Deep Stop functions in the library. However It remains knowing if lower pin count packages support this in practice, because of lack of those packages in the L020.Quote from: DavidAlfa on April 29, 2024, 09:11:50 pmIt looks like the F002B/L020 is aimed for replacing existing 8 bit low end MCUs. If you notice, GPIOs and AFs range from 0 to 7, and pinouts of various packages match the ones of other 8 bit MCUs such as STM8S, Nuvoton, FMD, etc.I noticed there is a new PY32T020 whose doc is only in chinese. AFAIK the T means "touch button" capability. I wonder if there is any correspondence to the ones we know about at silicon level...

author: John Celo
author_rank: Regular Contributor
timestamp: April 30, 2024, 12:41:48 pm
content: I can confirm that all three DMA channels of DMA1 work, USART with DMA works, PLL works (48mhz), continuous ADC sampling with DMA also works.All what has to be changed is you have to use the startup .s file from py32f030 (startup_py32f030xx.s) which contains all the extra interrupt vectors, and adjust RAM/ROM size (although this is not strictly necessary since base address is the same). And it "just" works!I've also switched over from using high level HAL to low level hal. Makes it way easier to understand things!For beginners out there: don't be afraid of the disassembly, turns out these Cortex-M0+ chips have very simple instruction set:https://developer.arm.com/documentation/ddi0484/c/Programmers-Model/Instruction-set-summaryThis includes timings! Two stage-pipeline!These chips are great! Way less complicated peripherals than all the fancy cortex-m7 chips, which makes them a great starting point!

author: Sacodepatatas
author_rank: Regular Contributor
timestamp: May 08, 2024, 03:57:57 pm
content: Quote from: ataradov on April 29, 2024, 06:45:16 pmFYI...

author: DavidAlfa
author_rank: Super Contributor
timestamp: May 08, 2024, 04:10:59 pm
content: Quote from: Sacodepatatas on May 08, 2024, 03:57:57 pmApparently only0x60001000ID code is supported.Easy fix, though:Code:{ 0x20220064, "py32f0", "PY32F002Bxx5", 24*1024 },

author: Sacodepatatas
author_rank: Regular Contributor
timestamp: May 08, 2024, 04:26:50 pm
content: Quote from: DavidAlfa on May 08, 2024, 04:10:59 pmRemember, the 002B has 24kB of flash, so the last member in the struct (flash size) would be 24*1024.EDIT:The JEDEC JEP-106 for this part is  (no surprises here), and the DBG_IDCODE at 0xE0042000 reads '0x00000000'. Here is the AP dump from the romtable at address 0xE00FFFD0:Code:0xE00FFFD0 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................0xE00FFFE0 C0 00 00 00 B4 00 00 00 0B 00 00 00 00 00 00 00 À...´...........0xE00FFFF0 0D 00 00 00 10 00 00 00 05 00 00 00 B1 00 00 00 ............±...

author: SaccharinGoat
author_rank: Newbie
timestamp: May 08, 2024, 05:56:51 pm
content: Forgive me if this should be in a separate thread but I can't find any documentation on if any of the GPIO pins on the Puya PY32F003F16 are pulled high or low during boot. Does anyone know the initial state of them on boot?

author: DavidAlfa
author_rank: Super Contributor
timestamp: May 08, 2024, 06:23:45 pm
content: See datasheet or RM. Usually they're set in analog mode by default (Hi-Z) except SWD pins.

author: ataradov
author_rank: Super Contributor
timestamp: May 08, 2024, 07:58:37 pm
content: Quote from: Sacodepatatas on May 08, 2024, 03:57:57 pmAdded.

author: client
author_rank: Contributor
timestamp: May 19, 2024, 03:22:02 am
content: Hello, I have installed these environments as above, but compile errors occured as the code is just a simple test,my chip number is py32f003f18p6, could you show me how to solve this problem? Thank you.Error info:警告：SrcWrapper 库声称在 AirMCU 体系结构上运行，可能与当前在 PY32 体系结构上运行的开发板不兼容。In file included from C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Inc/py32f0xx_hal_def.h:35,from C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Inc/py32f0xx_hal_rcc.h:32,from C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/PY32F0xx/py32f0xx_hal_conf_default.h:208,from C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/PY32F0xx/py32f0xx_hal_conf.h:13,from C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Inc/py32f0xx_hal.h:33,from C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc.c:57,from C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\libraries\SrcWrapper\src\HAL\py32yyxx_hal_rcc.c:8:C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc.c: In function 'HAL_RCC_DeInit':C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc.c:251:28: error: 'RCC_CR_PLLRDY' undeclared (first use in this function); did you mean 'RCC_IT_PLLRDY'?251 | while (READ_BIT(RCC->CR, RCC_CR_PLLRDY) != 0U)| ^~~~~~~~~~~~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/CMSIS/Device/PY32F0xx/Include/py32f0xx.h:174:41: note: in definition of macro 'READ_BIT'174 | #define READ_BIT(REG, BIT) ((REG) & (BIT))| ^~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc.c:251:28: note: each undeclared identifier is reported only once for each function it appears in251 | while (READ_BIT(RCC->CR, RCC_CR_PLLRDY) != 0U)| ^~~~~~~~~~~~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/CMSIS/Device/PY32F0xx/Include/py32f0xx.h:174:41: note: in definition of macro 'READ_BIT'174 | #define READ_BIT(REG, BIT) ((REG) & (BIT))| ^~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc.c:260:8: error: 'RCC_TypeDef' has no member named 'PLLCFGR'; did you mean 'CFGR'?260 | RCC->PLLCFGR = 0x00000000u;| ^~~~~~~| CFGRC:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc.c: In function 'HAL_RCC_OscConfig':C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Inc/py32f0xx_hal_rcc.h:1514:56: error: 'RCC_TypeDef' has no member named 'PLLCFGR'; did you mean 'CFGR'?1514 | #define __HAL_RCC_GET_PLL_OSCSOURCE() ((uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC))| ^~~~~~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc.c:322:21: note: in expansion of macro '__HAL_RCC_GET_PLL_OSCSOURCE'322 | temp_pllckcfg = __HAL_RCC_GET_PLL_OSCSOURCE();| ^~~~~~~~~~~~~~~~~~~~~~~~~~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Inc/py32f0xx_hal_rcc.h:1514:66: error: 'RCC_PLLCFGR_PLLSRC' undeclared (first use in this function)1514 | #define __HAL_RCC_GET_PLL_OSCSOURCE() ((uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC))| ^~~~~~~~~~~~~~~~~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc.c:322:21: note: in expansion of macro '__HAL_RCC_GET_PLL_OSCSOURCE'322 | temp_pllckcfg = __HAL_RCC_GET_PLL_OSCSOURCE();| ^~~~~~~~~~~~~~~~~~~~~~~~~~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc.c:325:29: error: 'RCC_CFGR_SWS_PLL' undeclared (first use in this function); did you mean 'RCC_CFGR_SWS_Pos'?325 | if (((temp_sysclksrc == RCC_CFGR_SWS_PLL) && (temp_pllckcfg == RCC_PLLSOURCE_HSE)) || (temp_sysclksrc == RCC_CFGR_SWS_HSE))| ^~~~~~~~~~~~~~~~| RCC_CFGR_SWS_PosC:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Inc/py32f0xx_hal_rcc.h:408:40: error: 'RCC_PLLCFGR_PLLSRC_HSE' undeclared (first use in this function); did you mean 'RCC_CFGR_SWS_HSE'?408 | #define RCC_PLLSOURCE_HSE RCC_PLLCFGR_PLLSRC_HSE /*!< HSE clock selected as PLL entry clock source */| ^~~~~~~~~~~~~~~~~~~~~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc.c:325:68: note: in expansion of macro 'RCC_PLLSOURCE_HSE'325 | if (((temp_sysclksrc == RCC_CFGR_SWS_PLL) && (temp_pllckcfg == RCC_PLLSOURCE_HSE)) || (temp_sysclksrc == RCC_CFGR_SWS_HSE))| ^~~~~~~~~~~~~~~~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Inc/py32f0xx_hal_rcc.h:1514:56: error: 'RCC_TypeDef' has no member named 'PLLCFGR'; did you mean 'CFGR'?1514 | #define __HAL_RCC_GET_PLL_OSCSOURCE() ((uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC))| ^~~~~~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc.c:398:21: note: in expansion of macro '__HAL_RCC_GET_PLL_OSCSOURCE'398 | temp_pllckcfg = __HAL_RCC_GET_PLL_OSCSOURCE();| ^~~~~~~~~~~~~~~~~~~~~~~~~~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Inc/py32f0xx_hal_rcc.h:407:40: error: 'RCC_PLLCFGR_PLLSRC_HSI' undeclared (first use in this function); did you mean 'RCC_CFGR_SWS_HSI'?407 | #define RCC_PLLSOURCE_HSI RCC_PLLCFGR_PLLSRC_HSI /*!< HSI clock selected as PLL entry clock source */| ^~~~~~~~~~~~~~~~~~~~~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc.c:399:68: note: in expansion of macro 'RCC_PLLSOURCE_HSI'399 | if (((temp_sysclksrc == RCC_CFGR_SWS_PLL) && (temp_pllckcfg == RCC_PLLSOURCE_HSI)) || (temp_sysclksrc == RCC_CFGR_SWS_HSI))| ^~~~~~~~~~~~~~~~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Inc/py32f0xx_hal_rcc.h:1492:59: error: 'RCC_CR_PLLON' undeclared (first use in this function); did you mean 'RCC_CR_HSION'?1492 | #define __HAL_RCC_PLL_DISABLE() CLEAR_BIT(RCC->CR, RCC_CR_PLLON)| ^~~~~~~~~~~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/CMSIS/Device/PY32F0xx/Include/py32f0xx.h:172:43: note: in definition of macro 'CLEAR_BIT'172 | #define CLEAR_BIT(REG, BIT) ((REG) &= ~(BIT))| ^~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc.c:656:9: note: in expansion of macro '__HAL_RCC_PLL_DISABLE'656 | __HAL_RCC_PLL_DISABLE();| ^~~~~~~~~~~~~~~~~~~~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc.c:662:34: error: 'RCC_CR_PLLRDY' undeclared (first use in this function); did you mean 'RCC_IT_PLLRDY'?662 | while (READ_BIT(RCC->CR, RCC_CR_PLLRDY) != 0U)| ^~~~~~~~~~~~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/CMSIS/Device/PY32F0xx/Include/py32f0xx.h:174:41: note: in definition of macro 'READ_BIT'174 | #define READ_BIT(REG, BIT) ((REG) & (BIT))| ^~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Inc/py32f0xx_hal_rcc.h:1505:35: error: 'RCC_TypeDef' has no member named 'PLLCFGR'; did you mean 'CFGR'?1505 | MODIFY_REG(RCC->PLLCFGR, RCC_PLLCFGR_PLLSRC, (__PLLSOURCE__))| ^~~~~~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/CMSIS/Device/PY32F0xx/Include/py32f0xx.h:178:33: note: in definition of macro 'WRITE_REG'178 | #define WRITE_REG(REG, VAL) ((REG) = (VAL))| ^~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Inc/py32f0xx_hal_rcc.h:1505:19: note: in expansion of macro 'MODIFY_REG'1505 | MODIFY_REG(RCC->PLLCFGR, RCC_PLLCFGR_PLLSRC, (__PLLSOURCE__))| ^~~~~~~~~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc.c:679:9: note: in expansion of macro '__HAL_RCC_PLL_PLLSOURCE_CONFIG'679 | __HAL_RCC_PLL_PLLSOURCE_CONFIG(RCC_OscInitStruct->PLL.PLLSource);| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Inc/py32f0xx_hal_rcc.h:1505:35: error: 'RCC_TypeDef' has no member named 'PLLCFGR'; did you mean 'CFGR'?1505 | MODIFY_REG(RCC->PLLCFGR, RCC_PLLCFGR_PLLSRC, (__PLLSOURCE__))| ^~~~~~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/CMSIS/Device/PY32F0xx/Include/py32f0xx.h:178:41: note: in definition of macro 'WRITE_REG'178 | #define WRITE_REG(REG, VAL) ((REG) = (VAL))| ^~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/CMSIS/Device/PY32F0xx/Include/py32f0xx.h:182:66: note: in expansion of macro 'READ_REG'182 | #define MODIFY_REG(REG, CLEARMASK, SETMASK) WRITE_REG((REG), (((READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK)))| ^~~~~~~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Inc/py32f0xx_hal_rcc.h:1505:19: note: in expansion of macro 'MODIFY_REG'1505 | MODIFY_REG(RCC->PLLCFGR, RCC_PLLCFGR_PLLSRC, (__PLLSOURCE__))| ^~~~~~~~~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc.c:679:9: note: in expansion of macro '__HAL_RCC_PLL_PLLSOURCE_CONFIG'679 | __HAL_RCC_PLL_PLLSOURCE_CONFIG(RCC_OscInitStruct->PLL.PLLSource);| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc.c:702:25: error: 'RCC_TypeDef' has no member named 'PLLCFGR'; did you mean 'CFGR'?702 | MODIFY_REG(RCC->PLLCFGR, RCC_PLLCFGR_PLLSRC, PLLSOURCE_NONE);| ^~~~~~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/CMSIS/Device/PY32F0xx/Include/py32f0xx.h:178:33: note: in definition of macro 'WRITE_REG'178 | #define WRITE_REG(REG, VAL) ((REG) = (VAL))| ^~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc.c:702:9: note: in expansion of macro 'MODIFY_REG'702 | MODIFY_REG(RCC->PLLCFGR, RCC_PLLCFGR_PLLSRC, PLLSOURCE_NONE);| ^~~~~~~~~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc.c:702:25: error: 'RCC_TypeDef' has no member named 'PLLCFGR'; did you mean 'CFGR'?702 | MODIFY_REG(RCC->PLLCFGR, RCC_PLLCFGR_PLLSRC, PLLSOURCE_NONE);| ^~~~~~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/CMSIS/Device/PY32F0xx/Include/py32f0xx.h:178:41: note: in definition of macro 'WRITE_REG'178 | #define WRITE_REG(REG, VAL) ((REG) = (VAL))| ^~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/CMSIS/Device/PY32F0xx/Include/py32f0xx.h:182:66: note: in expansion of macro 'READ_REG'182 | #define MODIFY_REG(REG, CLEARMASK, SETMASK) WRITE_REG((REG), (((READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK)))| ^~~~~~~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc.c:702:9: note: in expansion of macro 'MODIFY_REG'702 | MODIFY_REG(RCC->PLLCFGR, RCC_PLLCFGR_PLLSRC, PLLSOURCE_NONE);| ^~~~~~~~~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc.c:727:30: error: 'RCC_TypeDef' has no member named 'PLLCFGR'; did you mean 'CFGR'?727 | temp_pllckcfg = RCC->PLLCFGR;| ^~~~~~~| CFGRC:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc.c: In function 'HAL_RCC_ClockConfig':C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc.c:858:29: error: 'RCC_CR_PLLRDY' undeclared (first use in this function); did you mean 'RCC_IT_PLLRDY'?858 | if (READ_BIT(RCC->CR, RCC_CR_PLLRDY) == 0U)| ^~~~~~~~~~~~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/CMSIS/Device/PY32F0xx/Include/py32f0xx.h:174:41: note: in definition of macro 'READ_BIT'174 | #define READ_BIT(REG, BIT) ((REG) & (BIT))| ^~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc.c: In function 'HAL_RCC_GetSysClockFreq':C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc.c:1118:45: error: 'RCC_CFGR_SWS_PLL' undeclared (first use in this function); did you mean 'RCC_CFGR_SWS_Pos'?1118 | else if (__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_CFGR_SWS_PLL)| ^~~~~~~~~~~~~~~~| RCC_CFGR_SWS_PosC:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc.c:1120:23: error: 'RCC_TypeDef' has no member named 'PLLCFGR'; did you mean 'CFGR'?1120 | pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC);| ^~~~~~~| CFGRC:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc.c:1120:33: error: 'RCC_PLLCFGR_PLLSRC' undeclared (first use in this function)1120 | pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC);| ^~~~~~~~~~~~~~~~~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Inc/py32f0xx_hal_rcc.h:408:40: error: 'RCC_PLLCFGR_PLLSRC_HSE' undeclared (first use in this function); did you mean 'RCC_CFGR_SWS_HSE'?408 | #define RCC_PLLSOURCE_HSE RCC_PLLCFGR_PLLSRC_HSE /*!< HSE clock selected as PLL entry clock source */| ^~~~~~~~~~~~~~~~~~~~~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc.c:1124:10: note: in expansion of macro 'RCC_PLLSOURCE_HSE'1124 | case RCC_PLLSOURCE_HSE: /* HSE used as PLL clock source */| ^~~~~~~~~~~~~~~~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Inc/py32f0xx_hal_rcc.h:407:40: error: 'RCC_PLLCFGR_PLLSRC_HSI' undeclared (first use in this function); did you mean 'RCC_CFGR_SWS_HSI'?407 | #define RCC_PLLSOURCE_HSI RCC_PLLCFGR_PLLSRC_HSI /*!< HSI clock selected as PLL entry clock source */| ^~~~~~~~~~~~~~~~~~~~~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc.c:1128:10: note: in expansion of macro 'RCC_PLLSOURCE_HSI'1128 | case RCC_PLLSOURCE_HSI: /* HSI used as PLL clock source */| ^~~~~~~~~~~~~~~~~C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc.c: In function 'HAL_RCC_GetOscConfig':C:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc.c:1266:18: error: 'RCC_CR_PLLON' undeclared (first use in this function); did you mean 'RCC_CR_HSION'?1266 | if ((RCC->CR & RCC_CR_PLLON) == RCC_CR_PLLON)| ^~~~~~~~~~~~| RCC_CR_HSIONC:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc.c:1275:44: error: 'RCC_TypeDef' has no member named 'PLLCFGR'; did you mean 'CFGR'?1275 | RCC_OscInitStruct->PLL.PLLSource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC);| ^~~~~~~| CFGRC:\Users\Administrator\AppData\Local\Arduino15\packages\PY32Duino\hardware\PY32\0.1.3\system/Arduino-PY32F0xx-Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc.c:1275:54: error: 'RCC_PLLCFGR_PLLSRC' undeclared (first use in this function)1275 | RCC_OscInitStruct->PLL.PLLSource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC);| ^~~~~~~~~~~~~~~~~~exit status 1Compilation error: exit status 1

author: bingo600
author_rank: Super Contributor
timestamp: May 19, 2024, 05:16:32 am
content: Quote from: client on May 19, 2024, 03:22:02 amThe PLL related error , probably indicates that you have:Mixed F003 libraries (NO PLL) and F030 code. ... "Been there"You have to change the "makefile" libraries to match the F030 , when using the "extended" functions./Bingo

author: bingo600
author_rank: Super Contributor
timestamp: May 19, 2024, 05:54:51 am
content: STM32 has a lot of pins specified as 5v tolerant.Before digging through tonzzz of DS/RM pages -Does anyone know if the PY32Fxxx - Has 5v tolerant I/O pins ?When MCU VCC = 3v3I am reusing a DVB-T Receiver cabinet for a NTP server i'm making (DDROWN code).And it has a 4 digit 7-seg display/button board, based on a SC6928B_Superchip. That i have to interface to.I'm using a STM32F407 Ethernet board, for the NTP Server.And already have some proof of concept code running on a F401 (Blackpill) for bitbanging the communications.Even though the DS says "SC6928 - Vih" has to be 0.8xVcc (5v), it works fine with the 3v3 from the F407.But i'm burning a lot of "NOP" cycles, in the bitbang delay's, and have some worries about that wrt. the NTP code in the F407.So I was thinking of using a PY32F002 for controlling the display, and use SPI (1 or 2MHz) between the F407 and the F002 display MCU.Nice little challenge .....If the F002 desn't have 5v tolerant SPI I/O, I can probably run the F002 of 5v.And use the F407 SPI2, as think this one is 5v tolerant (will check).But for ease of implementing, i'd like to run the F002 at 3v3 if possible./Bingo

author: client
author_rank: Contributor
timestamp: May 19, 2024, 08:40:52 am
content: Thank you for your reply, I will try it.

author: bingo600
author_rank: Super Contributor
timestamp: May 21, 2024, 06:29:15 pm
content: Anyonehttps://www.eevblog.com/forum/microcontrollers/$0-11-py32f002a-m0-24mhz-320kb-actually-324kb-more-peripherals/msg5506495/#msg5506495

author: DavidAlfa
author_rank: Super Contributor
timestamp: May 21, 2024, 07:51:08 pm
content: Quote from: bingo600 on May 19, 2024, 05:54:51 amNo.Datasheet states max. voltage on any given pin is VCC+0.3V.

author: ThichXemHen
author_rank: Newbie
timestamp: May 22, 2024, 01:14:38 am
content: Have you tried this with the f003 yet? It has more flash and ram than the 02, and if can be overclocked is basically the f030 that's twice as cheap.

author: DavidAlfa
author_rank: Super Contributor
timestamp: May 22, 2024, 04:00:24 am
content: And the 002 is the same as the 030 too

author: John Celo
author_rank: Regular Contributor
timestamp: June 19, 2024, 12:07:46 am
content: I managed to bitbang neopixels ws2812s in arm32 assembly for the 8pin PY32F002. (by carefully counting the used instructions cycles & timing @ 24mhz). And after fixing some silly mistakes it works. (couldn't get the SPI with DMA working for it compared to it's larger 16pin siblings for some reason)However, in future I'd like to be able to measure and see the generated low/high duty cycle timings exactly (to verify that my theoretical calculations match with generated signal in practice).What do I need for this, oscilloscope? Or would signal analyzer suffice?Siglent SDS804X is 500eur, too expensive for me at the moment. I can get an OWON VDS1022 for 50eur (is it usable or too shabby?)(100mhz 16ch signal analyzer can be made from rp2040)

author: prosper
author_rank: Regular Contributor
timestamp: June 19, 2024, 01:00:02 am
content: if you send me your code (or a bin file), i can take some measurements for you. I have an 002a (tssop20) wired up to a ws2812 on my desk right now (using the 'LL' SPI example from @IOSetting's template. SPI is IMHO a better option than bitbang on arm mcu's, because stuff like wait states won't be a problem, abd it ought to be more portable)The tool you want is a logic analyzer. Even a cheap 'fx2 logic analyzer' should be able to do what you want. An oscilloscope will gitr done, too, but thats swatting a fly with a sledgehammer

author: DavidAlfa
author_rank: Super Contributor
timestamp: June 19, 2024, 03:37:23 am
content: $10 aliexpresz 24MHz 8ch logo analyzerSPI DMA works just fine, probably you missed something, you must understand the hardware and read a lot.Though it's pretty easy with LL library!Code:#include "py32f0xx.h"#include "py32f0xx_ll_adc.h"#include "py32f0xx_ll_bus.h"#include "py32f0xx_ll_cortex.h"#include "py32f0xx_ll_dma.h"#include "py32f0xx_ll_exti.h"#include "py32f0xx_ll_gpio.h"#include "py32f0xx_ll_pwr.h"#include "py32f0xx_ll_rcc.h"#include "py32f0xx_ll_system.h"#include "py32f0xx_ll_spi.h"#include "py32f0xx_ll_tim.h"#include "py32f0xx_ll_utils.h"#include <stdbool.h>#include <stdint.h>#include <stdlib.h>uint8_t led_data[] = { }; // LED bufferconst LL_DMA_InitTypeDef DMA_LED_Init = { // DMA init struct.PeriphOrM2MSrcAddress = (uint32_t)&SPI1->DR,.MemoryOrM2MDstAddress = (uint32_t)led_data,.Direction = LL_DMA_DIRECTION_MEMORY_TO_PERIPH,.Mode = LL_DMA_MODE_NORMAL,.PeriphOrM2MSrcIncMode = LL_DMA_PERIPH_NOINCREMENT,.MemoryOrM2MDstIncMode = LL_DMA_MEMORY_INCREMENT,.PeriphOrM2MSrcDataSize = LL_DMA_PDATAALIGN_BYTE,.MemoryOrM2MDstDataSize = LL_DMA_MDATAALIGN_BYTE,.NbData = sizeof(led_data),.Priority = LL_DMA_PRIORITY_HIGH,};const LL_SPI_InitTypeDef SPI_init = { // SPI init struct.TransferDirection = LL_SPI_HALF_DUPLEX_TX,.Mode = LL_SPI_MODE_MASTER,.DataWidth = LL_SPI_DATAWIDTH_8BIT,.ClockPolarity = LL_SPI_POLARITY_LOW,.ClockPhase = LL_SPI_PHASE_1EDGE,.NSS = LL_SPI_NSS_SOFT,.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV2,.BitOrder = LL_SPI_MSB_FIRST,.SlaveSpeedMode = LL_SPI_SLAVE_SPEED_FAST,};void init_(void){ // Init functionLL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA | LL_IOP_GRP1_PERIPH_GPIOB); // Enable peripheral clocksLL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1);LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_SYSCFG | LL_APB1_GRP2_PERIPH_SPI1);// Configure GPIOLL_GPIO_Init(GPIOA, &(LL_GPIO_InitTypeDef){ LL_GPIO_PIN_1, LL_GPIO_MODE_ALTERNATE, LL_GPIO_SPEED_FREQ_VERY_HIGH, LL_GPIO_OUTPUT_PUSHPULL, LL_GPIO_PULL_NO, LL_GPIO_AF10_SPI1 }); // PA1 = MOSILL_GPIO_Init(GPIOA, &(LL_GPIO_InitTypeDef){ LL_GPIO_PIN_2, LL_GPIO_MODE_ALTERNATE, LL_GPIO_SPEED_FREQ_VERY_HIGH, LL_GPIO_OUTPUT_PUSHPULL, LL_GPIO_PULL_NO, LL_GPIO_AF10_SPI1 }); // PA2 = SCKLL_SPI_Init(SPI1, (LL_SPI_InitTypeDef*)&SPI_init); // Init and enable SPILL_SPI_Enable(SPI1);LL_SYSCFG_SetDMARemap_CH1(LL_SYSCFG_DMA_MAP_SPI1_TX); // Init DMALL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_1);LL_DMA_Init(DMA1, LL_DMA_CHANNEL_1, (LL_DMA_InitTypeDef*)&DMA_LED_Init);LL_DMA_ClearFlag_GI1(DMA1);//NVIC_SetPriority(DMA1_Channel1_IRQn, 1); // DMA IRQ//NVIC_EnableIRQ(DMA1_Channel1_IRQn);//LL_DMA_EnableIT_TC(DMA1, LL_DMA_CHANNEL_1);}void DMA1_Channel1_IRQHandler(void){ // DMA ISR}void send_led_data(void){//LL_DMA_SetMemoryAddress(DMA1, LL_DMA_CHANNEL_1, (uint32_t)led_data); // Not required unless using different buffersLL_DMA_SetDataLength(DMA1, LL_DMA_CHANNEL_1, sizeof(led_data) );LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_1);LL_SPI_EnableDMAReq_TX(SPI1); // Enable SPI TX DMA request, will start sending data inmediatelywhile(!LL_DMA_IsActiveFlag_TC1(DMA1) && LL_SPI_IsActiveFlag_BSY(SPI1)); // Wait until DMA and SPI are doneLL_SPI_DisableDMAReq_TX(SPI1); // Disable DMALL_DMA_ClearFlag_TC1(DMA1);LL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_1);}int main(void){init_();send_led_data();while(1);}

author: John Celo
author_rank: Regular Contributor
timestamp: June 19, 2024, 03:36:15 pm
content: Yes, i had gotten DMA and other features work on 16pin version with no issues, but couldn't get it to work for 8pin version (probably my mistake) and I had time pressure to make a gift for my mom in time, so I knew that bigbanging is the most surefire way to make it work, since the chip is basically only used to drive the neopixels and no other interupts should be firing (maybe some HAL timer thing for delay once every 1ms?).Either way, it all works great! Thanks for advice!I'll order a spare rp2040 and turn it into a signal 16ch 100mhz analyzer, hopefully that will enable to analyze timings of various digital signals (to make sure code works exactly as I think it does)

author: DavidAlfa
author_rank: Super Contributor
timestamp: June 19, 2024, 08:59:10 pm
content: Probably due wrong pins assigned in the option bits, or IOMUX not configured?Try with PA1 and PA3, they aren't multiplexed and should work straight away.Code:LL_GPIO_Init(GPIOA, &(LL_GPIO_InitTypeDef){ LL_GPIO_PIN_1, LL_GPIO_MODE_ALTERNATE, LL_GPIO_SPEED_FREQ_VERY_HIGH, LL_GPIO_OUTPUT_PUSHPULL, LL_GPIO_PULL_NO, LL_GPIO_AF0_SPI1 }); // PA1 = SCKLL_GPIO_Init(GPIOA, &(LL_GPIO_InitTypeDef){ LL_GPIO_PIN_3, LL_GPIO_MODE_ALTERNATE, LL_GPIO_SPEED_FREQ_VERY_HIGH, LL_GPIO_OUTPUT_PUSHPULL, LL_GPIO_PULL_NO, LL_GPIO_AF10_SPI1 }); // PA3 = MOSI

author: NICHTEINSTEIN
author_rank: Newbie
timestamp: June 26, 2024, 06:59:13 am
content: Hi all!I want to use COMP as trigger for IC in TIM. The reference manual in COMP capture described that:"The outputs can also be internally connected to the inputs of various timers for the following purposes:* When the brake input is connected, the emergency shutdown of the PWM signal* Cycle-by-cycle current control using OCREF_CLR input* Input capture for timing measurements"But I can't find what registers must be configured in the right way. As a workaround, I can catch the capture register in an interrupt handler but it is not the best way for signal measI will be very grateful for your help

author: rosenrot
author_rank: Newbie
timestamp: June 29, 2024, 04:12:56 pm
content: I ordered a "dev-board" with the PY32F002A on it from Aliexpress and I expected it to have a bootloader installed but I tried several combinations with PyISP and UART and none worked so far for me.Maybe someone here has experience with this board already and could give me a hint?

author: DavidAlfa
author_rank: Super Contributor
timestamp: June 29, 2024, 10:05:33 pm
content: The bootloader is embedded into the mcu and can't be changed.To enable it, join PB6/Boot0 and 3v3.Then connect the uart as follows:- Rx to PA2- Tx to PA3Power it on, puyaISP should work.If not working, try reversing Tx/Rx as this is a common mistake.Remember this device has no USB, it's only for power.

author: rosenrot
author_rank: Newbie
timestamp: July 04, 2024, 07:14:18 pm
content: Quote from: DavidAlfa on June 29, 2024, 10:05:33 pmThanks a lot. That worked.Is it correct that the py32f002a has one DMA (LL_DMA_CHANNEL_1) that can be used and not more?

author: DavidAlfa
author_rank: Super Contributor
timestamp: July 04, 2024, 11:47:36 pm
content: It doesn't have DMA on the paper, but it actually has the full features from the py32f030, so 3 channels.

author: CheapHillbilly
author_rank: Newbie
timestamp: July 05, 2024, 09:56:55 pm
content: Hey people, I am trying to find info about these chips by people who have messed around with them. So seems like I found the right thread.I will read this entire thread to answer some of my own questions, but was wondering a few things.Would you who have worked with this chip recommend it as a good replacement chip for any general purpose mcu needs?At 1/10th of an arduino IC cost with similar storage and memory capabilities and faster processing speed, I am considering ordering 100 of these and completely switching any of my basic MCU needs to this one. Why? I can order 100 for about $12. Would never need to buy another microcontroller for a project.Things I would use these for would be basic sensor nodes, battery powered devices, etc.I am fairly experienced with PCB design and soldering tiny SMD parts so thats no issue for me either assembly wise.I have not done any ARM programming, have exclusively worked with arduino (dev boards and bare IC), pi pico, and esp modules.I know the STlink v-2 can be used to program stm32 chips, is there a similar affordable cost programmer that can be used on these?Thanks. Will read entire thread when I get the chance.

author: prosper
author_rank: Regular Contributor
timestamp: July 07, 2024, 03:37:17 am
content: only you can answer that.You have a HUGE safety net with arduino. Massive support community, vetted documentation, and example code of well, everything. With all the available libraries, you basically don't have to know what you're doing in order to get a working project. That safety net doesn't exist with these chips.Personally, I use a ton of these and other 10c Chinese chips, but mainly just for trivial applications. For anything much more complicated, I lean towards STM32F0/G0. They're almost as cheap, especially when you factor in shipping costs. And they eliminate a whole slew of potential unknowns to troubleshoot when things need work. And as a plus, its relatively easy to port known working code over to one of these Chinese MCUs.

author: CheapHillbilly
author_rank: Newbie
timestamp: July 08, 2024, 03:57:53 pm
content: Thanks for the reply. I have read most of whats been posted here and have ordered a couple dev boards and an stlink programmer to play around with and see for myself.I can see these chips being useful where i dont want to use a regular arduino, etc. For example 10 small battery powered sensors, etc.I think i will also get some stm dev boards and get more familiarised with that line of microcontrollers. Most of the devices I have been building have been focused on low power and seems like stm excels at that.

author: prosper
author_rank: Regular Contributor
timestamp: July 08, 2024, 06:30:15 pm
content: It's been my experience with these MCU's that they're a little 'wobbly' about which programmers and software they'll work with. You may or may not be able to use an stlink programmer. I've had mixed luck with DAPLink programmers - some work, some don't. JLink seems to be the most reliable option I've tried.As to software - openocd has no support for py32's, and the 'stlink' software likewise won't work. PyOCD does work, as does probe-rs and JLink. I think blackmagic recently added support to the blackmagic probe as well, but I haven't been able to get it working.

author: Pixie dust
author_rank: Contributor
timestamp: July 09, 2024, 12:56:51 pm
content: My DAP debugger is connected to the PY32F003. When I debug the code with the debugger it is all fine. When I use the debugger just to flash the PY32F003 the code works unreliable. Both instances with the same hardware and DAP debugger connected. What do I miss here ?

author: prosper
author_rank: Regular Contributor
timestamp: July 09, 2024, 02:53:11 pm
content: try a different debugger. Make sure you're working at 3V3 (unless your debugger uses 5V IO (rare) ). Make sure all our software is up to date.

author: Pixie dust
author_rank: Contributor
timestamp: July 09, 2024, 03:56:25 pm
content: The problem is when i use the debugger running the code it works fine. If I use the same debugger/ hardware and software to flash the part only it runs jittery. So it is like the debugger load some registers which have a positive impact on the behavior of the device. I have just no idea what and were it alters the code.

author: ataradov
author_rank: Super Contributor
timestamp: July 09, 2024, 04:09:12 pm
content: What is "jittery" exactly? Debugger should not affect the system that way. Debuggers may prevent the system from going into deep sleep modes, but if you are not using those, then there should be no difference.Another thing to check is that you are setting correct flash wait states (or latency how they call it).

author: Pixie dust
author_rank: Contributor
timestamp: July 09, 2024, 04:19:42 pm
content: I got the RTC IWDG and LPTIM to stop when hitting a breakpoint. When I remove all breakpoints everything runs fine while debugging. When I stop debugging and use the debugger only to flash the part the code hangs so now and then. It does not seem to recover which is strange as the watchdog is enabled. The software and hardware i do not change at all. So its the debugger which makes some difference.Here the debugger config file:// File: PY32F003xx.dbgconf// Version: 1.0.0// <<< Use Configuration Wizard in Context Menu >>>// <h> Debug MCU configuration register (DBGMCU_CR)// <o.1> DBG_STOPDebug stop mode// </h>DbgMCU_CR = 0x00000002;// <h> Debug MCU APB freeze1 register (DBG_APB_FZ1)//Reserved bits must be kept at reset value// <o.31> DBG_LPTIM_STOPLPTIM stopped when core is halted// <o.12> DBG_IWDG_STOPIndependent watchdog stopped when core is halted// <o.11> DBG_WWDG_STOPWindow watchdog stopped when core is halted// <o.10> DBG_RTC_STOPRTC stopped when core is halted// <o.1> DBG_TIM3_STOPTIM3 counter stopped when core is halted// </h>DbgMCU_APB_Fz1 = 0x80001400;// <h> Debug MCU APB freeze2 register (DBG_APB_FZ2)//Reserved bits must be kept at reset value// <o.18> DBG_TIM17_STOPTIM17 counter stopped when core is halted// <o.17> DBG_TIM16_STOPTIM16 counter stopped when core is halted// <o.15> DBG_TIM14_STOPTIM14 counter stopped when core is halted// <o.11> DBG_TIM1_STOPTIM1 counter stopped when core is halted// </h>DbgMCU_APB_Fz2 = 0x00000000;// <<< end of configuration section >>>;

author: Pixie dust
author_rank: Contributor
timestamp: July 09, 2024, 04:24:12 pm
content: Then I thought if I load these debug registers with the same values as the debugger config file maybe it solves the problem but that did not help as well. Something like this:int main(void){ DBGMCU->CR=0x00000002;DBGMCU->APBFZ1=0x80001400;DBGMCU->APBFZ2=0;

author: ataradov
author_rank: Super Contributor
timestamp: July 09, 2024, 04:29:57 pm
content: When the device is in a hanged state, attach the debugger without reprogramming or resetting and see where it is stuck. The way to do this depends on the software you are using.

author: Pixie dust
author_rank: Contributor
timestamp: July 09, 2024, 04:32:13 pm
content: I was thinking about that as well. But I use uvision and it does not look that it allows you to do that without either resetting it or going through a program cycle.

author: ataradov
author_rank: Super Contributor
timestamp: July 09, 2024, 04:34:55 pm
content: Of course it can do this. Any IDE that is worth using should be able to do this, and ARM's own can do that for sure.https://developer.arm.com/documentation/ka003020/latest/

author: Pixie dust
author_rank: Contributor
timestamp: July 09, 2024, 05:23:57 pm
content: Thank you for this advice. Was not aware of this. Super

author: Pixie dust
author_rank: Contributor
timestamp: July 10, 2024, 09:49:59 pm
content: Whatever I tried the moment I disconnect the debugger the same code on the same hardware seems to work differently. It has to do with the stop mode and the LSI clock which seems to cause some synchronization problem. Then I found out that you can enable the debugger in software without it being connected. This solved my problem as I got the same behavior with or without debugger connected. Here the 2 lines of code which made it work:// simulate as if debugger is ON by applying clock and enable stop modeRCC->APBENR1 |=0x08000000; // apply clock to debuggerLL_DBGMCU_EnableDBGStopMode();

author: amwales
author_rank: Regular Contributor
timestamp: October 25, 2024, 01:54:36 pm
content: I'm late to the party but thought someone might find these useful, they are mostly 0805 footprint parts.tssop20 breakouts with ch340 usb/serial.https://github.com/amwales-888/py32f002bf15p6https://github.com/amwales-888/py32f030f18p6I chose quite a beefy 600ma 5v-3.3v LDO,I'm fairly new to all this so please be kind, feedback appreciated.I haven't tested them with a oscillator connected, just used the internal but they should be fine.

author: John Celo
author_rank: Regular Contributor
timestamp: October 25, 2024, 04:09:56 pm
content: Quote from: CheapHillbilly on July 05, 2024, 09:56:55 pmWhile I love these chips, once you do a complete design and not just a breakout board, the cheapness is offset by PCB fabrication and shipping costs,and other components. And at that point it doesn't seem to make sense or make that much difference to overall cost to go for MCUs that cheap.If you only want to spam a lot of breakout boards, then sure, 11cents per MCU, 20cents per 50x20mm breakout PCB, if you order 200 boards (half of the cost is shipping from JLCPCB). It seems like to fully benefit from price of these MCUs in volume, you need to be in china such that you don't pay the shipping costs and can get PCBs made even cheaper in volume.STM32G030 in tssop20 is 25cents more than these, but is also significantly faster chip with more memory and so on.You need to be chasing very slim margins for these chips to make sense or use multiple of these in a single design.If you make a product with good amount of value add, going for these chips over stm32 just doesn't seem like a safe bet.And to make a product with low margins, you need to be in china to pull that off successfully anyway as far as I can tell.

author: positron96
author_rank: Newbie
timestamp: November 19, 2024, 02:34:53 pm
content: Hi all, just wanted to notify others that Black magic probe added support for PY32 this May (https://github.com/blackmagic-debug/blackmagic/pull/1817) and it worked for me quite well. I was able to flash the IC it with no problem.Also, just wanted to add to the previous discussion of PY32 pros and cons that PY32 is one of the few 5V-capable ARM cores, so it allows you to power your MCU directly from Li-Ion battery for example, in case your PCB is very constrained in space and/or partcount.

author: andrvisht
author_rank: Contributor
timestamp: November 27, 2024, 10:26:05 am
content: Hi.I am looking for a solution on how to select the port I need on pins 3, 4 and 9.There is no mention in the documentation.There is no datasheet on your link, I have version 0.8 and it does not contain an answer.It turns out that you are the only one who knows anything about this,can you share the information?Thanks.

author: ataradov
author_rank: Super Contributor
timestamp: November 27, 2024, 02:48:45 pm
content: You just configure the function you need and leave the other one alone. They bonded two pads to the same pin, so it looks like you have connected two pins together. But if you don't use one of the pins, it will remain an input and won't affect operation of the other pin.

author: DavidAlfa
author_rank: Super Contributor
timestamp: November 27, 2024, 03:04:56 pm
content: Of course there're datasheets and reference manuals... check the Google Drive link.I'm attaching them here, too.The pins AF settings are very well explained in the datasheet.

author: andrvisht
author_rank: Contributor
timestamp: November 27, 2024, 04:05:40 pm
content: ataradovYes, it seems logical, is this your personal experience or did I somehow miss a line in the datasheet where it says this?in STM32C011JxM several ports are also combined on one pin, but there the port is selected by setting SYSCFG. Therefore, in this target I expected something similar.DavidAlfaThanks for the documentation, I have these versions, but it's never superfluous.There are no questions about alternative functions, everything is really well described there. The only question is in combining ports.

author: andrvisht
author_rank: Contributor
timestamp: November 27, 2024, 04:18:29 pm
content: The answer is found in the Chinese version of the datasheet.Translation difficulties.The picture shows identical parts of the translated and original datasheets.The phrase under marker 4 is translated asTwo IO ports are connected to the same pin. Only one of them can be used at the same time, and the other one must be configured in analog mode (MODEy[1:0] is 0B11).I have attached the original datasheet.Thanks for pointing me in the right direction.

author: ataradov
author_rank: Super Contributor
timestamp: November 27, 2024, 04:38:38 pm
content: Quote from: andrvisht on November 27, 2024, 04:05:40 pmI don't remember where I've taken that from. But I do remember this because I also remember ST parts where pins are multiplexed internally and I think PY32 solution is way better. You get much more flexibility and instant firmware compatibility.

author: DavidAlfa
author_rank: Super Contributor
timestamp: November 28, 2024, 05:12:02 pm
content: Nice to know!Indeed, that part is missing in the english datasheet!

author: amwales
author_rank: Regular Contributor
timestamp: November 29, 2024, 03:34:26 pm
content: I am having trouble running a PY32F030F18P6TU at 48Mhz with LL_RCC_SYSCLK_DIV_1I am using the internal oscillator and powering with 3.3v ( single 0.1uf cap right between VCC and VSS pins ).The following code works, I can step the debugger to the end of the functionCode:static void APP_SystemClockConfig(void){LL_UTILS_ClkInitTypeDef UTILS_ClkInitStruct;//Enable internal high speedLL_RCC_HSI_Enable();//Set to 24MHz, the frequency can be fine-tuned here, and the higher the value, the faster the frequencyLL_RCC_HSI_SetCalibFreq(LL_RCC_HSICALIBRATION_24MHz);//Wait for stabilizationwhile (LL_RCC_HSI_IsReady() != 1);//AHB does not divide the frequencyUTILS_ClkInitStruct.AHBCLKDivider = LL_RCC_SYSCLK_DIV_2;//APB is not crossoverUTILS_ClkInitStruct.APB1CLKDivider = LL_RCC_APB1_DIV_1;//Set the system clock source to PLL+HSI, note the method nameLL_PLL_ConfigSystemClock_HSI(&UTILS_ClkInitStruct);//Update the settings for SysTickLL_InitTick(48000000U, 1000U);}The following hangs after calling LL_PLL_ConfigSystemClock_HSI()Code:static void APP_SystemClockConfig(void){LL_UTILS_ClkInitTypeDef UTILS_ClkInitStruct;//Enable internal high speedLL_RCC_HSI_Enable();//Set to 24MHz, the frequency can be fine-tuned here, and the higher the value, the faster the frequencyLL_RCC_HSI_SetCalibFreq(LL_RCC_HSICALIBRATION_24MHz);//Wait for stabilizationwhile (LL_RCC_HSI_IsReady() != 1);//AHB does not divide the frequencyUTILS_ClkInitStruct.AHBCLKDivider = LL_RCC_SYSCLK_DIV_1;//APB is not crossoverUTILS_ClkInitStruct.APB1CLKDivider = LL_RCC_APB1_DIV_1;//Set the system clock source to PLL+HSI, note the method nameLL_PLL_ConfigSystemClock_HSI(&UTILS_ClkInitStruct);//Update the settings for SysTickLL_InitTick(48000000U, 1000U);}Something obvious?Any ideas?

author: DavidAlfa
author_rank: Super Contributor
timestamp: November 29, 2024, 06:41:44 pm
content: Will post some code when I arrive at home

author: DavidAlfa
author_rank: Super Contributor
timestamp: November 30, 2024, 01:46:22 am
content: This workls for me, it's basically the same thing as yours. Try adding a 10uF cap in VDD pin...Code:void SystemClockConfig(void){LL_UTILS_ClkInitTypeDef ClkInit = { LL_RCC_SYSCLK_DIV_1, LL_RCC_APB1_DIV_1 };LL_RCC_HSI_Enable();LL_RCC_HSI_SetCalibFreq(LL_RCC_HSICALIBRATION_24MHz);while (LL_RCC_HSI_IsReady() != 1);LL_PLL_ConfigSystemClock_HSI(&ClkInit);SysTick_Config(48000);NVIC_SetPriority(SysTick_IRQn, 0);}

author: MBrahim
author_rank: Contributor
timestamp: November 30, 2024, 06:41:13 am
content: Quote from: John Celo on April 23, 2024, 01:34:10 amWhat are the problems that met you, I'm struggling with the I2C (as a slave), the master sees it, and know the address but if i tried to send or recieve it stuck right there, the whole bus, the pins sometimes pulled to ground it drove me insane!!.

author: amwales
author_rank: Regular Contributor
timestamp: November 30, 2024, 11:36:07 am
content: I'll try the code change first, then try adding the cap when I get a chance at my workbench.At a cursory look, I didn't find anywhere in the datasheet the voltage requirements for running at different clock speeds, are you running the same chip at 3.3v with those clock settings?As a note, It could also be the debugger ( JLINK clone ), I verified the hang by adding a breakpoint AFTER the code and it got stuck ( never reached the breakpoint ) when running with the LL_RCC_SYSCLK_DIV_1.Will report back with success or failure, thankyou so much for the effort.

author: amwales
author_rank: Regular Contributor
timestamp: November 30, 2024, 12:17:35 pm
content: Thanks DavidAlfa, I really needed the reassurance that this did actually work.Ok, looks like it was me being an idiot.My bad, I added your code and it didn't work and then I noticed in the file PY32F030x8\system_py32f0xx.c had been changed.I had added the line #define HSI_VALUE 2400000000U ( I know its a system file and I should have set it in the target options for the compiler but when I made the change I meant it to be temporary and just forgot )I removed the line I had added and left it using the default 8000000U#if !defined (HSI_VALUE)#define HSI_VALUE 8000000U /*!< Value of the Internal oscillator in Hz*/#endif /* HSI_VALUE */Then your code worked.I Added my old code back and that worked too.So for future reference NEVER fuck around with system files, something I have berated other for in the past and didn't learn the lesson myself.

author: DavidAlfa
author_rank: Super Contributor
timestamp: November 30, 2024, 01:02:34 pm
content: Well, that showed a bug, I realized LL_RCC_HSI_SetCalibFreq would never update SystemCoreClock variable, so it was kept at 8Mhz.The PLL function would effectively update it, but not when just raising HSI to >8MHz.https://github.com/IOsetting/py32f0-template/pull/51

author: yabba235
author_rank: Contributor
timestamp: December 05, 2024, 01:08:19 pm
content: Hi !I built a circuit from this project:https://github.com/flaviut/fan-controllerI have a quick question - how do I program this unit? Could someone compile a bin file for this processor? I can't do it. I have access to a stlinkv2 programmer - will I be able to program this circuit with it? I know I should have a seagar j-link but it costs a fortune and I would only need it once.The programming description is for someone who wants to play with these processors - I don't - I just want to silence my Qidi printer

author: DavidAlfa
author_rank: Super Contributor
timestamp: December 05, 2024, 04:39:44 pm
content: You can convert the ST-Link into JLink Edu, then program using JFLash. I attached everythinghere.Attaching the compiled binary.

author: Pixie dust
author_rank: Contributor
timestamp: December 05, 2024, 08:28:06 pm
content: When I was translating a manual from Wireless Shenzhen regarding an off line programmer they mentioned the error you found.."Note that depending on the chip (030/003) itself has defects. When the read protection is turned on, the user program needs to perform "interrupt vector table offset operation".Whether this operation is performed manually depends on the development packFile versions are considered at your own discretion."Strange that there is never an errata sheet published or on update of the data sheets.

author: yabba235
author_rank: Contributor
timestamp: December 05, 2024, 08:28:38 pm
content: Quote from: DavidAlfa on December 05, 2024, 04:39:44 pmThank you - you save my live !P.S.I can't convert stlink to Jlink: wrong FW error-I trying from .32 to .45 version without luck.But thanks for fw file.

author: DavidAlfa
author_rank: Super Contributor
timestamp: December 06, 2024, 01:25:54 am
content: Probably a bad stlink clone.Do you have a stm32f103c8 / cb somewhere?(Commonly found in bluepill boards)If so, you can flash the bootloader, load the official stlink fw and replace the one in the stlink.https://github.com/Krakenw/Stlink-BootloadersUse v2.1

author: yabba235
author_rank: Contributor
timestamp: December 06, 2024, 05:39:34 am
content: Quote from: DavidAlfa on December 06, 2024, 01:25:54 amI dont't think is clone:

author: DavidAlfa
author_rank: Super Contributor
timestamp: December 06, 2024, 08:54:47 am
content: Do you have a bluepill? Then you can flash it with jlink ob firmware, seehere.nRST PA0SWCLK PA5SWDIO PA7Pins can be connected directly to the mcu to be programmed.

author: positron96
author_rank: Newbie
timestamp: December 18, 2024, 01:53:36 pm
content: Hello again. Does anybody know where the GPIO speed is described in the datasheet or RM? There is a GPIOx_OSPEEDR register with 4 possible speed values, that is very similar to STM32, but STM32 datasheet has a table with frequencies and rise/fall timings. There is no such table for PY32 (at least I couldn't find any)

author: ataradov
author_rank: Super Contributor
timestamp: December 18, 2024, 03:20:18 pm
content: It is not described anywhere, and likely not characterized past a few basic tests you can do yourself as well.There is no magic, cost reduction comes at the expense of things like this.For the price of the device, I'm pleasantly surprised by the amount information they do publish.

author: positron96
author_rank: Newbie
timestamp: January 13, 2025, 01:14:16 pm
content: Hi everyone. In the middle of this thread there is a mention of the PlatformIO framework being developed for PY32. I couldn't find the results of that development, so I made my own:https://github.com/positron96/platform-py32f0It has HAL and LL drivers, no Arduino core.At the moment it was only tested with PY32F030 and blackmagicprobe debugger, but the project contains everything fromhttps://github.com/IOsetting/py32f0-templateproject, so using it with other MCUs should similarly easy.

author: DavidAlfa
author_rank: Super Contributor
timestamp: January 13, 2025, 02:14:58 pm
content: Nice work!I really tried VSCode but I find extremely awkard, also lacking debugging support.Any way to debug SWO or monitor variables in real time?

author: positron96
author_rank: Newbie
timestamp: January 17, 2025, 11:44:44 pm
content: QuoteNo, I don't think so. It relies on GDB under the hood, which, afaik, does not do any of that.

author: Sacodepatatas
author_rank: Regular Contributor
timestamp: January 30, 2025, 06:36:37 pm
content: What happened to the PY32F002, PY32F003 and PY32F030 parts? They're no longer listed in the puyasemi web. Are they discontinued?

author: PCB.Wiz
author_rank: Super Contributor
timestamp: January 30, 2025, 09:44:49 pm
content: Quote from: Sacodepatatas on January 30, 2025, 06:36:37 pmThat may be Chinese / English web page creepage. The /en/ pages have fewer parts listed.Their 'value' parts show up here :https://www.puyasemi.com/py32_xilie.html

author: DavidAlfa
author_rank: Super Contributor
timestamp: January 31, 2025, 12:04:16 am
content: lcsc has 50K+ in stock so it seems alive and healthy

author: Sacodepatatas
author_rank: Regular Contributor
timestamp: January 31, 2025, 10:36:58 am
content: Yes, I've seen that lcsc has 50K of F6 and 22K of U6 (among other references having 7K, 2K...) anyhow it seems a bit odd that even the chinese web doesn't list resources for the 002A (there's plenty of resources out there besides the official site, i know). Anyways I'm going to make a local mirror of the chinese web. Thanks.

author: DavidAlfa
author_rank: Super Contributor
timestamp: January 31, 2025, 12:12:15 pm
content: Definitely there:https://www.puyasemi.com/download.html?keywords=Py32f002Edit: And here:https://www.puyasemi.com/py32f002bxilie429/2711.html

author: PCB.Wiz
author_rank: Super Contributor
timestamp: January 31, 2025, 07:23:00 pm
content: Quote from: Sacodepatatas on January 31, 2025, 10:36:58 am? The link I gave above works for 002 even gives English download links, and they are new revisions too.PY32F002B Datasheet 1.5 2025.01.26PY32F002B Reference Manual 1.0 2025.01.26

author: PCB.Wiz
author_rank: Super Contributor
timestamp: January 31, 2025, 07:25:23 pm
content: Quote from: DavidAlfa on January 31, 2025, 12:12:15 pmI wonder how the new PY32F002B-Cdiffers ?

author: Sacodepatatas
author_rank: Regular Contributor
timestamp: February 01, 2025, 04:53:51 pm
content: Quote from: PCB.Wiz on January 31, 2025, 07:25:23 pmAnd also the new and very original "PuyaCubeProgrammer" 😅😅😅, when I leave the hospital I'll try if it works with the st-link (it is supposed to work with J-link or Py-link).

author: DavidAlfa
author_rank: Super Contributor
timestamp: February 01, 2025, 08:10:53 pm
content: Quote from: Sacodepatatas on February 01, 2025, 04:53:51 pmGet well soon Sacodepatatas!Indeed, very original programmer name, they cloned the GUI entirely!Also, it seems the PY32F002A was completely wiped off their site?

author: voltsandjolts
author_rank: Unknown
timestamp: February 01, 2025, 09:17:42 pm
content: I wonder if Puya see the irony on that screenshot...'Technology Innovator' it says in the top left, whereas the GUI is a total ripoff copy

author: DavidAlfa
author_rank: Super Contributor
timestamp: February 01, 2025, 10:07:44 pm
content: I have no problem with that as long it's their own work, with a "similar" gui

author: ataradov
author_rank: Super Contributor
timestamp: February 01, 2025, 10:07:47 pm
content: Copying UI is a very smart move, it simplifies the transition and lets you gain new customers quickly. Same goes for register sets. I don't really see a problem here. There is no need to "innovate" a UI of the programmer in this case.Plus they make a ton of other devices outside of MCUs and those are not a copy of anything.

author: voltsandjolts
author_rank: Unknown
timestamp: February 02, 2025, 12:29:53 pm
content: Copying the programming software, down to the layout and even the colour scheme, is just lame. It would have been smarter to copy the pinouts and have 100% pin compatability with stm32. That would have been much more useful by allowing many existing cost crictical designs to switch quickly.

author: ataradov
author_rank: Super Contributor
timestamp: February 02, 2025, 04:53:55 pm
content: Quote from: voltsandjolts on February 02, 2025, 12:29:53 pmIt just makes sure your new customers already familiar with the tools.Quote from: voltsandjolts on February 02, 2025, 12:29:53 pmThat's what other vendors do that actually make compatible devices. PY32 have no direct equivalents in STM32 world, ST does not bother with really low pin count devices.There is now STM32G03x, but those devices were released at about the same time as PY32 devices, so they did not have a chance to make them pin-compatible.

author: prosper
author_rank: Regular Contributor
timestamp: February 04, 2025, 01:36:30 am
content: Quote from: DavidAlfa on January 13, 2025, 02:14:58 pmI dont think the M0 *has* SWO. Otherwise, check out cortex debug for vscode. it does breakpoint debugging, memory ( and register, if you have an SVD file ) examine.I set up a quick 'template' project with my VSCode configs here:https://github.com/prosper00/py32-vscode

author: andrvisht
author_rank: Contributor
timestamp: February 13, 2025, 02:06:38 pm
content: Need help again with PY32F003I'm trying to configure EXTI so that RTC Alarm wakes up the controller on event.But the processor refuses to respond to RTC event.Code:RTC_ConfigAlarm(5); // Alarm on 5 sec (RTC_ALARM = RTC_CNT + 5)EXTI->IMR &= ~EXTI_IMR_IM19; // RTC Interrupt DisableEXTI->EMR |= EXTI_EMR_EM19; // RTC Event Enablewhile (1) {LED_OFF;SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;__WFE();// and we can't get here anymoreSCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;LED_ON;Delay_ms(100);}

author: DavidAlfa
author_rank: Super Contributor
timestamp: February 13, 2025, 04:44:45 pm
content: Try interrupt instead?

author: andrvisht
author_rank: Contributor
timestamp: February 13, 2025, 05:11:18 pm
content: It works by interrupt.Moreover, setting or resetting the bitCode:EXTI->IMR = EXTI_IMR_IM19;does not affect its behavior in any way.And I can't understand this either...Since RTC has a separate vector, what does channel 19 EXTI control?And if this is it, then why the interrupt enable bitCode:RTC->CRH = RTC_CRH_ALRIE;Well, the main question is how to configure by event ...PS:Can someone explain how NVIC is arranged in the event area?From the description of the core, we can conclude that there is one event input, which probably comes from the EXTI controller.And then the 19th line of the RTC should be connected to it.But what is this line ....It is mentioned only in the description of EXTI, there is not a word about this line in the RTC module itself.There are no explanations in the figure either.But, what is interesting ... after all, WFE expects an event bit.This bit, apparently, is set after the execution of the ISR, or in the presence of an external event.The problem is apparently that this line either does not exist, or it is prohibited.This means that there are some conditions under which it passes from the RTC to the kernel event line ...For now such thoughts...

author: DavidAlfa
author_rank: Super Contributor
timestamp: February 13, 2025, 08:56:01 pm
content: Try following an existing example:https://github.com/IOsetting/py32f0-template/blob/289ffc80de237c46171635b0f03b76b1a7f765be/Examples/PY32F0xx/LL/PWR/PWR_Stop/main.c#L58

author: andrvisht
author_rank: Contributor
timestamp: February 13, 2025, 10:51:40 pm
content: This is a good example, and I checked the operation with the button.The point is that with GPIO everything works correctly,but the EXTI lines for GPIO have their own handlers in NVIC.And in the case of RTC and LPTIM, the handlers have their own dedicated addresses,and the lines 19 and 29 themselves go to God knows where.Since there is no handler for these channels.And in the case of RTC and LPTIM, if their interrupts are disabled, then the events are not issued,or do not get where they shouldAnd since the state of bits 19 and 29 IMR does not affect the operation of the interrupt handler, I assume that it wakes up not from these channels at all, but from NVIC.

author: DavidAlfa
author_rank: Super Contributor
timestamp: February 14, 2025, 04:37:27 am
content: Have a look at the official library examples, maybe you find something useful:https://www.puyasemi.com/download_path/%E5%BA%93%E5%87%BD%E6%95%B0%E4%B8%8E%E4%BE%8B%E7%A8%8B/MCU%20%E5%BE%AE%E5%A4%84%E7%90%86%E5%99%A8/PY32F002B_Firmware_V1.1.4.rar

author: andrvisht
author_rank: Contributor
timestamp: February 14, 2025, 09:49:58 am
content: Yeah, thanks.I have a similar selection, but earlier versions.At the moment I managed to get the RTC to react to the event, but for this I need to disable the interrupt itself in NVIC.Probably the signal which according to the manual is called direct connection is an interrupt signal.As for IMR, these bits still do nothing.In addition, the role of the SAVEOPEND bit in the kernel is still unclear.I continue to investigate.

author: DavidAlfa
author_rank: Super Contributor
timestamp: February 14, 2025, 01:24:52 pm
content: I'd check the ARM M0+ core docs, that part is almost never described in RMs or datasheets.

author: andrvisht
author_rank: Contributor
timestamp: February 16, 2025, 10:28:19 pm
content: results of my experiments.In order for channels 29 and 19 to be connected to EXTI, you need to set the interrupt enable bits for these modules.Then, the enable is controlled by EMR and IMR.regarding SEVONPEND:setting it will allow waking up even from disabled interrupts of NVIC channels, provided that WFE is used.In this case, you need to monitor the reset of the flags of these channels manually NVIC_ClearPendingIRQ(), since only the transition from 0 to 1 of this bit initiates the wake-up event.The functionality itself is rather questionable, it would be easier to configure it by event, but ... as it is.Thanks for your help.

author: gerbay
author_rank: Regular Contributor
timestamp: April 19, 2025, 05:07:17 pm
content: what is the real difference between PY32F002Aand PY32F002B?

author: __george__
author_rank: Contributor
timestamp: April 19, 2025, 08:47:35 pm
content: Quote from: gerbay on April 19, 2025, 05:07:17 pmAFAIK the main difference is in the clocks, the PY32F002B has an LSE clock of 32.768 KHz and the PY32F002A has an HSE clock of 4-24 MHz. I read about this a while ago in another forum:https://www.stm32duino.com/viewtopic.php?t=1848&start=70I am not sure if this is the reason, but the PY32F002B has less than double power consumption in the stop mode as well. PY32F002B has 1.5uA compared to the 4.5uA of PY32F002B.

author: Sacodepatatas
author_rank: Regular Contributor
timestamp: April 19, 2025, 11:31:43 pm
content: Quote from: __george__ on April 19, 2025, 08:47:35 pmThey have different silicons inside. Peripherals are similar but not exactly the same. The 002A officially has not DMA but because it has the same die as the 030, then the DMA exists and can be used. While the 002B has the same die as the 020 so it lacks of DMA completely.

author: positron96
author_rank: Newbie
timestamp: June 17, 2025, 11:09:13 pm
content: Hello everyone!I am trying to do a DMA transfer from RAM to GPIO (specifically, to GPIOA->BSRR), and cannot make it work unfortunately. The same code that writes to TIM1->ARR works fine, so there is something about GPIO specifically. The MCU is PY32F003. Has anybody tried/succeed at this?I am starting to suspect that the chip can't do this, as there are no mentions of GPIO in DMA block diagram in Reference Manual, while it is present on same diagram for STM32F030, which I assume is the closest ST MCU (see picture).

author: DavidAlfa
author_rank: Super Contributor
timestamp: June 18, 2025, 02:26:16 pm
content: Cortex-M0 (STM32F0x) and Cortex-M0+ (STM32G0x, PY32F0xx) are quite different in some aspects. The closest would be a STM32G030.The GPIO is one of them, in CM0+ it's connected straight to the CPU through IOPORT to reduce latency, but the tradeoff is that nothing else can access it.See:https://community.st.com/t5/stm32-mcus-products/stm32g030-dma-to-gpio-bsrr-bus-error/td-p/291235What you can do if you're only trying to interface one pin: Use a timer in PWM mode.Configure it to be extremely fast, i.e. prescaler=0, overflow=1.Use DMA to write to CCRx, writing 0 or 2 will set the PWM to 100 or 0%, turning the pin fully on / off.Writing to the entire port will be much harder, if not impossible.Code:const LL_TIM_InitTypeDef TimInit = { 24999, LL_TIM_COUNTERMODE_UP, 1, LL_TIM_CLOCKDIVISION_DIV1, 249 };const LL_TIM_OC_InitTypeDef PWM_cfg = { LL_TIM_OCMODE_PWM2, LL_TIM_OCSTATE_DISABLE, LL_TIM_OCSTATE_ENABLE, 0, LL_TIM_OCPOLARITY_HIGH, LL_TIM_OCPOLARITY_HIGH, LL_TIM_OCIDLESTATE_LOW, LL_TIM_OCIDLESTATE_HIGH };const LL_TIM_BDTR_InitTypeDef BDTR_cfg = { LL_TIM_OSSR_DISABLE, LL_TIM_OSSI_DISABLE, LL_TIM_LOCKLEVEL_OFF, 0, LL_TIM_BREAK_DISABLE, LL_TIM_BREAK_POLARITY_HIGH, LL_TIM_AUTOMATICOUTPUT_DISABLE };const LL_GPIO_InitTypeDef PA0_PWM_cfg = { LL_GPIO_PIN_0, LL_GPIO_MODE_ALTERNATE, LL_GPIO_SPEED_FREQ_VERY_HIGH, LL_GPIO_OUTPUT_PUSHPULL, LL_GPIO_PULL_NO, LL_GPIO_AF14_TIM1 };const uint8_t PA0_PWM_data[] = { 0, 2, 0, 2, 0, 2 };const LL_DMA_InitTypeDef DMAInit = {.PeriphOrM2MSrcAddress = (uint32_t)&TIM1->CCR1,.MemoryOrM2MDstAddress = (uint32_t)PA0_PWM_data,.Direction = LL_DMA_DIRECTION_MEMORY_TO_PERIPH,.Mode = LL_DMA_MODE_CIRCULAR,.PeriphOrM2MSrcIncMode = LL_DMA_PERIPH_NOINCREMENT,.MemoryOrM2MDstIncMode = LL_DMA_MEMORY_INCREMENT,.PeriphOrM2MSrcDataSize = LL_DMA_PDATAALIGN_WORD,.MemoryOrM2MDstDataSize = LL_DMA_MDATAALIGN_BYTE,.NbData = sizeof(PA0_PWM_data)/sizeof(PA0_PWM_data),.Priority = LL_DMA_PRIORITY_HIGH,};void SystemClockConfig(void){LL_RCC_HSI_Enable();LL_RCC_HSI_SetCalibFreq(LL_RCC_HSICALIBRATION_24MHz);while (LL_RCC_HSI_IsReady() != 1);SysTick_Config(24000);NVIC_SetPriority(SysTick_IRQn, 0);}void PWMConfig(void){LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA);LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_DBGMCU);LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_TIM1 | LL_APB1_GRP2_PERIPH_SYSCFG);LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1);LL_DBGMCU_APB1_GRP2_FreezePeriph(LL_DBGMCU_APB1_GRP2_TIM1_STOP);LL_GPIO_Init(GPIOA, (LL_GPIO_InitTypeDef*)&PA0_PWM_cfg);LL_DMA_Init(DMA1, LL_DMA_CHANNEL_1, (LL_DMA_InitTypeDef*)&DMAInit);LL_SYSCFG_SetDMARemap_CH1(LL_SYSCFG_DMA_MAP_TIM1_UP);LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_1);LL_TIM_Init(TIM1, (LL_TIM_InitTypeDef*)&TimInit);LL_TIM_BDTR_Init(TIM1, (LL_TIM_BDTR_InitTypeDef*)&BDTR_cfg);LL_TIM_OC_Init(TIM1, LL_TIM_CHANNEL_CH1, (LL_TIM_OC_InitTypeDef*)&PWM_cfg);LL_TIM_EnableDMAReq_UPDATE(TIM1);LL_TIM_SetCounter(TIM1,0);LL_TIM_ClearFlag_UPDATE(TIM1);LL_TIM_EnableCounter(TIM1);LL_TIM_EnableAllOutputs(TIM1);}int main(void){SystemClockConfig();PWMConfig();while (1){}}

author: positron96
author_rank: Newbie
timestamp: June 18, 2025, 08:39:36 pm
content: Oh, thank you providing this info! And I was already considering moving from PY32 to G030...My goal is actually to generate PWM on more pins than timers can do, and not bother with carefully choosing maximum CC-capable pin subset. As you wrote, unfortunately it does not look like your suggestion can scale up to full port, which is my goal.

author: DavidAlfa
author_rank: Super Contributor
timestamp: June 18, 2025, 09:00:20 pm
content: You can use at least 10 pins as PWM, do you really need more?.Remember this MCU only has 3 DMA channels, thus you can't use 4 timers with DMA.Code:TIM1_CH1PA3TIM1_CH2PB3TIM1_CH3PA0TIM1_CH4PA1TIM3_CH1PA2TIM3_CH2PA5TIM3_CH3PA4TIM3_CH4PB1TIM14_CH1PA7TIM16_CH1PA6You can use DMA to update all the PWM channels of a timer (Burst mode), this triggers a defined number of transfers and updates all channels at once.This example updates Tim1 PWM channels 1, 2 and 3.Note that for burst mode to to work DMA should point to TIM1->DMAR.Then the timer routes the written data to the correct register (See LL_TIM_ConfigDMABurst).Code:const LL_TIM_InitTypeDef TimInit = { 92, LL_TIM_COUNTERMODE_UP, 255, LL_TIM_CLOCKDIVISION_DIV1, 16 }; // PWM freq = 24MHz / (92+1) / (255+1) = ~1KHz. Repetition counter=32, trigger DMA transfer at 1KHz/(16+1) = 59Hzconst LL_TIM_OC_InitTypeDef PWM_cfg = { LL_TIM_OCMODE_PWM2, LL_TIM_OCSTATE_DISABLE, LL_TIM_OCSTATE_ENABLE, 0, LL_TIM_OCPOLARITY_HIGH, LL_TIM_OCPOLARITY_HIGH, LL_TIM_OCIDLESTATE_LOW, LL_TIM_OCIDLESTATE_HIGH };const LL_TIM_BDTR_InitTypeDef BDTR_cfg = { LL_TIM_OSSR_DISABLE, LL_TIM_OSSI_DISABLE, LL_TIM_LOCKLEVEL_OFF, 0, LL_TIM_BREAK_DISABLE, LL_TIM_BREAK_POLARITY_HIGH, LL_TIM_AUTOMATICOUTPUT_DISABLE };const uint8_t led_data[] = {// G R B0,255,0, // red32,255,0, //64,255,0, //96,255,0, //128,255,0, //160,255,0, //192,255,0, //224,255,0, //255,255,0, // orange255,224,0, //255,192,0, //255,160,0, //255,128,0, //255,96,0, //255,64,0, //255,32,0, //255,0,0, // green255,0,32, //255,0,64, //255,0,96, //255,0,128, //255,0,160, //255,0,192, //255,0,224, //255,0,255, // cyan224,0,255, //192,0,255, //160,0,255, //128,0,255, //96,0,255, //64,0,255, //32,0,255, //0,0,255, // blue0,32,255, //0,64,255, //0,96,255, //0,128,255, //0,160,255, //0,192,255, //0,224,255, //0,255,255, // purple0,255,224, //0,255,192, //0,255,160, //0,255,128, //0,255,96, //0,255,64, //0,255,32, //};const LL_DMA_InitTypeDef DMAInit = { (uint32_t)&TIM1->DMAR, (uint32_t)led_data, LL_DMA_DIRECTION_MEMORY_TO_PERIPH, LL_DMA_MODE_CIRCULAR, LL_DMA_PERIPH_NOINCREMENT, LL_DMA_MEMORY_INCREMENT, LL_DMA_PDATAALIGN_WORD, LL_DMA_MDATAALIGN_BYTE, sizeof(led_data), LL_DMA_PRIORITY_HIGH };void PWMConfig(void){LL_GPIO_InitTypeDef gpio_init = {.Pin = LL_GPIO_PIN_0,.Mode = LL_GPIO_MODE_ALTERNATE,.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH,.OutputType = LL_GPIO_OUTPUT_PUSHPULL,.Pull = LL_GPIO_PULL_NO,.Alternate = LL_GPIO_AF14_TIM1,};LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA | LL_IOP_GRP1_PERIPH_GPIOB);LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_DBGMCU);LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_TIM1 | LL_APB1_GRP2_PERIPH_SYSCFG);LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1);LL_GPIO_Init(GPIOA, &gpio_init); // PA0, TIM1_CH1Ngpio_init.Alternate = LL_GPIO_AF2_TIM1;LL_GPIO_Init(GPIOB, &gpio_init); // PB0, TIM1_CH2Ngpio_init.Pin = LL_GPIO_PIN_1; // PB1, TIM1_CH3NLL_GPIO_Init(GPIOB, &gpio_init);LL_DBGMCU_APB1_GRP2_FreezePeriph(LL_DBGMCU_APB1_GRP2_TIM1_STOP);LL_DMA_Init(DMA1, LL_DMA_CHANNEL_1, (LL_DMA_InitTypeDef*)&DMAInit);LL_SYSCFG_SetDMARemap_CH1(LL_SYSCFG_DMA_MAP_TIM1_UP);LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_1);LL_TIM_Init(TIM1, (LL_TIM_InitTypeDef*)&TimInit);LL_TIM_BDTR_Init(TIM1, (LL_TIM_BDTR_InitTypeDef*)&BDTR_cfg);LL_TIM_OC_Init(TIM1, LL_TIM_CHANNEL_CH1, (LL_TIM_OC_InitTypeDef*)&PWM_cfg);LL_TIM_OC_Init(TIM1, LL_TIM_CHANNEL_CH2, (LL_TIM_OC_InitTypeDef*)&PWM_cfg);LL_TIM_OC_Init(TIM1, LL_TIM_CHANNEL_CH3, (LL_TIM_OC_InitTypeDef*)&PWM_cfg);LL_TIM_EnableDMAReq_UPDATE(TIM1);LL_TIM_ConfigDMABurst(TIM1, LL_TIM_DMABURST_BASEADDR_CCR1, LL_TIM_DMABURST_LENGTH_3TRANSFERS);LL_TIM_SetCounter(TIM1,0);LL_TIM_ClearFlag_UPDATE(TIM1);LL_TIM_EnableCounter(TIM1);LL_TIM_EnableAllOutputs(TIM1);}void SystemClockConfig(void){LL_RCC_HSI_Enable();/* Change this value to adjust clock frequency, larger is faster */LL_RCC_HSI_SetCalibFreq(LL_RCC_HSICALIBRATION_24MHz);while (LL_RCC_HSI_IsReady() != 1);SysTick_Config(24000);NVIC_SetPriority(SysTick_IRQn, 0);}int main(void){SystemClockConfig();PWMConfig();while (1){}}

author: positron96
author_rank: Newbie
timestamp: June 18, 2025, 10:12:40 pm
content: Thanks for the code snippet!Current iteration ofmy boardhas 4 H-bridges and 7 LED outputs. 6 pins control either H-bridges or LEDs and 3 pins are dedicated to specific functions. I crammed 9 PWM channels as my QFN PY32F003F1 package does not have all the pins from your list. I was hoping to increase the number of independent outputs in next iteration.Existing implementation simply updates CC values by CPU without DMA, and that's not a problem. By using DMA I was hoping to write to more pins on timer update (and update timer period in a second DMA channel), this way I can output independent BCM (binary code modulation) values to achieve PWM-like behavior.

author: DavidAlfa
author_rank: Super Contributor
timestamp: June 19, 2025, 06:43:21 am
content: I think you should get another mcu

author: andrvisht
author_rank: Contributor
timestamp: June 26, 2025, 09:28:34 pm
content: I found a problem with interrupt handling whenRDPis installed. And this is where this thread started (page 2).The processor goes into a HALT after an unhandled interrupt.One of the solutions - vectors inSRAM, seems to be the most correct, butDavidAlfa'sassumptions about the vulnerability of the method at that time force me to resume discussing this problem.As a result of testing on hardware, I can say that withRDP, any reading ofFLASHfromSRAMleads to a Hard Fault.This is also confirmed by the Reference Manual4.5.2. Flash read protectionBy setting RDP option byte, and perform system reset (POR/BOR or OPL reset) to load a new RDP option byte to activate the read protection function. RDP protects main Flash memory, option byte, and SRAM.And alsoTable 4-7 The relationship between access status and protection level and execution modeThere is noSWDfuse in PY32F0xx, so the only possible additional means arenRSTnBOOT1and switching GPIO AF.Does anyone have any thoughts on this?Perhaps I did not fully understand the vulnerability described by DavidAlfa, or it was an assumption that requires verification.Thanks

author: DavidAlfa
author_rank: Super Contributor
timestamp: June 27, 2025, 04:54:08 am
content: Other ISRs work well (SPI, UART, I2C, DMA, PWM, SYSTICK..), so it can't be that.I only encountered that issue with input capture, but if I remember correctly, it happenned only when running other interrupts concurrently, and it didn't fail every time, if it was the flash protection it would crash every time for all ISRs

author: andrvisht
author_rank: Contributor
timestamp: June 27, 2025, 08:20:05 am
content: I had problems with the UART and I2C in the case when the RDP is installed.This was due to multiple calls to the USART_SR_TXE interrupt at the moment when I was expecting USART_SR_TC.i.e. the buffer had already been sent, and I was waiting for the end of the sending.That's because USART_SR_TXE was triggered several times in idle mode, the processor went into HALT.There was a similar problem with I2Cthere I was generating a RESTART and while the event was being expected, the SR1_BTF interrupt was triggered several timessignaling that everything had already been sent.Here is an example on the timer (Vectors in FLASH).Code:void TIM14_IRQHandler(void){static uint16_t cnt = 0;LED_XOR;LED_XOR;cnt++;if (TIM14->SR & TIM_SR_UIF) {if (cnt & 0x0f) TIM14->SR &= ~TIM_SR_UIF;else LED_XOR;}}When RDP is not activated, the timer works adequately.Once every 16 overflow cycles, we miss the flag reset, which makes us execute the handler twice.But everything changes with active RDP.As soon as the processing was missed, the processor goes into HALT.I think the same situation with CCP. missed processing and as a result HALT.But my question is more about vulnerability, since vectors in SRAM are a safer thing.my tests show that it is impossible to directly subtract FLASH from SRAM. therefore, replacing the vector to call the code from SRAM is the only option to launch it.But what next?if this code cannot access FLASH, the only hope is to replace some pointers in SRAM, which is extremely doubtful, since the probability of catching a Hard Fault is extremely high.Or am I missing something?

author: DavidAlfa
author_rank: Super Contributor
timestamp: June 27, 2025, 01:14:35 pm
content: Probably a bug between RDP and the flash bus.

author: andrvisht
author_rank: Contributor
timestamp: June 27, 2025, 02:33:53 pm
content: well, it's clear that this is not a feature.it's just a reason, the solution to which is moving vectors to SRAM.The question is whether the processor is vulnerable to attacks in this case, and how to deal with it.

author: DavidAlfa
author_rank: Super Contributor
timestamp: July 25, 2025, 01:43:25 am
content: Hmm definitely not recommended for anything else than diy and hobby use.Today I made a PWM 3-phase sine DAC, streaming a local buffer with DMA to the pwm channels.I can finely adjust the frequency between 1Hz and ~1K, also the phase.To update the waveform my steps are:- Stop the dma, wait until it really stops.- Update the buffer, update the dma transfer size.- Enable the dma channel.Well, the dma randomly dies, no errors, nothing showing a hint of the issue.I tried clearing every flag, disabling the timer, disabling the dma request, reinitializing the dma peripheral, adding small delays between the steps... Nope!In the end I had to use RCC DMA force reset and reinitialize the DMA everytime I need to update the buffers.Not very fond of undocumented erratas...

author: andrvisht
author_rank: Contributor
timestamp: July 26, 2025, 12:52:40 pm
content: Yes, I agree.I conducted my own experiments on protection, and received 100% proofreading without any complicated investments.

author: DavidAlfa
author_rank: Super Contributor
timestamp: July 26, 2025, 03:08:07 pm
content: Or, perhabs that's why these 002A/B exists in first place, being 030 with defective peripherals.

author: U6emp
author_rank: Newbie
timestamp: August 30, 2025, 02:00:06 pm
content: Hello!Maybe someone had communication with PY32F002B?The situation is as follows, this chip is used in the PC211 cartridge.I can't reach it either via SWD or via UART. If I pull nRST to GND then via SWD:Switching out of dormant state into SWDDP DPIDR 0x0bc11477 (v1 MINDP rev0) designer 0x43b partno 0xbcAP 0: IDR=04770031 CFG=00000000 BASE=e00ff000 CSW=e3000040 (AHB3-AP var3 rev0)remote_v4_adiv5_mem_read_bytes error around 0xe000edf0Halt via DHCSR(000d0744): failure after 2510msTry again with longer timeout or connect under resetadiv5: Failed to prepare AP, results may be unpredictableremote_v4_adiv5_mem_read_bytes error around 0xe00ffff0Error reading CIDR on AP0: 2No target foundIs it possible to reset via ISP?Best regards!

author: DavidAlfa
author_rank: Super Contributor
timestamp: August 31, 2025, 12:19:04 pm
content: It won't connect with reset active.The code probably disables SWD interface, so you have only few micro seconds to establish the connection after releasing nRST, which is very difficult with a PC programmer, probably only dedicated programmers can do this.However, did you try with BOOT0=1 ?This will boot into SRAM, which contains nothing, so it should keep the SWD active.Keep in mind not all PY32F002x devices have this pin... In that case, it's pretty much a dead end.What are you trying to do? Repurpose the mcu? Just buy a new one, it costs cents...

author: U6emp
author_rank: Newbie
timestamp: August 31, 2025, 02:18:15 pm
content: RE:In that case, it's pretty much a dead end.What are you trying to do?Repurpose the mcu? Just buy a new one, it costs cents...I have no problems with the purchase, I am trying to analyze how effective the protective measures were that China used )))Connect via blackmagic probe:Switching out of dormant state into SWDDP DPIDR 0x0bc11477 (v1 MINDP rev0) designer 0x43b partno 0xbcAP 0: IDR=04770031 CFG=00000000 BASE=e00ff000 CSW=e3000040 (AHB3-AP var3 rev0)Halt via DHCSR(02000001): failure after 2002msTry again with longer timeout or connect under resetadiv5: Failed to prepare AP, results may be unpredictableROM Table: BASE=0xe00ff000 SYSMEM=1, Manufacturer 43b Partno 4c0 (PIDR = 0x04000bb4c0)0 0x0e000e000: Generic IP component - Cortex-M0 SCS (System Control Space) (PIDR = 0x04000bb008 DEVTYPE = 0x00 ARCHID = 0x0000)-> cortexm_probeCPUID 0x410cc601 (M0+ var 0 rev 1)remote_v3_adiv5_mem_read_bytes error around 0x1fff0ffcremote_v3_adiv5_mem_read_bytes error around 0xe00ff004ROM Table: ENDremote_v3_adiv5_mem_write_bytes error around 0xe000edf0*** 1 PY32Fxxx M0+remote_v3_adiv5_mem_write_bytes error around 0xe000edf0remote_v3_adiv5_mem_read_bytes error around 0xe000edf0Can not attach to target 1My Zoo!

author: IOsetting
author_rank: Regular Contributor
timestamp: September 01, 2025, 03:04:27 am
content: Quote from: U6emp on August 31, 2025, 02:18:15 pmAs David said, the conventional method may not work. 002B has no BOOT0 pin, and the NRST pin can also be turned off in the code, so unless there is a flaw in the chip itself, it is difficult to connect it with SWD. From the perspective of reverse engineering, a feasible way is to analyze the communication between the printer and the cartridge with a logic analyzer, and make a module to simulate this communication process.

author: U6emp
author_rank: Newbie
timestamp: September 01, 2025, 02:47:56 pm
content: Quote from: IOsetting on September 01, 2025, 03:04:27 amReplacing the chip is not the goal, I managed to drain the firmware, you can just print a few pages and look at the counter, which can be made a little bigger )))From which I managed to drain this PY32f003S18, 64k flash, 8k RAMI didn't want to throw these chips in the trash, at their price of 10 cents, but maybe somehow use them in the household )))Another question, what programmer or programmers are needed for Py32CubeProgrammer (PY-Link and PY-Programmer)? When using J-Link Segger 9 and programming OPTR via J-Link, it damaged two chips.

author: IOsetting
author_rank: Regular Contributor
timestamp: September 04, 2025, 03:49:20 am
content: Quote from: U6emp on September 01, 2025, 02:47:56 pmI am a Ubuntu user, I always use the cheap JLink ob(st-link does't work and pyocd too slow), it works perfectly, I never had a problem.

author: Pixie dust
author_rank: Contributor
timestamp: October 06, 2025, 07:18:53 pm
content: The PY32Fxx family seems to be extended with a new device called MS32C001 This one is scaled down to 18k flash and 1.5k RAM. They claim in volume you can get them for $0.04The following hardware is not onboard anymore:1) Comparators2) DMA channelsAs the data sheet is from a later date it seems they did some improvements on the silicon.The power consumption of the AD converter is now 300uA at full speed. Also can you use now scale the input voltage range of the AD converter to VCC or 2.5V or 2.048V or 1.5V) which is quite handy for low voltage analog signals.Currently the device is only available in QFN20 and QFN16.I have no idea why they called it the MS32C001 and not PY32F001 as it is still a flash device which can be re-programmed.Also strange is that on their official site they do not mention this device at all.Here a link were I found the documents:https://www.xinlinggo.com/col.jsp?id=111&m530pageno=2&utm_source=chatgpt.com

author: IOsetting
author_rank: Regular Contributor
timestamp: October 09, 2025, 02:14:20 am
content: Quote from: Pixie dust on October 06, 2025, 07:18:53 pmThe pin definitions and multiplexing are the same as those of the py32f002b by comparing the datasheet, it should be a reduced version of py32f002b with less peripherals. less ram and flash. Possibly, I guess, the peripheral of py32f002b might still be retained. The retail price 0.4CNY/0.055USD is also close to py32f002b (0.5CNY/0.07USD).