feat: KT mBMS 펌웨어 3종(HW1/2/3) 및 통합 빌드 환경 초기 커밋 (V4.0.0.1)

This commit is contained in:
2026-11-05 14:31:31 +09:00
commit c52dc2f348
10803 changed files with 4642514 additions and 0 deletions

View File

@@ -0,0 +1,270 @@
#include "delay.h"
#include "sys.h"
//////////////////////////////////////////////////////////////////////////////////
//If you are using ucos, include the following header file.
#if SYSTEM_SUPPORT_OS
#include "includes.h" //ucos use
#endif
//////////////////////////////////////////////////////////////////////////////////
//This program is for educational purposes only, without the author's permission, may not be used for any other purpose
//ALIENTEK STM32F407 Development Board
//SysTick managed to delay the normal counting mode (supports ucosii)
//Include delay_us,delay_ms
//Hot Atom@ALIENTEK
//Technical Forum:www.openedv.com
//Date created: 2014/5/2
//Version: V1.3
//All rights reserved pirated reserved.
//Copyright(C) Guangzhou wing electronic technology limited company 2014-2024
//All rights reserved
//********************************************************************************
//Modify the description
//V1.1 20140803
// 1,delay_us, add parameter equal to 0 to determine, if the parameter is equal to 0, then exit.
// 2, under the modified ucosii, delay_ms function, join the OSLockNesting judgment, entered after a break, also can be used to delay.
//V1.2 20150411
// Modify the way OS support to support any OS (not limited to UCOSII and UCOSIII, in theory any OS can support)
// Add: delay_osrunning/delay_ostickspersec/delay_osintnesting three macro definitions
// Add: delay_osschedlock/delay_osschedunlock/delay_ostimedly three-function
//V1.3 20150521
// 2 bug when amend UCOSIII support:
// Delay_tickspersec read: delay_ostickspersec
// Delay_intnesting read: delay_osintnesting
//////////////////////////////////////////////////////////////////////////////////
static u8 fac_us=0; //us delay times multiplier
static u16 fac_ms=0; //ms delay times multiplier under the OS, ms representing each beat
#if SYSTEM_SUPPORT_OS //If SYSTEM_SUPPORT_OS is defined, and instructions to support OS (not limited to UCOS).
//When delay_us/delay_ms needs to support OS requires three macro definitions and functions associated with the OS to support
//First 3 macro definition:
// delay_osrunning: used to indicate whether the OS is currently running to determine if you can use the correlation function
// delay_ostickspersec: used to represent the OS set the clock ticks, delay_init will be based on the parameters to initial systick
// delay_osintnesting: used to represent OS interrupt nesting level, since interrupts cannot be scheduled, delay_ms uses this parameter to determine how to run
//Then the 3 functions:
// delay_osschedlock:Used to lock a OS task scheduling, prohibit scheduling
//delay_osschedunlock:Used to unlock the OS task scheduling, reopening schedule
// delay_ostimedly:For the OS delay, can cause the task scheduling.
//This routine only UCOSII and UCOSIII support, other OS, please make reference to transplantation
//Support UCOSII
#ifdef OS_CRITICAL_METHOD //OS_CRITICAL_METHOD definitions, instructions to support UCOSII
#define delay_osrunning OSRunning //OS runs mark, 0, does not run 1, run
#define delay_ostickspersec OS_TICKS_PER_SEC //OS clock ticks, or scheduled per second times
#define delay_osintnesting OSIntNesting //Interrupt nesting level, which interrupt nesting times
#endif
//Support UCOSIII
#ifdef CPU_CFG_CRITICAL_METHOD //CPU_CFG_CRITICAL_METHOD definitions, instructions to support UCOSIII
#define delay_osrunning OSRunning //OS runs mark, 0, does not run 1, run
#define delay_ostickspersec OSCfg_TickRate_Hz //OS clock ticks, or scheduled per second times
#define delay_osintnesting OSIntNestingCtr //Interrupt nesting level, which interrupt nesting times
#endif
//us-level delay time, close the task schedule (to prevent interrupted us delay)
void delay_osschedlock(void)
{
#ifdef CPU_CFG_CRITICAL_METHOD //Use UCOSIII
OS_ERR err;
OSSchedLock(&err); //UCOSIII way, prohibit scheduling to prevent interrupted us delayed
#else //Otherwise UCOSII
OSSchedLock(); //UCOSII way prohibit scheduling to prevent interrupted us delayed
#endif
}
//us-level delay time, restore task scheduling
void delay_osschedunlock(void)
{
#ifdef CPU_CFG_CRITICAL_METHOD //Use UCOSIII
OS_ERR err;
OSSchedUnlock(&err); //UCOSIII way, prohibit scheduling to prevent interrupted us delayed
#else //Otherwise UCOSII
OSSchedUnlock(); //UCOSII way prohibit scheduling to prevent interrupted us delayed
#endif
}
//OS is called the delay function delay
//ticks:Delay number of beats
void delay_ostimedly(u32 ticks)
{
#ifdef CPU_CFG_CRITICAL_METHOD
OS_ERR err;
OSTimeDly(ticks,OS_OPT_TIME_PERIODIC,&err);//UCOSIII delay adoption cycle mode
#else
OSTimeDly(ticks); //UCOSII delay
#endif
}
void delay_os_ms(u32 ms)
{
OS_ERR err;
OSTimeDlyHMSM(0, 0, 0, ms,
OS_OPT_TIME_HMSM_STRICT,
&err);
}
//systick interrupt function, used to use the OS
void SysTick_Handler(void)
{
if(delay_osrunning==1) //OS begins to run and perform normal scheduling process
{
OSIntEnter(); //To enter a break
OSTimeTick(); //Call the ucos clock service program
OSIntExit(); //Task switching is triggered a soft interrupt
}
}
#endif
//Initialization delay function
//When using ucos when this function initializes the ucos ticks
//SYSTICK clock fixed to the AHB clock 1/8
//SYSCLK:System clock frequency
void delay_init(u8 SYSCLK)
{
#if SYSTEM_SUPPORT_OS //If you need to support OS.
u32 reload;
#endif
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);//SYSTICK using an external clock source
fac_us=SYSCLK/8; //Regardless of whether or not to use OS,fac_us you need to use
#if SYSTEM_SUPPORT_OS //If you need to support OS.
reload=SYSCLK/8; //Count number of times per second unit k
reload*=1000000/delay_ostickspersec; //According to the delay_ostickspersec set overrun time
//Reload is a 24-bit registers, and the maximum value: 16777216, 72M, about 1.86s
fac_ms=1000/delay_ostickspersec; //Representing OS can delay the minimum unit
SysTick->CTRL|=SysTick_CTRL_TICKINT_Msk;//Enable interrupted SYSTICK
SysTick->LOAD=reload; //Interrupted once every 1/OS_TICKS_PER_SEC seconds
SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk; //Enable the SYSTICK
#else
fac_ms=(u16)fac_us*1000; //Under non-OS, representing each of the MS needs systick clock
#endif
}
#if SYSTEM_SUPPORT_OS //If you need to support OS.
//Delay nus
//nus:Number of us to delay.
//nus:0~204522252(Maximum 2^32/fac_us@fac_us=21)
void delay_us(u32 nus)
{
u32 ticks;
u32 told,tnow,tcnt=0;
u32 reload=SysTick->LOAD; //LOAD value
ticks=nus*fac_us; //Number of beats you want
delay_osschedlock(); //Stop OS scheduling to prevent interrupted us delayed
told=SysTick->VAL; //When entering the counter value
while(1)
{
tnow=SysTick->VAL;
if(tnow!=told)
{
if(tnow<told)tcnt+=told-tnow; //Here look at the SYSTICK is a declining counters can.
else tcnt+=reload-tnow+told;
told=tnow;
if(tcnt>=ticks)break; //Time greater than or equal to the delay time, then exit.
}
};
delay_osschedunlock(); //Restore OS scheduling
}
//Delay nms
//nms:Number of ms to delay
//nms:0~65535
void delay_ms(u16 nms)
{
if (delay_osrunning && (delay_osintnesting == 0)) //If the OS is already running, and is not interrupted (broken not scheduling)
{
if (nms >= fac_ms) //Delay time is greater than the minimum OS time cycle
{
delay_ostimedly(nms/fac_ms); //OS extended
}
nms %= fac_ms; //OS has been unable to provide such a small time delay, using ordinary delay
}
delay_us((u32)(nms * 1000)); //Average delay
}
#else //When no ucos
//Delay nus
//nus as a number of us to delay.
//Note: the value of the nus, not greater than 798915us (max 2^24/fac_us@fac_us=21)
void delay_us(u32 nus)
{
u32 temp;
SysTick->LOAD=nus*fac_us; //Time to load
SysTick->VAL=0x00; //Clear counters
SysTick->CTRL=0x01 ; //Start the countdown
do
{
temp=SysTick->CTRL;
} while ((temp & 0x01) && !(temp & (1 << 16))); //Waiting for the time to arrive
SysTick->CTRL=0x00; //Closed counters
SysTick->VAL =0X00; //Clear counters
}
//Delay nms
//Note range of nms
//SysTick->LOAD is a 24-bit registers, so the delay as follows:
//nms < 0xffffff * 8 * 1000/SYSCLK =
//SYSCLK units are Hz,nms for ms
//Under the 168M, nms<=798ms
void delay_xms(u16 nms)
{
u32 temp;
SysTick->LOAD=(u32)nms*fac_ms; //Load time (SysTick->LOAD 24bit)
SysTick->VAL =0x00; //Clear counters
SysTick->CTRL=0x01 ; //Start the countdown
do
{
temp=SysTick->CTRL;
}while((temp&0x01)&&!(temp&(1<<16))); //Waiting for the time to arrive
SysTick->CTRL=0x00; //Closed counters
SysTick->VAL =0X00; //Clear counters
}
//Delay nms
//nms:0~65535
void delay_ms(u16 nms)
{
u8 repeat=nms/540; //540 here, some customers may overclock is taken into account,
//For example when overclocked to 248M, delay_xms maximum can only delay 541ms
u16 remain=nms%540;
while(repeat)
{
delay_xms(540);
repeat--;
}
if(remain)delay_xms(remain);
}
#endif

View File

@@ -0,0 +1,65 @@
#ifndef __DELAY_H
#define __DELAY_H
#include <sys.h>
//////////////////////////////////////////////////////////////////////////////////
//This program is for educational purposes only, without the author's permission, may not be used for any other purpose
//ALIENTEK STM32F407 Development Board
//SysTick managed to delay the normal counting mode (supports ucosii)
//Include delay_us,delay_ms
//Hot Atomic @ALIENTEK
//Forum: www.openedv.com
//Date created: 2014/5/2
//Version: V1.3
//All rights reserved pirated reserved.
//Copyright(C) Guangzhou wing electronic technology limited company 2014-2024
//All rights reserved
//********************************************************************************
//Modify the description
//V1.1 20140803
// 1,delay_us, add parameter equal to 0 to determine, if the parameter is equal to 0, then exit.
// 2, under the modified ucosii, delay_ms function, join the OSLockNesting judgment, entered after a break, also can be used to delay.
//V1.2 20150411
// Modify the way OS support to support any OS (not limited to UCOSII and UCOSIII, in theory any OS can support)
// Add: delay_osrunning/delay_ostickspersec/delay_osintnesting three macro definitions
// Add: delay_osschedlock/delay_osschedunlock/delay_ostimedly three-function
//V1.3 20150521
// 2 bug when amend UCOSIII support:
// delay_tickspersec read: delay_ostickspersec
// delay_intnesting read: delay_osintnesting
//////////////////////////////////////////////////////////////////////////////////
void delay_init(u8 SYSCLK);
void delay_ms(u16 nms);
void delay_us(u32 nus);
void delay_os_ms(u32 ms);
#endif

View File

@@ -0,0 +1,50 @@
#include "sys.h"
//////////////////////////////////////////////////////////////////////////////////
//This program is for educational purposes only, without the author's permission, may not be used for any other purpose
//ALIENTEK STM32F407 Development Board
//System clock initialize
///GPIO set clock set/break management
//Hot Atom@ALIENTEK
//Technical Forum:www.openedv.com
//Date created:2014/5/2
//Version: V1.0
//All rights reserved pirated reserved.
//Copyright(C) Guangzhou wing electronic technology limited company 2014-2024
//All rights reserved
//********************************************************************************
//Modify the description
//No
//////////////////////////////////////////////////////////////////////////////////
//THUMB instructions compilation is not supported inline
//Uses the following methods to achieve implementation of Assembly instructions WFI
__asm void WFI_SET(void)
{
WFI;
}
//Diable all interrupts (but not fault and NMI interrupt)
__asm void INTX_DISABLE(void)
{
CPSID I
BX LR
}
//Enable all the interrupts
__asm void INTX_ENABLE(void)
{
CPSIE I
BX LR
}
//Setting the stack address
//addr:The top of the stack address
__asm void MSR_MSP(u32 addr)
{
MSR MSP, r0 //set Main Stack value
BX r14
}
//Soft reset
void Sys_Soft_Reset(void)
{
SCB->AIRCR =0X05FA0000|(u32)0x04;
}

View File

@@ -0,0 +1,90 @@
#ifndef __SYS_H
#define __SYS_H
#include "stm32f4xx.h"
//////////////////////////////////////////////////////////////////////////////////
//This program is for educational purposes only, without the author's permission, may not be used for any other purpose
//ALIENTEK STM32F407 Development Board
//System clock initialize
//Hot Atom@ALIENTEK
//Technical Forum:www.openedv.com
//Date created:2014/5/2
//Version: V1.0
//All rights reserved pirated reserved.
//Copyright(C) Guangzhou wing electronic technology limited company 2014-2024
//All rights reserved
//********************************************************************************
//Modify the description
//No
//////////////////////////////////////////////////////////////////////////////////
//0,Not supported OS
//1,Supported OS
#define SYSTEM_SUPPORT_OS 1 //Defines whether the system folders supported OS
//-Bit operation, 51 similar GPIO functions
//Specific ideas, definitive guide to reference <<CM3 >> the fifth chapter (87 pages ~92 pages). M4 and M3, just register the address has changed.
//IO operation macro definitions
#define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2))
#define MEM_ADDR(addr) *((volatile unsigned long *)(addr))
#define BIT_ADDR(addr, bitnum) MEM_ADDR(BITBAND(addr, bitnum))
//IO port address mapping
#define GPIOA_ODR_Addr (GPIOA_BASE+20) //0x40020014
#define GPIOB_ODR_Addr (GPIOB_BASE+20) //0x40020414
#define GPIOC_ODR_Addr (GPIOC_BASE+20) //0x40020814
#define GPIOD_ODR_Addr (GPIOD_BASE+20) //0x40020C14
#define GPIOE_ODR_Addr (GPIOE_BASE+20) //0x40021014
#define GPIOF_ODR_Addr (GPIOF_BASE+20) //0x40021414
#define GPIOG_ODR_Addr (GPIOG_BASE+20) //0x40021814
#define GPIOH_ODR_Addr (GPIOH_BASE+20) //0x40021C14
#define GPIOI_ODR_Addr (GPIOI_BASE+20) //0x40022014
#define GPIOA_IDR_Addr (GPIOA_BASE+16) //0x40020010
#define GPIOB_IDR_Addr (GPIOB_BASE+16) //0x40020410
#define GPIOC_IDR_Addr (GPIOC_BASE+16) //0x40020810
#define GPIOD_IDR_Addr (GPIOD_BASE+16) //0x40020C10
#define GPIOE_IDR_Addr (GPIOE_BASE+16) //0x40021010
#define GPIOF_IDR_Addr (GPIOF_BASE+16) //0x40021410
#define GPIOG_IDR_Addr (GPIOG_BASE+16) //0x40021810
#define GPIOH_IDR_Addr (GPIOH_BASE+16) //0x40021C10
#define GPIOI_IDR_Addr (GPIOI_BASE+16) //0x40022010
//IO operation, only a single IO!
//Ensure that the value of n is less than 16!
#define PAout(n) BIT_ADDR(GPIOA_ODR_Addr,n) //Output
#define PAin(n) BIT_ADDR(GPIOA_IDR_Addr,n) //Input
#define PBout(n) BIT_ADDR(GPIOB_ODR_Addr,n) //Output
#define PBin(n) BIT_ADDR(GPIOB_IDR_Addr,n) //Input
#define PCout(n) BIT_ADDR(GPIOC_ODR_Addr,n) //Output
#define PCin(n) BIT_ADDR(GPIOC_IDR_Addr,n) //Input
#define PDout(n) BIT_ADDR(GPIOD_ODR_Addr,n) //Output
#define PDin(n) BIT_ADDR(GPIOD_IDR_Addr,n) //Input
#define PEout(n) BIT_ADDR(GPIOE_ODR_Addr,n) //Output
#define PEin(n) BIT_ADDR(GPIOE_IDR_Addr,n) //Input
#define PFout(n) BIT_ADDR(GPIOF_ODR_Addr,n) //Output
#define PFin(n) BIT_ADDR(GPIOF_IDR_Addr,n) //Input
#define PGout(n) BIT_ADDR(GPIOG_ODR_Addr,n) //Output
#define PGin(n) BIT_ADDR(GPIOG_IDR_Addr,n) //Input
#define PHout(n) BIT_ADDR(GPIOH_ODR_Addr,n) //Output
#define PHin(n) BIT_ADDR(GPIOH_IDR_Addr,n) //Input
#define PIout(n) BIT_ADDR(GPIOI_ODR_Addr,n) //Output
#define PIin(n) BIT_ADDR(GPIOI_IDR_Addr,n) //Input
//Following is a compilation of a function
void WFI_SET(void); //WFI instruction is executed
void INTX_DISABLE(void);//Disable all interrupts
void INTX_ENABLE(void); //Enable all the interrupts
void MSR_MSP(u32 addr); //Setting the stack address
void Sys_Soft_Reset(void);
#endif

View File

@@ -0,0 +1,215 @@
#include "sys.h"
#include "usart.h"
//////////////////////////////////////////////////////////////////////////////////
//If you are using ucos, include the following header file.
#if SYSTEM_SUPPORT_OS
#include "includes.h" //ucos Use
#endif
/////////////////////////////////////////////////////////////////////////////////
//This program is for educational purposes only, without the author's permission, may not be used for any other purpose
//ALIENTEK STM32F4 Explorer Board
//Initialize serial port 1
//Hot Atomic @ALIENTEK
//Forum: www.openedv.com
//Date modified: 2014/6/10
//Version: V1.5
//All rights reserved pirated reserved.
//Copyright(C) Guangzhou wing electronic technology limited company 2009-2019
//All rights reserved
//********************************************************************************
//V1.3 changes description
// Supports serial port baud rate setting at different frequencies.
// Added support for printf
// Serial port receive command features have been added.
// Fixed printf first character missing bug
//V1.4 amended description
// 1, modify the initialize serial IO bug
// 2, modify the USART_RX_STA makes serial port maximum bytes received 2 of 14
// 3, USART_REC_LEN, defines the serial port the maximum allowable number of bytes received (not more than 2 of 14)
// 4, the modified EN_USART1_RX method
//V1.5 modify the description
// 1, added support for UCOSII
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
//Add the following code, support for printf function and do not need to select use MicroLIB
#if 1
#pragma import(__use_no_semihosting)
//Standard library required support function
struct __FILE
{
int handle;
};
FILE __stdout;
//Define _sys_exit () to avoid using host model
void _sys_exit(int x)
{
x = x;
}
//Fputc function is defined
int fputc(int ch, FILE *f)
{
#ifdef CONSOLE_DEBUG
UART1_PutChar(ch);
#endif // #ifdef CONSOLE_DEBUG
return ch;
}
#endif
#ifdef CONSOLE_DEBUG
UART1_Info Uart1;
//Initializes IO serial port 1
//Bound: baud rate
void uart1_init(u32 bound)
{
//GPIO port settings
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE); //Enables GPIOA clock
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);//Enable USART1
//Serial port 1 pins reuse maps
GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_USART1); //GPIOA9 multiplex USART1
GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_USART1); //GPIOA10 multiplex USART1
//USART1 port configuration
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10; //GPIOA9 and GPIOA10
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//Multiplexing function
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //Speed 50MHz
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //Push-pull multiplexed output
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //Pull-up
GPIO_Init(GPIOA,&GPIO_InitStructure); //Initialize PA9,PA10
//USART1 Initialization settings
USART_InitStructure.USART_BaudRate = bound;//Baud rate setting
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//Word is 8-bit data format
USART_InitStructure.USART_StopBits = USART_StopBits_1;//One stop bit
USART_InitStructure.USART_Parity = USART_Parity_No;//No parity bit
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//No hardware flow control
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //Send and receive mode
USART_Init(USART1, &USART_InitStructure); //Initialize serial port 1
USART_Cmd(USART1, ENABLE); //Enabling serial port 1
USART_ClearFlag(USART1, USART_FLAG_TC);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);//Open break
}
void USART1_IRQHandler(void) //Serial port 1 interrupt service routine
{
USART_TypeDef *usart;
CPU_INT08U rx_data;
#if SYSTEM_SUPPORT_OS //Use operating system UCOS
OSIntEnter();
#endif
usart = USART1;
if (USART_GetITStatus(usart, USART_IT_RXNE) != RESET)
{
rx_data = USART_ReceiveData(usart) & 0xFF; /* Read one byte from the receive data register. */
Uart1.RxBuf[Uart1.RxInPos++] = rx_data;
Uart1.RxInPos %= UART1_RX_BUFFER_SIZE;
if (Uart1.RxInPos == Uart1.RxOutPos)
{
Uart1.RxOutPos++;
Uart1.RxOutPos %= UART1_RX_BUFFER_SIZE;
}
USART_ClearITPendingBit(usart, USART_IT_RXNE); /* Clear the USART1 receive interrupt. */
}
if (USART_GetITStatus(usart, USART_IT_TXE) != RESET)
{
/* Write one byte to the transmit data register */
USART_SendData(usart, Uart1.TxBuf[Uart1.TxOutPos++]);
Uart1.TxOutPos %= UART1_TX_BUFFER_SIZE;
if (Uart1.TxOutPos == Uart1.TxInPos)
{
/* Disable the USART1 Transmit interrupt */
USART_ITConfig(usart, USART_IT_TXE, DISABLE);
}
}
#if SYSTEM_SUPPORT_OS
OSIntExit(); //Exit interrupt
#endif
}
/*******************************************************************************
* Function Name : void UART1_PutChar(char data)
* Description : UART1 1문자 출력
* Parameters : 아스키코드
* Return : None
*******************************************************************************/
void UART1_PutChar(const u8 ascii)
{
CPU_SR_ALLOC();
while (((Uart1.TxInPos + 1)% UART1_TX_BUFFER_SIZE) == (Uart1.TxOutPos % UART1_TX_BUFFER_SIZE))
USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
CPU_CRITICAL_ENTER();
Uart1.TxBuf[Uart1.TxInPos++] = ascii;
Uart1.TxInPos %= UART1_TX_BUFFER_SIZE;
USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
CPU_CRITICAL_EXIT();
}
/*******************************************************************************
* Function Name : u8 UART1_GetChar(char *data)
* Description : UART1로 수신버퍼에서 데이타(1byte) 가져오기
* Parameters : none
* Return : 데이타 수신 여부(0: 수신버퍼가 비었음, 1: 수신버퍼에 데이타가 있음)
*******************************************************************************/
ErrorStatus UART1_GetChar(u8 *data)
{
if (Uart1.RxInPos != Uart1.RxOutPos)
{
data[0] = Uart1.RxBuf[Uart1.RxOutPos];
Uart1.RxOutPos++;
Uart1.RxOutPos %= UART1_RX_BUFFER_SIZE;
return SUCCESS;
}
else
return ERROR;
}
/*******************************************************************************
* Function Name : u8 UART1_GetChar(char *data)
* Description : UART1로 수신버퍼에서 데이타(1byte) 가져오기
* Parameters : none
* Return : 데이타 수신 여부(0: 수신버퍼가 비었음, 1: 수신버퍼에 데이타가 있음)
*******************************************************************************/
u8 UART1_GC(void)
{
u8 result = 0;
if (Uart1.RxInPos != Uart1.RxOutPos)
{
result = Uart1.RxBuf[Uart1.RxOutPos];
Uart1.RxOutPos++;
Uart1.RxOutPos %= UART1_RX_BUFFER_SIZE;
}
return result;
}
#endif // #ifdef CONSOLE_DEBUG

View File

@@ -0,0 +1,55 @@
#ifndef __USART_H
#define __USART_H
#include "stdio.h"
#include "stm32f4xx_conf.h"
#include "sys.h"
//////////////////////////////////////////////////////////////////////////////////
//This program is for educational purposes only, without the author's permission, may not be used for any other purpose
//ALIENTEK STM32F4 Explorer Board
//Initialize serial port 1
//Hot Atomic @ALIENTEK
//Forum: www.openedv.com
//Date modified: 2014/6/10
//Version: V1.4
//All rights reserved pirated reserved.
//Copyright(C) Guangzhou wing electronic technology limited company 2009-2019
//All rights reserved
//********************************************************************************
//V1.3 changes description
// Supports serial port baud rate setting at different frequencies.
// Added support for printf
// Serial port receive command features have been added.
// Fixed printf first character missing bug
//V1.4 amended description
// 1, modify the initialize serial IO bug
// 2, modify the USART_RX_STA makes serial port maximum bytes received 2 of 14
// 3, USART_REC_LEN, defines the serial port the maximum allowable number of bytes received (not more than 2 of 14)
// 4, the modified EN_USART1_RX method
//V1.5 modify the description
// 1, added support for UCOSII
//////////////////////////////////////////////////////////////////////////////////
#define DEBUG_PORT USART1
/* Defines -------------------------------------------------------------------*/
#define UART1_TX_BUFFER_SIZE 1024
#define UART1_RX_BUFFER_SIZE 128
/* Type declarations ---------------------------------------------------------*/
typedef struct{
u16 RxInPos, RxOutPos;
u16 TxInPos, TxOutPos;
u8 RxBuf[UART1_RX_BUFFER_SIZE];
u8 TxBuf[UART1_TX_BUFFER_SIZE];
} UART1_Info;
void uart1_init(u32 bound);
ErrorStatus UART1_GetChar(u8 *data);
void UART1_PutChar(const u8 ascii);
void UART1_PutStr(u8 *str, u16 len);
void UART1_printf(const char *fmt,...);
u8 UART1_GC(void);
#endif