搭建GD32F405基础工程
创意脱衣机工程
[一]准备工作
1.1 创作文件夹 GD32F405_RTT 并创作文件目录
文件目录释义:
Application ---- 应用文件
Board ---- 版级相关文件
Driver ---- 驱动程序
Firmware ---- 生成固件
Library ---- 固件库
Project ---- 工程文件
System ---- rtt-thread源代码
1.2 添加固定文件到库
1.3 添加it.c systick.c到Board
1.4 添加main.c到Application
[二]创建工程
2.1 新建工程并选型号为GD32F405VG 新建工程目录
2.2 添加固定文件库文件
2.3 添加CMSIS文件
2.4 gd32f4xx_it.c systick.c 放入Board目录下
2.5 main放板目录下
2.6 工程配置
2.7 编译
2.8 配置系统时钟为HSE 12MHZ 配置滴答定时器中断为10ms触发(根据自己硬件来的)
2.8 添加测试代码在main.c中添加跑马灯测试程序
#include "gd32f4xx.h"
#include "systick.h"
#include <stdio.h>
static void RCC_Configuration(void);
#define LED_RCC RCU_GPIOE
#define LED_GPIO GPIOE
#define LED_R_PIN GPIO_PIN_9
#define LED_Y_PIN GPIO_PIN_10
#define LED_G_PIN GPIO_PIN_11
int main(void)
{
//配置系统时钟时钟
RCC_Configuration();
//配置系统滴答定时器 10ms
systick_config();
rcu_periph_clock_enable(LED_RCC);
gpio_mode_set(LED_GPIO, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LED_R_PIN);
gpio_output_options_set(LED_GPIO, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, LED_R_PIN);
gpio_bit_reset(LED_GPIO, LED_R_PIN);
gpio_mode_set(LED_GPIO, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LED_Y_PIN);
gpio_output_options_set(LED_GPIO, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, LED_Y_PIN);
gpio_bit_reset(LED_GPIO, LED_Y_PIN);
gpio_mode_set(LED_GPIO, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LED_G_PIN);
gpio_output_options_set(LED_GPIO, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, LED_G_PIN);
gpio_bit_reset(LED_GPIO, LED_G_PIN);
while (1)
{
delay_1ms(100); //配置的10ms一次触发中断 100*10 = 1s
gpio_bit_set(LED_GPIO, LED_R_PIN);
delay_1ms(100);
gpio_bit_set(LED_GPIO, LED_Y_PIN);
delay_1ms(100);
gpio_bit_set(LED_GPIO, LED_G_PIN);
delay_1ms(100);
gpio_bit_reset(LED_GPIO, LED_R_PIN);
delay_1ms(100);
gpio_bit_reset(LED_GPIO, LED_Y_PIN);
delay_1ms(100);
gpio_bit_reset(LED_GPIO, LED_G_PIN);
}
}
static void RCC_Configuration(void)
{
ErrStatus HSEStartUpStatus;
rcu_deinit();
rcu_osci_on(RCU_HXTAL);
HSEStartUpStatus = rcu_osci_stab_wait(RCU_HXTAL);
if (HSEStartUpStatus == SUCCESS)
{
rcu_ahb_clock_config(RCU_AHB_CKSYS_DIV1); // 24MHz
rcu_apb2_clock_config(RCU_APB2_CKAHB_DIV1); // 24MHz
rcu_apb1_clock_config(RCU_APB1_CKAHB_DIV2); // 12MHz
rcu_pll_config(RCU_PLLSRC_HXTAL, 12, 192, 8, 8);
rcu_osci_on(RCU_PLL_CK);
if (rcu_osci_stab_wait(RCU_PLL_CK) != SUCCESS)
{
while (1)
;
}
rcu_system_clock_source_config(RCU_CKSYSSRC_PLLP);
while (rcu_system_clock_source_get() != RCU_SCSS_PLLP)
{
}
}
}
添加RTT源代码(完整版)
[一]准备工作
1.1 准备一个dist 这里用的是GD32F450Z-EVAL的bsp 按图放好文件即可
把startup_gd32f4xx.s放在板文件夹下
[二]工程配置
2.1 删除源startup_gd32405.s 增加startup_gd32f4xx.s
2.2 添加源文件 src 文件夹下所有文件 不需要kconfig
2.3 新建工程目录 CPU —> 添加libcpu中的文件
2.4 配置RT-rhread
董事会.h
/*
Copyright (c) 2006-2021, RT-Thread Development Team
SPDX-License-Identifier: Apache-2.0
Change Logs:
Date Author Notes
2009-09-22 Bernard add board.h to this bsp
/
// <<< Use Configuration Wizard in Context Menu >>>
#ifndef BOARD_H
#define BOARD_H
#include <gd32f4xx.h>
#define EXT_SDRAM_BEGIN (0xC0000000U) /* the begining address of external SDRAM /
#define EXT_SDRAM_END (EXT_SDRAM_BEGIN + (32U * 1024 * 1024)) / the end address of external SDRAM */
// Internal SRAM memory size[Kbytes] <8-64>
// Default: 64
#ifdef ICCARM
// Use *.icf ram symbal, to avoid hardcode.
extern char ICFEDIT_region_RAM_end;
#define GD32_SRAM_END &ICFEDIT_region_RAM_end
#else
#define GD32_SRAM_SIZE 128
#define GD32_SRAM_END (0x20000000 + GD32_SRAM_SIZE * 1024)
#endif
#ifdef __CC_ARM
extern int Image$$
RW_IRAM1
Limit;
#define HEAP_BEGIN (&Image
RW_IRAM1
ZI
Limit)
#elif ICCARM
#pragma section="HEAP"
#define HEAP_BEGIN (__segment_end("HEAP"))
#else
extern int bss_end;
#define HEAP_BEGIN (&bss_end)
#endif
#define HEAP_END GD32_SRAM_END
#endif
//*** <<< end of configuration section >>> ***
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_USING_IDLE_HOOK
#define RT_IDLE_HOOK_LIST_SIZE 4
#define IDLE_THREAD_STACK_SIZE 256
#define RT_DEBUG
#define RT_DEBUG_COLOR
/ 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_HEAP
/ Kernel Device Object /
//#define RT_USING_DEVICE
//#define RT_USING_CONSOLE
//#define RT_CONSOLEBUF_SIZE 128
//#define RT_CONSOLE_DEVICE_NAME "uart0"
#define RT_VER_NUM 0x40002
/ 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
/ C++ features /
/ Command shell /
//#define RT_USING_FINSH
//#define FINSH_THREAD_NAME "tshell"
//#define FINSH_USING_HISTORY
//#define FINSH_HISTORY_LINES 5
//#define FINSH_USING_SYMTAB
//#define FINSH_USING_DESCRIPTION
//#define FINSH_THREAD_PRIORITY 20
//#define FINSH_THREAD_STACK_SIZE 4096
//#define FINSH_CMD_SIZE 80
//#define FINSH_USING_MSH
//#define FINSH_USING_MSH_DEFAULT
//#define FINSH_ARG_MAX 10
/ Device virtual file system /
/ elm-chan's FatFs, Generic FAT Filesystem Module /
/ Device Drivers /
/ Using Hardware Crypto drivers /
/ Using WiFi /
/ Using USB /
/ POSIX layer and C standard library /
/ Network /
/ Socket abstraction layer /
/ protocol stack implement /
/ Network interface device /
/ light weight TCP/IP stack /
/ Static IPv4 Address /
/ Modbus master and slave stack /
/ AT commands /
/ VBUS(Virtual Software BUS) /
/ Utilities /
/ RT-Thread online packages /
/ IoT - internet of things /
/ Wi-Fi /
/ Marvell WiFi /
/ Wiced WiFi /
/ IoT Cloud /
/ security packages /
/ language packages /
/ multimedia packages /
/ tools packages /
/ system packages /
/ peripheral libraries and drivers /
/ miscellaneous packages /
/ samples: kernel and components samples */
#define BSP_USING_SDRAM
#define BSP_USING_UART0
#endif
[三]编译
对接驱动以及测试
应用程序编写
原作者:keyq