Skip to content
Snippets Groups Projects
Commit 5912a0a0 authored by Sergi Hernandez's avatar Sergi Hernandez
Browse files

Used the USART functions and data types instead of the UART.

parent 7c4cf729
No related branches found
No related tags found
No related merge requests found
......@@ -6,8 +6,8 @@
#include "comm.h"
/* public functions */
void usart1_init(TComm *comm_dev,UART_InitTypeDef *conf,TUSART_IRQ_Priorities *priorities);
void usart1_config(TComm *comm_dev,UART_InitTypeDef *conf);
void usart1_init(TComm *comm_dev,USART_InitTypeDef *conf,TUSART_IRQ_Priorities *priorities);
void usart1_config(TComm *comm_dev,USART_InitTypeDef *conf);
void usart1_set_priorities(TComm *comm_dev,TUSART_IRQ_Priorities *priorities);
void usart1_set_baudrate(TComm *comm_dev,unsigned int baudrate);
/* IRQ functions */
......
......@@ -26,7 +26,7 @@
#define USART_DMA_RX_IRQHandler DMA1_Channel5_IRQHandler
// private variables
UART_HandleTypeDef Uart1Handle;
USART_HandleTypeDef Uart1Handle;
DMA_HandleTypeDef usart1_hdma_tx;
DMA_HandleTypeDef usart1_hdma_rx;
TComm *usart1_comm_dev;
......@@ -37,56 +37,56 @@ void USART_IRQHandler(void)
unsigned char data,ret;
uint32_t source;
if(__HAL_UART_GET_FLAG(&Uart1Handle, UART_FLAG_RXNE) != RESET)
if(__HAL_USART_GET_FLAG(&Uart1Handle, USART_FLAG_RXNE) != RESET)
{
if(__HAL_UART_GET_IT_SOURCE(&Uart1Handle, UART_IT_RXNE) !=RESET)
if(__HAL_USART_GET_IT_SOURCE(&Uart1Handle, USART_IT_RXNE) !=RESET)
{
__HAL_UART_CLEAR_FLAG(&Uart1Handle,UART_FLAG_RXNE);
__HAL_USART_CLEAR_FLAG(&Uart1Handle,USART_FLAG_RXNE);
data=(uint8_t)(Uart1Handle.Instance->DR & (uint8_t)0x00FF);
// call the reception function
if(!comm_do_irq_receive(usart1_comm_dev,data))
__HAL_UART_DISABLE_IT(&Uart1Handle, UART_IT_RXNE);
__HAL_USART_DISABLE_IT(&Uart1Handle, USART_IT_RXNE);
}
}
if(__HAL_UART_GET_FLAG(&Uart1Handle, UART_FLAG_TC) != RESET)
if(__HAL_USART_GET_FLAG(&Uart1Handle, USART_FLAG_TC) != RESET)
{
if(__HAL_UART_GET_IT_SOURCE(&Uart1Handle, UART_IT_TC) !=RESET)
if(__HAL_USART_GET_IT_SOURCE(&Uart1Handle, USART_IT_TC) !=RESET)
{
__HAL_UART_CLEAR_FLAG(&Uart1Handle,UART_FLAG_TC);
__HAL_USART_CLEAR_FLAG(&Uart1Handle,USART_FLAG_TC);
ret=comm_do_irq_send(usart1_comm_dev,&data);
if(ret==0x01)
Uart1Handle.Instance->DR=data;
else if(ret==0x00)
__HAL_UART_DISABLE_IT(&Uart1Handle, UART_IT_TC);
__HAL_USART_DISABLE_IT(&Uart1Handle, USART_IT_TC);
}
}
if(__HAL_UART_GET_FLAG(&Uart1Handle, UART_FLAG_PE) != RESET)// parity error
if(__HAL_USART_GET_FLAG(&Uart1Handle, USART_FLAG_PE) != RESET)// parity error
{
if(__HAL_UART_GET_IT_SOURCE(&Uart1Handle, UART_IT_PE) !=RESET)
if(__HAL_USART_GET_IT_SOURCE(&Uart1Handle, USART_IT_PE) !=RESET)
{
__HAL_UART_CLEAR_PEFLAG(&Uart1Handle);
__HAL_USART_CLEAR_PEFLAG(&Uart1Handle);
}
}
source=__HAL_UART_GET_IT_SOURCE(&Uart1Handle, UART_IT_ERR);
if(__HAL_UART_GET_FLAG(&Uart1Handle, UART_FLAG_FE) != RESET)// frame error
source=__HAL_USART_GET_IT_SOURCE(&Uart1Handle, USART_IT_ERR);
if(__HAL_USART_GET_FLAG(&Uart1Handle, USART_FLAG_FE) != RESET)// frame error
{
if(source !=RESET)
{
__HAL_UART_CLEAR_FEFLAG(&Uart1Handle);
__HAL_USART_CLEAR_FEFLAG(&Uart1Handle);
}
}
if(__HAL_UART_GET_FLAG(&Uart1Handle, UART_FLAG_NE) != RESET)// noise error
if(__HAL_USART_GET_FLAG(&Uart1Handle, USART_FLAG_NE) != RESET)// noise error
{
if(source !=RESET)
{
__HAL_UART_CLEAR_NEFLAG(&Uart1Handle);
__HAL_USART_CLEAR_NEFLAG(&Uart1Handle);
}
}
if(__HAL_UART_GET_FLAG(&Uart1Handle, UART_FLAG_ORE) != RESET)// overrun error
if(__HAL_USART_GET_FLAG(&Uart1Handle, USART_FLAG_ORE) != RESET)// overrun error
{
if(source !=RESET)
{
__HAL_UART_CLEAR_OREFLAG(&Uart1Handle);
__HAL_USART_CLEAR_OREFLAG(&Uart1Handle);
}
}
}
......@@ -168,7 +168,7 @@ void USART_DMA_RX_IRQHandler(void)
}
/* public functions*/
void usart1_init(TComm *comm_dev,UART_InitTypeDef *conf,TUSART_IRQ_Priorities *priorities)
void usart1_init(TComm *comm_dev,USART_InitTypeDef *conf,TUSART_IRQ_Priorities *priorities)
{
GPIO_InitTypeDef GPIO_InitStructure;
......@@ -208,7 +208,7 @@ void usart1_init(TComm *comm_dev,UART_InitTypeDef *conf,TUSART_IRQ_Priorities *p
HAL_DMA_Init(&usart1_hdma_tx);
/* Associate the initialized DMA handle to the UART handle */
/* Associate the initialized DMA handle to the USART handle */
__HAL_LINKDMA(&Uart1Handle, hdmatx, usart1_hdma_tx);
/* Configure the DMA handler for reception process */
......@@ -223,7 +223,7 @@ void usart1_init(TComm *comm_dev,UART_InitTypeDef *conf,TUSART_IRQ_Priorities *p
HAL_DMA_Init(&usart1_hdma_rx);
/* Associate the initialized DMA handle to the the UART handle */
/* Associate the initialized DMA handle to the the USART handle */
__HAL_LINKDMA(&Uart1Handle, hdmarx, usart1_hdma_rx);
}
usart1_set_priorities(comm_dev,priorities);
......@@ -248,16 +248,17 @@ void usart1_init(TComm *comm_dev,UART_InitTypeDef *conf,TUSART_IRQ_Priorities *p
usart1_comm_dev=comm_dev;
}
void usart1_config(TComm *comm_dev,UART_InitTypeDef *conf)
void usart1_config(TComm *comm_dev,USART_InitTypeDef *conf)
{
Uart1Handle.Init.BaudRate = conf->BaudRate;
Uart1Handle.Init.WordLength = conf->WordLength;
Uart1Handle.Init.StopBits = conf->StopBits;
Uart1Handle.Init.Parity = conf->Parity;
Uart1Handle.Init.Mode = conf->Mode;
Uart1Handle.Init.HwFlowCtl = conf->HwFlowCtl;
Uart1Handle.Init.OverSampling = conf->OverSampling;
HAL_UART_Init(&Uart1Handle);
Uart1Handle.Init.CLKPolarity = conf->CLKPolarity;
Uart1Handle.Init.CLKPhase = conf->CLKPhase;
Uart1Handle.Init.CLKLastBit = conf->CLKLastBit;
HAL_USART_Init(&Uart1Handle);
}
void usart1_set_priorities(TComm *comm_dev,TUSART_IRQ_Priorities *priorities)
......@@ -276,14 +277,14 @@ void usart1_set_priorities(TComm *comm_dev,TUSART_IRQ_Priorities *priorities)
void usart1_set_baudrate(TComm *comm_dev,unsigned int baudrate)
{
Uart1Handle.Init.BaudRate = baudrate;
HAL_UART_Init(&Uart1Handle);
HAL_USART_Init(&Uart1Handle);
}
/* IRQ functions */
unsigned char usart1_send_irq(unsigned char first_byte)
{
__HAL_UART_CLEAR_FLAG(&Uart1Handle,UART_FLAG_TC);
__HAL_UART_ENABLE_IT(&Uart1Handle, UART_IT_TC);
__HAL_USART_CLEAR_FLAG(&Uart1Handle,USART_FLAG_TC);
__HAL_USART_ENABLE_IT(&Uart1Handle, USART_IT_TC);
Uart1Handle.Instance->DR=first_byte;
return 0x00;
......@@ -291,8 +292,8 @@ unsigned char usart1_send_irq(unsigned char first_byte)
unsigned char usart1_enable_tx_irq(void)
{
__HAL_UART_CLEAR_FLAG(&Uart1Handle,UART_FLAG_TC);
__HAL_UART_ENABLE_IT(&Uart1Handle, UART_IT_TC);
__HAL_USART_CLEAR_FLAG(&Uart1Handle,USART_FLAG_TC);
__HAL_USART_ENABLE_IT(&Uart1Handle, USART_IT_TC);
return 0x00;
}
......@@ -300,7 +301,7 @@ unsigned char usart1_enable_tx_irq(void)
unsigned char usart1_receive_irq(void)
{
/* enable the rx interrupt */
__HAL_UART_ENABLE_IT(&Uart1Handle, UART_IT_RXNE);
__HAL_USART_ENABLE_IT(&Uart1Handle, USART_IT_RXNE);
return 0x00;
}
......@@ -308,7 +309,7 @@ unsigned char usart1_receive_irq(void)
unsigned char usart1_cancel_receive_irq(void)
{
/* disable the rx interrupt */
__HAL_UART_DISABLE_IT(&Uart1Handle, UART_IT_RXNE);
__HAL_USART_DISABLE_IT(&Uart1Handle, USART_IT_RXNE);
return 0x00;
}
......@@ -318,9 +319,9 @@ unsigned char usart1_send_dma(unsigned char *data,unsigned short int length)
{
HAL_DMA_Start_IT(Uart1Handle.hdmatx,(uint32_t)data,(uint32_t)&Uart1Handle.Instance->DR,length);
/* Clear the TC flag in the SR register by writing 0 to it */
__HAL_UART_CLEAR_FLAG(&Uart1Handle,UART_FLAG_TC);
__HAL_USART_CLEAR_FLAG(&Uart1Handle,USART_FLAG_TC);
/* Enable the DMA transfer for transmit request by setting the DMAT bit
in the UART CR3 register */
in the USART CR3 register */
SET_BIT(Uart1Handle.Instance->CR3, USART_CR3_DMAT);
return 0x00;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment