PUYA projects is an experiment to use low-cost ARM PUYA microcontrollers.
- MCU Core – 32-bit Arm Cortex-M0+ @ 24 MHz
- Memory – 3KB SRAM
- Storage – 20KB flash
- Peripherals:
- 5 GPIOs (PF0, PA1, PA5, PA6, PA7)
- 1x USART
- 1x I2C, 1x SPI, 1x PWM (PA1 AF13 TIM1_CH4)
- Up to 9-channel 12-bit ADC
- Timers
- 1x general-purpose 16-bit timers
- 1x 16-bit advanced control timer
- 1x low-power timer (LPTIM) to support wake-up from stop mode
- 1x SysTick timer
- 1x watchdog timers (IWDT)
- Clocks
- 4/24MHz RC (HSI)
- 32.768KHz RC (LSI)
- 4~24MHz HSE (External crystal oscillator)
- Supply Voltage – 1.7V to 5.5V DC
- Packages – SOP8 (4.9×3.7×1.75 mm), SOP16, ESSOP10, TSSOP20
- Temperature Range – – 40°C to +85°C
- PUYA microcontroller (We used a PUYA Dev Board with a PY32F002AA15M6TU microcontroller)
- J-Link Segger Debugger
- Visual Studio Code (mandatory)
- Git (Recommended)
-
Install GNU Arm Embedded Toolchain:
- Download the appropriate version from Arm GNU Toolchain Downloads (We use arm-none-eabi v12.3 rel1).
- Add the tool's binary directory to the Windows PATH.
To add the environment variable we look in the windows bar: "Edit environment variables for your account".
- Open the Command Line: To open the "Command Line" search "cmd" or "PowerShell" in your windows bar. In this case "Windows PowerShell" was used, and a window like the following should open:
- Verify GNU Toolchain Installation:
In your Command Line verify if GNU Toolchain Installation was correct.
If it has been installed correctly you should obtain a result similar to the following:
&"C:\Program Files (x86)\Arm GNU Toolchain arm-none-eabi\12.3 rel1\bin\arm-none-eabi-gcc" -v
-
Install Make:
- Download Make from GnuWin.
- Add Make to the environment variables.
-
Check Make Installation:
make -v
-
Install SEGGER J-Link:
- Download from J-Link / J-Trace Downloads.
- Install J-Link tools.
-
Clone the PY32 Examples Repository: Copy code
git clone https://github.com/TDLOGY/py32f0-template-project
-
Copy the JLinkDevices Directory: Copy
[PY32 Directory]/Misc/Flash/JLinkDevices
toC:\Users\[User]\AppData\Roaming\SEGGER\JLinkDevices\
. -
Find the JLink Path: Locate the path where JLink is installed, typically something like:
"C:\Program Files\SEGGER\JLink\JLink"
. Save it for future configurations. -
Connect J-Link and Verify: In Windows PowerShell, use the following command to verify the J-Link connection:
&"C:\Program Files\SEGGER\JLink\JLink"
-
Open Visual Studio Code:
- Open the
py32f0-template-project
folder.
- Open the
-
Adjust Makefile for Your Chip (The "Makerfile" is located in the project folder):
- Edit the Makefile to change the tools references, it uses the path references of the previously installed tools.
- Edit the Makefile to change all the chip reference to `"PY32F002AX5"`.
-
Compile the Project:
- In Visual Studio Code open a terminal.
- Execute:
make -j4
in the Visual Studio Code (VSC) terminal and verify that it compiles correctly, otherwise, it could be that the "Makefile" has not been configured correctly.
-
Modify the Code:
- Open the
/User/main.c
file. - Adjust pin references from ports B and F to A as needed.
- Open the
-
Compile Again: Execute
make clean
to clean the compilation and aftermake -j4
to compile with the changes made. -
Program the Board: Use
make flash
to upload the code to your board using J-Link. (You must have your J-Link connected to your computer and with the corresponding connections to the development board) -
Save Your Changes: Remember to save the modified files before compiling.
-
Clean Previous Compilation: If you make changes to the code, run
make clean
before compiling again.
PUYA Dev Board with the PY32F002AA15M6TU microcontroller should now be configured and ready to go!
The development board can be programmed via SWD by a J-Link (The J-link connections will depend on which J-Link and connector you are going to use).
SWD is a bidirectional communication protocol that allows for fast and efficient microcontroller debugging and programming.
SWD uses two signal lines, one for data (SWDIO) and one for clock (SWCLK), to communicate with the microcontroller. Through these lines, you can load programs into the microcontroller, stop code execution to inspect variables and debug errors, and perform other debugging operations. It is faster and more efficient than older debugging methods, such as JTAG.
As mentioned earlier, SWD communication involves two key lines: SWDIO for data and SWCLK for the clock signal. However, in addition to these two lines, we also require two more connections:
- GND (Ground): This connection is essential to establish a common reference point for electrical potential and ensure proper communication.
- VRef (Voltage Reference): In this case, our PUYA Dev board works with a logical voltage level of 3.3V so it is necessary to provide this voltage to the J-Link tool. This voltage, known as VRef, is necessary to support the communication between the J-Link and the target board.
Note: You need to power up the PUYA Dev board with an external 5V power supply.
To program the PUYA Dev Board with the J-Link PLUS Compact we will need the following components:
In addition to this, in order to make the connections we must know what the J-Link pinout is, take the image below as a reference and connect each wire from your PUYA Dev Board to the corresponding one on the J-Link:
To program the PUYA Dev Board with the J-Link EDU Mini we will need the following components:
As shown in the required material, the J-Link EDU Mini PCB Adapter helps us a lot in identifying where we need to connect each wire from our PUYA development board to the PCB adapter. After connecting the corresponding wires you can program your board.
The image above is just a reference image of the connections. The board is being powered directly with 5V and there are the following connections:
PUYA Dev Board | J-Link Compact | J-Link EDU | Power Supply |
---|---|---|---|
3.3V | VTref | Vref | X |
GND | GND | GND | GND |
DIO | SWDIO | SWIO | X |
CLK | SWCLK | CLK | X |
5V | X | X | 5V |
This example is based on the Example Code PY32F0
Electronic Cats invests time and resources providing this open source design, please support Electronic Cats and open-source hardware by purchasing products from Electronic Cats!