串口和中断写完
This commit is contained in:
@@ -1,64 +1,5 @@
|
||||
#include "Bsp.h"
|
||||
|
||||
void AllPeriphClockDisable(void);
|
||||
|
||||
/**
|
||||
* @brief 关闭所有外设时钟
|
||||
* @note void
|
||||
* @param void
|
||||
* @retval void
|
||||
*/
|
||||
void AllPeriphClockDisable(void)
|
||||
{
|
||||
// ==================== GPIOA 组 ====================
|
||||
#ifdef GPIOA
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, DISABLE);
|
||||
#endif
|
||||
#ifdef GPIOB
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, DISABLE);
|
||||
// ==================== GPIOB 组 ====================
|
||||
#endif
|
||||
#ifdef GPIOC
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, DISABLE);
|
||||
// ==================== GPIOC 组 ====================
|
||||
#endif
|
||||
#ifdef GPIOD
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, DISABLE);
|
||||
// ==================== GPIOD 组 ====================
|
||||
#endif
|
||||
#ifdef GPIOE
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, DISABLE);
|
||||
// ==================== GPIOE 组 ====================
|
||||
#endif
|
||||
#ifdef GPIOF
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF, DISABLE);
|
||||
// ==================== GPIOF 组 ====================
|
||||
#endif
|
||||
#ifdef GPIOG
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOG, DISABLE);
|
||||
// ==================== GPIOG 组 ====================
|
||||
#endif
|
||||
|
||||
#ifdef USART1
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, DISABLE);
|
||||
#endif
|
||||
|
||||
#ifdef USART2
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, DISABLE);
|
||||
#endif
|
||||
|
||||
#ifdef USART3
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, DISABLE);
|
||||
#endif
|
||||
|
||||
#ifdef UART4
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, DISABLE);
|
||||
#endif
|
||||
|
||||
#ifdef UART5
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, DISABLE);
|
||||
#endif
|
||||
}
|
||||
//
|
||||
// #ifdef USE_DIGITAL_OUTPUT
|
||||
// GPIO_ST DigiTalOutPut[DO_NUM] =
|
||||
|
||||
+8
-26
@@ -8,26 +8,7 @@
|
||||
*/
|
||||
void GpioClockEnable(const GPIO_MAP_T *GpioX)
|
||||
{
|
||||
if(GpioX->Periph == GPIOA)
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
|
||||
|
||||
if(GpioX->Periph == GPIOB)
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
|
||||
|
||||
if(GpioX->Periph == GPIOC)
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
|
||||
|
||||
if(GpioX->Periph == GPIOD)
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
|
||||
|
||||
if(GpioX->Periph == GPIOE)
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
|
||||
|
||||
if(GpioX->Periph == GPIOF)
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF, ENABLE);
|
||||
|
||||
if(GpioX->Periph == GPIOG)
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOG, ENABLE);
|
||||
GpioX->ClockCmd(GpioX->ClockTree,ENABLE);
|
||||
}
|
||||
/**
|
||||
* @brief 配置GPIO口
|
||||
@@ -39,11 +20,12 @@ void GpioConfig(const GPIO_MAP_T *GpioX, GPIOMode_TypeDef GpioMode, GPIOSpeed_Ty
|
||||
{
|
||||
GPIO_InitTypeDef GpioInitSt;
|
||||
|
||||
GpioInitSt.GPIO_Pin = GpioX->GpioPin;
|
||||
GpioInitSt.GPIO_Pin = GpioX->Periph.GpioPin;
|
||||
GpioInitSt.GPIO_Mode = GpioMode;
|
||||
GpioInitSt.GPIO_Speed = GpioSpeed;
|
||||
|
||||
GPIO_Init(GpioX->Periph, &GpioInitSt);
|
||||
//打开外设时钟
|
||||
GpioClockEnable(GpioX);
|
||||
GPIO_Init(GpioX->Periph.GpioPort, &GpioInitSt);
|
||||
}
|
||||
/**
|
||||
* @brief 改变GPIO口状态
|
||||
@@ -55,11 +37,11 @@ void GpioSet(const GPIO_MAP_T *GpioX, uint8_t Value)
|
||||
{
|
||||
if (Value == (uint8_t)RESET)
|
||||
{
|
||||
GPIO_ResetBits(GpioX->Periph, GpioX->GpioPin);
|
||||
GPIO_ResetBits(GpioX->Periph.GpioPort, GpioX->Periph.GpioPin);
|
||||
}
|
||||
else if (Value == (uint8_t)SET)
|
||||
{
|
||||
GPIO_SetBits(GpioX->Periph, GpioX->GpioPin);
|
||||
GPIO_SetBits(GpioX->Periph.GpioPort, GpioX->Periph.GpioPin);
|
||||
}
|
||||
}
|
||||
/**
|
||||
@@ -70,6 +52,6 @@ void GpioSet(const GPIO_MAP_T *GpioX, uint8_t Value)
|
||||
*/
|
||||
unsigned char GpioGet(const GPIO_MAP_T *GpioX)
|
||||
{
|
||||
return (unsigned char)GPIO_ReadInputDataBit(GpioX->Periph, GpioX->GpioPin);
|
||||
return (unsigned char)GPIO_ReadInputDataBit(GpioX->Periph.GpioPort, GpioX->Periph.GpioPin);
|
||||
}
|
||||
|
||||
|
||||
+120
-114
@@ -1,114 +1,120 @@
|
||||
// #include "Bsp.h"
|
||||
//
|
||||
// INTERRUPT_ST Interrupt[INTERRUPT_NUM];
|
||||
//
|
||||
// /**
|
||||
// * @brief 中断回调函数初始化为空
|
||||
// * @param void
|
||||
// * @retval void
|
||||
// * @note 初始化系统中断
|
||||
// * @example void
|
||||
// */
|
||||
// void SystemInterruptInit(void)
|
||||
// {
|
||||
// //设定系统中断组
|
||||
// NVIC_PriorityGroupConfig(NVIC_GROUP_LEVEL);
|
||||
// //清空结构体
|
||||
// for (uint8_t i = 0;i < INTERRUPT_NUM;i++)
|
||||
// {
|
||||
// Interrupt[i].CallBack = NULL;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @brief 中断回调函数注册
|
||||
// * @param Vector:中断号 void(*Func)(uint32_t):回调函数
|
||||
// * @retval void
|
||||
// * @note 将外部传入的函数地址关联到INTERRUPT_ST表中
|
||||
// * @example void
|
||||
// */
|
||||
// void InterruptRegister(uint32_t Irqn, void(*Func)(uint32_t))
|
||||
// {
|
||||
// Interrupt[Irqn].CallBack = Func;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @brief 中断NVIC配置
|
||||
// * @param Vector:中断号 NvicPrePriority:主优先级 NvicSubPriority:抢占优先级
|
||||
// * @retval void
|
||||
// * @note 设定一个中断的优先级
|
||||
// * @example void
|
||||
// */
|
||||
// void InterruptSetLevel(uint32_t Vector, uint8_t NvicPrePriority, uint8_t NvicSubPriority)
|
||||
// {
|
||||
// NVIC_InitTypeDef NVIC_InitStructure;
|
||||
//
|
||||
// NVIC_InitStructure.NVIC_IRQChannel = Vector;
|
||||
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NvicPrePriority;
|
||||
// NVIC_InitStructure.NVIC_IRQChannelSubPriority = NvicSubPriority;
|
||||
// NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
// NVIC_Init(&NVIC_InitStructure);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @brief 关闭中断
|
||||
// * @param Vector:中断号
|
||||
// * @retval void
|
||||
// * @note void
|
||||
// * @example void
|
||||
// */
|
||||
// void InterruptDisable(uint32_t Vector)
|
||||
// {
|
||||
// NVIC_InitTypeDef NVIC_InitStructure;
|
||||
// NVIC_InitStructure.NVIC_IRQChannel = Vector;
|
||||
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
||||
// NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||
// NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
// NVIC_Init(&NVIC_InitStructure);
|
||||
// }
|
||||
//
|
||||
// void USART1_IRQHandler(void)
|
||||
// {
|
||||
// if (USART_GetFlagStatus(USART1, USART_FLAG_ORE) == SET)
|
||||
// {
|
||||
// USART_ClearFlag(USART1, USART_FLAG_ORE);
|
||||
// }
|
||||
// (*Interrupt[USART1_IRQn].CallBack)((uint32_t)USART1);
|
||||
// }
|
||||
//
|
||||
// void USART2_IRQHandler(void)
|
||||
// {
|
||||
// if (USART_GetFlagStatus(USART2, USART_FLAG_ORE) == SET)
|
||||
// {
|
||||
// USART_ClearFlag(USART2, USART_FLAG_ORE);
|
||||
// }
|
||||
// (*Interrupt[USART2_IRQn].CallBack)((uint32_t)USART2);
|
||||
// }
|
||||
//
|
||||
// void USART3_IRQHandler(void)
|
||||
// {
|
||||
// if (USART_GetFlagStatus(USART3, USART_FLAG_ORE) == SET)
|
||||
// {
|
||||
// USART_ClearFlag(USART3, USART_FLAG_ORE);
|
||||
// }
|
||||
// (*Interrupt[USART3_IRQn].CallBack)((uint32_t)USART3);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// void USART4_IRQHandler(void)
|
||||
// {
|
||||
// if (USART_GetFlagStatus(UART4, USART_FLAG_ORE) == SET)
|
||||
// {
|
||||
// USART_ClearFlag(UART4, USART_FLAG_ORE);
|
||||
// }
|
||||
// (*Interrupt[UART4_IRQn].CallBack)((uint32_t)UART4);
|
||||
// }
|
||||
//
|
||||
// void USART5_IRQHandler(void)
|
||||
// {
|
||||
// if (USART_GetFlagStatus(UART5, USART_FLAG_ORE) == SET)
|
||||
// {
|
||||
// USART_ClearFlag(UART5, USART_FLAG_ORE);
|
||||
// }
|
||||
// (*Interrupt[UART5_IRQn].CallBack)((uint32_t)UART5);
|
||||
// }
|
||||
#include "Bsp.h"
|
||||
|
||||
#define IRQ_NULL ((void *)0)
|
||||
|
||||
IRQ_MAP_T IRQ_PERIPH[IRQ_NUM] = {0x00};
|
||||
|
||||
/**
|
||||
* @brief 中断回调函数初始化为空
|
||||
* @note 初始化系统中断
|
||||
* @param void
|
||||
* @retval void
|
||||
*/
|
||||
void IrqInit(void)
|
||||
{
|
||||
//设定系统中断组
|
||||
NVIC_PriorityGroupConfig(NVIC_GROUP_LEVEL);
|
||||
for (uint8_t i = 0; i < IRQ_NUM; i++) {
|
||||
IRQ_PERIPH[i].IrqCallback = IRQ_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 中断回调函数注册
|
||||
* @note 将外部传入的函数地址关联到INTERRUPT_ST表中
|
||||
* @param Vector:中断号 void(*Func)(uint32_t):回调函数
|
||||
* @retval void
|
||||
*/
|
||||
void IrqRegister(unsigned int Irq, void(*Func)(void *Param))
|
||||
{
|
||||
IRQ_PERIPH[Irq].IrqCallback = Func;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 中断NVIC配置
|
||||
* @note 设定一个中断的优先级
|
||||
* @param Vector:中断号 NvicPrePriority:主优先级 NvicSubPriority:抢占优先级
|
||||
* @retval void
|
||||
*/
|
||||
void IrqConfig(uint32_t Irq, uint8_t NvicPrePriority, uint8_t NvicSubPriority)
|
||||
{
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = Irq;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NvicPrePriority;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = NvicSubPriority;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 关闭中断
|
||||
* @note void
|
||||
* @param Vector:中断号
|
||||
* @retval void
|
||||
*/
|
||||
void IrqDisable(uint32_t Irq)
|
||||
{
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
NVIC_InitStructure.NVIC_IRQChannel = Irq;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
}
|
||||
|
||||
void USART1_IRQHandler(void)
|
||||
{
|
||||
if (USART_GetFlagStatus(COM0->Periph.UartId, USART_FLAG_ORE) == SET)
|
||||
{
|
||||
USART_ClearFlag(COM0->Periph.UartId, USART_FLAG_ORE);
|
||||
}
|
||||
if (IRQ_PERIPH[COM0->Periph.Irqn].IrqCallback != IRQ_NULL) {
|
||||
IRQ_PERIPH[COM0->Periph.Irqn].IrqCallback(COM0);
|
||||
}
|
||||
}
|
||||
|
||||
void USART2_IRQHandler(void)
|
||||
{
|
||||
if (USART_GetFlagStatus(COM1->Periph.UartId, USART_FLAG_ORE) == SET)
|
||||
{
|
||||
USART_ClearFlag(COM1->Periph.UartId, USART_FLAG_ORE);
|
||||
}
|
||||
if (IRQ_PERIPH[COM1->Periph.Irqn].IrqCallback != IRQ_NULL) {
|
||||
IRQ_PERIPH[COM1->Periph.Irqn].IrqCallback(COM1);
|
||||
}
|
||||
}
|
||||
|
||||
void USART3_IRQHandler(void)
|
||||
{
|
||||
if (USART_GetFlagStatus(COM2->Periph.UartId, USART_FLAG_ORE) == SET)
|
||||
{
|
||||
USART_ClearFlag(COM2->Periph.UartId, USART_FLAG_ORE);
|
||||
}
|
||||
if (IRQ_PERIPH[COM2->Periph.Irqn].IrqCallback != IRQ_NULL) {
|
||||
IRQ_PERIPH[COM2->Periph.Irqn].IrqCallback(COM1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void USART4_IRQHandler(void)
|
||||
{
|
||||
if (USART_GetFlagStatus(COM3->Periph.UartId, USART_FLAG_ORE) == SET)
|
||||
{
|
||||
USART_ClearFlag(COM3->Periph.UartId, USART_FLAG_ORE);
|
||||
}
|
||||
if (IRQ_PERIPH[COM3->Periph.Irqn].IrqCallback != IRQ_NULL) {
|
||||
IRQ_PERIPH[COM3->Periph.Irqn].IrqCallback(COM3);
|
||||
}
|
||||
}
|
||||
|
||||
void USART5_IRQHandler(void)
|
||||
{
|
||||
if (USART_GetFlagStatus(COM4->Periph.UartId, USART_FLAG_ORE) == SET)
|
||||
{
|
||||
USART_ClearFlag(COM4->Periph.UartId, USART_FLAG_ORE);
|
||||
}
|
||||
if (IRQ_PERIPH[COM4->Periph.Irqn].IrqCallback != IRQ_NULL) {
|
||||
IRQ_PERIPH[COM4->Periph.Irqn].IrqCallback(COM4);
|
||||
}
|
||||
}
|
||||
|
||||
+49
-52
@@ -2,65 +2,62 @@
|
||||
#include "shell.h"
|
||||
/* 板级BSP头文件 */
|
||||
#include "Bsp.h"
|
||||
#include "Voilet.h"
|
||||
|
||||
#define WR_BUFFER_SIZE 512
|
||||
|
||||
/* 1. 创建shell对象,开辟shell缓冲区 */
|
||||
Shell Host; //Shell实例化
|
||||
char HostBuffer[WR_BUFFER_SIZE]; //读写缓冲区
|
||||
uint32_t HostId; //串口号
|
||||
const COM_MAP_T *HostCom = TTY_COM;
|
||||
/**
|
||||
* @brief Shell写函数
|
||||
* @param ComId 串口号,ch 数据
|
||||
* @retval void
|
||||
* @note void
|
||||
* @example void
|
||||
*/
|
||||
signed short ShellWrite(char* ch, unsigned short Len)
|
||||
{
|
||||
ComSendStr(HostCom, (uint8_t* )ch,Len);
|
||||
return Len;
|
||||
}
|
||||
/**
|
||||
* @brief Shell读函数 - 中断回调实现
|
||||
* @param Vector 中断向量号
|
||||
* @retval void
|
||||
* @note void
|
||||
* @example void
|
||||
*/
|
||||
void LetterShellIrqFunc(void *Param)
|
||||
{
|
||||
uint8_t ch = 0x00;
|
||||
ch = ComReceiveChar(Param);
|
||||
shellHandler(&Host, ch);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 初始化Shell
|
||||
* @param ComId 串口号,baud 波特率
|
||||
* @retval void
|
||||
* @note void
|
||||
* @example void
|
||||
*/
|
||||
void LetterShellInit(const COM_MAP_T *ComX, uint32_t Baud)
|
||||
{
|
||||
//初始化串口
|
||||
ComStdConfig(ComX, Baud);
|
||||
//设置串口回调函数
|
||||
IrqRegister(ComX->Periph.Irqn, LetterShellIrqFunc);
|
||||
//设置中断等级
|
||||
IrqConfig(ComX->Periph.Irqn,1,1);
|
||||
//注册写函数
|
||||
Host.write = ShellWrite;
|
||||
//初始化LetterShell
|
||||
shellInit(&Host, HostBuffer, WR_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @brief Shell写函数
|
||||
// * @param ComId 串口号,ch 数据
|
||||
// * @retval void
|
||||
// * @note void
|
||||
// * @example void
|
||||
// */
|
||||
// signed short ShellWrite(char* ch, unsigned short Len)
|
||||
// {
|
||||
// UsartSendStr(HostId, (uint8_t* )ch,Len);
|
||||
// return Len;
|
||||
// }
|
||||
// /**
|
||||
// * @brief Shell读函数 - 中断回调实现
|
||||
// * @param Vector 中断向量号
|
||||
// * @retval void
|
||||
// * @note void
|
||||
// * @example void
|
||||
// */
|
||||
// void LetterShellIrqFunc(uint32_t Vector)
|
||||
// {
|
||||
// uint8_t ch = 0x00;
|
||||
// ch = UsartReceiveChar(Vector);
|
||||
//
|
||||
// shellHandler(&Host, ch);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * @brief 初始化Shell
|
||||
// * @param ComId 串口号,baud 波特率
|
||||
// * @retval void
|
||||
// * @note void
|
||||
// * @example void
|
||||
// */
|
||||
// void LetterShellInit(uint32_t ComId, uint32_t baud)
|
||||
// {
|
||||
// HostId = ComId;
|
||||
//
|
||||
// //初始化串口
|
||||
// UsartStdConfig(ComId, baud);
|
||||
// //设置串口回调函数
|
||||
// InterruptRegister(TTY_COM_IRQN, LetterShellIrqFunc);
|
||||
// //设置中断等级
|
||||
// InterruptSetLevel(TTY_COM_IRQN,1,1);
|
||||
// //注册写函数
|
||||
// Host.write = ShellWrite;
|
||||
//
|
||||
// shellInit(&Host, HostBuffer, WR_BUFFER_SIZE);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @brief 打印版本号
|
||||
// * @param void
|
||||
|
||||
+31
-57
@@ -3,37 +3,21 @@
|
||||
/**
|
||||
* @brief 初始化UART口外设的时钟
|
||||
* @note void
|
||||
* @param void
|
||||
* @param ComX:串口号
|
||||
* @retval void
|
||||
*/
|
||||
void UartClockEnable(const COM_MAP_T *ComX)
|
||||
{
|
||||
if (ComX->Periph == USART1)
|
||||
{
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
|
||||
}
|
||||
if (ComX->Periph == USART2) {
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
|
||||
}
|
||||
if (ComX->Periph == USART3) {
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
|
||||
}
|
||||
if (ComX->Periph == UART4) {
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
|
||||
}
|
||||
if (ComX->Periph == UART5) {
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE);
|
||||
}
|
||||
ComX->ClockCmd(ComX->ClockTree,ENABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 初始化USART口
|
||||
* @param ComId 串口号 baud 波特率 DataBits 数据位 StopBits 停止位 Parity校验位
|
||||
* @note void
|
||||
* @param Comx 串口号 baud 波特率 DataBits 数据位 StopBits 停止位 Parity校验位
|
||||
* @retval void
|
||||
* @note void
|
||||
* @example void
|
||||
*/
|
||||
void UartInit(const COM_MAP_T *Comx, uint32_t baud, uint8_t DataBits, uint8_t StopBits, uint8_t Parity)
|
||||
void ComInit(const COM_MAP_T *ComX, uint32_t baud, uint8_t DataBits, uint8_t StopBits, uint8_t Parity)
|
||||
{
|
||||
USART_InitTypeDef UsartInitSt;
|
||||
|
||||
@@ -45,76 +29,66 @@ void UartInit(const COM_MAP_T *Comx, uint32_t baud, uint8_t DataBits, uint8_t St
|
||||
UsartInitSt.USART_Parity = Parity;
|
||||
UsartInitSt.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
||||
UsartInitSt.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
|
||||
USART_Init(Comx->Periph, &UsartInitSt);
|
||||
|
||||
UartClockEnable(ComX);
|
||||
USART_Init(ComX->Periph.UartId, &UsartInitSt);
|
||||
//配置中断
|
||||
USART_ITConfig(Comx->Periph, USART_IT_RXNE, ENABLE);
|
||||
|
||||
USART_ITConfig(ComX->Periph.UartId, USART_IT_RXNE, ENABLE);
|
||||
//启用串口
|
||||
USART_Cmd(Comx->Periph, ENABLE);
|
||||
USART_Cmd(ComX->Periph.UartId, ENABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USART口发送数据
|
||||
* @param ComId 串口号 Data数据
|
||||
* @note void
|
||||
* @param ComX 串口号 Data数据
|
||||
* @retval void
|
||||
* @note void
|
||||
* @example void
|
||||
*/
|
||||
void UartSendChar(uint32_t ComId,uint8_t Data)
|
||||
void ComSendChar(const COM_MAP_T *ComX,uint8_t Data)
|
||||
{
|
||||
USART_SendData((USART_TypeDef*)ComId, Data);
|
||||
while (USART_GetFlagStatus((USART_TypeDef*)ComId, USART_FLAG_TC) != SET);
|
||||
USART_SendData(ComX->Periph.UartId, Data);
|
||||
while (USART_GetFlagStatus(ComX->Periph.UartId, USART_FLAG_TC) != SET);
|
||||
}
|
||||
/**
|
||||
* @brief USART口发送字符串
|
||||
* @param ComId 串口号 Data数据 Len 长度
|
||||
* @note void
|
||||
* @param ComX 串口号 Data数据 Len 长度
|
||||
* @retval void
|
||||
* @note void
|
||||
* @example void
|
||||
*/
|
||||
void UartSendStr(uint32_t ComId,uint8_t* Data, uint64_t Len)
|
||||
void ComSendStr(const COM_MAP_T *ComX,uint8_t *Data, uint64_t Len)
|
||||
{
|
||||
for (uint64_t i = 0;i < Len;i++)
|
||||
{
|
||||
USART_SendData((USART_TypeDef*)ComId, Data[i]);
|
||||
while (USART_GetFlagStatus((USART_TypeDef*)ComId, USART_FLAG_TC) != SET);
|
||||
USART_SendData(ComX->Periph.UartId, Data[i]);
|
||||
while (USART_GetFlagStatus(ComX->Periph.UartId, USART_FLAG_TC) != SET);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USART口发送数据
|
||||
* @param ComId 串口号
|
||||
* @note void
|
||||
* @param ComX 串口号
|
||||
* @retval 读取的数据
|
||||
* @note void
|
||||
* @example void
|
||||
*/
|
||||
uint8_t UartReceiveChar(uint32_t ComId)
|
||||
uint8_t ComReceiveChar(const COM_MAP_T *ComX)
|
||||
{
|
||||
return USART_ReceiveData((USART_TypeDef*)ComId);
|
||||
return USART_ReceiveData(ComX->Periph.UartId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 通用USART配置
|
||||
* @note void
|
||||
* @param ComId 串口号 baud 波特率
|
||||
* @note void
|
||||
* @param ComX 串口号 baud 波特率
|
||||
* @retval void
|
||||
*/
|
||||
void UartStdConfig(COM_MAP_T ComX, uint32_t baud)
|
||||
void ComStdConfig(const COM_MAP_T *ComX, uint32_t Baud)
|
||||
{
|
||||
UartInit(&ComX, baud, USART_WordLength_8b, USART_StopBits_1, USART_Parity_No);
|
||||
ComInit(ComX, Baud, USART_WordLength_8b, USART_StopBits_1, USART_Parity_No);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 高级串口配置
|
||||
* @note void
|
||||
* @param ComId 串口号 baud 波特率 Data Bits 数据位 StopBits 停止位 Parity校验位
|
||||
* @param ComX 串口号 baud 波特率 Data Bits 数据位 StopBits 停止位 Parity校验位
|
||||
* @retval void
|
||||
*/
|
||||
void UartAdvConfig(const COM_MAP_T *ComX, uint32_t baud, uint8_t DataBits, uint8_t StopBits, uint8_t Parity)
|
||||
void ComAdvConfig(const COM_MAP_T *ComX, uint32_t Baud, uint8_t DataBits, uint8_t StopBits, uint8_t Parity)
|
||||
{
|
||||
UartInit(ComX, baud, DataBits, StopBits, Parity);
|
||||
}
|
||||
|
||||
|
||||
|
||||
ComInit(ComX, Baud, DataBits, StopBits, Parity);
|
||||
}
|
||||
Reference in New Issue
Block a user