• Stars
    star
    155
  • Rank 240,864 (Top 5 %)
  • Language
    C
  • Created almost 2 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Puya PY32F002A PY32F003 PY32F030 GNU GCC SDK, template and examples

py32f0-template

  • Template project for Puya PY32F0 MCU
  • Supports GNU Arm Embedded Toolchain
  • Supports J-Link and DAPLink/PyOCD programmers
  • Supports IDE: VSCode

Puya PY32F0 Family

PY32F0 are cost-effective Arm Cortex-M0+ microcontrollers featured with wide range operating voltage from 1.7V to 5.5V. Datesheets and Reference Manuals can be found at WIKI.

PY32F002B

Frequency up to 24 MHz, 24 Kbytes of Flash memory, 3 Kbytes of SRAM.

  • PY32F002B
    • PY32F002Bx(24KB Flash/3KB RAM)

PY32F0xx

Frequency up to 48 MHz, 16 to 64 Kbytes of Flash memory, 3 to 8 Kbytes of SRAM.

  • PY32F002A
    • PY32F002Ax5(20KB Flash/3KB RAM)
  • PY32F003
    • PY32F003x4(16KB Flash/2KB RAM), PY32F003x6(32KB Flash/4KB RAM), PY32F003x8(64KB Flash/8KB RAM)
  • PY32F030
    • PY32F030x4(16KB Flash/2KB RAM), PY32F030x6(32KB Flash/4KB RAM), PY32F030x8(64KB Flash/8KB RAM)

PY32F07x

Frequency up to 72 MHz, 128 Kbytes of Flash memory, 16 Kbytes of SRAM, with more peripherals(CAN, USB)

  • PY32F040
    • PY32F040xB(128KB Flash/16KB RAM)
  • PY32F071
    • PY32F071xB(128KB Flash/16KB RAM)
  • PY32F072
    • PY32F072xB(128KB Flash/16KB RAM)

File Structure

β”œβ”€β”€ Build                       # Build results
β”œβ”€β”€ Docs                        # Datesheets and User Manuals
β”œβ”€β”€ Examples
β”‚Β Β  β”œβ”€β”€ PY32F002B               # PY32F002B examples
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ HAL                 # HAL library examples
β”‚Β Β  β”‚Β Β  └── LL                  # LL(Low Layer) library examples
β”‚Β Β  β”œβ”€β”€ PY32F07x                # PY32F07x examples
β”‚Β Β  β”‚Β Β  └── HAL                 # HAL library examples
β”‚Β Β  └── PY32F0xx                # PY32F002A,PY32F003,PY32F030 examples
β”‚Β Β      β”œβ”€β”€ FreeRTOS            # FreeRTOS examples
β”‚Β Β      β”œβ”€β”€ HAL                 # HAL library examples
β”‚Β Β      └── LL                  # LL(Low Layer) library examples
β”œβ”€β”€ Libraries
β”‚Β Β  β”œβ”€β”€ CMSIS
β”‚Β Β  β”œβ”€β”€ EPaper                  # Waveshare e-paper library
β”‚Β Β  β”œβ”€β”€ FreeRTOS                # FreeRTOS library
β”‚Β Β  β”œβ”€β”€ LDScripts               # LD files
β”‚Β Β  β”œβ”€β”€ PY32F002B_HAL_BSP       # PY32F002B HAL BSP
β”‚Β Β  β”œβ”€β”€ PY32F002B_HAL_Driver    # PY32F002B HAL library
β”‚Β Β  β”œβ”€β”€ PY32F002B_LL_BSP        # PY32F002B LL(low layer) BSP
β”‚Β Β  β”œβ”€β”€ PY32F002B_LL_Driver     # PY32F002B LL library
β”‚Β Β  β”œβ”€β”€ PY32F07x_HAL_BSP        # PY32F040/071/072 HAL BSP
β”‚Β Β  β”œβ”€β”€ PY32F07x_HAL_Driver     # PY32F040/071/072 HAL library
β”‚Β Β  β”œβ”€β”€ PY32F0xx_HAL_BSP        # PY32F002A/003/030 HAL BSP
β”‚Β Β  β”œβ”€β”€ PY32F0xx_HAL_Driver     # PY32F002A/003/030 HAL library
β”‚Β Β  β”œβ”€β”€ PY32F0xx_LL_BSP         # PY32F002A/003/030 LL BSP
β”‚Β Β  └── PY32F0xx_LL_Driver      # PY32F002A/003/030 LL library
|
β”œβ”€β”€ Makefile                    # Make config
β”œβ”€β”€ Misc
β”‚Β Β  β”œβ”€β”€ Flash
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ JLinkDevices        # JLink flash loaders
β”‚Β Β  β”‚Β Β  └── Sources             # Flash algorithm source code
β”‚Β Β  β”œβ”€β”€ Puya.PY32F0xx_DFP.x.pack # DFP pack file for PyOCD
β”‚Β Β  └── SVD                     # SVD files
β”œβ”€β”€ README.md
β”œβ”€β”€ rules.mk                    # Pre-defined rules include in Makefile 
└── User                        # User application code

Requirements

Building

1. Install GNU Arm Embedded Toolchain

Download the toolchain from Arm GNU Toolchain Downloads according to your pc architecture, extract the files

sudo mkdir -p /opt/gcc-arm/
sudo tar xvf arm-gnu-toolchain-12.2.rel1-x86_64-arm-none-eabi.tar.xz -C /opt/gcc-arm/
cd /opt/gcc-arm/
sudo chown -R root:root arm-gnu-toolchain-12.2.rel1-x86_64-arm-none-eabi/

2. Clone This Repository

Clone this repository to local workspace

git clone https://github.com/IOsetting/py32f0-template.git

3. Install SEGGER J-Link Or PyOCD

Option 1: Install SEGGER J-Link

Download and install JLink from J-Link / J-Trace Downloads.

# installation command for .deb
sudo dpkg -i JLink_Linux_V784f_x86_64.deb
# uncompression command for .tar.gz
sudo tar xvf JLink_Linux_V784f_x86_64.tgz -C [target folder]

The default installation directory is /opt/SEGGER

Copy [Project directory]/Misc/Flash/JLinkDevices to [User home]/.config/SEGGER/

cd py32f0-template
cp -r Misc/Flash/JLinkDevices/ ~/.config/SEGGER/

Read more: https://wiki.segger.com/J-Link_Device_Support_Kit

Option 2: Install PyOCD

Don't install from apt repository, because the version 0.13.1+dfsg-1 is too low for J-Link probe.

Install PyOCD from pip

pip uninstall pyocd

This will install PyOCD into:

/home/[user]/.local/bin/pyocd
/home/[user]/.local/bin/pyocd-gdbserver
/home/[user]/.local/lib/python3.10/site-packages/pyocd-0.34.2.dist-info/*
/home/[user]/.local/lib/python3.10/site-packages/pyocd/*

In Ubuntu, .profile will take care of the PATH, run source ~/.profile to make pyocd command available

4. Edit Makefile

Change the settings in Makefile

  • MCU_TYPE The MCU type you are using
  • USE_LL_LIB Puya provides two sets of library, HAL and LL, set USE_LL_LIB ?= y to use LL instead of HAL.
    • No LL Library for PY32F07x
  • ENABLE_PRINTF_FLOAT set it to y to -u _printf_float to link options. This will increase the binary size.
  • USE_FREERTOS Set USE_FREERTOS ?= y will include FreeRTOS in compilation
  • USE_DSP Include CMSIS DSP or not
  • FLASH_PROGRM
    • If you use J-Link, FLASH_PROGRM can be jlink or pyocd
    • If you use DAPLink, set FLASH_PROGRM ?= pyocd
    • ST-LINK is not supported yet.
  • ARM_TOOCHAIN Make sure it points to the correct path of arm-none-eabi-gcc
##### Project #####

PROJECT			?= app
# The path for generated files
BUILD_DIR		= Build

# MCU types: 
#   PY32F002Ax5
#   PY32F002Bx5
#   PY32F003x6, PY32F003x8, 
#   PY32F030x6, PY32F030x8, 
#   PY32F072xB
MCU_TYPE		= PY32F072xB

##### Options #####

# Use LL library instead of HAL, y:yes, n:no
USE_LL_LIB        ?= n
# Enable printf float %f support, y:yes, n:no
ENABLE_PRINTF_FLOAT ?= n
# Build with FreeRTOS, y:yes, n:no
USE_FREERTOS      ?= n
# Build with CMSIS DSP functions, y:yes, n:no
USE_DSP           ?= n
# Programmer, jlink or pyocd
FLASH_PROGRM      ?= pyocd

##### Toolchains #######
ARM_TOOCHAIN      ?= /opt/gcc-arm/arm-gnu-toolchain-12.2.rel1-x86_64-arm-none-eabi/bin

# path to JLinkExe
JLINKEXE		?= /opt/SEGGER/JLink/JLinkExe
# path to PyOCD
PYOCD_EXE		?= pyocd

5. Compiling And Flashing

# clean source code
make clean
# build
make
# or make with verbose output
V=1 make
# flash
make flash

Debugging In VSCode

Install Cortex Debug extension, add a new configuration in launch.json, e.g.

{
    "armToolchainPath": "/opt/gcc-arm/arm-gnu-toolchain-12.2.rel1-x86_64-arm-none-eabi/bin/",
    "toolchainPrefix": "arm-none-eabi",
    "name": "Cortex Debug",
    "cwd": "${workspaceFolder}",
    "executable": "${workspaceFolder}/Build/app.elf",
    "request": "launch",        // can be launch or attach
    "type": "cortex-debug",
    "runToEntryPoint": "Reset_Handler", // "main" or other function name. runToMain is deprecated
    "servertype": "jlink",  // jlink, openocd, pyocd, pe and stutil
    "device": "PY32F030X8",
    "interface": "swd",
    "preLaunchTask": "build",  // Set this to run a task from tasks.json before starting a debug session
    // "preLaunchCommands": ["Build all"], // Uncomment this if not using preLaunchTask
    "svdFile": "${workspaceFolder}/Misc/SVD/py32f030xx.svd",  // svd for this part number
    "showDevDebugOutput": "vscode", // parsed, raw, vscode:vscode log and raw
    "swoConfig":
    {
        "enabled": true,
        "cpuFrequency": 8000000, // Target CPU frequency in Hz
        "swoFrequency":  4000000,
        "source": "probe", // either be β€œprobe” to get directly from the debug probe, 
                           // or a serial port device to use a serial port external to the debug probe.
        "decoders":
        [
            {
                "label": "ITM port 0 output",
                "type": "console",
                "port": 0,
                "showOnStartup": true,
                "encoding": "ascii"
            }
        ]
    }
}

If Cortex Debug cannot find JLinkGDBServerCLExe, add the following line to settings.json

"cortex-debug.JLinkGDBServerPath": "/opt/SEGGER/JLink/JLinkGDBServerCLExe",

Try Other Examples

More examples can be found in Examples folder, copy and replace the files under User folder to try different examples.

Links

More Repositories

1

wm-sdk-w806

A SDK for WinnerMicro W806
C
127
star
2

FwLib_STC8

A lite firmware library for STC8G/STC8H series MCU
C
113
star
3

v2rock

V2ray GUI client for Ubuntu and Debian
C++
76
star
4

stc8prog

Open Source STC8G/STC8H ISP flash tool
C
61
star
5

hk32f030m-template

HSXP HK32F030M template project for GNU Arm Embedded Toolchain
C
29
star
6

air32f103-template

AIR32F103 template project for GNU Arm Embedded Toolchain
C
27
star
7

HML_FwLib_STC12

A lite firmware library for STC12 series MCU
C
27
star
8

stm32f103-esp8266

A working demo of ESP8266 ESP-01S UART WiFi module running on STM32F103C8T6
C
22
star
9

stm32f103-w5500

A working demo of W5500 Ethernet module running on STM32F103C8T6
C
21
star
10

ipfs-gateway-selector

An IPFS site displaying public IPFS gateways and their connection latency to user.
HTML
21
star
11

hc32l110-template

HDSC HC32L110 GNU GCC SDK, template and examples
C
16
star
12

StdPeriphLib_CH32F1

A StdPeriph Library for CH32F103 series MCU
C
14
star
13

stm32f103-nrf24l01

A working demo of nRF24L01 WiFi module running on STM32F103C8T6
C
10
star
14

at32f403a_407-template

Artery AT32F403A AT32F407 template project for GNU Arm Embedded Toolchain
C
8
star
15

libopencm3-freertos-template

Project template of libopencm3 + FreeRTOS
Makefile
6
star
16

ch32v103-template

Project template of WCH CH32V103
C
6
star
17

stcmx

stcmx is a command-line tool that allows a very easy generation of the corresponding initialization C code for STC8 MCUs through a step-by-step process.
Python
6
star
18

redinav

RediNav is a GUI management tool for Redis
C++
5
star
19

stm32f401-esp8266

A working demo of ESP8266-S01 UART module running on STM32F401CCU6 (Black Pill)
C
5
star
20

stm32f103-enc28j60

A working demo of ENC28J60 Ethernet module running on STM32F103C8T6.
C
5
star
21

ch32v208-template

Project template of WCH CH32V208
C
4
star
22

stm32f401-wireless-car

C
4
star
23

stm32f4-hal-projects

STM32F4 HAL Demo Projects
C
4
star
24

stm32f401-nrf24l01

A working demo of nRF24L01 WiFi module running on STM32F401CCU6
C
3
star
25

at32f421-template

Artery AT32F421 template project for GNU Arm Embedded Toolchain
C
2
star
26

py32f002a-remote-control

PY32F002A XL2400 6+1CH Remote Control
C
1
star
27

ch583-template

WCH CH582/CH583 GNU GCC project template and examples
C
1
star