Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
stm32_libraries
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
humanoides
tools
stm32_libraries
Commits
01cd8052
Commit
01cd8052
authored
5 years ago
by
Sergi Hernandez
Browse files
Options
Downloads
Patches
Plain Diff
Changed the UART data structures for the USART ones.
parent
bb00112f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
f1/usart/include/usart2.h
+3
-3
3 additions, 3 deletions
f1/usart/include/usart2.h
f1/usart/src/usart2.c
+81
-80
81 additions, 80 deletions
f1/usart/src/usart2.c
with
84 additions
and
83 deletions
f1/usart/include/usart2.h
+
3
−
3
View file @
01cd8052
...
...
@@ -6,9 +6,9 @@
#include
"comm.h"
/* public functions */
void
usart2_init
(
TComm
*
comm_dev
,
UART_InitTypeDef
*
conf
,
TUART_IRQ_Priorities
*
priorities
);
void
usart2_config
(
TComm
*
comm_dev
,
UART_InitTypeDef
*
conf
);
void
usart2_set_priorities
(
TComm
*
comm_dev
,
TUART_IRQ_Priorities
*
priorities
);
void
usart2_init
(
TComm
*
comm_dev
,
U
S
ART_InitTypeDef
*
conf
,
TU
S
ART_IRQ_Priorities
*
priorities
);
void
usart2_config
(
TComm
*
comm_dev
,
U
S
ART_InitTypeDef
*
conf
);
void
usart2_set_priorities
(
TComm
*
comm_dev
,
TU
S
ART_IRQ_Priorities
*
priorities
);
void
usart2_set_baudrate
(
TComm
*
comm_dev
,
unsigned
int
baudrate
);
/* IRQ functions */
unsigned
char
usart2_send_irq
(
unsigned
char
first_byte
);
...
...
This diff is collapsed.
Click to expand it.
f1/usart/src/usart2.c
+
81
−
80
View file @
01cd8052
#include
"usart2.h"
#define UART UART2
#define UART_ENABLE_CLK __HAL_RCC_UART2_CLK_ENABLE()
#define UART_IRQn UART2_IRQn
#define UART_IRQHandler UART2_IRQHandler
#define U
S
ART U
S
ART2
#define U
S
ART_ENABLE_CLK __HAL_RCC_U
S
ART2_CLK_ENABLE()
#define U
S
ART_IRQn U
S
ART2_IRQn
#define U
S
ART_IRQHandler U
S
ART2_IRQHandler
#define UART_TX_PIN GPIO_PIN_2
#define UART_TX_GPIO_PORT GPIOA
#define UART_ENABLE_TX_GPIO_CLK __HAL_RCC_GPIOA_CLK_ENABLE()
#define U
S
ART_TX_PIN GPIO_PIN_2
#define U
S
ART_TX_GPIO_PORT GPIOA
#define U
S
ART_ENABLE_TX_GPIO_CLK __HAL_RCC_GPIOA_CLK_ENABLE()
#define UART_RX_PIN GPIO_PIN_3
#define UART_RX_GPIO_PORT GPIOA
#define UART_ENABLE_RX_GPIO_CLK __HAL_RCC_GPIOA_CLK_ENABLE()
#define U
S
ART_RX_PIN GPIO_PIN_3
#define U
S
ART_RX_GPIO_PORT GPIOA
#define U
S
ART_ENABLE_RX_GPIO_CLK __HAL_RCC_GPIOA_CLK_ENABLE()
/* DMA configuration */
#define UART_DMA DMA1
#define UART_ENABLE_DMA_CLK __HAL_RCC_DMA1_CLK_ENABLE()
#define U
S
ART_DMA DMA1
#define U
S
ART_ENABLE_DMA_CLK __HAL_RCC_DMA1_CLK_ENABLE()
#define UART_TX_DMA_CHANNEL DMA1_Channel7
#define UART_RX_DMA_CHANNEL DMA1_Channel6
#define U
S
ART_TX_DMA_CHANNEL DMA1_Channel7
#define U
S
ART_RX_DMA_CHANNEL DMA1_Channel6
#define UART_DMA_TX_IRQn DMA1_Channel7_IRQn
#define UART_DMA_RX_IRQn DMA1_Channel6_IRQn
#define UART_DMA_TX_IRQHandler DMA1_Channel7_IRQHandler
#define UART_DMA_RX_IRQHandler DMA1_Channel6_IRQHandler
#define U
S
ART_DMA_TX_IRQn DMA1_Channel7_IRQn
#define U
S
ART_DMA_RX_IRQn DMA1_Channel6_IRQn
#define U
S
ART_DMA_TX_IRQHandler DMA1_Channel7_IRQHandler
#define U
S
ART_DMA_RX_IRQHandler DMA1_Channel6_IRQHandler
// private variables
UART_HandleTypeDef
Uart2Handle
;
U
S
ART_HandleTypeDef
Uart2Handle
;
DMA_HandleTypeDef
usart2_hdma_tx
;
DMA_HandleTypeDef
usart2_hdma_rx
;
TComm
*
usart2_comm_dev
;
// interrupt handlers
void
UART_IRQHandler
(
void
)
void
U
S
ART_IRQHandler
(
void
)
{
unsigned
char
data
,
ret
;
uint32_t
source
;
if
(
__HAL_UART_GET_FLAG
(
&
Uart2Handle
,
UART_FLAG_RXNE
)
!=
RESET
)
if
(
__HAL_U
S
ART_GET_FLAG
(
&
Uart2Handle
,
U
S
ART_FLAG_RXNE
)
!=
RESET
)
{
if
(
__HAL_UART_GET_IT_SOURCE
(
&
Uart2Handle
,
UART_IT_RXNE
)
!=
RESET
)
if
(
__HAL_U
S
ART_GET_IT_SOURCE
(
&
Uart2Handle
,
U
S
ART_IT_RXNE
)
!=
RESET
)
{
__HAL_UART_CLEAR_FLAG
(
&
Uart2Handle
,
UART_FLAG_RXNE
);
__HAL_U
S
ART_CLEAR_FLAG
(
&
Uart2Handle
,
U
S
ART_FLAG_RXNE
);
data
=
(
uint8_t
)(
Uart2Handle
.
Instance
->
DR
&
(
uint8_t
)
0x00FF
);
// call the reception function
if
(
!
comm_do_irq_receive
(
usart2_comm_dev
,
data
))
__HAL_UART_DISABLE_IT
(
&
Uart2Handle
,
UART_IT_RXNE
);
__HAL_U
S
ART_DISABLE_IT
(
&
Uart2Handle
,
U
S
ART_IT_RXNE
);
}
}
if
(
__HAL_UART_GET_FLAG
(
&
Uart2Handle
,
UART_FLAG_TC
)
!=
RESET
)
if
(
__HAL_U
S
ART_GET_FLAG
(
&
Uart2Handle
,
U
S
ART_FLAG_TC
)
!=
RESET
)
{
if
(
__HAL_UART_GET_IT_SOURCE
(
&
Uart2Handle
,
UART_IT_TC
)
!=
RESET
)
if
(
__HAL_U
S
ART_GET_IT_SOURCE
(
&
Uart2Handle
,
U
S
ART_IT_TC
)
!=
RESET
)
{
__HAL_UART_CLEAR_FLAG
(
&
Uart2Handle
,
UART_FLAG_TC
);
__HAL_U
S
ART_CLEAR_FLAG
(
&
Uart2Handle
,
U
S
ART_FLAG_TC
);
ret
=
comm_do_irq_send
(
usart2_comm_dev
,
&
data
);
if
(
ret
==
0x01
)
Uart2Handle
.
Instance
->
DR
=
data
;
else
if
(
ret
==
0x00
)
__HAL_UART_DISABLE_IT
(
&
Uart2Handle
,
UART_IT_TC
);
__HAL_U
S
ART_DISABLE_IT
(
&
Uart2Handle
,
U
S
ART_IT_TC
);
}
}
if
(
__HAL_UART_GET_FLAG
(
&
Uart2Handle
,
UART_FLAG_PE
)
!=
RESET
)
// parity error
if
(
__HAL_U
S
ART_GET_FLAG
(
&
Uart2Handle
,
U
S
ART_FLAG_PE
)
!=
RESET
)
// parity error
{
if
(
__HAL_UART_GET_IT_SOURCE
(
&
Uart2Handle
,
UART_IT_PE
)
!=
RESET
)
if
(
__HAL_U
S
ART_GET_IT_SOURCE
(
&
Uart2Handle
,
U
S
ART_IT_PE
)
!=
RESET
)
{
__HAL_UART_CLEAR_PEFLAG
(
&
Uart2Handle
);
__HAL_U
S
ART_CLEAR_PEFLAG
(
&
Uart2Handle
);
}
}
source
=
__HAL_UART_GET_IT_SOURCE
(
&
Uart2Handle
,
UART_IT_ERR
);
if
(
__HAL_UART_GET_FLAG
(
&
Uart2Handle
,
UART_FLAG_FE
)
!=
RESET
)
// frame error
source
=
__HAL_U
S
ART_GET_IT_SOURCE
(
&
Uart2Handle
,
U
S
ART_IT_ERR
);
if
(
__HAL_U
S
ART_GET_FLAG
(
&
Uart2Handle
,
U
S
ART_FLAG_FE
)
!=
RESET
)
// frame error
{
if
(
source
!=
RESET
)
{
__HAL_UART_CLEAR_FEFLAG
(
&
Uart2Handle
);
__HAL_U
S
ART_CLEAR_FEFLAG
(
&
Uart2Handle
);
}
}
if
(
__HAL_UART_GET_FLAG
(
&
Uart2Handle
,
UART_FLAG_NE
)
!=
RESET
)
// noise error
if
(
__HAL_U
S
ART_GET_FLAG
(
&
Uart2Handle
,
U
S
ART_FLAG_NE
)
!=
RESET
)
// noise error
{
if
(
source
!=
RESET
)
{
__HAL_UART_CLEAR_NEFLAG
(
&
Uart2Handle
);
__HAL_U
S
ART_CLEAR_NEFLAG
(
&
Uart2Handle
);
}
}
if
(
__HAL_UART_GET_FLAG
(
&
Uart2Handle
,
UART_FLAG_ORE
)
!=
RESET
)
// overrun error
if
(
__HAL_U
S
ART_GET_FLAG
(
&
Uart2Handle
,
U
S
ART_FLAG_ORE
)
!=
RESET
)
// overrun error
{
if
(
source
!=
RESET
)
{
__HAL_UART_CLEAR_OREFLAG
(
&
Uart2Handle
);
__HAL_U
S
ART_CLEAR_OREFLAG
(
&
Uart2Handle
);
}
}
}
void
UART_DMA_TX_IRQHandler
(
void
)
void
U
S
ART_DMA_TX_IRQHandler
(
void
)
{
if
(
__HAL_DMA_GET_FLAG
(
Uart2Handle
.
hdmatx
,
__HAL_DMA_GET_TE_FLAG_INDEX
(
Uart2Handle
.
hdmatx
))
!=
RESET
)
{
...
...
@@ -111,7 +111,7 @@ void UART_DMA_TX_IRQHandler(void)
__HAL_DMA_DISABLE_IT
(
Uart2Handle
.
hdmatx
,
DMA_IT_TC
);
/* Clear the transfer complete flag */
__HAL_DMA_CLEAR_FLAG
(
Uart2Handle
.
hdmatx
,
__HAL_DMA_GET_TC_FLAG_INDEX
(
Uart2Handle
.
hdmatx
));
CLEAR_BIT
(
Uart2Handle
.
Instance
->
CR3
,
(
UART_CR3_DMAT
|
UART_CR3_DMAR
));
CLEAR_BIT
(
Uart2Handle
.
Instance
->
CR3
,
(
U
S
ART_CR3_DMAT
|
U
S
ART_CR3_DMAR
));
HAL_DMA_Abort
(
Uart2Handle
.
hdmatx
);
// call the user function
comm_do_dma_send
(
usart2_comm_dev
);
...
...
@@ -129,7 +129,7 @@ void UART_DMA_TX_IRQHandler(void)
}
}
void
UART_DMA_RX_IRQHandler
(
void
)
void
U
S
ART_DMA_RX_IRQHandler
(
void
)
{
if
(
__HAL_DMA_GET_FLAG
(
Uart2Handle
.
hdmarx
,
__HAL_DMA_GET_TE_FLAG_INDEX
(
Uart2Handle
.
hdmarx
))
!=
RESET
)
{
...
...
@@ -149,7 +149,7 @@ void UART_DMA_RX_IRQHandler(void)
__HAL_DMA_DISABLE_IT
(
Uart2Handle
.
hdmarx
,
DMA_IT_TC
);
/* Clear the transfer complete flag */
__HAL_DMA_CLEAR_FLAG
(
Uart2Handle
.
hdmarx
,
__HAL_DMA_GET_TC_FLAG_INDEX
(
Uart2Handle
.
hdmarx
));
CLEAR_BIT
(
Uart2Handle
.
Instance
->
CR3
,
(
UART_CR3_DMAT
|
UART_CR3_DMAR
));
CLEAR_BIT
(
Uart2Handle
.
Instance
->
CR3
,
(
U
S
ART_CR3_DMAT
|
U
S
ART_CR3_DMAR
));
HAL_DMA_Abort
(
Uart2Handle
.
hdmarx
);
// call the user function
comm_do_dma_receive
(
usart2_comm_dev
);
...
...
@@ -168,36 +168,36 @@ void UART_DMA_RX_IRQHandler(void)
}
/* public functions*/
void
usart2_init
(
TComm
*
comm_dev
,
UART_InitTypeDef
*
conf
,
TUART_IRQ_Priorities
*
priorities
)
void
usart2_init
(
TComm
*
comm_dev
,
U
S
ART_InitTypeDef
*
conf
,
TU
S
ART_IRQ_Priorities
*
priorities
)
{
GPIO_InitTypeDef
GPIO_InitStructure
;
/* Enable GPIO clock */
UART_ENABLE_TX_GPIO_CLK
;
UART_ENABLE_RX_GPIO_CLK
;
UART_ENABLE_DMA_CLK
;
U
S
ART_ENABLE_TX_GPIO_CLK
;
U
S
ART_ENABLE_RX_GPIO_CLK
;
U
S
ART_ENABLE_DMA_CLK
;
// configure the GPIO pins
/* Configure UART Tx and Rx as alternate function push-pull */
GPIO_InitStructure
.
Pin
=
UART_TX_PIN
;
/* Configure U
S
ART Tx and Rx as alternate function push-pull */
GPIO_InitStructure
.
Pin
=
U
S
ART_TX_PIN
;
GPIO_InitStructure
.
Mode
=
GPIO_MODE_AF_PP
;
GPIO_InitStructure
.
Pull
=
GPIO_PULLUP
;
GPIO_InitStructure
.
Speed
=
GPIO_SPEED_HIGH
;
HAL_GPIO_Init
(
UART_TX_GPIO_PORT
,
&
GPIO_InitStructure
);
HAL_GPIO_Init
(
U
S
ART_TX_GPIO_PORT
,
&
GPIO_InitStructure
);
GPIO_InitStructure
.
Pin
=
UART_RX_PIN
;
GPIO_InitStructure
.
Pin
=
U
S
ART_RX_PIN
;
GPIO_InitStructure
.
Mode
=
GPIO_MODE_INPUT
;
HAL_GPIO_Init
(
UART_RX_GPIO_PORT
,
&
GPIO_InitStructure
);
HAL_GPIO_Init
(
U
S
ART_RX_GPIO_PORT
,
&
GPIO_InitStructure
);
UART_ENABLE_CLK
;
U
S
ART_ENABLE_CLK
;
Uart2Handle
.
Instance
=
UART
;
Uart2Handle
.
Instance
=
U
S
ART
;
usart2_config
(
comm_dev
,
conf
);
if
(
comm_dev
->
use_dma
)
{
// configure the DMA channels
usart2_hdma_tx
.
Instance
=
UART_TX_DMA_CHANNEL
;
usart2_hdma_tx
.
Instance
=
U
S
ART_TX_DMA_CHANNEL
;
usart2_hdma_tx
.
Init
.
Direction
=
DMA_MEMORY_TO_PERIPH
;
usart2_hdma_tx
.
Init
.
PeriphInc
=
DMA_PINC_DISABLE
;
usart2_hdma_tx
.
Init
.
MemInc
=
DMA_MINC_ENABLE
;
...
...
@@ -208,11 +208,11 @@ void usart2_init(TComm *comm_dev,UART_InitTypeDef *conf,TUART_IRQ_Priorities *pr
HAL_DMA_Init
(
&
usart2_hdma_tx
);
/* Associate the initialized DMA handle to the UART handle */
/* Associate the initialized DMA handle to the U
S
ART handle */
__HAL_LINKDMA
(
&
Uart2Handle
,
hdmatx
,
usart2_hdma_tx
);
/* Configure the DMA handler for reception process */
usart2_hdma_rx
.
Instance
=
UART_RX_DMA_CHANNEL
;
usart2_hdma_rx
.
Instance
=
U
S
ART_RX_DMA_CHANNEL
;
usart2_hdma_rx
.
Init
.
Direction
=
DMA_PERIPH_TO_MEMORY
;
usart2_hdma_rx
.
Init
.
PeriphInc
=
DMA_PINC_DISABLE
;
usart2_hdma_rx
.
Init
.
MemInc
=
DMA_MINC_ENABLE
;
...
...
@@ -223,7 +223,7 @@ void usart2_init(TComm *comm_dev,UART_InitTypeDef *conf,TUART_IRQ_Priorities *pr
HAL_DMA_Init
(
&
usart2_hdma_rx
);
/* Associate the initialized DMA handle to the the UART handle */
/* Associate the initialized DMA handle to the the U
S
ART handle */
__HAL_LINKDMA
(
&
Uart2Handle
,
hdmarx
,
usart2_hdma_rx
);
}
usart2_set_priorities
(
comm_dev
,
priorities
);
...
...
@@ -248,42 +248,43 @@ void usart2_init(TComm *comm_dev,UART_InitTypeDef *conf,TUART_IRQ_Priorities *pr
usart2_comm_dev
=
comm_dev
;
}
void
usart2_config
(
TComm
*
comm_dev
,
UART_InitTypeDef
*
conf
)
void
usart2_config
(
TComm
*
comm_dev
,
U
S
ART_InitTypeDef
*
conf
)
{
Uart2Handle
.
Init
.
BaudRate
=
conf
->
BaudRate
;
Uart2Handle
.
Init
.
WordLength
=
conf
->
WordLength
;
Uart2Handle
.
Init
.
StopBits
=
conf
->
StopBits
;
Uart2Handle
.
Init
.
Parity
=
conf
->
Parity
;
Uart2Handle
.
Init
.
Mode
=
conf
->
Mode
;
Uart2Handle
.
Init
.
HwFlowCtl
=
conf
->
HwFlowCtl
;
Uart2Handle
.
Init
.
OverSampling
=
conf
->
OverSampling
;
HAL_UART_Init
(
&
Uart2Handle
);
Uart2Handle
.
Init
.
CLKPolarity
=
conf
->
CLKPolarity
;
Uart2Handle
.
Init
.
CLKPhase
=
conf
->
CLKPhase
;
Uart2Handle
.
Init
.
CLKLastBit
=
conf
->
CLKLastBit
;
HAL_USART_Init
(
&
Uart2Handle
);
}
void
usart2_set_priorities
(
TComm
*
comm_dev
,
TUART_IRQ_Priorities
*
priorities
)
void
usart2_set_priorities
(
TComm
*
comm_dev
,
TU
S
ART_IRQ_Priorities
*
priorities
)
{
HAL_NVIC_SetPriority
(
UART_IRQn
,
priorities
->
irq_priority
,
priorities
->
irq_subpriority
);
HAL_NVIC_EnableIRQ
(
UART_IRQn
);
HAL_NVIC_SetPriority
(
U
S
ART_IRQn
,
priorities
->
irq_priority
,
priorities
->
irq_subpriority
);
HAL_NVIC_EnableIRQ
(
U
S
ART_IRQn
);
if
(
comm_dev
->
use_dma
)
{
HAL_NVIC_SetPriority
(
UART_DMA_TX_IRQn
,
priorities
->
dma_tx_priority
,
priorities
->
dma_tx_subpriority
);
HAL_NVIC_EnableIRQ
(
UART_DMA_TX_IRQn
);
HAL_NVIC_SetPriority
(
UART_DMA_RX_IRQn
,
priorities
->
dma_rx_priority
,
priorities
->
dma_rx_subpriority
);
HAL_NVIC_EnableIRQ
(
UART_DMA_RX_IRQn
);
HAL_NVIC_SetPriority
(
U
S
ART_DMA_TX_IRQn
,
priorities
->
dma_tx_priority
,
priorities
->
dma_tx_subpriority
);
HAL_NVIC_EnableIRQ
(
U
S
ART_DMA_TX_IRQn
);
HAL_NVIC_SetPriority
(
U
S
ART_DMA_RX_IRQn
,
priorities
->
dma_rx_priority
,
priorities
->
dma_rx_subpriority
);
HAL_NVIC_EnableIRQ
(
U
S
ART_DMA_RX_IRQn
);
}
}
void
usart2_set_baudrate
(
TComm
*
comm_dev
,
unsigned
int
baudrate
)
{
Uart2Handle
.
Init
.
BaudRate
=
baudrate
;
HAL_UART_Init
(
&
Uart2Handle
);
HAL_U
S
ART_Init
(
&
Uart2Handle
);
}
/* IRQ functions */
unsigned
char
usart2_send_irq
(
unsigned
char
first_byte
)
{
__HAL_UART_CLEAR_FLAG
(
&
Uart2Handle
,
UART_FLAG_TC
);
__HAL_UART_ENABLE_IT
(
&
Uart2Handle
,
UART_IT_TC
);
__HAL_U
S
ART_CLEAR_FLAG
(
&
Uart2Handle
,
U
S
ART_FLAG_TC
);
__HAL_U
S
ART_ENABLE_IT
(
&
Uart2Handle
,
U
S
ART_IT_TC
);
Uart2Handle
.
Instance
->
DR
=
first_byte
;
return
0x00
;
...
...
@@ -291,8 +292,8 @@ unsigned char usart2_send_irq(unsigned char first_byte)
unsigned
char
usart2_enable_tx_irq
(
void
)
{
__HAL_UART_CLEAR_FLAG
(
&
Uart2Handle
,
UART_FLAG_TC
);
__HAL_UART_ENABLE_IT
(
&
Uart2Handle
,
UART_IT_TC
);
__HAL_U
S
ART_CLEAR_FLAG
(
&
Uart2Handle
,
U
S
ART_FLAG_TC
);
__HAL_U
S
ART_ENABLE_IT
(
&
Uart2Handle
,
U
S
ART_IT_TC
);
return
0x00
;
}
...
...
@@ -300,7 +301,7 @@ unsigned char usart2_enable_tx_irq(void)
unsigned
char
usart2_receive_irq
(
void
)
{
/* enable the rx interrupt */
__HAL_UART_ENABLE_IT
(
&
Uart2Handle
,
UART_IT_RXNE
);
__HAL_U
S
ART_ENABLE_IT
(
&
Uart2Handle
,
U
S
ART_IT_RXNE
);
return
0x00
;
}
...
...
@@ -308,7 +309,7 @@ unsigned char usart2_receive_irq(void)
unsigned
char
usart2_cancel_receive_irq
(
void
)
{
/* disable the rx interrupt */
__HAL_UART_DISABLE_IT
(
&
Uart2Handle
,
UART_IT_RXNE
);
__HAL_U
S
ART_DISABLE_IT
(
&
Uart2Handle
,
U
S
ART_IT_RXNE
);
return
0x00
;
}
...
...
@@ -318,10 +319,10 @@ unsigned char usart2_send_dma(unsigned char *data,unsigned short int length)
{
HAL_DMA_Start_IT
(
Uart2Handle
.
hdmatx
,(
uint32_t
)
data
,(
uint32_t
)
&
Uart2Handle
.
Instance
->
DR
,
length
);
/* Clear the TC flag in the SR register by writing 0 to it */
__HAL_UART_CLEAR_FLAG
(
&
Uart2Handle
,
UART_FLAG_TC
);
__HAL_U
S
ART_CLEAR_FLAG
(
&
Uart2Handle
,
U
S
ART_FLAG_TC
);
/* Enable the DMA transfer for transmit request by setting the DMAT bit
in the UART CR3 register */
SET_BIT
(
Uart2Handle
.
Instance
->
CR3
,
UART_CR3_DMAT
);
in the U
S
ART CR3 register */
SET_BIT
(
Uart2Handle
.
Instance
->
CR3
,
U
S
ART_CR3_DMAT
);
return
0x00
;
}
...
...
@@ -329,14 +330,14 @@ unsigned char usart2_send_dma(unsigned char *data,unsigned short int length)
unsigned
char
usart2_receive_dma
(
unsigned
char
*
data
,
unsigned
short
int
length
)
{
HAL_DMA_Start_IT
(
Uart2Handle
.
hdmarx
,(
uint32_t
)
&
Uart2Handle
.
Instance
->
DR
,(
uint32_t
)
data
,
length
);
SET_BIT
(
Uart2Handle
.
Instance
->
CR3
,
UART_CR3_DMAR
);
SET_BIT
(
Uart2Handle
.
Instance
->
CR3
,
U
S
ART_CR3_DMAR
);
return
0x00
;
}
unsigned
char
usart2_cancel_receive_dma
(
void
)
{
CLEAR_BIT
(
Uart2Handle
.
Instance
->
CR3
,
(
UART_CR3_DMAT
|
UART_CR3_DMAR
));
CLEAR_BIT
(
Uart2Handle
.
Instance
->
CR3
,
(
U
S
ART_CR3_DMAT
|
U
S
ART_CR3_DMAR
));
HAL_DMA_Abort
(
Uart2Handle
.
hdmarx
);
return
0x00
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment