Code Monkey home page Code Monkey logo

py32f0_cmake_template's Introduction

PY32F0 MCU CMake project template. Using GCC, cross-platform. You can use VSCode, CLion, etc. for development.

This project is in its early stage and may have many bugs or areas that are incomplete.

Most of the information for this project comes from Puya Semiconductor. Puya Semiconductor's information is in a semi-public state, and I have collected data such as chip manuals and libraries from various sources. Please refer to:

HAL, LL, CMSIS, BSP Drivers decaday/PY32F0_Drivers

Datasheets, packs, reference manuals, etc. decaday/PY32_Docs

GCC startup and ldscript are from IOsetting/py32f0-template (this repo uses makefile on Linux), thanks to the contributors to that project.

Supported MCUs

---PY32F002B Series---

Puya PY32F002B

Xinlinggo XL32F001*, XL32F002B*

---PY32F0xx Series---

Puya PY32F002A, PY32F003, PY32F030

Xinlinggo XL32F003*, XL32F002A*

Luat AIR001

---PY32F07x Series---(TODO)

Puya PY32F040, PY32F(M)070*, PY32F071, PY32F072

*:Guessing based on chip specifications, haven’t tried it yet.

**:There are too many naming approaches for puya MCU, some MCUs such as PY32L020, PY32C613, etc. I didn't buy these chips, if you have them, please contribute relevant information. You can try above series with the same flash, ram, and clock speed, which may work because they are most likely produced from the same die.

Steps

1. Install gcc-arm-none-eabi

Downloads | GNU Arm Embedded Toolchain Downloads – Arm Developer

Choose the appropriate package for your system and add bin to your environment variable (if you use the installer, it may have already been added automatically).

2. Clone this template project

git clone --recursive https://github.com/decaday/py32f0_cmake_template.git

This repo has a submodule, so you need to add --recursive.

3. Edit the py32f0.cmake file.

# project settings
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_C_STANDARD 11)

# Use HAL lib or LL lib
set(USE_HAL_OR_LL LL)

# MCU:
#   PY32F002Ax5
#   PY32F002Bx5
#   PY32F003x4, PY32F003x6, PY32F003x8
#   PY32F030x4, PY32F030x6, PY32F030x7, PY32F030x8
set(MCU_MODEL PY32F030x6)

# Enable printf float %f support
set(ENABLE_PRINTF_FLOAT OFF)

# Build with CMSIS DSP functions
set(USE_DSP OFF)

# Enable auto generation of Misc/pyocd.yaml if needed
set(AUTO_GENERATE_PYOCD_YAML ON)

Set MCU_MODEL

Puya's MCU naming can be a bit cumbersome, for example, PY32F002AF15P6TU.

PY32F002A is the Product type, F1 is the 20 pins Pinout1, 5 is 20 Kbytes of code, P is Package TSSOP, 6 is Temperature range 6 = -40 to +85, TU is Tube Packing.

Therefore, you need to choose PY32F002Ax5.

If you are using AIR001, you can choose PY32F030x6. If you are using XL32, please choose the appropriate settings based on the core and flash size.

AUTO_GENERATE_PYOCD_YAML

I have written a script in CMake to automatically generate Misc/pyocd.yaml. For more information about debugging, please see below.

4. Compilation

You can use IDEs like VSCode, CLion, or compile from the command line.

5. Debugging and Flashing

Puya has several ISP tools and official debuggers. You can find some information about them here: decaday/PY32_Docs. However, in reality, we can use a regular DAPlink. I don't have STlink or Jlink, but contributions to the documentation are welcome.

I recommend using PyOCD as it supports MDK PACK.

Please download and install PyOCD.

Clion PyOCD Configure

image-20240121211255909

image-20240121211434382

You can keep the default settings for now. Later on, we will configure the target ourselves.(Misc/pyocd.yaml)

image-20240121211527071

image-20240121211613733

gdbserver -p 33462 --config Misc\pyocd.yaml

VSCode Pyocd Configure

TODO

6.Use Examples

The examples are under ‘Drivers/Examples’. You need to copy the files to the outside to run and debug. These examples are from Puya, using scripts to delete the MDK project related files. You may need to make slight modifications to run normally.

Compilation Reference Size

Compiler MCU Project RAM FLASH
GCC -Og -g F030 HAL Toggle Pin 1584 B 1720 B
GCC -Og -g F030 LL Toggle Pin 1568 B 1156 B
GCC -Og -g F002B HAL Toggle Pin 816 B 1736 B
GCC -O1 F030 HAL Toggle Pin 1584 B 1692 B
MDK ARMCC6 -O1 F030 HAL Toggle Pin 1240 B* 1448 B*
MDK ARMCC6 -O1 F030 LL Toggle Pin 1224 B* 912 B*

*RAM = ZI-data + RW-data

*Flash = Code + RO-data + RW-data

GCC:12.2mpacbti-rel1 ARMCC:v6.19

Puya Naming Instructions

image-20240121212122728

code Flash memory
3 8 Kbytes
4 16 Kbytes
5 20/24 Kbytes
6 32 Kbytes
8 64 Kbytes
9 96 Kbytes
B 128 Kbytes

py32f0_cmake_template's People

Contributors

decaday avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

py32f0_cmake_template's Issues

ninja:build stopped:subcommand failed

====================[ 构建 | py32_cmake_template.elf | Debug ]====================
"C:\Program Files\JetBrains\CLion 2023.3.1\bin\cmake\win\x64\bin\cmake.exe" --build C:\Users\light\OneDrive\PYF002A\PY32_Cmake_test2\py32f0_cmake_template\cmake-build-debug --target py32_cmake_template.elf -j 6
[1/1] Linking C executable py32_cmake_template.elf
FAILED: py32_cmake_template.elf
C:\Windows\system32\cmd.exe /C "cd . && arm-none-eabi-gcc -g -Wl,-gc-sections,--print-memory-usage,-Map=C:/Users/light/OneDrive/PYF002A/PY32_Cmake_test2/py32f0_cmake_template/cmake-build-debug/py32_cmake_template.map -specs=nano.specs -specs=nosys.specs -static -lc -lm -Wl,--no-warn-rwx-segments -mcpu=cortex-m0plus -mthumb -mthumb-interwork -T C:/Users/light/OneDrive/PYF002A/PY32_Cmake_test2/py32f0_cmake_template/Drivers/LDScripts/py32f002ax5.ld CMakeFiles/py32_cmake_template.elf.dir/Drivers/CMSIS/Device/PY32F0xx/Source/system_py32f0xx.c.obj CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal.c.obj CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_adc.c.obj CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_adc_ex.c.obj CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_comp.c.obj CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_cortex.c.obj CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_crc.c.obj CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_dma.c.obj CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_exti.c.obj CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_flash.c.obj CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_gpio.c.obj CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_i2c.c.obj CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_irda.c.obj CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_iwdg.c.obj CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_led.c.obj CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_lptim.c.obj CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_pwr.c.obj CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc.c.obj CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc_ex.c.obj CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rtc.c.obj CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rtc_ex.c.obj CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_spi.c.obj CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_tim.c.obj CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_tim_ex.c.obj CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_uart.c.obj CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_usart.c.obj CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_wwdg.c.obj CMakeFiles/py32_cmake_template.elf.dir/Drivers/CMSIS/Device/PY32F0xx/Source/gcc/startup_py32f002a.s.obj CMakeFiles/py32_cmake_template.elf.dir/App/main.c.obj CMakeFiles/py32_cmake_template.elf.dir/App/py32f0xx_hal_msp.c.obj CMakeFiles/py32_cmake_template.elf.dir/App/py32f0xx_it.c.obj -o py32_cmake_template.elf && C:\Windows\system32\cmd.exe /C "cd /D C:\Users\light\OneDrive\PYF002A\PY32_Cmake_test2\py32f0_cmake_template\cmake-build-debug && arm-none-eabi-objcopy -Oihex C:/Users/light/OneDrive/PYF002A/PY32_Cmake_test2/py32f0_cmake_template/cmake-build-debug/py32_cmake_template.elf C:/Users/light/OneDrive/PYF002A/PY32_Cmake_test2/py32f0_cmake_template/cmake-build-debug/py32_cmake_template.hex && arm-none-eabi-objcopy -Obinary C:/Users/light/OneDrive/PYF002A/PY32_Cmake_test2/py32f0_cmake_template/cmake-build-debug/py32_cmake_template.elf C:/Users/light/OneDrive/PYF002A/PY32_Cmake_test2/py32f0_cmake_template/cmake-build-debug/py32_cmake_template.bin""
c:/program files/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: unrecognized option '--no-warn-rwx-segments'
c:/program files/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: use the --help option for usage information
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

Buide Error:unknown type name 'DMA_Channel_TypeDef'

[main] Building folder: py32f0_cmake_template-master all
[build] Starting build
[proc] Executing command: chcp
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --build p:/SYSTEM_FOLDER/DOCUMENTS/Stm32Cube_Projects/py32f0_cmake_template-master/build --config Debug --target all -j 14 --
[build] [ 3%] Building C object CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal.c.obj
[build] [ 6%] Building C object CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_adc.c.obj
[build] [ 9%] Building C object CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_adc_ex.c.obj
[build] In file included from P:/SYSTEM_FOLDER/DOCUMENTS/Stm32Cube_Projects/py32f0_cmake_template-master/App/py32f0xx_hal_conf.h:147,
[build] from P:/SYSTEM_FOLDER/DOCUMENTS/Stm32Cube_Projects/py32f0_cmake_template-master/Drivers/PY32F0xx_HAL_Driver/Inc/py32f0xx_hal.h:33,
[build] from P:/SYSTEM_FOLDER/DOCUMENTS/Stm32Cube_Projects/py32f0_cmake_template-master/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal.c:39:
[build] P:/SYSTEM_FOLDER/DOCUMENTS/Stm32Cube_Projects/py32f0_cmake_template-master/Drivers/PY32F0xx_HAL_Driver/Inc/py32f0xx_hal_dma.h:116:3: error: unknown type name 'DMA_Channel_TypeDef'
[build] 116 | DMA_Channel_TypeDef Instance; /!< Register base address */
[build] | ^~~~~~~~~~~~~~~~~~~
[build] P:/SYSTEM_FOLDER/DOCUMENTS/Stm32Cube_Projects/py32f0_cmake_template-master/Drivers/PY32F0xx_HAL_Driver/Inc/py32f0xx_hal_dma.h:136:3: error: unknown type name 'DMA_TypeDef'
[build] 136 | DMA_TypeDef DmaBaseAddress; /!< DMA Channel Base Address */
[build] | ^~~~~~~~~~~
[build] make.exe[2]: *** [CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal.c.obj] Error 1
[build] CMakeFiles/py32_cmake_template.elf.dir/build.make:89: recipe for target 'CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal.c.obj' failed
[build] make.exe[2]: *** Waiting for unfinished jobs....
[build] [ 12%] Building C object CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_comp.c.obj
[build] In file included from P:/SYSTEM_FOLDER/DOCUMENTS/Stm32Cube_Projects/py32f0_cmake_template-master/App/py32f0xx_hal_conf.h:147,
[build] from P:/SYSTEM_FOLDER/DOCUMENTS/Stm32Cube_Projects/py32f0_cmake_template-master/Drivers/PY32F0xx_HAL_Driver/Inc/py32f0xx_hal.h:33,
[build] from P:/SYSTEM_FOLDER/DOCUMENTS/Stm32Cube_Projects/py32f0_cmake_template-master/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_adc.c:72:
[build] P:/SYSTEM_FOLDER/DOCUMENTS/Stm32Cube_Projects/py32f0_cmake_template-master/Drivers/PY32F0xx_HAL_Driver/Inc/py32f0xx_hal_dma.h:116:3: error: unknown type name 'DMA_Channel_TypeDef'
[build] 116 | DMA_Channel_TypeDef Instance; /!< Register base address */
[build] | ^~~~~~~~~~~~~~~~~~~
[build] P:/SYSTEM_FOLDER/DOCUMENTS/Stm32Cube_Projects/py32f0_cmake_template-master/Drivers/PY32F0xx_HAL_Driver/Inc/py32f0xx_hal_dma.h:136:3: error: unknown type name 'DMA_TypeDef'
[build] 136 | DMA_TypeDef DmaBaseAddress; /!< DMA Channel Base Address */
[build] | ^~~~~~~~~~~
[build] make.exe[2]: *** [CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_adc.c.obj] Error 1
[build] CMakeFiles/py32_cmake_template.elf.dir/build.make:103: recipe for target 'CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_adc.c.obj' failed
[build] In file included from P:/SYSTEM_FOLDER/DOCUMENTS/Stm32Cube_Projects/py32f0_cmake_template-master/App/py32f0xx_hal_conf.h:147,
[build] from P:/SYSTEM_FOLDER/DOCUMENTS/Stm32Cube_Projects/py32f0_cmake_template-master/Drivers/PY32F0xx_HAL_Driver/Inc/py32f0xx_hal.h:33,
[build] from P:/SYSTEM_FOLDER/DOCUMENTS/Stm32Cube_Projects/py32f0_cmake_template-master/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_adc_ex.c:37:
[build] P:/SYSTEM_FOLDER/DOCUMENTS/Stm32Cube_Projects/py32f0_cmake_template-master/Drivers/PY32F0xx_HAL_Driver/Inc/py32f0xx_hal_dma.h:116:3: error: unknown type name 'DMA_Channel_TypeDef'
[build] 116 | DMA_Channel_TypeDef Instance; /!< Register base address */
[build] | ^~~~~~~~~~~~~~~~~~~
[build] P:/SYSTEM_FOLDER/DOCUMENTS/Stm32Cube_Projects/py32f0_cmake_template-master/Drivers/PY32F0xx_HAL_Driver/Inc/py32f0xx_hal_dma.h:136:3: error: unknown type name 'DMA_TypeDef'
[build] 136 | DMA_TypeDef DmaBaseAddress; /!< DMA Channel Base Address */
[build] | ^~~~~~~~~~~
[build] CMakeFiles/py32_cmake_template.elf.dir/build.make:117: recipe for target 'CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_adc_ex.c.obj' failed
[build] make.exe[2]: *** [CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_adc_ex.c.obj] Error 1
[build] In file included from P:/SYSTEM_FOLDER/DOCUMENTS/Stm32Cube_Projects/py32f0_cmake_template-master/App/py32f0xx_hal_conf.h:147,
[build] from P:/SYSTEM_FOLDER/DOCUMENTS/Stm32Cube_Projects/py32f0_cmake_template-master/Drivers/PY32F0xx_HAL_Driver/Inc/py32f0xx_hal.h:33,
[build] from P:/SYSTEM_FOLDER/DOCUMENTS/Stm32Cube_Projects/py32f0_cmake_template-master/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_comp.c:164:
[build] P:/SYSTEM_FOLDER/DOCUMENTS/Stm32Cube_Projects/py32f0_cmake_template-master/Drivers/PY32F0xx_HAL_Driver/Inc/py32f0xx_hal_dma.h:116:3: error: unknown type name 'DMA_Channel_TypeDef'
[build] 116 | DMA_Channel_TypeDef Instance; /!< Register base address */
[build] | ^~~~~~~~~~~~~~~~~~~
[build] P:/SYSTEM_FOLDER/DOCUMENTS/Stm32Cube_Projects/py32f0_cmake_template-master/Drivers/PY32F0xx_HAL_Driver/Inc/py32f0xx_hal_dma.h:136:3: error: unknown type name 'DMA_TypeDef'
[build] 136 | DMA_TypeDef DmaBaseAddress; /!< DMA Channel Base Address */
[build] | ^~~~~~~~~~~
[build] CMakeFiles/py32_cmake_template.elf.dir/build.make:131: recipe for target 'CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_comp.c.obj' failed
[build] make.exe[2]: *** [CMakeFiles/py32_cmake_template.elf.dir/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_comp.c.obj] Error 1
[build] CMakeFiles/Makefile2:82: recipe for target 'CMakeFiles/py32_cmake_template.elf.dir/all' failed
[build] make.exe[1]: *** [CMakeFiles/py32_cmake_template.elf.dir/all] Error 2
[build] Makefile:90: recipe for target 'all' failed
[build] make.exe: *** [all] Error 2
[proc] The command: "C:\Program Files\CMake\bin\cmake.EXE" --build p:/SYSTEM_FOLDER/DOCUMENTS/Stm32Cube_Projects/py32f0_cmake_template-master/build --config Debug --target all -j 14 -- exited with code: 2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.