Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
TianYing_ty100
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
TY
TianYing_ty100
Commits
4ce9204a
Commit
4ce9204a
authored
May 14, 2024
by
李俭双
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'lijianshuang' into 'dev'
✨
feat:增加串口驱动 See merge request
!17
parents
d9acfdc2
9bc752bd
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
208 additions
and
389 deletions
+208
-389
TianYing.uvprojx
...ware/Project/Cmsemicon/BAT32A239/MDK_ARM/TianYing.uvprojx
+10
-10
TianYing200.BAT
Firmware/Project/Cmsemicon/BAT32A239/MDK_ARM/TianYing200.BAT
+1
-4
PowerManag_user.c
Firmware/Source/Component/PowerManagement/PowerManag_user.c
+3
-1
UART.c
Firmware/Source/Device/Cmsemicon/BAT32A239/RTE/UART/UART.c
+0
-227
UART.h
Firmware/Source/Device/Cmsemicon/BAT32A239/RTE/UART/UART.h
+0
-147
UART_DEMO.c
...re/Source/Device/Cmsemicon/BAT32A239/RTE/UART/UART_DEMO.c
+170
-0
UART_DEMO.h
...re/Source/Device/Cmsemicon/BAT32A239/RTE/UART/UART_DEMO.h
+24
-0
No files found.
Firmware/Project/Cmsemicon/BAT32A239/MDK_ARM/TianYing.uvprojx
View file @
4ce9204a
...
...
@@ -863,16 +863,6 @@
<FileType>
5
</FileType>
<FilePath>
..\..\..\..\Source\Device\Cmsemicon\BAT32A239\RTE\GPIO\RTE_GPIO_BAT32A239.h
</FilePath>
</File>
<File>
<FileName>
UART.c
</FileName>
<FileType>
1
</FileType>
<FilePath>
..\..\..\..\Source\Device\Cmsemicon\BAT32A239\RTE\UART\UART.c
</FilePath>
</File>
<File>
<FileName>
UART.h
</FileName>
<FileType>
5
</FileType>
<FilePath>
..\..\..\..\Source\Device\Cmsemicon\BAT32A239\RTE\UART\UART.h
</FilePath>
</File>
<File>
<FileName>
DeepSleep.c
</FileName>
<FileType>
1
</FileType>
...
...
@@ -933,6 +923,16 @@
<FileType>
1
</FileType>
<FilePath>
..\..\..\..\Source\Device\Cmsemicon\BAT32A239\RTE\CLOCK_Select\RTE_CLOCK_Select_BAT32A239.c
</FilePath>
</File>
<File>
<FileName>
UART_DEMO.c
</FileName>
<FileType>
1
</FileType>
<FilePath>
..\..\..\..\Source\Device\Cmsemicon\BAT32A239\RTE\UART\UART_DEMO.c
</FilePath>
</File>
<File>
<FileName>
UART_DEMO.h
</FileName>
<FileType>
5
</FileType>
<FilePath>
..\..\..\..\Source\Device\Cmsemicon\BAT32A239\RTE\UART\UART_DEMO.h
</FilePath>
</File>
</Files>
</Group>
<Group>
...
...
Firmware/Project/Cmsemicon/BAT32A239/MDK_ARM/TianYing200.BAT
View file @
4ce9204a
SET PATH=C:\Keil_v5\ARM\ARMCC\Bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Users\tyw05\AppData\Local\Microsoft\WindowsApps;
SET ARMCC5_ASMOPT=--diag_suppress=9931
SET ARMCC5_CCOPT=--diag_suppress=9931
SET ARMCC5_LINKOPT=--diag_suppress=9931
SET CPU_TYPE=BAT32G139GK64FB
SET CPU_VENDOR=Cmsemicon
SET UV2_TARGET=TianYing200
...
...
@@ -38,13 +35,13 @@ SET CPU_CLOCK=0x00B71B00
"C:\Keil_v5\ARM\ARMCC\Bin\ArmCC" --Via ".\objects\rte_tick_timer_bat32a239.__i"
"C:\Keil_v5\ARM\ARMCC\Bin\ArmCC" --Via ".\objects\rte_wdt_bat32a239.__i"
"C:\Keil_v5\ARM\ARMCC\Bin\ArmCC" --Via ".\objects\rte_gpio_bat32a239.__i"
"C:\Keil_v5\ARM\ARMCC\Bin\ArmCC" --Via ".\objects\uart.__i"
"C:\Keil_v5\ARM\ARMCC\Bin\ArmCC" --Via ".\objects\deepsleep.__i"
"C:\Keil_v5\ARM\ARMCC\Bin\ArmCC" --Via ".\objects\rte_rtc.__i"
"C:\Keil_v5\ARM\ARMCC\Bin\ArmCC" --Via ".\objects\trmerm.__i"
"C:\Keil_v5\ARM\ARMCC\Bin\ArmCC" --Via ".\objects\rte_adc_interim_version.__i"
"C:\Keil_v5\ARM\ARMCC\Bin\ArmCC" --Via ".\objects\rte_can.__i"
"C:\Keil_v5\ARM\ARMCC\Bin\ArmCC" --Via ".\objects\rte_clock_select_bat32a239.__i"
"C:\Keil_v5\ARM\ARMCC\Bin\ArmCC" --Via ".\objects\uart_demo.__i"
"C:\Keil_v5\ARM\ARMCC\Bin\ArmCC" --Via ".\objects\main.__i"
"C:\Keil_v5\ARM\ARMCC\Bin\ArmCC" --Via ".\objects\sys_scheduler.__i"
"C:\Keil_v5\ARM\ARMCC\Bin\ArmCC" --Via ".\objects\sys_scheduler_lib.__i"
...
...
Firmware/Source/Component/PowerManagement/PowerManag_user.c
View file @
4ce9204a
...
...
@@ -50,7 +50,9 @@ static void Power_KL30_Init(void)
Can_Init
();
DFlash_init
();
Analog_Signal_Conv_Init
();
BU98R10_Init
();
BU98R10_Init
();
Uart0_Init
(
115200
);
Sys_KL30_Init
();
Checkself_Init
();
Data_Vehicle_Speed_KL30_Init
();
...
...
Firmware/Source/Device/Cmsemicon/BAT32A239/RTE/UART/UART.c
deleted
100644 → 0
View file @
d9acfdc2
/*
* UART.c
*
* Created on: 2024��2��23��
*/
#include <stdint.h>
#include "UART.h"
#include "uart.h"
#include "gpio.h"
int8_t
RTE_UART_Init
(
SCIAFSelect_TypeDef
UARTx
,
uint32_t
baudRate
,
uint16_t
bitorder
)
{
switch
(
UARTx
)
{
case
UART0
:
{
int8_t
ret
;
GPIO_InitTypeDef
GPIO_InitStruct
=
{
0
};
UART_InitTypeDef
UART_InitStructure
=
{
0
};
GPIO_PinAFConfig
(
GPIO_PORT5
,
GPIO_Pin_1
,
GPIO_P51
,
GROUP_AF_ODEFAULT
);
GPIO_PinAFConfig
(
GPIO_PORT5
,
GPIO_Pin_0
,
GPIO_P50
,
GROUP_AF_ODEFAULT
);
/*TX GPIO CONFIG*/
GPIO_InitStruct
.
GPIO_Pin
=
GPIO_Pin_1
;
GPIO_InitStruct
.
GPIO_Mode
=
GPIO_Mode_OUT
;
GPIO_InitStruct
.
GPIO_OType
=
GPIO_OType_PP
;
GPIO_InitStruct
.
GPIO_Level
=
GPIO_Level_HIGH
;
GPIO_InitStruct
.
GPIO_Ctrl
=
GPIO_Control_DIG
;
GPIO_Init
(
GPIO_PORT5
,
&
GPIO_InitStruct
);
/*RX GPIO CONFIG*/
GPIO_InitStruct
.
GPIO_Pin
=
GPIO_Pin_0
;
GPIO_InitStruct
.
GPIO_Mode
=
GPIO_Mode_IN
;
GPIO_InitStruct
.
GPIO_Ctrl
=
GPIO_Control_DIG
;
GPIO_Init
(
GPIO_PORT5
,
&
GPIO_InitStruct
);
/*USART CONFIG*/
UART_InitStructure
.
UART_BaudRate
=
baudRate
;
UART_InitStructure
.
UART_WordLength
=
UART_WordLength_8b
;
UART_InitStructure
.
UART_StopBits
=
UART_StopBits_1
;
UART_InitStructure
.
UART_Parity
=
UART_Parity_No
;
UART_InitStructure
.
phase
=
UART_Phase_Normal
;
UART_InitStructure
.
bitorder
=
bitorder
;
UART_InitStructure
.
UART_Mode
=
UART_Mode_Rx
|
UART_Mode_Tx
;
ret
=
UART_Init
(
UART0
,
&
UART_InitStructure
);
if
(
ret
)
{
SCI_ERROR_LOG
(
ret
);
return
ret
;
}
// ISR_Register(ST0_IRQn, uart0_interrupt_send);
// ISR_Register(SR0_IRQn, uart0_interrupt_receive);
return
SCI_SUCCESS
;
}
// break;
case
UART1
:
{
int8_t
res
;
GPIO_InitTypeDef
GPIO_InitStruct
=
{
0
};
UART_InitTypeDef
UART_InitStructure
=
{
0
};
#ifndef BAT32G1XX_48PIN
GPIO_PinAFConfig
(
GPIO_PORT0
,
GPIO_Pin_2
,
GPIO_P02
,
GROUP_AF_ODEFAULT
);
GPIO_PinAFConfig
(
GPIO_PORT0
,
GPIO_Pin_3
,
GPIO_P03
,
GROUP_AF_ODEFAULT
);
/*TX GPIO CONFIG*/
GPIO_InitStruct
.
GPIO_Pin
=
GPIO_Pin_2
;
GPIO_InitStruct
.
GPIO_Mode
=
GPIO_Mode_OUT
;
GPIO_InitStruct
.
GPIO_OType
=
GPIO_OType_PP
;
GPIO_InitStruct
.
GPIO_Level
=
GPIO_Level_HIGH
;
GPIO_InitStruct
.
GPIO_Ctrl
=
GPIO_Control_DIG
;
GPIO_Init
(
GPIO_PORT0
,
&
GPIO_InitStruct
);
/*RX GPIO CONFIG*/
GPIO_InitStruct
.
GPIO_Pin
=
GPIO_Pin_3
;
GPIO_InitStruct
.
GPIO_Mode
=
GPIO_Mode_IN
;
GPIO_InitStruct
.
GPIO_Ctrl
=
GPIO_Control_DIG
;
GPIO_Init
(
GPIO_PORT0
,
&
GPIO_InitStruct
);
#else
GPIO_PinAFConfig
(
GPIO_PORT0
,
GPIO_Pin_0
,
GPIO_P00
,
GROUP_AF_ODEFAULT
);
GPIO_PinAFConfig
(
GPIO_PORT0
,
GPIO_Pin_1
,
GPIO_P01
,
GROUP_AF_ODEFAULT
);
/*TX GPIO CONFIG*/
GPIO_InitStruct
.
GPIO_Pin
=
GPIO_Pin_2
;
GPIO_InitStruct
.
GPIO_Mode
=
GPIO_Mode_OUT
;
GPIO_InitStruct
.
GPIO_OType
=
GPIO_OType_PP
;
GPIO_InitStruct
.
GPIO_Level
=
GPIO_Level_HIGH
;
GPIO_InitStruct
.
GPIO_Ctrl
=
GPIO_Control_DIG
;
GPIO_Init
(
GPIO_PORT0
,
&
GPIO_InitStruct
);
/*RX GPIO CONFIG*/
GPIO_InitStruct
.
GPIO_Pin
=
GPIO_Pin_3
;
GPIO_InitStruct
.
GPIO_Mode
=
GPIO_Mode_IN
;
GPIO_InitStruct
.
GPIO_Ctrl
=
GPIO_Control_DIG
;
GPIO_Init
(
GPIO_PORT0
,
&
GPIO_InitStruct
);
#endif
/*USART CONFIG*/
UART_InitStructure
.
UART_BaudRate
=
baudRate
;
UART_InitStructure
.
UART_WordLength
=
UART_WordLength_8b
;
UART_InitStructure
.
UART_StopBits
=
UART_StopBits_1
;
UART_InitStructure
.
UART_Parity
=
UART_Parity_No
;
UART_InitStructure
.
phase
=
UART_Phase_Normal
;
UART_InitStructure
.
bitorder
=
bitorder
;
UART_InitStructure
.
UART_Mode
=
UART_Mode_Rx
|
UART_Mode_Tx
;
res
=
UART_Init
(
UART1
,
&
UART_InitStructure
);
if
(
res
)
{
SCI_ERROR_LOG
(
res
);
return
res
;
}
// ISR_Register(ST1_IRQn, uart1_interrupt_send);
// ISR_Register(SR1_IRQn, uart1_interrupt_receive);
return
SCI_SUCCESS
;
}
// break;
case
UART2
:
{
int8_t
res
;
GPIO_InitTypeDef
GPIO_InitStruct
=
{
0
};
UART_InitTypeDef
UART_InitStructure
=
{
0
};
GPIO_PinAFConfig
(
GPIO_PORT1
,
GPIO_Pin_3
,
GPIO_P13
,
GROUP_AF_ODEFAULT
);
GPIO_PinAFConfig
(
GPIO_PORT1
,
GPIO_Pin_4
,
GPIO_P14
,
GROUP_AF_ODEFAULT
);
/*TX GPIO CONFIG*/
GPIO_InitStruct
.
GPIO_Pin
=
GPIO_Pin_3
;
GPIO_InitStruct
.
GPIO_Mode
=
GPIO_Mode_OUT
;
GPIO_InitStruct
.
GPIO_OType
=
GPIO_OType_PP
;
GPIO_InitStruct
.
GPIO_Level
=
GPIO_Level_HIGH
;
GPIO_InitStruct
.
GPIO_Ctrl
=
GPIO_Control_DIG
;
GPIO_Init
(
GPIO_PORT1
,
&
GPIO_InitStruct
);
/*RX GPIO CONFIG*/
GPIO_InitStruct
.
GPIO_Pin
=
GPIO_Pin_4
;
GPIO_InitStruct
.
GPIO_Mode
=
GPIO_Mode_IN
;
GPIO_InitStruct
.
GPIO_Ctrl
=
GPIO_Control_DIG
;
GPIO_Init
(
GPIO_PORT1
,
&
GPIO_InitStruct
);
/*USART CONFIG*/
UART_InitStructure
.
UART_BaudRate
=
baudRate
;
UART_InitStructure
.
UART_WordLength
=
UART_WordLength_8b
;
UART_InitStructure
.
UART_StopBits
=
UART_StopBits_1
;
UART_InitStructure
.
UART_Parity
=
UART_Parity_No
;
UART_InitStructure
.
phase
=
UART_Phase_Normal
;
UART_InitStructure
.
bitorder
=
bitorder
;
UART_InitStructure
.
UART_Mode
=
UART_Mode_Rx
|
UART_Mode_Tx
;
res
=
UART_Init
(
UART2
,
&
UART_InitStructure
);
if
(
res
)
{
SCI_ERROR_LOG
(
res
);
return
res
;
}
// ISR_Register(ST2_IRQn, uart2_interrupt_send);
// ISR_Register(SR2_IRQn, uart2_interrupt_receive);
return
SCI_SUCCESS
;
}
// break;
}
}
//void RTE_UART_Init(SCIAFSelect_TypeDef UARTx, uint32_t baudRate, uint16_t bitorder)
//{
// UART_Init(UARTx, baudRate, bitorder);
//}
void
RTE_UART_SendData
(
SCIAFSelect_TypeDef
UARTx
,
uint8_t
*
pData
)
{
switch
(
UARTx
)
{
case
UART0
:
{
UART_SendByte
(
UART0
,
*
pData
);
}
break
;
case
UART1
:
{
UART_SendByte
(
UART1
,
*
pData
);
}
break
;
case
UART2
:
{
UART_SendByte
(
UART2
,
*
pData
);
}
break
;
}
}
char
RTE_UART_ReceiveData
(
SCIAFSelect_TypeDef
UARTx
,
uint8_t
*
pData
)
{
switch
(
UARTx
)
{
case
UART0
:
{
return
UART_ReceiveByte
(
UART0
);
}
// break;
case
UART1
:
{
return
UART_ReceiveByte
(
UART1
);
}
// break;
case
UART2
:
{
return
UART_ReceiveByte
(
UART2
);
}
// break;
}
}
Firmware/Source/Device/Cmsemicon/BAT32A239/RTE/UART/UART.h
deleted
100644 → 0
View file @
d9acfdc2
#ifndef RTE_UART_H_
#define RTE_UART_H_
#include <stdint.h>
#include "sci_common.h"
//Need to delete after SCI framework is ready
#define UART0_TX SCI0->SCI.TXD0
#define UART0_RX SCI0->SCI.RXD0
#define UART1_TX SCI0->SCI.TXD1
#define UART1_RX SCI0->SCI.RXD1
#define UART2_TX SCI1->SCI.TXD2
#define UART2_RX SCI1->SCI.RXD2
#define UART3_TX SCI2->SCI.TXD3
#define UART3_RX SCI2->SCI.RXD3
#define PLL_SR_FIH_ENABLE 0
#if PLL_SR_FIH_ENABLE
#define PLL_SR_FIH
#endif
#define PLL_SR_FIH_ENABLE 0
#if PLL_SR_FMX_ENABLE
#define PLL_SR_FMX_SYSCLK
#endif
#define PLL_SR_FMX_FREQ 640000000
#if defined( BAT32G1XX_100PIN) || defined( BAT32G1XX_80PIN)
#define IS_UART_ALL_PERIPH(PERIPH) \
(((PERIPH) == UART0) || ((PERIPH) == UART1) || ((PERIPH) == UART2)|| ((PERIPH) == UART3))
#else
#define IS_UART_ALL_PERIPH(PERIPH) \
(((PERIPH) == UART0) || ((PERIPH) == UART1) || ((PERIPH) == UART2))
#endif
/** @defgroup UART_Word_Length
* @{
*/
#define UART_WordLength_7b ((uint16_t)0x0006)
#define UART_WordLength_8b ((uint16_t)0x0007)
#define UART_WordLength_9b ((uint16_t)0x0008)
#define UART_WordLength_16b ((uint16_t)0x000E)
#define IS_UART_WORD_LENGTH(LENGTH) (((LENGTH) == UART_WordLength_7b) || \
((LENGTH) == UART_WordLength_8b) || \
((LENGTH) == UART_WordLength_9b) || \
((LENGTH) == UART_WordLength_16b))
/** @defgroup UART_Stop_Bits
* @{
*/
#define UART_StopBits_1 ((uint16_t)0x0010)
#define UART_StopBits_2 ((uint16_t)0x0020)
#define IS_UART_STOPBITS(STOPBITS) (((STOPBITS) == UART_StopBits_1) || \
((STOPBITS) == UART_StopBits_2))
/**
* @}
*/
/** @defgroup UART_Parity
* @{
*/
#define UART_Parity_No ((uint16_t)0x0000)
#define UART_Parity_Even ((uint16_t)0x0200)
#define UART_Parity_Odd ((uint16_t)0x0300)
#define IS_UART_PARITY(PARITY) (((PARITY) == UART_Parity_No) || \
((PARITY) == UART_Parity_Even) || \
((PARITY) == UART_Parity_Odd))
/** @defgroup UART_Mode
* @{
*/
#define UART_Mode_Rx ((uint16_t)0x0012)
#define UART_Mode_Tx ((uint16_t)0x0022)
#define IS_UART_MODE(MODE) ((((MODE) & (uint16_t)0x00CD) == 0x00) && ((MODE) != (uint16_t)0x00))
/** @defgroup UART_bitorder
* @{
*/
#define UART_Bit_LSB ((uint16_t)0x0080)
#define UART_Bit_MSB ((uint16_t)0x0000)
/** @defgroup UART_phase
* @{
*/
#define UART_Phase_Normal ((uint16_t)0x0000)
#define UART_Phase_Reverse ((uint16_t)0x0040)
#define UART_PHASE_MASK ((uint16_t)0x0005)
#define UART0_PHASE_POS ((uint16_t)((1 << 0) & UART_PHASE_MASK))
#define UART1_PHASE_POS ((uint16_t)((1 << 2) & UART_PHASE_MASK))
#define UART2_PHASE_POS ((uint16_t)((1 << 0) & UART_PHASE_MASK))
#define UART_CTRL_POS ((uint16_t)0x01)
/** @defgroup UART_Flags
* @{
*/
#define UART_FLAG_TSF ((uint16_t)0x0040)
#define UART_FLAG_BFF ((uint16_t)0x0020)
#define UART_FLAG_FEF ((uint16_t)0x0004)
#define UART_FLAG_PEF ((uint16_t)0x0002)
#define UART_FLAG_OVF ((uint16_t)0x0001)
#define IS_UART_FLAG(FLAG) ((((FLAG) & (uint16_t)0xFF98) == 0x00) && ((FLAG) != (uint16_t)0x00))
#define IS_UART_CLEAR_FLAG(FLAG) ((((FLAG) & (uint16_t)0xFFF8) == 0x00) && ((FLAG) != (uint16_t)0x00))
typedef
struct
{
uint32_t
UART_BaudRate
;
/*!< This member configures the UART communication baud rate. */
uint16_t
UART_WordLength
;
/*!< Specifies the number of data bits transmitted or received in a frame.
This parameter can be a value of @ref UART_Word_Length */
uint16_t
UART_StopBits
;
/*!< Specifies the number of stop bits transmitted.
This parameter can be a value of @ref UART_Stop_Bits */
uint16_t
UART_Parity
;
/*!< Specifies the parity mode. This parameter can be a value of @ref UART_Parity
@note When parity is enabled, the computed parity is inserted at the MSB position of the transmitted data (9th bit when
the word length is set to 9 data bits; 8th bit when the word length is set to 8 data bits). */
uint16_t
UART_Mode
;
/*!< Specifies wether the Receive or Transmit mode is enabled or disabled.
This parameter can be a value of @ref UART_Mode */
uint16_t
bitorder
;
/*!< Specifies the bit stream transit order: LSB or MSB */
uint16_t
phase
;
/*!< Specifies UART output clock_Phase Normal or Reverse */
}
UART_InitTypeDef
;
// 初始化串�?
int8_t
RTE_UART_Init
(
SCIAFSelect_TypeDef
UARTx
,
uint32_t
baudRate
,
uint16_t
bitorder
);
// 发送数�?
void
RTE_UART_SendData
(
SCIAFSelect_TypeDef
UARTx
,
uint8_t
*
pData
);
// 接收数据
char
RTE_UART_ReceiveData
(
SCIAFSelect_TypeDef
UARTx
,
uint8_t
*
pData
);
#endif
/* RTE_UART_H_ */
Firmware/Source/Device/Cmsemicon/BAT32A239/RTE/UART/UART_DEMO.c
0 → 100644
View file @
4ce9204a
/*******************************************************************************
* COPYRIGHT (C) 2021 CMS Technologies Ltd. *
* *
********************************************************************************
* FileName : uart_demo.c *
* Author : *
* Version : 1.0 *
* Date : 2021.08.13 *
* Description : *
* Function List : *
********************************************************************************/
//#include "uart_demo.h"
//#include "tim_demo.h"
//#include "dma_demo.h"
//#include "uart.h"
//#include "gpio.h"
#include "UART_DEMO.h"
//#include <stdint.h>
unsigned
char
UART0_RX_BUF
[
UART_MAX_RECV_LEN
];
unsigned
short
UART0_RX_STA
=
0
;
/******************************************************************************
* Function Name: Uart0_Init
* @brief UART0 init demo
* @param bound
* @return init status
******************************************************************************/
int8_t
Uart0_Init
(
uint32_t
bound
)
{
int8_t
ret
;
GPIO_InitTypeDef
GPIO_InitStruct
=
{
0
};
UART_InitTypeDef
UART_InitStructure
=
{
0
};
GPIO_PinAFConfig
(
GPIO_PORT1
,
GPIO_Pin_1
,
GPIO_P11
,
GROUP_AF_RXD0
);
GPIO_PinAFConfig
(
GPIO_PORT1
,
GPIO_Pin_2
,
GPIO_P12
,
GROUP_AF_TXD0
);
/*TX GPIO CONFIG*/
GPIO_InitStruct
.
GPIO_Pin
=
GPIO_Pin_2
;
GPIO_InitStruct
.
GPIO_Mode
=
GPIO_Mode_OUT
;
GPIO_InitStruct
.
GPIO_OType
=
GPIO_OType_PP
;
GPIO_InitStruct
.
GPIO_Level
=
GPIO_Level_HIGH
;
GPIO_InitStruct
.
GPIO_Ctrl
=
GPIO_Control_DIG
;
GPIO_Init
(
GPIO_PORT1
,
&
GPIO_InitStruct
);
/*RX GPIO CONFIG*/
GPIO_InitStruct
.
GPIO_Pin
=
GPIO_Pin_1
;
GPIO_InitStruct
.
GPIO_Mode
=
GPIO_Mode_IN
;
GPIO_InitStruct
.
GPIO_Ctrl
=
GPIO_Control_DIG
;
GPIO_Init
(
GPIO_PORT1
,
&
GPIO_InitStruct
);
/*USART CONFIG*/
UART_InitStructure
.
UART_BaudRate
=
bound
;
UART_InitStructure
.
UART_WordLength
=
UART_WordLength_8b
;
UART_InitStructure
.
UART_StopBits
=
UART_StopBits_1
;
//Ò»¸öֹͣλ
UART_InitStructure
.
UART_Parity
=
UART_Parity_No
;
//ÎÞÆæżУÑéλ
UART_InitStructure
.
phase
=
UART_Phase_Normal
;
UART_InitStructure
.
bitorder
=
UART_Bit_LSB
;
UART_InitStructure
.
UART_Mode
=
UART_Mode_Rx
|
UART_Mode_Tx
;
//ÊÕ·¢Ä£Ê½
ret
=
UART_Init
(
UART0
,
&
UART_InitStructure
);
//³õʼ»¯´®¿Ú
if
(
ret
)
{
SCI_ERROR_LOG
(
ret
);
return
ret
;
}
ISR_Register
(
ST0_IRQn
,
uart0_interrupt_send
);
//´®¿Ú0·¢ËÍÖжϷþÎñ·¾¶×¢²á
ISR_Register
(
SR0_IRQn
,
uart0_interrupt_receive
);
//´®¿Ú0½ÓÊÕÖжϷþÎñ·¾¶×¢²á
return
SCI_SUCCESS
;
}
/******************************************************************************
* Function Name: Uart0_Send
* @brief UART0 Send data
* @param None
* @return None
*******************************************************************************/
void
Uart0_Send
(
uint8_t
ch
)
{
UART_SendByte
(
UART0
,
ch
);
}
/*****************************************************************************
* Function Name: Uart0_Receive
* @brief UART0 receive data
* @param None
* @return rx data
*****************************************************************************/
char
Uart0_Receive
(
void
)
{
return
UART_ReceiveByte
(
UART0
);
}
/*****************************************************************************
* Function Name: Uart0_IntSend
* @brief UART0 Send data by interrupt
* @param None
* @return None
*****************************************************************************/
void
Uart0_IntSend
(
uint8_t
*
tx_buf
,
uint16_t
tx_num
)
{
pData
.
data
=
tx_buf
;
pData
.
len
=
tx_num
;
INTC_SetPendingIRQ
(
ST0_IRQn
);
}
/****************************************************************************
* Function Name: uart0_interrupt_send
* @brief UART0 Send interrupt service routine
* @param None
* @return None
*****************************************************************************/
void
uart0_interrupt_send
(
void
*
msg
)
{
ATE_FRAME_t
*
pFrame
=
(
ATE_FRAME_t
*
)
msg
;
INTC_ClearPendingIRQ
(
ST0_IRQn
);
if
((
pFrame
->
len
>
0U
)
&&
pFrame
->
data
)
{
UART0_TX
=
*
pFrame
->
data
;
pFrame
->
data
++
;
pFrame
->
len
--
;
}
else
//send finished
{
}
}
/*****************************************************************************
* Function Name: uart_callback_error
* @brief
* @param None
* @return None
******************************************************************************/
void
uart_callback_error
(
uint8_t
err_type
)
{
//user edit here when appear error
}
/*****************************************************************************
* Function Name: uart0_interrupt_receive
* @brief UART0 Receive interrupt service routine
* @param None
* @return None
*****************************************************************************/
uint8_t
uart0_interrupt_receive
(
void
)
{
uint8_t
rx_data
;
uint8_t
err_type
;
INTC_ClearPendingIRQ
(
SR0_IRQn
);
err_type
=
UART_GetErrStaus
(
UART0
,
UART_FLAG_FEF
|
UART_FLAG_PEF
|
UART_FLAG_OVF
);
if
(
err_type
)
{
uart_callback_error
(
err_type
);
}
rx_data
=
UART0_RX
;
return
rx_data
;
}
Firmware/Source/Device/Cmsemicon/BAT32A239/RTE/UART/UART_DEMO.h
0 → 100644
View file @
4ce9204a
#ifndef __UART_DEMO_H__
#define __UART_DEMO_H__
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include "uart.h"
#include "gpio.h"
#include "isr.h"
#define UART0_DMA_RCV
#define UART_MAX_RECV_LEN 64
extern
unsigned
char
UART1_RX_BUF
[
UART_MAX_RECV_LEN
];
extern
unsigned
short
UART1_RX_STA
;
int8_t
Uart0_Init
(
uint32_t
bound
);
void
Uart0_Send
(
uint8_t
ch
);
char
Uart0_Receive
(
void
);
void
Uart0_IntSend
(
uint8_t
*
tx_buf
,
uint16_t
tx_num
);
void
uart0_interrupt_send
(
void
*
msg
);
uint8_t
uart0_interrupt_receive
(
void
);
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment