gd32笔记[1]-搭建PlatformIO开发环境

摘要

在macOS上搭建gd32f103cbt6的PlatformIO的开发环境,编译点灯例程.

关键信息

  • macOS 14.4.1(Apple Silicon M2)
  • 宿主平台:VSCODE
  • PIO Core v6.1.7
  • 芯片:GD32F103CBT6

原理简介

PlatformIO简介

[https://docs.platformio.org/en/latest/what-is-platformio.html]
A place where Developers and Teams have true Freedom! No more vendor lock-in!
PlatformIO is a cross-platform, cross-architecture, multiple framework, professional tool for embedded systems engineers and for software developers who write applications for embedded products.
PlatformIO’s unique philosophy in the embedded market provides developers with a modern integrated development environment (Cloud & Desktop IDEs) that works cross-platform, supports many different software development kits (SDKs) or Frameworks, and includes sophisticated debugging (Debugging), unit testing (Unit Testing), automated code analysis (Static Code Analysis), and remote management (Remote Development). It is architected to maximize flexibility and choice by developers, who can use either graphical or command line editors (PlatformIO Core (CLI)), or both.
PlatformIO is a must-have tool for professional embedded systems engineers who develop solutions on more than one specific platform. In addition, by having a decentralized architecture, PlatformIO offers both new and existing developers a quick integration path for developing commercial-ready products, and reduces the overall time-to-market.
And it runs on any one of your favorite modern operating systems (macOS, MS Windows, Linux, FreeBSD).
一个开发者和团队能够享有真正自由的地方!不再有供应商锁定!
PlatformIO 是一个跨平台、跨架构、多框架的专业工具,适用于嵌入式系统工程师,以及为嵌入式产品编写应用程序的软件开发人员。
PlatformIO 在嵌入式市场的独特理念为开发者提供了一个现代化的集成开发环境(云和桌面 IDE),它能够跨平台工作,支持许多不同的软件开发套件(SDK)或框架,并包括复杂的调试(调试)、单元测试(单元测试)、自动代码分析(静态代码分析)和远程管理(远程开发)。它的架构旨在最大化开发者的灵活性和选择权,开发者可以使用图形界面或命令行编辑器(PlatformIO Core (CLI)),或两者兼用。
PlatformIO 是专业嵌入式系统工程师必不可少的工具,他们开发的产品不仅仅针对一个特定的平台。此外,通过拥有去中心化的架构,PlatformIO 为新晋和现有开发者提供了一个快速整合的路径,用于开发商业级产品,并减少了上市总时间。
它能够在您喜欢的任何现代操作系统上运行(macOS、MS Windows、Linux、FreeBSD)。

GD32F103CBT6简介

[https://blog.csdn.net/a1058191679/article/details/120954423]
[https://www.gigadevice.com/product/mcu/arm-cortex-m3/gd32f103cbt6]
GD32F1 is a new series product of 32-bit general-purpose, high-performance, and low-power MCU powered by the ARM® Cortex®-M3 core, suitable for a wide range of application scenarios. The GD32F1 product series integrates rich features to simplify system design and provide customers with a wide range of superior cost-effective MCU portfolios with proven technology and great innovations. Building on GigaDevice advanced gFlash technology and mass production experiences, it provides a new form of MCUs which offer customers high functionality and quality. The GD32F1 series is available in a lineup of basic, mainstream, connectivity, value, and performance.

The GD32F1 series of MCUs incorporates the 32-bit ARM® Cortex®-M3 core operating at 108MHz maximum frequency with Flash accesses zero wait states to obtain maximum efficiency. Meanwhile, it provides up to 3024KB on-chip Flash memory and up to 96KB SRAM. An extensive range of enhanced I/O ports and on-chip peripherals are connected to two APB buses. The MCU series provides up to three 12-bit 1MSPS ADCs and ten general-purpose 16-bit timers plus one PWM advanced timer, as well as standard and advanced communication interfaces.

The GD32F1 series of MCUs also brings many advantages to end-users. The maximum speed of GD32F1 series MCUs has been increased 50% than market's products. The code execution efficiency has been enhanced by 30% to 40% and power consumption had reduced by 20% to 30% in the same frequency. These performances provide maximum capability and bandwidth options for various market requirements.

The GD32F1 series of MCUs is widely suitable for fields of industrial control, human-machine interface, motor control, power monitor and alarm systems, consumer and handheld equipment, solar photovoltaic control, touch panel, and more.
GD32F1 是一款由 ARM® Cortex®-M3 内核提供支持的全新 32 位通用、高性能、低功耗微控制器系列,适用于广泛的应用场景。GD32F1 产品系列集成了丰富的特性,以简化系统设计,为客户提供具有经过验证技术和重大创新的高性价比 MCU 组合。基于 GigaDevice 先进的 gFlash 技术和大规模生产经验,它为客户提供了一种提供高功能和质量的新型 MCU。GD32F1 系列包括基础型、主流型、连接型、价值型和性能型等多种型号。
GD32F1 系列的微控制器内置了 32 位 ARM® Cortex®-M3 内核,最高运行频率可达 108MHz,并且 Flash 存储器访问零等待状态,以获得最大效率。同时,它提供高达 3024KB 的片上 Flash 存储器和高达 96KB 的 SRAM。一系列增强的 I/O 端口和片上外设连接到两个 APB 总线上。该 MCU 系列提供多达三个 12 位 1MSPS ADC 和十个通用 16 位定时器以及一个 PWM 高级定时器,以及标准和高级通信接口。
GD32F1 系列的微控制器也为终端用户带来了许多优势。GD32F1 系列微控制器的最大速度比市场产品提高了 50%。代码执行效率提高了 30% 到 40%,并且在相同频率下功耗降低了 20% 到 30%。这些性能为满足各种市场需求提供了最大的能力和带宽选项。
GD32F1 系列的微控制器广泛应用于工业控制、人机界面、电机控制、电源监控和报警系统、消费类和手持设备、太阳能光伏控制、触摸面板等领域。

GD32的SPL库简介

[https://bbs.21ic.com/icview-3381260-1-1.html]
GD32系列提供了一些库函数,与STM32的标准外设库(SPL)类似,用于配置和控制硬件资源。这些库函数可以帮助简化代码编写和硬件操作。尽管它们与STM32的库函数类似,但并不完全兼容。因此,在从STM32迁移到GD32时,可能需要进行一些适配和调整以确保代码的正确性和可靠性。

CommunityGD32Cores/platform-gd32简介

[https://gitcode.com/CommunityGD32Cores/platform-gd32/overview]
这是专为 GD32F、GD32E、GD32W 和 GD32C 系列芯片设计的 PlatformIO 平台实现。目前仍在开发中。
支持的板卡
请查阅 boards 文件夹。

  • GD32L23x(Cortex-M23)
  • GD32C10x(Cortex-M4)
  • GD32W51x(Cortex-M33)
  • GD32E10x(Cortex-M4)
  • GD32E23x(Cortex-M23)
  • GD32E50x(Cortex-M33)
  • GD32F10x(Cortex-M4)
  • GD32F1x0(Cortex-M3)
  • GD32F20x(Cortex-M3)
  • GD32F30x(Cortex-M4)
  • GD32F3x0(Cortex-M4)
  • GD32F4xx(Cortex-M4)
  • GD32F403(Cortex-M4)
    所有基于 ARM 架构的 GD32 微控制器都可通过 genericGD32... 板卡定义支持。此外,还支持由 Gigadevice 及其他厂商制造的许多 GD32 开发板。
    请参考示例项目:https://github.com/CommunityGD32Cores/gd32-pio-projects。
    该平台可以通过命令行工具手动安装:pio platform install https://github.com/CommunityGD32Cores/platform-gd32.git(参见 PlatformIO Core CLI 文档)。当你编译其中一个示例项目时,这会自动完成。

实现

安装PlatformIO

  1. VSCODE安装PlatformIO插件
    启用插件会显示初始化中,如果有魔法可以跳过如下步骤.
  2. 使用国内源进行初始化
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
conda create -n platformio python=3.9 -y
# 激活新创建的环境
conda init bash
conda activate platformio
python -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pqi 
python -m PQI.pqi use ustc
wget https://raw.gitcode.com/platformio/platformio-core-installer/raw/master/get-platformio.py
python get-platformio.py 
echo 'export PATH=$PATH:/Users/workspace/.platformio/penv/bin' >> ~/.zshrc
source ~/.zshrc
pio boards

然后重启vscode;

初始化GD32支持&新建工程

#安装gd32 sdk和toolchain等
export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890
pio pkg install -l https://gitcode.com/QS2002/platform-gd32.git
# 新建一个项目文件夹
mkdir nebula-gd32f103cbt6-blink-platformio && cd nebula-gd32f103cbt6-blink-platformio
# 初始化一个genericGD32F103CB board项目
pio project init --board genericGD32F103CB

编译

工程目录下新建src/main.c

#if defined(GD32F10x)
#include "gd32f10x.h"
#endif

/* define blinky LED pin here, board specific, otherwise default PC13 */
#define LEDPORT     GPIOC
#define LEDPIN      GPIO_PIN_13
#define LED_CLOCK   RCU_GPIOC

void systick_config(void);
void delay_1ms(uint32_t count);

int main(void)
{
    systick_config();

    rcu_periph_clock_enable(LED_CLOCK);

    /* set output as output */
#if defined(GD32F3x0) || defined(GD32F1x0) || defined(GD32F4xx) || defined(GD32E23x) || defined(GD32L23x) || defined(GD32W51x)
    gpio_mode_set(LEDPORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LEDPIN);
    gpio_output_options_set(LEDPORT, GPIO_OTYPE_PP, GPIO_OSPEED_2MHZ, LEDPIN);
#else /* valid for GD32F10x, GD32E20x, GD32F30x, GD32F403, GD32E10X, GD32C10X */
    gpio_init(LEDPORT, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, LEDPIN);
#endif
    while (1)
    {
        gpio_bit_set(LEDPORT, LEDPIN);
        delay_1ms(100);
        gpio_bit_reset(LEDPORT, LEDPIN);
        delay_1ms(100);
    }
}

volatile static uint32_t delay;

void systick_config(void)
{
    /* setup systick timer for 1000Hz interrupts */
    if (SysTick_Config(SystemCoreClock / 1000U))
    {
        /* capture error */
        while (1)
        {
        }
    }
    /* configure the systick handler priority */
    NVIC_SetPriority(SysTick_IRQn, 0x00U);
}

void delay_1ms(uint32_t count)
{
    delay = count;

    while (0U != delay)
    {
    }
}

void delay_decrement(void)
{
    if (0U != delay)
    {
        delay--;
    }
}

void NMI_Handler(void) {}

void HardFault_Handler(void)
{
    while (1)
        ;
}

void MemManage_Handler(void)
{
    while (1)
        ;
}

void BusFault_Handler(void)
{
    while (1)
        ;
}

void UsageFault_Handler(void)
{
    while (1)
        ;
}

void SVC_Handler(void)
{
}

void DebugMon_Handler(void)
{
}

void PendSV_Handler(void)
{
}

void SysTick_Handler(void)
{
    delay_decrement();
}

然后编译:

pio run -e genericGD32F103CB

效果

h:1492:13: warning: 'enet_delay' declared 'static' but never defined [-Wunused-function]
 1492 | static void enet_delay(uint32_t ncount);
      |             ^~~~~~~~~~
Archiving .pio/build/genericGD32F103CB/libFrameworkSPL.a
Indexing .pio/build/genericGD32F103CB/libFrameworkCMSISVariant.a
Indexing .pio/build/genericGD32F103CB/libFrameworkSPL.a
Indexing .pio/build/genericGD32F103CB/lib81a/libplatform-gd32.a
Linking .pio/build/genericGD32F103CB/firmware.elf
Checking size .pio/build/genericGD32F103CB/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   0.2% (used 36 bytes from 20480 bytes)
Flash: [          ]   0.7% (used 920 bytes from 131072 bytes)
Building .pio/build/genericGD32F103CB/firmware.bin
================ [SUCCESS] Took 10.40 seconds ================
posted @ 2024-06-09 02:43  qsBye  阅读(199)  评论(0编辑  收藏  举报