Compare commits

...

1 Commits

Author SHA1 Message Date
iorebuild 42ceefc5ad gpio写完,延时不准 2026-05-24 22:33:20 +08:00
15 changed files with 1426 additions and 560 deletions
+82 -47
View File
@@ -1,23 +1,10 @@
#ifndef __BSP_H__ #ifndef __BSP_H__
#define __BSP_H__ #define __BSP_H__
/* 板级BSP头文件 */ #include "VoiletTypeDef.h"
#include "Board.h" #include "Voilet.h"
/* SHELL头文件 */ #define ARRAY_LEN(arr) (sizeof(arr) / sizeof((arr)[0]))
#include "LetterShell.h"
/* BSP版本 */
#define VERSION_0 0
#define VERSION_1 1
#define VERSION_2 2
/* RTOS宏开关 */
#ifdef USE_RTOS
#ifdef USE_THREADX
#include "tx_api.h"
#endif
#endif
/* BOOL类型定义 */ /* BOOL类型定义 */
typedef enum { typedef enum {
@@ -25,44 +12,92 @@ typedef enum {
true = 1, true = 1,
} bool_t; } bool_t;
//System
void BspInit(void);
void BspExtraInit(void);
void SystemStart(void);
void BspSystemReboot(void);
//GPIO //GPIO
//数组信号输出开关 //数组信号输入/出开关
#define DO_ON 0 #define DI_ON 1
#define DO_OFF 1 #define DI_OFF 0
#define DO_ON 1
#define DO_OFF 0
//LED灯开关 //LED灯开关
#define LED_ON 0 #define LED_ON 0
#define LED_OFF 1 #define LED_OFF 1
void SystemGpioInit(void);
void GpioConfig(GPIO_TypeDef *GpioX, uint16_t GpioPinX,GPIOMode_TypeDef GpioMode, GPIOSpeed_TypeDef GpioSpeed); /* Voilet */
void GpioSetSts(GPIO_TypeDef *GpioX, uint16_t GpioPinX, uint8_t Status); void VoiletBspInit(void);
uint8_t GpioGetSts(GPIO_TypeDef *GpioX, uint16_t GpioPinX);
void LedToggle(uint8_t Chnl); /* BSP */
void LedOff(uint8_t Chnl); void AllPeriphClockDisable(void);
void LedOn(uint8_t Chnl); void LedOn(uint8_t Chnl);
void LedOff(uint8_t Chnl);
void LedSet(uint8_t Chnl,uint8_t Value);
void LedToggle(uint8_t Chnl);
//System Delay //System Delay
void SystemDelayConfig(void); void DelayConfig(void);
uint32_t SystemGetDwtCnt(void); unsigned int DwtCntGet(void);
void SystemDelayUs(uint32_t Us); void DelayUs(unsigned int Us);
void SystemDelayMs(uint32_t Ms); void DelayMs(unsigned int Ms);
//Interrupt /* GPIO */
void SystemInterruptInit(void); void GpioClockEnable(const GPIO_MAP_T *GpioX);
void InterruptRegister(uint32_t Irqn, void(*Func)(uint32_t)); void GpioConfig(const GPIO_MAP_T *GpioX, GPIOMode_TypeDef GpioMode, GPIOSpeed_TypeDef GpioSpeed);
void InterruptSetLevel(uint32_t Vector, uint8_t NvicPrePriority, uint8_t NvicSubPriority); void GpioSet(const GPIO_MAP_T *GpioX, uint8_t Value);
void InterruptDisable(uint32_t Vector); unsigned char GpioGet(const GPIO_MAP_T *GpioX);
/* UART */
void UartClockEnable(const COM_MAP_T *ComX);
// void UartSendChar(uint32_t ComId,uint8_t Data);
// void UartSendStr(uint32_t ComId,uint8_t* Data, uint64_t Len);
// void UartStdConfig(COM_MAP_T ComX, uint32_t baud);
// void UartAdvConfig(const COM_MAP_T *ComX, uint32_t baud, uint8_t DataBits, uint8_t StopBits, uint8_t Parity);
// #define UartStdConfig(ComX, baud) UartStdConfig((COM_MAP_T)ComX, baud)
// /* 板级BSP头文件 */
// #include "Board.h"
//
// /* SHELL头文件 */
// #include "LetterShell.h"
//
// /* BSP版本 */
// #define VERSION_0 0
// #define VERSION_1 1
// #define VERSION_2 2
//
// /* RTOS宏开关 */
// #ifdef USE_RTOS
// #ifdef USE_THREADX
// #include "tx_api.h"
// #endif
// #endif
//
//
// //System
// void BspInit(void);
// void BspExtraInit(void);
// void SystemStart(void);
// void BspSystemReboot(void);
//
// void SystemGpioInit(void);
// void GpioConfig(GPIO_TypeDef *GpioX, uint16_t GpioPinX,GPIOMode_TypeDef GpioMode, GPIOSpeed_TypeDef GpioSpeed);
// void GpioSetSts(GPIO_TypeDef *GpioX, uint16_t GpioPinX, uint8_t Status);
// uint8_t GpioGetSts(GPIO_TypeDef *GpioX, uint16_t GpioPinX);
// void LedToggle(uint8_t Chnl);
// void LedOff(uint8_t Chnl);
// void LedOn(uint8_t Chnl);
//
//
// //Interrupt
// void SystemInterruptInit(void);
// void InterruptRegister(uint32_t Irqn, void(*Func)(uint32_t));
// void InterruptSetLevel(uint32_t Vector, uint8_t NvicPrePriority, uint8_t NvicSubPriority);
// void InterruptDisable(uint32_t Vector);
//
// //Usart
// void SystemUsartInit(void);
// void UsartSendChar(uint32_t ComId,uint8_t Data);
// void UsartSendStr(uint32_t ComId,uint8_t* Data, uint64_t Len);
// uint8_t UsartReceiveChar(uint32_t ComId);
// void UsartStdConfig(uint32_t ComId, uint32_t baud);
// void UsartAdvConfig(uint32_t ComId, uint32_t baud, uint8_t DataBits, uint8_t StopBits, uint8_t Parity);
//Usart
void SystemUsartInit(void);
void UsartSendChar(uint32_t ComId,uint8_t Data);
void UsartSendStr(uint32_t ComId,uint8_t* Data, uint64_t Len);
uint8_t UsartReceiveChar(uint32_t ComId);
void UsartStdConfig(uint32_t ComId, uint32_t baud);
void UsartAdvConfig(uint32_t ComId, uint32_t baud, uint8_t DataBits, uint8_t StopBits, uint8_t Parity);
#endif #endif
View File
+8
View File
@@ -0,0 +1,8 @@
#ifndef __LETTER_SHELL_H__
#define __LETTER_SHELL_H__
#include "Bsp.h"
void LetterShellInit(uint32_t ComId, uint32_t baud);
#endif
+173
View File
@@ -0,0 +1,173 @@
//
// Created by anonymous on 2026/5/24.
//
#ifndef VOILETTYPEDEF_H
#define VOILETTYPEDEF_H
#include "stm32f10x.h"
#define INTERRUPT_ENABLE __set_PRIMASK(0); //开启中断
#define INTERRUPT_DISABLE __set_PRIMASK(1); //关闭中断
typedef struct {
GPIO_TypeDef *Periph;
unsigned short GpioPin;
} GPIO_MAP_T;
// ==================== GPIOA 组 ====================
#ifdef GPIOA
#define GPIO0 {GPIOA, GPIO_Pin_0}
#define GPIO1 {GPIOA, GPIO_Pin_1}
#define GPIO2 {GPIOA, GPIO_Pin_2}
#define GPIO3 {GPIOA, GPIO_Pin_3}
#define GPIO4 {GPIOA, GPIO_Pin_4}
#define GPIO5 {GPIOA, GPIO_Pin_5}
#define GPIO6 {GPIOA, GPIO_Pin_6}
#define GPIO7 {GPIOA, GPIO_Pin_7}
#define GPIO8 {GPIOA, GPIO_Pin_8}
#define GPIO9 {GPIOA, GPIO_Pin_9}
#define GPIO10 {GPIOA, GPIO_Pin_10}
#define GPIO11 {GPIOA, GPIO_Pin_11}
#define GPIO12 {GPIOA, GPIO_Pin_12}
#define GPIO13 {GPIOA, GPIO_Pin_13}
#define GPIO14 {GPIOA, GPIO_Pin_14}
#define GPIO15 {GPIOA, GPIO_Pin_15}
#endif
#ifdef GPIOB
// ==================== GPIOB 组 ====================
#define GPIO16 {GPIOB, GPIO_Pin_0}
#define GPIO17 {GPIOB, GPIO_Pin_1}
#define GPIO18 {GPIOB, GPIO_Pin_2}
#define GPIO19 {GPIOB, GPIO_Pin_3}
#define GPIO20 {GPIOB, GPIO_Pin_4}
#define GPIO21 {GPIOB, GPIO_Pin_5}
#define GPIO22 {GPIOB, GPIO_Pin_6}
#define GPIO23 {GPIOB, GPIO_Pin_7}
#define GPIO24 {GPIOB, GPIO_Pin_8}
#define GPIO25 {GPIOB, GPIO_Pin_9}
#define GPIO26 {GPIOB, GPIO_Pin_10}
#define GPIO27 {GPIOB, GPIO_Pin_11}
#define GPIO28 {GPIOB, GPIO_Pin_12}
#define GPIO29 {GPIOB, GPIO_Pin_13}
#define GPIO30 {GPIOB, GPIO_Pin_14}
#define GPIO31 {GPIOB, GPIO_Pin_15}
#endif
#ifdef GPIOC
// ==================== GPIOC 组 ====================
#define GPIO32 {GPIOC, GPIO_Pin_0}
#define GPIO33 {GPIOC, GPIO_Pin_1}
#define GPIO34 {GPIOC, GPIO_Pin_2}
#define GPIO35 {GPIOC, GPIO_Pin_3}
#define GPIO36 {GPIOC, GPIO_Pin_4}
#define GPIO37 {GPIOC, GPIO_Pin_5}
#define GPIO38 {GPIOC, GPIO_Pin_6}
#define GPIO39 {GPIOC, GPIO_Pin_7}
#define GPIO40 {GPIOC, GPIO_Pin_8}
#define GPIO41 {GPIOC, GPIO_Pin_9}
#define GPIO42 {GPIOC, GPIO_Pin_10}
#define GPIO43 {GPIOC, GPIO_Pin_11}
#define GPIO44 {GPIOC, GPIO_Pin_12}
#define GPIO45 {GPIOC, GPIO_Pin_13}
#define GPIO46 {GPIOC, GPIO_Pin_14}
#define GPIO47 {GPIOC, GPIO_Pin_15}
#endif
#ifdef GPIOD
// ==================== GPIOD 组 ====================
#define GPIO48 {GPIOD, GPIO_Pin_0}
#define GPIO49 {GPIOD, GPIO_Pin_1}
#define GPIO50 {GPIOD, GPIO_Pin_2}
#define GPIO51 {GPIOD, GPIO_Pin_3}
#define GPIO52 {GPIOD, GPIO_Pin_4}
#define GPIO53 {GPIOD, GPIO_Pin_5}
#define GPIO54 {GPIOD, GPIO_Pin_6}
#define GPIO55 {GPIOD, GPIO_Pin_7}
#define GPIO56 {GPIOD, GPIO_Pin_8}
#define GPIO57 {GPIOD, GPIO_Pin_9}
#define GPIO58 {GPIOD, GPIO_Pin_10}
#define GPIO59 {GPIOD, GPIO_Pin_11}
#define GPIO60 {GPIOD, GPIO_Pin_12}
#define GPIO61 {GPIOD, GPIO_Pin_13}
#define GPIO62 {GPIOD, GPIO_Pin_14}
#define GPIO63 {GPIOD, GPIO_Pin_15}
#endif
#ifdef GPIOE
// ==================== GPIOE 组 ====================
#define GPIO64 {GPIOE, GPIO_Pin_0}
#define GPIO65 {GPIOE, GPIO_Pin_1}
#define GPIO66 {GPIOE, GPIO_Pin_2}
#define GPIO67 {GPIOE, GPIO_Pin_3}
#define GPIO68 {GPIOE, GPIO_Pin_4}
#define GPIO69 {GPIOE, GPIO_Pin_5}
#define GPIO70 {GPIOE, GPIO_Pin_6}
#define GPIO71 {GPIOE, GPIO_Pin_7}
#define GPIO72 {GPIOE, GPIO_Pin_8}
#define GPIO73 {GPIOE, GPIO_Pin_9}
#define GPIO74 {GPIOE, GPIO_Pin_10}
#define GPIO75 {GPIOE, GPIO_Pin_11}
#define GPIO76 {GPIOE, GPIO_Pin_12}
#define GPIO77 {GPIOE, GPIO_Pin_13}
#define GPIO78 {GPIOE, GPIO_Pin_14}
#define GPIO79 {GPIOE, GPIO_Pin_15}
#endif
#ifdef GPIOF
// ==================== GPIOF 组 ====================
#define GPIO80 {GPIOF, GPIO_Pin_0}
#define GPIO81 {GPIOF, GPIO_Pin_1}
#define GPIO82 {GPIOF, GPIO_Pin_2}
#define GPIO83 {GPIOF, GPIO_Pin_3}
#define GPIO84 {GPIOF, GPIO_Pin_4}
#define GPIO85 {GPIOF, GPIO_Pin_5}
#define GPIO86 {GPIOF, GPIO_Pin_6}
#define GPIO87 {GPIOF, GPIO_Pin_7}
#define GPIO88 {GPIOF, GPIO_Pin_8}
#define GPIO89 {GPIOF, GPIO_Pin_9}
#define GPIO90 {GPIOF, GPIO_Pin_10}
#define GPIO91 {GPIOF, GPIO_Pin_11}
#define GPIO92 {GPIOF, GPIO_Pin_12}
#define GPIO93 {GPIOF, GPIO_Pin_13}
#define GPIO94 {GPIOF, GPIO_Pin_14}
#define GPIO95 {GPIOF, GPIO_Pin_15}
#endif
#ifdef GPIOG
// ==================== GPIOG 组 ====================
#define GPIO96 {GPIOG, GPIO_Pin_0}
#define GPIO97 {GPIOG, GPIO_Pin_1}
#define GPIO98 {GPIOG, GPIO_Pin_2}
#define GPIO99 {GPIOG, GPIO_Pin_3}
#define GPIO100 {GPIOG, GPIO_Pin_4}
#define GPIO101 {GPIOG, GPIO_Pin_5}
#define GPIO102 {GPIOG, GPIO_Pin_6}
#define GPIO103 {GPIOG, GPIO_Pin_7}
#define GPIO104 {GPIOG, GPIO_Pin_8}
#define GPIO105 {GPIOG, GPIO_Pin_9}
#define GPIO106 {GPIOG, GPIO_Pin_10}
#define GPIO107 {GPIOG, GPIO_Pin_11}
#define GPIO108 {GPIOG, GPIO_Pin_12}
#define GPIO109 {GPIOG, GPIO_Pin_13}
#define GPIO110 {GPIOG, GPIO_Pin_14}
#define GPIO111 {GPIOG, GPIO_Pin_15}
#endif
#define GPIOEND {(GPIO_TypeDef *)0xFFFFFFFF, 0xFFFF}
typedef struct {
USART_TypeDef *Periph;
unsigned int Irqn;
} COM_MAP_T;
#ifdef USART1
#define COM0 {USART1,USART1_IRQn}
#endif
#ifdef USART2
#define COM1 {USART2,USART2_IRQn}
#endif
#ifdef USART3
#define COM2 {USART3,USART3_IRQn}
#endif
#ifdef UART4
#define COM3 {UART4,UART4_IRQn}
#endif
#define COM4 {UART5,UART5_IRQn}
#endif //VOILETTYPEDEF_H
+190 -185
View File
@@ -1,206 +1,211 @@
#include "Bsp.h" #include "Bsp.h"
#ifdef USE_DIGITAL_OUTPUT void AllPeriphClockDisable(void);
GPIO_ST DigiTalOutPut[DO_NUM] =
{
GPIOB,GPIO_Pin_8,RESET,
};
#endif
#ifdef USE_DIGITAL_INPUT
GPIO_ST DigiTalInPut[DI_NUM] =
{
GPIOF,GPIO_Pin_8,SET,
GPIOE,GPIO_Pin_4,SET,
GPIOE,GPIO_Pin_3,SET,
};
#endif
//LED灯数组
#ifdef USE_LED
GPIO_ST DigiTalLed[LED_NUM] =
{
GPIOB,GPIO_Pin_5,SET,
GPIOE,GPIO_Pin_5,SET,
};
#endif
/** /**
* @brief BSP的配置和初始化 * @brief 关闭所有外设时钟
* @param void * @note void
* @param void
* @retval void * @retval void
* @note void
* @example void
*/ */
void BspInit(void) void AllPeriphClockDisable(void)
{ {
//关闭所有系统中断 // ==================== GPIOA 组 ====================
INTERRUPT_DISABLE #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
//System Delay #ifdef USART1
SystemDelayConfig(); RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, DISABLE);
#endif
//Interrupt #ifdef USART2
SystemInterruptInit(); RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, DISABLE);
#endif
//Gpio #ifdef USART3
SystemGpioInit(); RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, DISABLE);
#endif
{ #ifdef UART4
//DO RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, DISABLE);
#ifdef USE_DIGITAL_OUTPUT #endif
for (uint8_t i = 0; i < DO_NUM; i++) {
GpioConfig(DigiTalOutPut[i].GpioPort,DigiTalOutPut[i].GpioPin,GPIO_Mode_Out_PP,GPIO_Speed_50MHz);
GpioSetSts(DigiTalOutPut[i].GpioPort,DigiTalOutPut[i].GpioPin,DigiTalOutPut[i].DefaultStatus);
}
#endif
//DI
#ifdef USE_DIGITAL_INPUT
for (uint8_t i = 0; i < DI_NUM; i++) {
GpioConfig(DigiTalInPut[i].GpioPort,DigiTalInPut[i].GpioPin,GPIO_Mode_IPU,GPIO_Speed_50MHz);
}
#endif
//LED
#ifdef USE_LED
for (uint8_t i = 0; i < LED_NUM; i++) {
GpioConfig(DigiTalLed[i].GpioPort,DigiTalLed[i].GpioPin,GPIO_Mode_Out_PP,GPIO_Speed_50MHz);
GpioSetSts(DigiTalLed[i].GpioPort,DigiTalLed[i].GpioPin,DigiTalLed[i].DefaultStatus);
}
#endif
}
//Usart #ifdef UART5
SystemUsartInit(); RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, DISABLE);
{
//串口的TX引脚需要复用推挽模式,RX引脚需要浮空输入模式
#ifdef USE_USART1
GpioConfig(COM0_TX_PORT,COM0_TX_PIN,GPIO_Mode_AF_PP,GPIO_Speed_50MHz);
GpioConfig(COM0_RX_PORT,COM0_RX_PIN,GPIO_Mode_IPU,GPIO_Speed_50MHz);
#endif
#ifdef USE_USART2
GpioConfig(COM1_TX_PORT,COM1_TX_PIN,GPIO_Mode_AF_PP,GPIO_Speed_50MHz);
GpioConfig(COM1_RX_PORT,COM1_RX_PIN,GPIO_Mode_IPU,GPIO_Speed_50MHz);
#endif
#ifdef USE_USART3
GpioConfig(COM2_TX_PORT,COM2_TX_PIN,GPIO_Mode_AF_PP,GPIO_Speed_50MHz);
GpioConfig(COM2_RX_PORT,COM2_RX_PIN,GPIO_Mode_AF_PP,GPIO_Speed_50MHz);
#endif
#ifdef USE_USART4
GpioConfig(COM3_TX_PORT,COM3_TX_PIN,GPIO_Mode_AF_PP,GPIO_Speed_50MHz);
GpioConfig(COM3_RX_PORT,COM3_RX_PIN,GPIO_Mode_AF_PP,GPIO_Speed_50MHz);
#endif
#ifdef USE_USART5
GpioConfig(COM4_TX_PORT,COM4_TX_PIN,GPIO_Mode_AF_PP,GPIO_Speed_50MHz);
GpioConfig(COM4_RX_PORT,COM4_RX_PIN,GPIO_Mode_AF_PP,GPIO_Speed_50MHz);
#endif
}
#ifdef EXTRA_BSP
BspExtraInit();
#endif #endif
} }
//
void SystemStart(void) // #ifdef USE_DIGITAL_OUTPUT
{ // GPIO_ST DigiTalOutPut[DO_NUM] =
//开启系统中断 // {
INTERRUPT_ENABLE // GPIOB,GPIO_Pin_8,RESET,
// };
#ifdef USE_RTOS // #endif
#ifdef USE_FREERTOS //
#endif // #ifdef USE_DIGITAL_INPUT
#ifdef USE_UCOS // GPIO_ST DigiTalInPut[DI_NUM] =
#endif // {
#ifdef USE_THREADX // GPIOF,GPIO_Pin_8,SET,
#endif // GPIOE,GPIO_Pin_4,SET,
#endif // GPIOE,GPIO_Pin_3,SET,
} // };
// #endif
/** //
* @brief 扩展库初始化 // //LED灯数组
* @param void // #ifdef USE_LED
* @retval void // GPIO_ST DigiTalLed[LED_NUM] =
* @note 理论上扩展库要在BSP的最后加载 // {
* @example void // GPIOB,GPIO_Pin_5,SET,
*/ // GPIOE,GPIO_Pin_5,SET,
void BspExtraInit(void) // };
{ // #endif
//LetterShell初始化 //
#ifdef USE_SHELL // /**
LetterShellInit(TTY_COM,TTY_BAUD); // * @brief BSP的配置和初始化
#endif // * @param void
} // * @retval void
// * @note void
//用户层接口 // * @example void
void BspSystemReboot(void) // */
{ // void BspInit(void)
INTERRUPT_DISABLE // {
NVIC_SystemReset(); // 执行软件复位 // //关闭所有系统中断
} // INTERRUPT_DISABLE
/** //
* @brief 打开LED灯 // //System Delay
* @param Chnl 通道 // SystemDelayConfig();
* @retval void //
* @note void // //Interrupt
* @example void // SystemInterruptInit();
*/ //
void LedOn(uint8_t Chnl) // //Gpio
{ // SystemGpioInit();
if (Chnl >= LED_NUM) //
return; // {
GpioSetSts(DigiTalLed[Chnl].GpioPort, DigiTalLed[Chnl].GpioPin, LED_ON); // //DO
} // #ifdef USE_DIGITAL_OUTPUT
/** // for (uint8_t i = 0; i < DO_NUM; i++) {
* @brief 关闭LED灯 // GpioConfig(DigiTalOutPut[i].GpioPort,DigiTalOutPut[i].GpioPin,GPIO_Mode_Out_PP,GPIO_Speed_50MHz);
* @param Chnl 通道 // GpioSetSts(DigiTalOutPut[i].GpioPort,DigiTalOutPut[i].GpioPin,DigiTalOutPut[i].DefaultStatus);
* @retval void // }
* @note void // #endif
* @example void // //DI
*/ // #ifdef USE_DIGITAL_INPUT
void LedOff(uint8_t Chnl) // for (uint8_t i = 0; i < DI_NUM; i++) {
{ // GpioConfig(DigiTalInPut[i].GpioPort,DigiTalInPut[i].GpioPin,GPIO_Mode_IPU,GPIO_Speed_50MHz);
if (Chnl >= LED_NUM) // }
return; // #endif
GpioSetSts(DigiTalLed[Chnl].GpioPort, DigiTalLed[Chnl].GpioPin, LED_OFF); // //LED
} // #ifdef USE_LED
// for (uint8_t i = 0; i < LED_NUM; i++) {
void LedSet(uint8_t Chnl,uint8_t Sts) // GpioConfig(DigiTalLed[i].GpioPort,DigiTalLed[i].GpioPin,GPIO_Mode_Out_PP,GPIO_Speed_50MHz);
{ // GpioSetSts(DigiTalLed[i].GpioPort,DigiTalLed[i].GpioPin,DigiTalLed[i].DefaultStatus);
if (Chnl >= LED_NUM) // }
return; // #endif
GpioSetSts(DigiTalLed[Chnl].GpioPort, DigiTalLed[Chnl].GpioPin, Sts); // }
} //
// //Usart
/** // SystemUsartInit();
* @brief 切换LED灯状态 //
* @param Chnl 通道 Status 状态 // {
* @retval void // //串口的TX引脚需要复用推挽模式,RX引脚需要浮空输入模式
* @note void // #ifdef USE_USART1
* @example void // GpioConfig(COM0_TX_PORT,COM0_TX_PIN,GPIO_Mode_AF_PP,GPIO_Speed_50MHz);
*/ // GpioConfig(COM0_RX_PORT,COM0_RX_PIN,GPIO_Mode_IPU,GPIO_Speed_50MHz);
void LedToggle(uint8_t Chnl) // #endif
{ // #ifdef USE_USART2
if (Chnl >= LED_NUM) // GpioConfig(COM1_TX_PORT,COM1_TX_PIN,GPIO_Mode_AF_PP,GPIO_Speed_50MHz);
return; // GpioConfig(COM1_RX_PORT,COM1_RX_PIN,GPIO_Mode_IPU,GPIO_Speed_50MHz);
if (GpioGetSts(DigiTalLed[Chnl].GpioPort, DigiTalLed[Chnl].GpioPin) == LED_ON) // #endif
{ // #ifdef USE_USART3
GpioSetSts(DigiTalLed[Chnl].GpioPort,DigiTalLed[Chnl].GpioPin,LED_OFF); // GpioConfig(COM2_TX_PORT,COM2_TX_PIN,GPIO_Mode_AF_PP,GPIO_Speed_50MHz);
} // GpioConfig(COM2_RX_PORT,COM2_RX_PIN,GPIO_Mode_AF_PP,GPIO_Speed_50MHz);
else // #endif
{ // #ifdef USE_USART4
GpioSetSts(DigiTalLed[Chnl].GpioPort,DigiTalLed[Chnl].GpioPin,LED_ON); // GpioConfig(COM3_TX_PORT,COM3_TX_PIN,GPIO_Mode_AF_PP,GPIO_Speed_50MHz);
} // GpioConfig(COM3_RX_PORT,COM3_RX_PIN,GPIO_Mode_AF_PP,GPIO_Speed_50MHz);
} // #endif
// #ifdef USE_USART5
// GpioConfig(COM4_TX_PORT,COM4_TX_PIN,GPIO_Mode_AF_PP,GPIO_Speed_50MHz);
// GpioConfig(COM4_RX_PORT,COM4_RX_PIN,GPIO_Mode_AF_PP,GPIO_Speed_50MHz);
// #endif
// }
//
// #ifdef EXTRA_BSP
// BspExtraInit();
// #endif
// }
//
// void SystemStart(void)
// {
// //开启系统中断
// INTERRUPT_ENABLE
//
// #ifdef USE_RTOS
// #ifdef USE_FREERTOS
// #endif
// #ifdef USE_UCOS
// #endif
// #ifdef USE_THREADX
// #endif
// #endif
// }
//
// /**
// * @brief 扩展库初始化
// * @param void
// * @retval void
// * @note 理论上扩展库要在BSP的最后加载
// * @example void
// */
// void BspExtraInit(void)
// {
// //LetterShell初始化
// #ifdef USE_SHELL
// LetterShellInit(TTY_COM,TTY_BAUD);
// #endif
// }
//
// //用户层接口
// void BspSystemReboot(void)
// {
// INTERRUPT_DISABLE
// NVIC_SystemReset(); // 执行软件复位
// }
/** /**
* @brief 重写Printf函数 * @brief 重写Printf函数
* @param * @note void
* @param void
* @retval void * @retval void
* @note void
* @example void
*/ */
#if defined (__GNUC__) || defined (__SEGGER__) // ||
#include <SysCall.c> // #include <SysCall.c>
#elif defined(__CC_ARM) || defined(__CLANG_ARM) #if defined(__CC_ARM) || defined(__CLANG_ARM)
int fputc(int ch, FILE *f) int fputc(int ch, FILE *f)
{ {
UsartSendChar(TTY_COM, ch); UsartSendChar(TTY_COM, ch);
+7 -7
View File
@@ -14,7 +14,7 @@
* @note void * @note void
* @example void * @example void
*/ */
void SystemDelayConfig(void) void DelayConfig(void)
{ {
DEM_CR |= DEM_CR_TRCENA; DEM_CR |= DEM_CR_TRCENA;
DWT_CR |= DWT_CR_CYCCNTENA; DWT_CR |= DWT_CR_CYCCNTENA;
@@ -28,7 +28,7 @@ void SystemDelayConfig(void)
* @note void * @note void
* @example void * @example void
*/ */
uint32_t SystemGetDwtCnt(void) unsigned int DwtCntGet(void)
{ {
return((uint32_t)DWT_CYCCNT); return((uint32_t)DWT_CYCCNT);
} }
@@ -40,16 +40,16 @@ uint32_t SystemGetDwtCnt(void)
* @note void * @note void
* @example void * @example void
*/ */
void SystemDelayUs(uint32_t Us) void DelayUs(unsigned int Us)
{ {
uint32_t Start = 0,End = 0,Ts = 0; uint32_t Start = 0,End = 0,Ts = 0;
Start = SystemGetDwtCnt(); Start = DwtCntGet();
Ts = Us * (SystemCoreClock / 1000000U); Ts = Us * (SystemCoreClock / 1000000U);
End = Start + Ts; End = Start + Ts;
while(SystemGetDwtCnt() < End){;} while(DwtCntGet() < End){;}
} }
/** /**
* @brief 毫秒级延时函数 * @brief 毫秒级延时函数
@@ -58,7 +58,7 @@ void SystemDelayUs(uint32_t Us)
* @note void * @note void
* @example void * @example void
*/ */
void SystemDelayMs(uint32_t Ms) void DelayMs(unsigned int Ms)
{ {
SystemDelayUs(Ms * 1000); DelayUs(Ms * 1000);
} }
+32 -81
View File
@@ -1,124 +1,75 @@
#include "Bsp.h" #include "Bsp.h"
#ifdef USE_DIGITAL_OUTPUT /**
extern GPIO_ST DigiTalOutPut[DO_NUM]; * @brief 启用GPIO口时钟
#endif * @note void
* @param GpioX:GPIO引脚
#ifdef USE_DIGITAL_INPUT * @retval void
extern GPIO_ST DigiTalInPut[DI_NUM]; */
#endif void GpioClockEnable(const GPIO_MAP_T *GpioX)
//LED灯数组
#ifdef USE_LED
extern GPIO_ST DigiTalLed[LED_NUM];
#endif
void SystemEnableGpioClock(uint32_t GpioBase)
{ {
if(GpioBase == (uint32_t)GPIOA) if(GpioX->Periph == GPIOA)
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
if(GpioBase == (uint32_t)GPIOB) if(GpioX->Periph == GPIOB)
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
if(GpioBase == (uint32_t)GPIOC) if(GpioX->Periph == GPIOC)
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
if(GpioBase == (uint32_t)GPIOD) if(GpioX->Periph == GPIOD)
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
if(GpioBase == (uint32_t)GPIOE) if(GpioX->Periph == GPIOE)
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
if(GpioBase == (uint32_t)GPIOF) if(GpioX->Periph == GPIOF)
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF, ENABLE);
if(GpioBase == (uint32_t)GPIOG) if(GpioX->Periph == GPIOG)
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOG, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOG, ENABLE);
} }
/**
* @brief 初始化GPIO口外设的时钟
* @param void
* @retval void
* @note void
* @example void
*/
void SystemGpioInit(void)
{
uint8_t i = 0x00;
if (DO_NUM != NULL)
{
for (i = 0;i < DO_NUM;i++)
{
SystemEnableGpioClock((uint32_t)DigiTalOutPut[i].GpioPort);
}
}
if (DI_NUM != NULL)
{
for (i = 0;i < DI_NUM;i++)
{
SystemEnableGpioClock((uint32_t)DigiTalInPut[i].GpioPort);
}
}
if (LED_NUM != NULL)
{
for (i = 0;i < LED_NUM;i++)
{
SystemEnableGpioClock((uint32_t)DigiTalLed[i].GpioPort);
}
}
}
/** /**
* @brief 配置GPIO口 * @brief 配置GPIO口
* @param GpioX:GPIO组 GpioPinX:GPIO引脚 GpioMode:GPIO模式 GpioSpeed:GPIO速度 * @note void
* @param GpioX:引脚 GpioMode:GPIO模式 GpioSpeed:GPIO速度
* @retval void * @retval void
* @note void
* @example void
*/ */
void GpioConfig(GPIO_TypeDef *GpioX, uint16_t GpioPinX, void GpioConfig(const GPIO_MAP_T *GpioX, GPIOMode_TypeDef GpioMode, GPIOSpeed_TypeDef GpioSpeed)
GPIOMode_TypeDef GpioMode, GPIOSpeed_TypeDef GpioSpeed)
{ {
GPIO_InitTypeDef GpioInitSt; GPIO_InitTypeDef GpioInitSt;
GpioInitSt.GPIO_Pin = GpioPinX; GpioInitSt.GPIO_Pin = GpioX->GpioPin;
GpioInitSt.GPIO_Mode = GpioMode; GpioInitSt.GPIO_Mode = GpioMode;
GpioInitSt.GPIO_Speed = GpioSpeed; GpioInitSt.GPIO_Speed = GpioSpeed;
GPIO_Init(GpioX, &GpioInitSt); GPIO_Init(GpioX->Periph, &GpioInitSt);
} }
/** /**
* @brief 改变GPIO口状态 * @brief 改变GPIO口状态
* @param GpioX:GPIO组 GpioPinX:GPIO引脚 state: GPIO状态 * @note
* @param GpioX:GPIO引脚 Value:设置值
* @retval void * @retval void
* @note void
* @example void
*/ */
void GpioSetSts(GPIO_TypeDef *GpioX, uint16_t GpioPinX, uint8_t Status) void GpioSet(const GPIO_MAP_T *GpioX, uint8_t Value)
{ {
if (Status == (uint8_t)RESET) if (Value == (uint8_t)RESET)
{ {
GPIO_ResetBits(GpioX, GpioPinX); GPIO_ResetBits(GpioX->Periph, GpioX->GpioPin);
} }
else if (Status == (uint8_t)SET) else if (Value == (uint8_t)SET)
{ {
GPIO_SetBits(GpioX, GpioPinX); GPIO_SetBits(GpioX->Periph, GpioX->GpioPin);
} }
} }
/** /**
* @brief 读取GPIO口状态 * @brief 读取GPIO口状态
* @param GpioX:GPIO组 GpioPinX:GPIO引脚 * @note
* @retval GPIO状态 * @param GpioX:GPIO引脚
* @note void * @retval 0:低电平,1高电平
* @example void
*/ */
uint8_t GpioGetSts(GPIO_TypeDef *GpioX, uint16_t GpioPinX) unsigned char GpioGet(const GPIO_MAP_T *GpioX)
{ {
return (uint8_t)GPIO_ReadInputDataBit(GpioX, GpioPinX); return (unsigned char)GPIO_ReadInputDataBit(GpioX->Periph, GpioX->GpioPin);
} }
+114 -114
View File
@@ -1,114 +1,114 @@
#include "Bsp.h" // #include "Bsp.h"
//
INTERRUPT_ST Interrupt[INTERRUPT_NUM]; // INTERRUPT_ST Interrupt[INTERRUPT_NUM];
//
/** // /**
* @brief 中断回调函数初始化为空 // * @brief 中断回调函数初始化为空
* @param void // * @param void
* @retval void // * @retval void
* @note 初始化系统中断 // * @note 初始化系统中断
* @example void // * @example void
*/ // */
void SystemInterruptInit(void) // void SystemInterruptInit(void)
{ // {
//设定系统中断组 // //设定系统中断组
NVIC_PriorityGroupConfig(NVIC_GROUP_LEVEL); // NVIC_PriorityGroupConfig(NVIC_GROUP_LEVEL);
//清空结构体 // //清空结构体
for (uint8_t i = 0;i < INTERRUPT_NUM;i++) // for (uint8_t i = 0;i < INTERRUPT_NUM;i++)
{ // {
Interrupt[i].CallBack = NULL; // Interrupt[i].CallBack = NULL;
} // }
} // }
//
/** // /**
* @brief 中断回调函数注册 // * @brief 中断回调函数注册
* @param Vector:中断号 void(*Func)(uint32_t):回调函数 // * @param Vector:中断号 void(*Func)(uint32_t):回调函数
* @retval void // * @retval void
* @note 将外部传入的函数地址关联到INTERRUPT_ST表中 // * @note 将外部传入的函数地址关联到INTERRUPT_ST表中
* @example void // * @example void
*/ // */
void InterruptRegister(uint32_t Irqn, void(*Func)(uint32_t)) // void InterruptRegister(uint32_t Irqn, void(*Func)(uint32_t))
{ // {
Interrupt[Irqn].CallBack = Func; // Interrupt[Irqn].CallBack = Func;
} // }
//
/** // /**
* @brief 中断NVIC配置 // * @brief 中断NVIC配置
* @param Vector:中断号 NvicPrePriority:主优先级 NvicSubPriority:抢占优先级 // * @param Vector:中断号 NvicPrePriority:主优先级 NvicSubPriority:抢占优先级
* @retval void // * @retval void
* @note 设定一个中断的优先级 // * @note 设定一个中断的优先级
* @example void // * @example void
*/ // */
void InterruptSetLevel(uint32_t Vector, uint8_t NvicPrePriority, uint8_t NvicSubPriority) // void InterruptSetLevel(uint32_t Vector, uint8_t NvicPrePriority, uint8_t NvicSubPriority)
{ // {
NVIC_InitTypeDef NVIC_InitStructure; // NVIC_InitTypeDef NVIC_InitStructure;
//
NVIC_InitStructure.NVIC_IRQChannel = Vector; // NVIC_InitStructure.NVIC_IRQChannel = Vector;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NvicPrePriority; // NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NvicPrePriority;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = NvicSubPriority; // NVIC_InitStructure.NVIC_IRQChannelSubPriority = NvicSubPriority;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; // NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure); // NVIC_Init(&NVIC_InitStructure);
} // }
//
/** // /**
* @brief 关闭中断 // * @brief 关闭中断
* @param Vector:中断号 // * @param Vector:中断号
* @retval void // * @retval void
* @note void // * @note void
* @example void // * @example void
*/ // */
void InterruptDisable(uint32_t Vector) // void InterruptDisable(uint32_t Vector)
{ // {
NVIC_InitTypeDef NVIC_InitStructure; // NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = Vector; // NVIC_InitStructure.NVIC_IRQChannel = Vector;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; // NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; // NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; // NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure); // NVIC_Init(&NVIC_InitStructure);
} // }
//
void USART1_IRQHandler(void) // void USART1_IRQHandler(void)
{ // {
if (USART_GetFlagStatus(USART1, USART_FLAG_ORE) == SET) // if (USART_GetFlagStatus(USART1, USART_FLAG_ORE) == SET)
{ // {
USART_ClearFlag(USART1, USART_FLAG_ORE); // USART_ClearFlag(USART1, USART_FLAG_ORE);
} // }
(*Interrupt[USART1_IRQn].CallBack)((uint32_t)USART1); // (*Interrupt[USART1_IRQn].CallBack)((uint32_t)USART1);
} // }
//
void USART2_IRQHandler(void) // void USART2_IRQHandler(void)
{ // {
if (USART_GetFlagStatus(USART2, USART_FLAG_ORE) == SET) // if (USART_GetFlagStatus(USART2, USART_FLAG_ORE) == SET)
{ // {
USART_ClearFlag(USART2, USART_FLAG_ORE); // USART_ClearFlag(USART2, USART_FLAG_ORE);
} // }
(*Interrupt[USART2_IRQn].CallBack)((uint32_t)USART2); // (*Interrupt[USART2_IRQn].CallBack)((uint32_t)USART2);
} // }
//
void USART3_IRQHandler(void) // void USART3_IRQHandler(void)
{ // {
if (USART_GetFlagStatus(USART3, USART_FLAG_ORE) == SET) // if (USART_GetFlagStatus(USART3, USART_FLAG_ORE) == SET)
{ // {
USART_ClearFlag(USART3, USART_FLAG_ORE); // USART_ClearFlag(USART3, USART_FLAG_ORE);
} // }
(*Interrupt[USART3_IRQn].CallBack)((uint32_t)USART3); // (*Interrupt[USART3_IRQn].CallBack)((uint32_t)USART3);
} // }
//
//
void USART4_IRQHandler(void) // void USART4_IRQHandler(void)
{ // {
if (USART_GetFlagStatus(UART4, USART_FLAG_ORE) == SET) // if (USART_GetFlagStatus(UART4, USART_FLAG_ORE) == SET)
{ // {
USART_ClearFlag(UART4, USART_FLAG_ORE); // USART_ClearFlag(UART4, USART_FLAG_ORE);
} // }
(*Interrupt[UART4_IRQn].CallBack)((uint32_t)UART4); // (*Interrupt[UART4_IRQn].CallBack)((uint32_t)UART4);
} // }
//
void USART5_IRQHandler(void) // void USART5_IRQHandler(void)
{ // {
if (USART_GetFlagStatus(UART5, USART_FLAG_ORE) == SET) // if (USART_GetFlagStatus(UART5, USART_FLAG_ORE) == SET)
{ // {
USART_ClearFlag(UART5, USART_FLAG_ORE); // USART_ClearFlag(UART5, USART_FLAG_ORE);
} // }
(*Interrupt[UART5_IRQn].CallBack)((uint32_t)UART5); // (*Interrupt[UART5_IRQn].CallBack)((uint32_t)UART5);
} // }
+105
View File
@@ -0,0 +1,105 @@
#include "LetterShell.h"
#include "shell.h"
/* 板级BSP头文件 */
#include "Bsp.h"
#define WR_BUFFER_SIZE 512
/* 1. 创建shell对象,开辟shell缓冲区 */
Shell Host; //Shell实例化
char HostBuffer[WR_BUFFER_SIZE]; //读写缓冲区
uint32_t HostId; //串口号
// /**
// * @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
// * @retval void
// * @note void
// * @example void
// */
// void version(void)
// {
// printf("%s,%s\r\n",HARDWARE_VERSION,SOFTWARE_VERSION);
// }
//
// /**
// * @brief 重启单片机
// * @param void
// * @retval void
// * @note void
// * @example void
// */
// void reboot(void)
// {
// SystemReboot();
// }
//
// /**
// * @brief 串口测试程序
// * @param void
// * @retval void
// * @note void
// * @example void
// */
//
// void comTest(uint8_t ComId)
// {
// }
//
// //打印版本号
// SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC), version, version, version);
// //软重启单片机
// SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC), reboot, reboot, reboot);
// //串口测试
// SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC), comTest, comTest, comTest);
+288
View File
@@ -0,0 +1,288 @@
/*********************************************************************
* (c) SEGGER Microcontroller GmbH *
* The Embedded Experts *
* www.segger.com *
**********************************************************************
-------------------------- END-OF-HEADER -----------------------------
Purpose : Implementation of low-level functions for I/O with the
SEGGER Runtime Library
using a UART (SEGGER's BSP UART module)
*/
/*********************************************************************
*
* #include section
*
**********************************************************************
*/
#ifdef defined (__SEGGER__)
#include "__SEGGER_RTL_Int.h"
#include "stdio.h"
#include "Bsp.h"
/*********************************************************************
*
* Local types
*
**********************************************************************
*/
struct __SEGGER_RTL_FILE_impl { // NOTE: Provides implementation for FILE
int stub; // only needed so impl has size != 0.
};
/*********************************************************************
*
* Static data
*
**********************************************************************
*/
static FILE __SEGGER_RTL_stdin_file = { 0 }; // stdin reads from UART
static FILE __SEGGER_RTL_stdout_file = { 0 }; // stdout writes to UART
static FILE __SEGGER_RTL_stderr_file = { 0 }; // stderr writes to UART
static unsigned int _UART_Port = TTY_COM;
static int _stdin_ungot = EOF;
/*********************************************************************
*
* Public data
*
**********************************************************************
*/
FILE *stdin = &__SEGGER_RTL_stdin_file; // NOTE: Provide implementation of stdin for RTL.
FILE *stdout = &__SEGGER_RTL_stdout_file; // NOTE: Provide implementation of stdout for RTL.
FILE *stderr = &__SEGGER_RTL_stderr_file; // NOTE: Provide implementation of stderr for RTL.
void *__aeabi_read_tp(void) {
return 0; // 单线程环境下直接返回 0
}
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
/*********************************************************************
*
* _stdin_getc()
*
* Function description
* Get character from standard input.
*
* Return value
* Character received.
*
* Additional information
* This function never fails to deliver a character.
*/
static char _stdin_getc(void) {
unsigned char c;
if (_stdin_ungot != EOF) {
c = _stdin_ungot;
_stdin_ungot = EOF;
} else {
c = UsartReceiveChar(_UART_Port);
}
return c;
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* RTL_UART_Init()
*
* Function description
* Initialize RTL to use given UART for stdio.
*
* Parameters
* Unit : UART unit number (typically zero-based).
* Baudrate : Baud rate to configure [Hz].
* NumDataBits: Number of data bits to use.
* Parity : One of the following values:
* * BSP_UART_PARITY_NONE
* * BSP_UART_PARITY_ODD
* * BSP_UART_PARITY_EVEN
* NumStopBits: Number of stop bits to use.
*
* Additional description
* Parameters are same as for BSP_UART_Init().
* This also sets appropriate RX and TX interrupt handlers.
*/
void RTL_UART_Init(unsigned int Unit, unsigned long Baudrate, unsigned char NumDataBits, unsigned char Parity, unsigned char NumStopBits) {
_UART_Port = Unit;
UsartStdConfig(_UART_Port, Baudrate);
}
/*********************************************************************
*
* __SEGGER_RTL_X_file_stat()
*
* Function description
* Get file status.
*
* Parameters
* stream - Pointer to file.
*
* Additional information
* Low-overhead test to determine if stream is valid. If stream
* is a valid pointer and the stream is open, this function must
* succeed. If stream is a valid pointer and the stream is closed,
* this function must fail.
*
* The implementation may optionally determine whether stream is
* a valid pointer: this may not always be possible and is not
* required, but may assist debugging when clients provide wild
* pointers.
*
* Return value
* < 0 - Failure, stream is not a valid file.
* >= 0 - Success, stream is a valid file.
*/
int __SEGGER_RTL_X_file_stat(FILE *stream) {
if (stream == stdin || stream == stdout || stream == stderr) {
return 0; // NOTE: stdin, stdout, and stderr are assumed to be valid.
} else {
return EOF;
}
}
/*********************************************************************
*
* __SEGGER_RTL_X_file_bufsize()
*
* Function description
* Get stream buffer size.
*
* Parameters
* stream - Pointer to file.
*
* Additional information
* Returns the number of characters to use for buffered I/O on
* the file stream. The I/O buffer is allocated on the stack
* for the duration of the I/O call, therefore this value should
* not be set arbitrarily large.
*
* For unbuffered I/O, return 1.
*
* Return value
* Nonzero number of characters to use for buffered I/O; for
* unbuffered I/O, return 1.
*/
int __SEGGER_RTL_X_file_bufsize(FILE *stream) {
(void)stream;
return 1;
}
/*********************************************************************
*
* __SEGGER_RTL_X_file_read()
*
* Function description
* Read data from file.
*
* Parameters
* stream - Pointer to file to read from.
* s - Pointer to object that receives the input.
* len - Number of characters to read from file.
*
* Return value
* >= 0 - Success, amount of data read.
* < 0 - Failure.
*
* Additional information
* Reading from any stream other than stdin results in an error.
*/
int __SEGGER_RTL_X_file_read(FILE *stream, char *s, unsigned len) {
int c;
if (stream == stdin) {
c = 0;
while (len > 0) {
*s = _stdin_getc();
++s;
++c;
--len;
}
} else {
c = EOF;
}
return c;
}
/*********************************************************************
*
* __SEGGER_RTL_X_file_write()
*
* Function description
* Write data to file.
*
* Parameters
* stream - Pointer to file to write to.
* s - Pointer to object to write to file.
* len - Number of characters to write to the file.
*
* Return value
* >= 0 - Success.
* < 0 - Failure.
*
* Additional information
* this version is NOT reentrant!
* stdout and stderr are directed to UART;
* writing to any stream other than stdout or stderr results in an error
*/
int __SEGGER_RTL_X_file_write(FILE *stream, const char *s, unsigned len) {
if ((stream == stdout) || (stream == stderr)) {
UsartSendStr(_UART_Port, (uint8_t* ) s, len);
return len;
} else {
return EOF;
}
}
/*********************************************************************
*
* __SEGGER_RTL_X_file_unget()
*
* Function description
* Push character back to stream.
*
* Parameters
* stream - Pointer to file to push back to.
* c - Character to push back.
*
* Return value
* >= 0 - Success.
* < 0 - Failure.
*
* Additional information
* Push-back is only supported for standard input, and
* only a single-character pushback buffer is implemented.
*/
int __SEGGER_RTL_X_file_unget(FILE *stream, int c) {
if (stream == stdin) {
if (c != EOF && _stdin_ungot == EOF) {
_stdin_ungot = c;
} else {
c = EOF;
}
} else {
c = EOF;
}
return c;
}
#endif
/*************************** End of file ****************************/
+93
View File
@@ -0,0 +1,93 @@
/**
******************************************************************************
* @file syscalls.c
* @author Suroy Wrote with Auto-generated by STM32CubeIDE
* @url https://suroy.cn
* @brief STM32CubeIDE Minimal System calls file
*
* For more information about which c-functions
* need which of these lowlevel functions
* please consult the Newlib libc-manual
******************************************************************************
* @attention
*
* Copyright (c) 2020-2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
#ifdef defined (__GNUC__)
/* Includes */
#include "Bsp.h"
/* Variables */
extern int __io_putchar(int ch) __attribute__((weak));
extern int __io_getchar(void) __attribute__((weak));
/* Functions */
__attribute__((weak)) int _read(int file, char *ptr, int len)
{
(void)file;
int DataIdx;
for (DataIdx = 0; DataIdx < len; DataIdx++)
{
*ptr++ = __io_getchar();
}
return len;
}
__attribute__((weak)) int _write(int file, char *ptr, int len)
{
(void)file;
int DataIdx;
for (DataIdx = 0; DataIdx < len; DataIdx++)
{
__io_putchar(*ptr++);
}
return len;
}
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#define GETCHAR_PROTOTYPE int __io_getchar(void)
/**
* 函数功能: 重定向 c库函数 printf到 DEBUG_USARTx
* 输入参数: 无
* 返 回 值: 无
* 说 明:无
*/
PUTCHAR_PROTOTYPE
{
UsartSendChar(TTY_COM, ch); //阻塞式无限等待
return ch;
}
/**
* 函数功能: 重定向 c库函数 getchar,scanf到 DEBUG_USARTx
* 输入参数: 无
* 返 回 值: 无
* 说 明:无
*/
GETCHAR_PROTOTYPE
{
uint8_t ch = 0;
ch = UsartReceiveChar(TTY_COM);
return ch;
}
#endif
+120
View File
@@ -0,0 +1,120 @@
#include "Bsp.h"
/**
* @brief 初始化UART口外设的时钟
* @note void
* @param void
* @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);
}
}
/**
* @brief 初始化USART口
* @param ComId 串口号 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)
{
USART_InitTypeDef UsartInitSt;
//初始化串口
USART_StructInit(&UsartInitSt);
UsartInitSt.USART_BaudRate = baud;
UsartInitSt.USART_WordLength = DataBits;
UsartInitSt.USART_StopBits = StopBits;
UsartInitSt.USART_Parity = Parity;
UsartInitSt.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
UsartInitSt.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(Comx->Periph, &UsartInitSt);
//配置中断
USART_ITConfig(Comx->Periph, USART_IT_RXNE, ENABLE);
//启用串口
USART_Cmd(Comx->Periph, ENABLE);
}
/**
* @brief USART口发送数据
* @param ComId 串口号 Data数据
* @retval void
* @note void
* @example void
*/
void UartSendChar(uint32_t ComId,uint8_t Data)
{
USART_SendData((USART_TypeDef*)ComId, Data);
while (USART_GetFlagStatus((USART_TypeDef*)ComId, USART_FLAG_TC) != SET);
}
/**
* @brief USART口发送字符串
* @param ComId 串口号 Data数据 Len 长度
* @retval void
* @note void
* @example void
*/
void UartSendStr(uint32_t ComId,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);
}
}
/**
* @brief USART口发送数据
* @param ComId 串口号
* @retval 读取的数据
* @note void
* @example void
*/
uint8_t UartReceiveChar(uint32_t ComId)
{
return USART_ReceiveData((USART_TypeDef*)ComId);
}
/**
* @brief 通用USART配置
* @note void
* @param ComId 串口号 baud 波特率
* @retval void
*/
void UartStdConfig(COM_MAP_T ComX, uint32_t baud)
{
UartInit(&ComX, baud, USART_WordLength_8b, USART_StopBits_1, USART_Parity_No);
}
/**
* @brief 高级串口配置
* @note void
* @param ComId 串口号 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)
{
UartInit(ComX, baud, DataBits, StopBits, Parity);
}
-122
View File
@@ -1,122 +0,0 @@
#include "Bsp.h"
/**
* @brief 初始化USART口外设的时钟
* @param void
* @retval void
* @note void
* @example void
*/
void SystemUsartInit(void)
{
#ifdef USE_USART1
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
#endif
#ifdef USE_USART2
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
#endif
#ifdef USE_USART3
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
#endif
#ifdef USE_USART4
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
#endif
#ifdef USE_USART5
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE);
#endif
}
/**
* @brief 配置USART口
* @param ComId 串口号 baud 波特率 DataBits 数据位 StopBits 停止位 Parity校验位
* @retval void
* @note void
* @example void
*/
void UsartConfig(uint32_t ComId, uint32_t baud, uint8_t DataBits, uint8_t StopBits, uint8_t Parity)
{
USART_InitTypeDef UsartInitSt;
//初始化串口
USART_StructInit(&UsartInitSt);
UsartInitSt.USART_BaudRate = baud;
UsartInitSt.USART_WordLength = DataBits;
UsartInitSt.USART_StopBits = StopBits;
UsartInitSt.USART_Parity = Parity;
UsartInitSt.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
UsartInitSt.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init((USART_TypeDef*)ComId, &UsartInitSt);
//配置中断
USART_ITConfig((USART_TypeDef*)ComId, USART_IT_RXNE, ENABLE);
//启用串口
USART_Cmd((USART_TypeDef*)ComId, ENABLE);
}
/**
* @brief USART口发送数据
* @param ComId 串口号 Data数据
* @retval void
* @note void
* @example void
*/
void UsartSendChar(uint32_t ComId,uint8_t Data)
{
USART_SendData((USART_TypeDef*)ComId, Data);
while (USART_GetFlagStatus((USART_TypeDef*)ComId, USART_FLAG_TC) != SET);
}
/**
* @brief USART口发送字符串
* @param ComId 串口号 Data数据 Len 长度
* @retval void
* @note void
* @example void
*/
void UsartSendStr(uint32_t ComId,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);
}
}
/**
* @brief USART口发送数据
* @param ComId 串口号
* @retval 读取的数据
* @note void
* @example void
*/
uint8_t UsartReceiveChar(uint32_t ComId)
{
return USART_ReceiveData((USART_TypeDef*)ComId);
}
/**
* @brief 通用USART配置
* @param ComId 串口号 baud 波特率
* @retval void
* @note void
* @example void
*/
void UsartStdConfig(uint32_t ComId, uint32_t baud)
{
UsartConfig(ComId, baud, USART_DATA_BIT_8, USART_STOP_BIT_1, USART_PARITY_NO);
}
/**
* @brief 高级串口配置
* @param ComId 串口号 baud 波特率 DataBits 数据位 StopBits 停止位 Parity校验位
* @retval void
* @note void
* @example void
*/
void UsartAdvConfig(uint32_t ComId, uint32_t baud, uint8_t DataBits, uint8_t StopBits, uint8_t Parity)
{
UsartConfig(ComId, baud, DataBits, StopBits, Parity);
}
+158
View File
@@ -0,0 +1,158 @@
/**
******************************************************************************
* @file Project/STM32F10x_StdPeriph_Template/stm32f10x_it.c
* @author MCD Application Team
* @version V3.6.0
* @date 20-September-2021
* @brief Main Interrupt Service Routines.
* This file provides template for all exceptions handler and
* peripherals interrupt service routine.
******************************************************************************
* @attention
*
* Copyright (c) 2011 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x_it.h"
/** @addtogroup STM32F10x_StdPeriph_Template
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/******************************************************************************/
/* Cortex-M3 Processor Exceptions Handlers */
/******************************************************************************/
/**
* @brief This function handles NMI exception.
* @param None
* @retval None
*/
void NMI_Handler(void)
{
}
/**
* @brief This function handles Hard Fault exception.
* @param None
* @retval None
*/
void HardFault_Handler(void)
{
/* Go to infinite loop when Hard Fault exception occurs */
while (1)
{
}
}
/**
* @brief This function handles Memory Manage exception.
* @param None
* @retval None
*/
void MemManage_Handler(void)
{
/* Go to infinite loop when Memory Manage exception occurs */
while (1)
{
}
}
/**
* @brief This function handles Bus Fault exception.
* @param None
* @retval None
*/
void BusFault_Handler(void)
{
/* Go to infinite loop when Bus Fault exception occurs */
while (1)
{
}
}
/**
* @brief This function handles Usage Fault exception.
* @param None
* @retval None
*/
void UsageFault_Handler(void)
{
/* Go to infinite loop when Usage Fault exception occurs */
while (1)
{
}
}
/**
* @brief This function handles SVCall exception.
* @param None
* @retval None
*/
void SVC_Handler(void)
{
}
/**
* @brief This function handles Debug Monitor exception.
* @param None
* @retval None
*/
void DebugMon_Handler(void)
{
}
/**
* @brief This function handles PendSVC exception.
* @param None
* @retval None
*/
void PendSV_Handler(void)
{
}
/**
* @brief This function handles SysTick Handler.
* @param None
* @retval None
*/
void SysTick_Handler(void)
{
}
/******************************************************************************/
/* STM32F10x Peripherals Interrupt Handlers */
/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */
/* available peripheral interrupt handler's name please refer to the startup */
/* file (startup_stm32f10x_xx.s). */
/******************************************************************************/
/**
* @brief This function handles PPP interrupt request.
* @param None
* @retval None
*/
/*void PPP_IRQHandler(void)
{
}*/
/**
* @}
*/
+52
View File
@@ -0,0 +1,52 @@
/**
******************************************************************************
* @file Project/STM32F10x_StdPeriph_Template/stm32f10x_it.h
* @author MCD Application Team
* @version V3.6.0
* @date 20-September-2021
* @brief This file contains the headers of the interrupt handlers.
******************************************************************************
* @attention
*
* Copyright (c) 2011 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32F10x_IT_H
#define __STM32F10x_IT_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void NMI_Handler(void);
void HardFault_Handler(void);
void MemManage_Handler(void);
void BusFault_Handler(void);
void UsageFault_Handler(void);
void SVC_Handler(void);
void DebugMon_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);
#ifdef __cplusplus
}
#endif
#endif /* __STM32F10x_IT_H */