1.增加rt-thread-v4.1.0源码
rt-thread-v4.1.0\bsp\gd32350r-eval复制重命名为gd32f330_v1
2.文件组织结构
Usr:存放App任务应用,属于应用层,完全脱离硬件
CMSIS:硬件层,启动文件、系统文件
Driver:硬件外设驱动库(MCU厂商提供)
rt-thread_components_board:bsp\gd32f330_v1\drivers文件夹,板级BSP
rt-thread_src:\src文件夹,rt-thread内核源码
rt-thread_libcpu:\libcpu文件夹,rt-thread内核源码
rt-thread_components_finsh:components\finsh文件夹
rt-thread_components_driver:components\drivers文件夹
插一句,\bsp\gd32\libraries\gd32_drivers不适合用于GD32F330芯片
宏定义,–c99,头文件路径
3.menuconfig
保存之后自动更新rtconfig.h
//rtconfig.h
#ifndef RT_CONFIG_H__
#define RT_CONFIG_H__/* Automatically generated file; DO NOT EDIT. */
/* RT-Thread Configuration *//* RT-Thread Kernel */#define RT_NAME_MAX 8
#define RT_ALIGN_SIZE 4
#define RT_THREAD_PRIORITY_32
#define RT_THREAD_PRIORITY_MAX 32
#define RT_TICK_PER_SECOND 100
#define RT_USING_OVERFLOW_CHECK
#define RT_USING_HOOK
#define RT_HOOK_USING_FUNC_PTR
#define RT_USING_IDLE_HOOK
#define RT_IDLE_HOOK_LIST_SIZE 4
#define IDLE_THREAD_STACK_SIZE 256
#define RT_USING_TIMER_SOFT
#define RT_TIMER_THREAD_PRIO 4
#define RT_TIMER_THREAD_STACK_SIZE 512/* kservice optimization */#define RT_DEBUG/* Inter-Thread communication */#define RT_USING_SEMAPHORE
#define RT_USING_MUTEX
#define RT_USING_EVENT
#define RT_USING_MAILBOX
#define RT_USING_MESSAGEQUEUE/* Memory Management */#define RT_USING_MEMPOOL
#define RT_USING_SMALL_MEM
#define RT_USING_SMALL_MEM_AS_HEAP
#define RT_USING_HEAP/* Kernel Device Object */#define RT_USING_DEVICE
#define RT_USING_CONSOLE
#define RT_CONSOLEBUF_SIZE 128
#define RT_CONSOLE_DEVICE_NAME "uart1"
#define RT_VER_NUM 0x40100/* RT-Thread Components */#define RT_USING_COMPONENTS_INIT
#define RT_USING_USER_MAIN
#define RT_MAIN_THREAD_STACK_SIZE 2048
#define RT_MAIN_THREAD_PRIORITY 10
#define RT_USING_MSH
#define RT_USING_FINSH
#define FINSH_USING_MSH
#define FINSH_THREAD_NAME "tshell"
#define FINSH_THREAD_PRIORITY 20
#define FINSH_THREAD_STACK_SIZE 4096
#define FINSH_USING_HISTORY
#define FINSH_HISTORY_LINES 5
#define FINSH_USING_SYMTAB
#define FINSH_CMD_SIZE 80
#define MSH_USING_BUILT_IN_COMMANDS
#define FINSH_USING_DESCRIPTION
#define FINSH_ARG_MAX 10/* Device Drivers */#define RT_USING_DEVICE_IPC
#define RT_USING_SERIAL
#define RT_USING_SERIAL_V1
#define RT_SERIAL_USING_DMA
#define RT_SERIAL_RB_BUFSZ 64
#define RT_USING_PIN/* Using USB *//* C/C++ and POSIX layer */#define RT_LIBC_DEFAULT_TIMEZONE 8/* POSIX (Portable Operating System Interface) layer *//* Interprocess Communication (IPC) *//* Socket is in the 'Network' category *//* Network *//* Utilities *//* RT-Thread Utestcases *//* RT-Thread online packages *//* IoT - internet of things *//* Wi-Fi *//* Marvell WiFi *//* Wiced WiFi *//* CYW43012 WiFi *//* IoT Cloud *//* security packages *//* language packages *//* JSON: JavaScript Object Notation, a lightweight data-interchange format *//* XML: Extensible Markup Language *//* multimedia packages *//* LVGL: powerful and easy-to-use embedded GUI library *//* u8g2: a monochrome graphic library *//* tools packages *//* system packages *//* enhanced kernel services *//* acceleration: Assembly language or algorithmic acceleration packages *//* CMSIS: ARM Cortex-M Microcontroller Software Interface Standard *//* Micrium: Micrium software products porting for RT-Thread *//* peripheral libraries and drivers *//* sensors drivers *//* touch drivers *//* Kendryte SDK *//* AI packages *//* Signal Processing and Control Algorithm Packages *//* miscellaneous packages *//* project laboratory *//* samples: kernel and components samples *//* entertainment: terminal games and other interesting software packages */#define SOC_GD32350R
#define BSP_USING_UART1#endif
4.代码
主要修改Usr(App)、rt-thread_bsp_board(BSP)文件,但rtconfig.h使用ENV菜单方式menuconfig命令修改后保存自动得到。
//main.c
#include <rthw.h>
#include <stdio.h>
#include <rtthread.h>
#include <rtdevice.h>
#include "drv_gpio.h"
#include "gd32f3x0.h"/* defined the LED2 pin: PC6 */
#define LED1_PIN GET_PIN(B, 1)
#define LED2_PIN GET_PIN(B, 2)#define delay_ms(x) rt_thread_mdelay(x)#define RT_USR1_THREAD_PRIO 6
#define USR1_THREAD_NAME "usr1"
static struct rt_thread usr1_thread;
static rt_uint8_t usr1_thread_stack[RT_MAIN_THREAD_STACK_SIZE];void rt_thread_usr1_entry(void *parameter)
{/* set LED2 pin mode to output */rt_pin_mode(LED2_PIN, PIN_MODE_OUTPUT);while (1){rt_pin_write(LED2_PIN, PIN_HIGH);rt_thread_mdelay(2000);rt_pin_write(LED2_PIN, PIN_LOW);rt_thread_mdelay(2000);}
}int main(void)
{rt_thread_init(&usr1_thread,USR1_THREAD_NAME,rt_thread_usr1_entry,RT_NULL,&usr1_thread_stack[0],sizeof(usr1_thread_stack),RT_USR1_THREAD_PRIO,20);rt_thread_startup(&usr1_thread);/* set LED1 pin mode to output */rt_pin_mode(LED1_PIN, PIN_MODE_OUTPUT);while (1){rt_pin_write(LED1_PIN, PIN_HIGH);rt_thread_mdelay(500);rt_pin_write(LED1_PIN, PIN_LOW);rt_thread_mdelay(500);}
}