PY32 Ubuntu GCC 和Vscode开发环境搭建
今天和大家分享一下我这两天玩的py32f003,仅需6毛钱,提供HAL库和LL库,支持MDK和IAR开发
同时github上面也有gcc的模板程序,本次就介绍一下linux下基于gcc+pyocd的环境搭建
这个理论上其实是可以对接RT-Thread Nano的,这里先画一个饼,有空的时候可以试着对接一下
1. 安装 GNU Arm Embedded Toolchain
建议在实体机内下载后,传到虚拟机之中,再进行下面的解压等操作
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. 安装 PyOCD
官方建议从pip安装PyOCD,不要用自带apt仓库,不然版本太低,无法识别JLink OB
pip uninstall pyocd
/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/*
source ~/.profile
3. 克隆py32的 template
git clone
4. Edit Makefile
根据自己需要编辑Makefile
可以控制使用LL库,HAL库,FreeRTOS等
这里是针对py32f003x6型号,使用DAPLink烧录的。
##### Project #####
PROJECT ?= app
# The path for generated files
BUILD_DIR = Build
# 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
# Build with Waveshare e-paper lib, y:yes, n:no
USE_EPAPER ?= n
# Programmer, jlink or pyocd
FLASH_PROGRM ?= pyocd
##### Toolchains #######
#ARM_TOOCHAIN ?= /opt/gcc-arm/gcc-arm-11.2-2022.02-x86_64-arm-none-eabi/bin
#ARM_TOOCHAIN ?= /opt/gcc-arm/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi/bin
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
# JLink device type, options:
# PY32F002AX5, PY32F002X5,
# PY32F003X4, PY32F003X6, PY32F003X8,
# PY32F030X4, PY32F030X6, PY32F030X7, PY32F030X8
JLINK_DEVICE ?= PY32F003X6
# path to PyOCD,
PYOCD_EXE ?= pyocd
# PyOCD device type, options:
# py32f002ax5, py32f002x5,
# py32f003x4, py32f003x6, py32f003x8,
# py32f030x3, py32f030x4, py32f030x6, py32f030x7, py32f030x8
# py32f072xb
PYOCD_DEVICE ?= py32f003x6
##### Paths ############
# Link descript file: py32f002x5.ld, py32f003x6.ld, py32f003x8.ld, py32f030x6.ld, py32f030x8.ld
LDSCRIPT = Libraries/LDScripts/py32f003x6.ld
# Library build flags:
# PY32F002x5, PY32F002Ax5,
# PY32F003x4, PY32F003x6, PY32F003x8,
# PY32F030x3, PY32F030x4, PY32F030x6, PY32F030x7, PY32F030x8,
# PY32F072xB
LIB_FLAGS = PY32F003x6
# C source folders
CDIRS := User
Libraries/CMSIS/Device/PY32F0xx/Source
# C source files (if there are any single ones)
CFILES :=
# ASM source folders
ADIRS := User
# ASM single files
AFILES := Libraries/CMSIS/Device/PY32F0xx/Source/gcc/startup_py32f003.s
# Include paths
INCLUDES := Libraries/CMSIS/Core/Include
Libraries/CMSIS/Device/PY32F0xx/Include
User
ifeq ($(USE_LL_LIB),y)
CDIRS += Libraries/PY32F0xx_LL_Driver/Src
Libraries/BSP_LL/Src
INCLUDES += Libraries/PY32F0xx_LL_Driver/Inc
Libraries/BSP_LL/Inc
LIB_FLAGS += USE_FULL_LL_DRIVER
else
CDIRS += Libraries/PY32F0xx_HAL_Driver/Src
INCLUDES += Libraries/PY32F0xx_HAL_Driver/Inc
endif
ifeq ($(USE_FREERTOS),y)
CDIRS += Libraries/FreeRTOS
Libraries/FreeRTOS/portable/GCC/ARM_CM0
CFILES += Libraries/FreeRTOS/portable/MemMang/heap_4.c
INCLUDES += Libraries/FreeRTOS/include
Libraries/FreeRTOS/portable/GCC/ARM_CM0
endif
ifeq ($(USE_DSP),y)
CFILES += Libraries/CMSIS/DSP/Source/BasicMathFunctions/BasicMathFunctions.c
Libraries/CMSIS/DSP/Source/BayesFunctions/BayesFunctions.c
Libraries/CMSIS/DSP/Source/CommonTables/CommonTables.c
Libraries/CMSIS/DSP/Source/ComplexMathFunctions/ComplexMathFunctions.c
Libraries/CMSIS/DSP/Source/ControllerFunctions/ControllerFunctions.c
Libraries/CMSIS/DSP/Source/DistanceFunctions/DistanceFunctions.c
Libraries/CMSIS/DSP/Source/FastMathFunctions/FastMathFunctions.c
Libraries/CMSIS/DSP/Source/FilteringFunctions/FilteringFunctions.c
Libraries/CMSIS/DSP/Source/InterpolationFunctions/InterpolationFunctions.c
Libraries/CMSIS/DSP/Source/MatrixFunctions/MatrixFunctions.c
Libraries/CMSIS/DSP/Source/QuaternionMathFunctions/QuaternionMathFunctions.c
Libraries/CMSIS/DSP/Source/StatisticsFunctions/StatisticsFunctions.c
Libraries/CMSIS/DSP/Source/SupportFunctions/SupportFunctions.c
Libraries/CMSIS/DSP/Source/SVMFunctions/SVMFunctions.c
Libraries/CMSIS/DSP/Source/TransformFunctions/TransformFunctions.c
INCLUDES += Libraries/CMSIS/DSP/Include
Libraries/CMSIS/DSP/PrivateInclude
endif
ifeq ($(USE_EPAPER),y)
CDIRS += Libraries/EPaper/Lib
Libraries/EPaper/Examples
Libraries/EPaper/Fonts
Libraries/EPaper/GUI
INCLUDES += Libraries/EPaper/Lib
Libraries/EPaper/Examples
Libraries/EPaper/Fonts
Libraries/EPaper/GUI
endif
include 。/rules.mk
5. 尝试编译,烧录
# clean source code
make clean
# build
make
# or make with verbose output
V=1 make
# flash
make flash
6. Vscode配置
c_cpp_properties.json
这个要是没有写的话会报include出错,虽然编译烧录起来都没有问题,但是代码提示功能就基本没有了。
{
“configurations”: [
{
“name”: “Linux”,
“includePath”: [
“${workspaceFolder}/**”,
“${workspaceFolder}/User/**”,
“${workspaceFolder}/Libraries/CMSIS/Core”,
“/opt/gcc-arm/arm-gnu-toolchain-12.2.rel1-x86_64-arm-none-eabi/arm-none-eabi/include”,
“/opt/gcc-arm/arm-gnu-toolchain-12.2.rel1-x86_64-arm-none-eabi/lib/gcc/arm-none-eabi/12.2.1/include”
],
“defines”: [
“PY32F003x6”
],
“compilerPath”: “/opt/gcc-arm/arm-gnu-toolchain-12.2.rel1-x86_64-arm-none-eabi/bin/arm-none-eabi-gcc”,
“cStandard”: “gnu99”,
“cppStandard”: “gnu++14”,
“intelliSenseMode”: “gcc-arm”
}
],
“version”: 4
}
OA
识别不到DAPLink怎么办?
实际发现有时候运行make flash,会一直在等待debug probe connect这时候可以试试拔插DAPLINK,重连一下,以及检查是不是连接到主机了而不是实体机中。
原作者:goldengrandpa