PER Firmware
Loading...
Searching...
No Matches
usart.h File Reference
#include "common/phal_F4_F7/dma/dma.h"
#include "common/phal_F4_F7/phal_F4_F7.h"

Go to the source code of this file.

Classes

struct  usart_rx_errors_t
 
struct  usart_tx_errors_t
 
struct  usart_init_t
 

Macros

#define USART1_RXDMA_CONT_CONFIG(rx_addr_, priority_)
 
#define USART1_TXDMA_CONT_CONFIG(tx_addr_, priority_)
 
#define USART4_RXDMA_CONT_CONFIG(rx_addr_, priority_)
 
#define USART4_TXDMA_CONT_CONFIG(tx_addr_, priority_)
 
#define UART5_RXDMA_CONT_CONFIG(rx_addr_, priority_)
 
#define UART5_TXDMA_CONT_CONFIG(tx_addr_, priority_)
 

Typedefs

typedef uint32_t ptr_int
 

Enumerations

enum  parity_t { PT_EVEN = 0b010 , PT_ODD = 0b100 , PT_NONE = 0b000 }
 
enum  word_length_t { WORD_8 , WORD_9 }
 
enum  stop_bits_t { SB_ONE = 0b00 , SB_TWO = 0b01 , SB_HALF = 0b10 , SB_ONE_HALF = 0b11 }
 
enum  hw_flow_ctl_t { HW_DISABLE , CTS , RTS , CTS_RTS }
 
enum  ovsample_t { OV_16 = 0 , OV_8 = 1 }
 
enum  obsample_t { OB_DISABLE , OB_ENABLE }
 

Functions

bool PHAL_initUSART (usart_init_t *handle, const uint32_t fck)
 Initialize a USART Peripheral with desired settings.
 
void PHAL_usartTxBl (usart_init_t *handle, uint8_t *data, uint32_t len)
 TX using no DMA (blocks until complete)
 
void PHAL_usartRxBl (usart_init_t *handle, uint8_t *data, uint32_t len)
 RX using no DMA (blocks until complete)
 
bool PHAL_usartTxDma (usart_init_t *handle, uint16_t *data, uint32_t len)
 Starts a tx using dma, use PHAL_usartTxDmaComplete to ensure the previous transmission is complete.
 
bool PHAL_usartRxDma (usart_init_t *handle, uint16_t *data, uint32_t len, bool cont)
 Starts an rx using dma of a specific length.
 
bool PHAL_disableContinousRxDMA (usart_init_t *handle)
 Disables the Continous RX that was previously used.
 
bool PHAL_usartTxBusy (usart_init_t *handle)
 Returns whether USART peripheral is currently transmitting data.
 
bool PHAL_usartRxBusy (usart_init_t *handle)
 Returns whether USART peripheral is currently receiving data.
 
void usart_recieve_complete_callback (usart_init_t *handle)
 Callback function called immediately after reception of a USART RX message Uses USART IDLE line interrupt.
 

Detailed Description

Author
Aditya Anand (anand.nosp@m.89@p.nosp@m.urdue.nosp@m..edu) - Redesign of L4 USART HAL by Dawson Moore (moore.nosp@m.800@.nosp@m.purdu.nosp@m.e.ed.nosp@m.u)
Version
0.1
Date
2024-1-4

Macro Definition Documentation

◆ UART5_RXDMA_CONT_CONFIG

#define UART5_RXDMA_CONT_CONFIG ( rx_addr_,
priority_ )
Value:
{ \
.periph_addr = (uint32_t)&(UART5->RDR), \
.mem_addr = (uint32_t)(rx_addr_), \
.tx_size = 1, \
.increment = false, \
.circular = false, \
.dir = 0b0, \
.mem_inc = true, \
.periph_inc = false, \
.mem_to_mem = false, \
.priority = (priority_), \
.mem_size = 0b00, \
.periph_size = 0b00, \
.tx_isr_en = true, \
.dma_chan_request = 0b0100, \
.stream_idx = 0, \
.periph = DMA1, \
.stream = DMA1_Stream0}

◆ UART5_TXDMA_CONT_CONFIG

#define UART5_TXDMA_CONT_CONFIG ( tx_addr_,
priority_ )
Value:
{ \
.periph_addr = (uint32_t)&(UART5->TDR), \
.mem_addr = (uint32_t)(tx_addr_), \
.tx_size = 1, \
.increment = false, \
.circular = false, \
.dir = 0b1, \
.mem_inc = true, \
.periph_inc = false, \
.mem_to_mem = false, \
.priority = (priority_), \
.mem_size = 0b00, \
.periph_size = 0b00, \
.tx_isr_en = true, \
.dma_chan_request = 0b0100, \
.stream_idx = 7, \
.periph = DMA1, \
.stream = DMA1_Stream7}

◆ USART1_RXDMA_CONT_CONFIG

#define USART1_RXDMA_CONT_CONFIG ( rx_addr_,
priority_ )
Value:
{ \
.periph_addr = (uint32_t)&(USART1->RDR), \
.mem_addr = (uint32_t)(rx_addr_), \
.tx_size = 1, \
.increment = false, \
.circular = false, \
.dir = 0b0, \
.mem_inc = true, \
.periph_inc = false, \
.mem_to_mem = false, \
.priority = (priority_), \
.mem_size = 0b00, \
.periph_size = 0b00, \
.tx_isr_en = true, \
.dma_chan_request = 0b0100, \
.stream_idx = 5, \
.periph = DMA2, \
.stream = DMA2_Stream5}

◆ USART1_TXDMA_CONT_CONFIG

#define USART1_TXDMA_CONT_CONFIG ( tx_addr_,
priority_ )
Value:
{ \
.periph_addr = (uint32_t)&(USART1->TDR), \
.mem_addr = (uint32_t)(tx_addr_), \
.tx_size = 1, \
.increment = false, \
.circular = false, \
.dir = 0b1, \
.mem_inc = true, \
.periph_inc = false, \
.mem_to_mem = false, \
.priority = (priority_), \
.mem_size = 0b00, \
.periph_size = 0b00, \
.tx_isr_en = true, \
.dma_chan_request = 0b0100, \
.stream_idx = 7, \
.periph = DMA2, \
.stream = DMA2_Stream7}

◆ USART4_RXDMA_CONT_CONFIG

#define USART4_RXDMA_CONT_CONFIG ( rx_addr_,
priority_ )
Value:
{ \
.periph_addr = (uint32_t)&(UART4->RDR), \
.mem_addr = (uint32_t)(rx_addr_), \
.tx_size = 1, \
.increment = false, \
.circular = false, \
.dir = 0b0, \
.mem_inc = true, \
.periph_inc = false, \
.mem_to_mem = false, \
.priority = (priority_), \
.mem_size = 0b00, \
.periph_size = 0b00, \
.tx_isr_en = true, \
.dma_chan_request = 0b0100, \
.stream_idx = 2, \
.periph = DMA1, \
.stream = DMA1_Stream2}

◆ USART4_TXDMA_CONT_CONFIG

#define USART4_TXDMA_CONT_CONFIG ( tx_addr_,
priority_ )
Value:
{ \
.periph_addr = (uint32_t)&(UART4->TDR), \
.mem_addr = (uint32_t)(tx_addr_), \
.tx_size = 1, \
.increment = false, \
.circular = false, \
.dir = 0b1, \
.mem_inc = true, \
.periph_inc = false, \
.mem_to_mem = false, \
.priority = (priority_), \
.mem_size = 0b00, \
.periph_size = 0b00, \
.tx_isr_en = true, \
.dma_chan_request = 0b0100, \
.stream_idx = 4, \
.periph = DMA1, \
.stream = DMA1_Stream4}

Enumeration Type Documentation

◆ hw_flow_ctl_t

Enumerator
HW_DISABLE 

Hardware flow control disable.

CTS 

Enable Clear to send control.

RTS 

Enable Request to send control.

CTS_RTS 

Enable both CTS and RTS.

◆ obsample_t

enum obsample_t
Enumerator
OB_DISABLE 

Disable one bit sampling.

OB_ENABLE 

Enable one bit sampling.

◆ ovsample_t

enum ovsample_t
Enumerator
OV_16 

Oversample by 16.

OV_8 

Oversample by 8.

◆ parity_t

enum parity_t
Enumerator
PT_EVEN 

Even Parity.

PT_ODD 

Odd Parity.

PT_NONE 

Disable Parity bits.

◆ stop_bits_t

Enumerator
SB_ONE 

One Stop bit.

SB_TWO 

Two Stop bits.

SB_HALF 

One half stop bit.

SB_ONE_HALF 

1.5 Stop bits

◆ word_length_t

Enumerator
WORD_8 

8-Bit word length

WORD_9 

9-Bit word length

Function Documentation

◆ PHAL_disableContinousRxDMA()

bool PHAL_disableContinousRxDMA ( usart_init_t * handle)

Disables the Continous RX that was previously used.

Parameters
handleThe handle for the usart configuration

Disables the Continous RX that was previously used.

Parameters
handlePointer to the USART handle.
Returns
true if the operation was successful, false otherwise.

◆ PHAL_initUSART()

bool PHAL_initUSART ( usart_init_t * handle,
const uint32_t fck )

Initialize a USART Peripheral with desired settings.

Parameters
handleHandle containing settings for USART peripheral
fckClock rate going to USART peripheral (APBx bus)
Returns
true Successfully initialized USART peripheral
false Failed to initialize USART peripheral

Initialize a USART Peripheral with desired settings.

This function configures the USART peripheral, calculates and sets the baud rate, and enables the necessary clocks and DMA streams.

Parameters
handlePointer to a usart_init_t struct containing the configuration.
fckThe clock frequency of the peripheral in Hz.
Returns
true if initialization is successful, false otherwise.

◆ PHAL_usartRxBl()

void PHAL_usartRxBl ( usart_init_t * handle,
uint8_t * data,
uint32_t len )

RX using no DMA (blocks until complete)

Parameters
handleThe handle for the usart configuration
dataThe address of the data to receive
lenNumber of u8s expected to receive. Will block if not received.

RX using no DMA (blocks until complete)

Parameters
handlePointer to the USART handle.
dataPointer to the buffer to store received data.
lenThe length of the data to receive in bytes.

◆ PHAL_usartRxBusy()

bool PHAL_usartRxBusy ( usart_init_t * handle)

Returns whether USART peripheral is currently receiving data.

Parameters
handleHandle of USART peripheral check
Returns
true USART peripheral is currently receiving a message
false USART peripheal is not currently receiving a message

Returns whether USART peripheral is currently receiving data.

Parameters
handlePointer to the USART handle.
Returns
true if the peripheral is busy, false otherwise.

◆ PHAL_usartRxDma()

bool PHAL_usartRxDma ( usart_init_t * handle,
uint16_t * data,
uint32_t len,
bool cont )

Starts an rx using dma of a specific length.

Parameters
handleThe handle for the usart configuration
dataThe address to put the received data, ensure a cast to (uint16_t *), even if 8 bits
lenNumber of units of data, depending on the configured word length
contEnable Continous RX using the idle line interrupt (only need to call this function once, and HAL will keep recieving messages of the same length)

◆ PHAL_usartTxBl()

void PHAL_usartTxBl ( usart_init_t * handle,
uint8_t * data,
uint32_t len )

TX using no DMA (blocks until complete)

Parameters
handleThe handle for the usart configuration
dataThe address of the data to send
lenNumber of u8s

TX using no DMA (blocks until complete)

Parameters
handlePointer to the USART handle.
dataPointer to the data to transmit.
lenThe length of the data in bytes.

◆ PHAL_usartTxBusy()

bool PHAL_usartTxBusy ( usart_init_t * handle)

Returns whether USART peripheral is currently transmitting data.

Parameters
handleHandle of USART peripheral to check
Returns
true USART peripheral is currently sending a message
false USART peripheal is not currently sending a message

Returns whether USART peripheral is currently transmitting data.

Parameters
handlePointer to the USART handle.
Returns
true if the peripheral is busy, false otherwise.

◆ PHAL_usartTxDma()

bool PHAL_usartTxDma ( usart_init_t * handle,
uint16_t * data,
uint32_t len )

Starts a tx using dma, use PHAL_usartTxDmaComplete to ensure the previous transmission is complete.

Parameters
handleThe handle for the usart configuration
dataThe address of the data to send, ensure a cast to (uint16_t *), even if 8 bits
lenNumber of units of data, depending on the configured word length

◆ usart_recieve_complete_callback()

void usart_recieve_complete_callback ( usart_init_t * handle)
extern

Callback function called immediately after reception of a USART RX message Uses USART IDLE line interrupt.

NOTE: this is executed during an interrupt handler call, so keep code in this function light

Parameters
handleHandle of USART peripheral that just recieved a message