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
1956ca8d
Commit
1956ca8d
authored
5 years ago
by
Sergi Hernandez
Browse files
Options
Downloads
Patches
Plain Diff
UART substituted by USART.
parent
e6977afb
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/usart3.h
+2
-2
2 additions, 2 deletions
f1/usart/include/usart3.h
f1/usart/src/usart3.c
+37
-36
37 additions, 36 deletions
f1/usart/src/usart3.c
with
39 additions
and
38 deletions
f1/usart/include/usart3.h
+
2
−
2
View file @
1956ca8d
...
...
@@ -6,8 +6,8 @@
#include
"comm.h"
/* public functions */
void
usart3_init
(
TComm
*
comm_dev
,
UART_InitTypeDef
*
conf
,
TUSART_IRQ_Priorities
*
priorities
);
void
usart3_config
(
TComm
*
comm_dev
,
UART_InitTypeDef
*
conf
);
void
usart3_init
(
TComm
*
comm_dev
,
U
S
ART_InitTypeDef
*
conf
,
TUSART_IRQ_Priorities
*
priorities
);
void
usart3_config
(
TComm
*
comm_dev
,
U
S
ART_InitTypeDef
*
conf
);
void
usart3_set_priorities
(
TComm
*
comm_dev
,
TUSART_IRQ_Priorities
*
priorities
);
void
usart3_set_baudrate
(
TComm
*
comm_dev
,
unsigned
int
baudrate
);
/* IRQ functions */
...
...
This diff is collapsed.
Click to expand it.
f1/usart/src/usart3.c
+
37
−
36
View file @
1956ca8d
...
...
@@ -26,7 +26,7 @@
#define USART_DMA_RX_IRQHandler DMA1_Channel3_IRQHandler
// private variables
UART_HandleTypeDef
Uart3Handle
;
U
S
ART_HandleTypeDef
Uart3Handle
;
DMA_HandleTypeDef
usart3_hdma_tx
;
DMA_HandleTypeDef
usart3_hdma_rx
;
TComm
*
usart3_comm_dev
;
...
...
@@ -37,56 +37,56 @@ void USART_IRQHandler(void)
unsigned
char
data
,
ret
;
uint32_t
source
;
if
(
__HAL_UART_GET_FLAG
(
&
Uart3Handle
,
UART_FLAG_RXNE
)
!=
RESET
)
if
(
__HAL_U
S
ART_GET_FLAG
(
&
Uart3Handle
,
U
S
ART_FLAG_RXNE
)
!=
RESET
)
{
if
(
__HAL_UART_GET_IT_SOURCE
(
&
Uart3Handle
,
UART_IT_RXNE
)
!=
RESET
)
if
(
__HAL_U
S
ART_GET_IT_SOURCE
(
&
Uart3Handle
,
U
S
ART_IT_RXNE
)
!=
RESET
)
{
__HAL_UART_CLEAR_FLAG
(
&
Uart3Handle
,
UART_FLAG_RXNE
);
__HAL_U
S
ART_CLEAR_FLAG
(
&
Uart3Handle
,
U
S
ART_FLAG_RXNE
);
data
=
(
uint8_t
)(
Uart3Handle
.
Instance
->
DR
&
(
uint8_t
)
0x00FF
);
// call the reception function
if
(
!
comm_do_irq_receive
(
usart3_comm_dev
,
data
))
__HAL_UART_DISABLE_IT
(
&
Uart3Handle
,
UART_IT_RXNE
);
__HAL_U
S
ART_DISABLE_IT
(
&
Uart3Handle
,
U
S
ART_IT_RXNE
);
}
}
if
(
__HAL_UART_GET_FLAG
(
&
Uart3Handle
,
UART_FLAG_TC
)
!=
RESET
)
if
(
__HAL_U
S
ART_GET_FLAG
(
&
Uart3Handle
,
U
S
ART_FLAG_TC
)
!=
RESET
)
{
if
(
__HAL_UART_GET_IT_SOURCE
(
&
Uart3Handle
,
UART_IT_TC
)
!=
RESET
)
if
(
__HAL_U
S
ART_GET_IT_SOURCE
(
&
Uart3Handle
,
U
S
ART_IT_TC
)
!=
RESET
)
{
__HAL_UART_CLEAR_FLAG
(
&
Uart3Handle
,
UART_FLAG_TC
);
__HAL_U
S
ART_CLEAR_FLAG
(
&
Uart3Handle
,
U
S
ART_FLAG_TC
);
ret
=
comm_do_irq_send
(
usart3_comm_dev
,
&
data
);
if
(
ret
==
0x01
)
Uart3Handle
.
Instance
->
DR
=
data
;
else
if
(
ret
==
0x00
)
__HAL_UART_DISABLE_IT
(
&
Uart3Handle
,
UART_IT_TC
);
__HAL_U
S
ART_DISABLE_IT
(
&
Uart3Handle
,
U
S
ART_IT_TC
);
}
}
if
(
__HAL_UART_GET_FLAG
(
&
Uart3Handle
,
UART_FLAG_PE
)
!=
RESET
)
// parity error
if
(
__HAL_U
S
ART_GET_FLAG
(
&
Uart3Handle
,
U
S
ART_FLAG_PE
)
!=
RESET
)
// parity error
{
if
(
__HAL_UART_GET_IT_SOURCE
(
&
Uart3Handle
,
UART_IT_PE
)
!=
RESET
)
if
(
__HAL_U
S
ART_GET_IT_SOURCE
(
&
Uart3Handle
,
U
S
ART_IT_PE
)
!=
RESET
)
{
__HAL_UART_CLEAR_PEFLAG
(
&
Uart3Handle
);
__HAL_U
S
ART_CLEAR_PEFLAG
(
&
Uart3Handle
);
}
}
source
=
__HAL_UART_GET_IT_SOURCE
(
&
Uart3Handle
,
UART_IT_ERR
);
if
(
__HAL_UART_GET_FLAG
(
&
Uart3Handle
,
UART_FLAG_FE
)
!=
RESET
)
// frame error
source
=
__HAL_U
S
ART_GET_IT_SOURCE
(
&
Uart3Handle
,
U
S
ART_IT_ERR
);
if
(
__HAL_U
S
ART_GET_FLAG
(
&
Uart3Handle
,
U
S
ART_FLAG_FE
)
!=
RESET
)
// frame error
{
if
(
source
!=
RESET
)
{
__HAL_UART_CLEAR_FEFLAG
(
&
Uart3Handle
);
__HAL_U
S
ART_CLEAR_FEFLAG
(
&
Uart3Handle
);
}
}
if
(
__HAL_UART_GET_FLAG
(
&
Uart3Handle
,
UART_FLAG_NE
)
!=
RESET
)
// noise error
if
(
__HAL_U
S
ART_GET_FLAG
(
&
Uart3Handle
,
U
S
ART_FLAG_NE
)
!=
RESET
)
// noise error
{
if
(
source
!=
RESET
)
{
__HAL_UART_CLEAR_NEFLAG
(
&
Uart3Handle
);
__HAL_U
S
ART_CLEAR_NEFLAG
(
&
Uart3Handle
);
}
}
if
(
__HAL_UART_GET_FLAG
(
&
Uart3Handle
,
UART_FLAG_ORE
)
!=
RESET
)
// overrun error
if
(
__HAL_U
S
ART_GET_FLAG
(
&
Uart3Handle
,
U
S
ART_FLAG_ORE
)
!=
RESET
)
// overrun error
{
if
(
source
!=
RESET
)
{
__HAL_UART_CLEAR_OREFLAG
(
&
Uart3Handle
);
__HAL_U
S
ART_CLEAR_OREFLAG
(
&
Uart3Handle
);
}
}
}
...
...
@@ -168,7 +168,7 @@ void USART_DMA_RX_IRQHandler(void)
}
/* public functions*/
void
usart3_init
(
TComm
*
comm_dev
,
UART_InitTypeDef
*
conf
,
TUSART_IRQ_Priorities
*
priorities
)
void
usart3_init
(
TComm
*
comm_dev
,
U
S
ART_InitTypeDef
*
conf
,
TUSART_IRQ_Priorities
*
priorities
)
{
GPIO_InitTypeDef
GPIO_InitStructure
;
...
...
@@ -191,7 +191,7 @@ void usart3_init(TComm *comm_dev,UART_InitTypeDef *conf,TUSART_IRQ_Priorities *p
USART_ENABLE_CLK
;
Uart3Handle
.
Instance
=
USART
;
Uart3Handle
.
Instance
=
USART
3
;
usart3_config
(
comm_dev
,
conf
);
if
(
comm_dev
->
use_dma
)
...
...
@@ -208,7 +208,7 @@ void usart3_init(TComm *comm_dev,UART_InitTypeDef *conf,TUSART_IRQ_Priorities *p
HAL_DMA_Init
(
&
usart3_hdma_tx
);
/* Associate the initialized DMA handle to the UART handle */
/* Associate the initialized DMA handle to the U
S
ART handle */
__HAL_LINKDMA
(
&
Uart3Handle
,
hdmatx
,
usart3_hdma_tx
);
/* Configure the DMA handler for reception process */
...
...
@@ -223,7 +223,7 @@ void usart3_init(TComm *comm_dev,UART_InitTypeDef *conf,TUSART_IRQ_Priorities *p
HAL_DMA_Init
(
&
usart3_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
(
&
Uart3Handle
,
hdmarx
,
usart3_hdma_rx
);
}
usart3_set_priorities
(
comm_dev
,
priorities
);
...
...
@@ -248,16 +248,17 @@ void usart3_init(TComm *comm_dev,UART_InitTypeDef *conf,TUSART_IRQ_Priorities *p
usart3_comm_dev
=
comm_dev
;
}
void
usart3_config
(
TComm
*
comm_dev
,
UART_InitTypeDef
*
conf
)
void
usart3_config
(
TComm
*
comm_dev
,
U
S
ART_InitTypeDef
*
conf
)
{
Uart3Handle
.
Init
.
BaudRate
=
conf
->
BaudRate
;
Uart3Handle
.
Init
.
WordLength
=
conf
->
WordLength
;
Uart3Handle
.
Init
.
StopBits
=
conf
->
StopBits
;
Uart3Handle
.
Init
.
Parity
=
conf
->
Parity
;
Uart3Handle
.
Init
.
Mode
=
conf
->
Mode
;
Uart3Handle
.
Init
.
HwFlowCtl
=
conf
->
HwFlowCtl
;
Uart3Handle
.
Init
.
OverSampling
=
conf
->
OverSampling
;
HAL_UART_Init
(
&
Uart3Handle
);
Uart3Handle
.
Init
.
CLKPolarity
=
conf
->
CLKPolarity
;
Uart3Handle
.
Init
.
CLKPhase
=
conf
->
CLKPhase
;
Uart3Handle
.
Init
.
CLKLastBit
=
conf
->
CLKLastBit
;
HAL_USART_Init
(
&
Uart3Handle
);
}
void
usart3_set_priorities
(
TComm
*
comm_dev
,
TUSART_IRQ_Priorities
*
priorities
)
...
...
@@ -276,14 +277,14 @@ void usart3_set_priorities(TComm *comm_dev,TUSART_IRQ_Priorities *priorities)
void
usart3_set_baudrate
(
TComm
*
comm_dev
,
unsigned
int
baudrate
)
{
Uart3Handle
.
Init
.
BaudRate
=
baudrate
;
HAL_UART_Init
(
&
Uart3Handle
);
HAL_U
S
ART_Init
(
&
Uart3Handle
);
}
/* IRQ functions */
unsigned
char
usart3_send_irq
(
unsigned
char
first_byte
)
{
__HAL_UART_CLEAR_FLAG
(
&
Uart3Handle
,
UART_FLAG_TC
);
__HAL_UART_ENABLE_IT
(
&
Uart3Handle
,
UART_IT_TC
);
__HAL_U
S
ART_CLEAR_FLAG
(
&
Uart3Handle
,
U
S
ART_FLAG_TC
);
__HAL_U
S
ART_ENABLE_IT
(
&
Uart3Handle
,
U
S
ART_IT_TC
);
Uart3Handle
.
Instance
->
DR
=
first_byte
;
return
0x00
;
...
...
@@ -291,8 +292,8 @@ unsigned char usart3_send_irq(unsigned char first_byte)
unsigned
char
usart3_enable_tx_irq
(
void
)
{
__HAL_UART_CLEAR_FLAG
(
&
Uart3Handle
,
UART_FLAG_TC
);
__HAL_UART_ENABLE_IT
(
&
Uart3Handle
,
UART_IT_TC
);
__HAL_U
S
ART_CLEAR_FLAG
(
&
Uart3Handle
,
U
S
ART_FLAG_TC
);
__HAL_U
S
ART_ENABLE_IT
(
&
Uart3Handle
,
U
S
ART_IT_TC
);
return
0x00
;
}
...
...
@@ -300,7 +301,7 @@ unsigned char usart3_enable_tx_irq(void)
unsigned
char
usart3_receive_irq
(
void
)
{
/* enable the rx interrupt */
__HAL_UART_ENABLE_IT
(
&
Uart3Handle
,
UART_IT_RXNE
);
__HAL_U
S
ART_ENABLE_IT
(
&
Uart3Handle
,
U
S
ART_IT_RXNE
);
return
0x00
;
}
...
...
@@ -308,7 +309,7 @@ unsigned char usart3_receive_irq(void)
unsigned
char
usart3_cancel_receive_irq
(
void
)
{
/* disable the rx interrupt */
__HAL_UART_DISABLE_IT
(
&
Uart3Handle
,
UART_IT_RXNE
);
__HAL_U
S
ART_DISABLE_IT
(
&
Uart3Handle
,
U
S
ART_IT_RXNE
);
return
0x00
;
}
...
...
@@ -318,9 +319,9 @@ unsigned char usart3_send_dma(unsigned char *data,unsigned short int length)
{
HAL_DMA_Start_IT
(
Uart3Handle
.
hdmatx
,(
uint32_t
)
data
,(
uint32_t
)
&
Uart3Handle
.
Instance
->
DR
,
length
);
/* Clear the TC flag in the SR register by writing 0 to it */
__HAL_UART_CLEAR_FLAG
(
&
Uart3Handle
,
UART_FLAG_TC
);
__HAL_U
S
ART_CLEAR_FLAG
(
&
Uart3Handle
,
U
S
ART_FLAG_TC
);
/* Enable the DMA transfer for transmit request by setting the DMAT bit
in the UART CR3 register */
in the U
S
ART CR3 register */
SET_BIT
(
Uart3Handle
.
Instance
->
CR3
,
USART_CR3_DMAT
);
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