串口和中断写完

This commit is contained in:
2026-05-25 23:53:30 +08:00
parent 589b67a3f9
commit bedceb1785
4 changed files with 15 additions and 20 deletions
+9 -12
View File
@@ -1,7 +1,6 @@
// //
// Created by anonymous on 2026/5/24. // Created by anonymous on 2026/5/24.
// //
#include "Bsp.h"
#include "Voilet.h" #include "Voilet.h"
// LED灯数组 // LED灯数组
@@ -25,7 +24,8 @@ const GPIO_CONFIG DO_PERIPH[] = {
#endif #endif
//串口配置表 //串口配置表
const COM_CONFIG COM_PERIPH[] = { const COM_CONFIG COM_PERIPH[] = {
{COM1,.TxPort = GPIO2, .TxMode = GPIO_Mode_AF_PP,.RxPort = GPIO3, .RxMode = GPIO_Mode_IPU,.Speed = GPIO_Speed_50MHz}, {COM0,.TxPort = GPIO9, .RxPort =GPIO10, .Speed = GPIO_Speed_50MHz},
{COM1,.TxPort = GPIO2, .RxPort = GPIO3, .Speed = GPIO_Speed_50MHz},
}; };
void BspExtraInit(void); void BspExtraInit(void);
@@ -41,17 +41,15 @@ void VoiletBspInit(void) {
INTERRUPT_DISABLE INTERRUPT_DISABLE
//初始化中断系统
IrqInit();
//初始化延时库 //初始化延时库
DelayConfig(); DelayConfig();
//关闭所有外设时钟
AllPeriphClockDisable();
//LED灯配置 //LED灯配置
#if (LED_NUM != 0) #if (LED_NUM != 0)
for (i = 0;i < LED_NUM;i++) { for (i = 0;i < ARRAY_LEN(LED_PERIPH);i++) {
//打开外设时钟
GpioClockEnable(&LED_PERIPH[i].GpioX);
//配置GPIO口 //配置GPIO口
GpioConfig(&LED_PERIPH[i].GpioX, LED_PERIPH[i].Mode, LED_PERIPH[i].Speed); GpioConfig(&LED_PERIPH[i].GpioX, LED_PERIPH[i].Mode, LED_PERIPH[i].Speed);
} }
@@ -79,9 +77,8 @@ void VoiletBspInit(void) {
//串口配置 //串口配置
for (i = 0;i < ARRAY_LEN(COM_PERIPH);i++) { for (i = 0;i < ARRAY_LEN(COM_PERIPH);i++) {
UartClockEnable(&COM_PERIPH[i].ComX); GpioConfig(&COM_PERIPH[i].TxPort, GPIO_Mode_AF_PP, COM_PERIPH[i].Speed);
GpioConfig(&COM_PERIPH[i].TxPort, COM_PERIPH[i].TxMode, COM_PERIPH[i].Speed); GpioConfig(&COM_PERIPH[i].RxPort, GPIO_Mode_IPU, COM_PERIPH[i].Speed);
GpioConfig(&COM_PERIPH[i].TxPort, COM_PERIPH[i].RxMode, COM_PERIPH[i].Speed);
} }
INTERRUPT_ENABLE INTERRUPT_ENABLE
@@ -99,7 +96,7 @@ void BspExtraInit(void)
{ {
//LetterShell初始化 //LetterShell初始化
#ifdef USE_SHELL #ifdef USE_SHELL
// LetterShellInit(TTY_COM,TTY_BAUD); LetterShellInit(TTY_COM,TTY_BAUD);
#endif #endif
} }
+4 -4
View File
@@ -5,6 +5,8 @@
#ifndef VOILET_H #ifndef VOILET_H
#define VOILET_H #define VOILET_H
#include "Bsp.h"
#define LED_NUM 2 //LED灯数量 #define LED_NUM 2 //LED灯数量
#if (LED_NUM != 0) #if (LED_NUM != 0)
#define LED0 0 #define LED0 0
@@ -19,8 +21,8 @@
#if (DO_NUM != 0) #if (DO_NUM != 0)
#endif #endif
#define USE_SHELL //系统使用Shell
#define TTY_COM COM1 #define TTY_COM COM1
#define TTY_BAUD 115200
typedef struct { typedef struct {
GPIO_MAP_T GpioX; GPIO_MAP_T GpioX;
@@ -29,11 +31,9 @@ typedef struct {
}GPIO_CONFIG; }GPIO_CONFIG;
typedef struct { typedef struct {
COM_MAP_T ComX; COM_MAP_T *ComX;
GPIO_MAP_T TxPort; GPIO_MAP_T TxPort;
GPIOMode_TypeDef TxMode;
GPIO_MAP_T RxPort; GPIO_MAP_T RxPort;
GPIOMode_TypeDef RxMode;
GPIOSpeed_TypeDef Speed; GPIOSpeed_TypeDef Speed;
}COM_CONFIG; }COM_CONFIG;
+1 -3
View File
@@ -6,14 +6,12 @@
#include <stdint.h> #include <stdint.h>
/* BSP文件 */ /* BSP文件 */
#include "main.h" #include "main.h"
#include "Bsp.h" #include "Voilet.h"
int main(void) { int main(void) {
VoiletBspInit(); VoiletBspInit();
UartStdConfig((COM_MAP_T)COM1,9600);
while (1) { while (1) {
LedToggle(LED0); LedToggle(LED0);
DelayMs(100); DelayMs(100);