Skip to content

ElectronicCats/puya-projects

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PUYA Projects

PUYA projects is an experiment to use low-cost ARM PUYA microcontrollers.

PY32F002A key features and specifications:

  • 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

FOR WINDOWS

Requirements

  • PUYA microcontroller (We used a PUYA Dev Board with a PY32F002AA15M6TU microcontroller)
  • J-Link Segger Debugger
  • Visual Studio Code (mandatory)
  • Git (Recommended)

Tools Installation

  1. 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 "Edit environment variables for your account".

Open "Environment Variables...".

Select "Path" and then "Edit...".

Add "New" variable and add the path: "C:\Program Files (x86)\Arm GNU Toolchain arm-none-eabi\12.3 rel1\bin".

  1. 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:

  1. Verify GNU Toolchain Installation: In your Command Line verify if GNU Toolchain Installation was correct.
    &"C:\Program Files (x86)\Arm GNU Toolchain arm-none-eabi\12.3 rel1\bin\arm-none-eabi-gcc" -v 
    If it has been installed correctly you should obtain a result similar to the following:

  1. Install Make:

    • Download Make from GnuWin.
    • Add Make to the environment variables.
  2. Check Make Installation:

    make -v
    
  3. Install SEGGER J-Link:

Project Configuration

  1. Clone the PY32 Examples Repository: Copy code

    git clone https://github.com/TDLOGY/py32f0-template-project

  2. Copy the JLinkDevices Directory: Copy [PY32 Directory]/Misc/Flash/JLinkDevices to C:\Users\[User]\AppData\Roaming\SEGGER\JLinkDevices\.

  3. 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.

  4. Connect J-Link and Verify: In Windows PowerShell, use the following command to verify the J-Link connection:

       &"C:\Program Files\SEGGER\JLink\JLink"
  5. Open Visual Studio Code:

    • Open the py32f0-template-project folder.
  6. Adjust Makefile for Your Chip (The "Makerfile" is located in the project folder):

Located in the project folder.

    • Edit the Makefile to change the tools references, it uses the path references of the previously installed tools.

Tools references.

    • Edit the Makefile to change all the chip reference to `"PY32F002AX5"`.
  1. Compile the Project:

    • In Visual Studio Code open a terminal.

Opening 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.
  1. Modify the Code:

    • Open the /User/main.c file.
    • Adjust pin references from ports B and F to A as needed.
  2. Compile Again: Execute make clean to clean the compilation and after make -j4 to compile with the changes made.

  3. 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)

  4. Save Your Changes: Remember to save the modified files before compiling.

  5. 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).

What is SWD?

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.

J-Link Connections to the Dev Board

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.

Instructions to use the J-Link PLUS Compact

To program the PUYA Dev Board with the J-Link PLUS Compact we will need the following components:

Imagen 0
USB Cable.
Imagen 1
J-Link PLUS Compact.
Imagen 2
Dupont Wires.

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:

J-Link PLUS Compact connector.

Instructions to use the J-Link EDU Mini:

To program the PUYA Dev Board with the J-Link EDU Mini we will need the following components:

Imagen 0
USB Cable.
Imagen 1
J-Link EDU Mini.
Imagen 2
J-Link EDU Mini PCB Adapter.
Imagen 3
J-Link EDU Mini Cable.
Imagen 2
Dupont Wires.

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.

Connection example:

Illustrative image of connections.

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

Thanks / Contributors

This example is based on the Example Code PY32F0

Maintainer

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!