APM:Libraries
Macros | Functions | Variables
usart.c File Reference
#include <usart.h>
#include <hal.h>
#include <systick.h>
Include dependency graph for usart.c:

Go to the source code of this file.

Macros

#define _USART2   NULL
 

Functions

void usart_foreach (void(*fn)(const usart_dev *))
 Call a function on each USART. More...
 
void usart_init (const usart_dev *dev)
 Initialize a serial port. More...
 
void usart_setup (const usart_dev *dev, uint32_t baudRate, uint16_t wordLength, uint16_t stopBits, uint16_t parity, uint16_t mode, uint16_t hardwareFlowControl)
 Configure a serial port's baud rate. More...
 
uint32_t usart_tx (const usart_dev *dev, const uint8_t *buf, uint32_t len)
 Nonblocking USART transmit. More...
 
void usart_putudec (const usart_dev *dev, uint32_t val)
 Transmit an unsigned integer to the specified serial port in decimal format. More...
 
static void usart_rx_irq (const usart_dev *dev)
 
static void usart_tx_irq (const usart_dev *dev)
 
void USART1_IRQHandler (void)
 
void USART3_IRQHandler (void)
 

Variables

static ring_buffer usart1_txrb IN_CCM
 
static const usart_dev usart1
 
const usart_dev *const _USART1 = &usart1
 
static const usart_dev usart3
 
const usart_dev *const _USART3 = &usart3
 
const usart_dev *const UARTS []
 
uint32_t us_ticks
 

Macro Definition Documentation

◆ _USART2

#define _USART2   NULL

Definition at line 55 of file usart.c.

Function Documentation

◆ USART1_IRQHandler()

void USART1_IRQHandler ( void  )

Definition at line 362 of file usart.c.

Referenced by usart_set_callback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ USART3_IRQHandler()

void USART3_IRQHandler ( void  )

Definition at line 376 of file usart.c.

Referenced by usart_set_callback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ usart_foreach()

void usart_foreach ( void(*)(const usart_dev *)  fn)

Call a function on each USART.

Parameters
fnFunction to call.

Definition at line 163 of file usart.c.

Referenced by usart_disable(), and usart_disable_all().

Here is the caller graph for this function:

◆ usart_init()

void usart_init ( const usart_dev dev)

Initialize a serial port.

Parameters
devSerial port to be initialized

Definition at line 187 of file usart.c.

Referenced by F4Light::UARTDriver::begin().

Here is the caller graph for this function:

◆ usart_putudec()

void usart_putudec ( const usart_dev dev,
uint32_t  val 
)

Transmit an unsigned integer to the specified serial port in decimal format.

This function blocks until the integer's digits have been completely transmitted.

Parameters
devSerial port to send on
valNumber to print

Definition at line 282 of file usart.c.

Referenced by usart_disable_all().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ usart_rx_irq()

static void usart_rx_irq ( const usart_dev dev)
inlinestatic

Definition at line 301 of file usart.c.

Referenced by USART1_IRQHandler(), and USART3_IRQHandler().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ usart_setup()

void usart_setup ( const usart_dev dev,
uint32_t  baudRate,
uint16_t  wordLength,
uint16_t  stopBits,
uint16_t  parity,
uint16_t  mode,
uint16_t  hardwareFlowControl 
)

Configure a serial port's baud rate.

Parameters
devSerial port to be configured
baudRateBaud rate for transmit/receive.
wordLengthSpecifies the number of data bits transmitted or received in a frame. This parameter can be a value of USART_Word_Length
stopBitsSpecifies the number of stop bits transmitted. This parameter can be a value of USART_Stop_Bits
paritySpecifies the parity mode. This parameter can be a value of USART_Parity
modeSpecifies wether the Receive or Transmit mode is enabled or disabled. This parameter can be a value of USART_Mode
hardwareFlowControlSpecifies wether the hardware flow control mode is enabled or disabled. This parameter can be a value of USART_Hardware_Flow_Control

Definition at line 199 of file usart.c.

Referenced by F4Light::UARTDriver::begin().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ usart_tx()

uint32_t usart_tx ( const usart_dev dev,
const uint8_t *  buf,
uint32_t  len 
)

Nonblocking USART transmit.

Parameters
devSerial port to transmit over
bufBuffer to transmit
lenMaximum number of bytes to transmit
Returns
Number of bytes transmitted

Definition at line 258 of file usart.c.

Referenced by usart_disable_all(), usart_putc(), and F4Light::UARTDriver::write().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ usart_tx_irq()

static void usart_tx_irq ( const usart_dev dev)
inlinestatic

Definition at line 334 of file usart.c.

Referenced by USART1_IRQHandler(), and USART3_IRQHandler().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ _USART1

const usart_dev* const _USART1 = &usart1

USART1 device

Definition at line 34 of file usart.c.

◆ _USART3

const usart_dev* const _USART3 = &usart3

USART3 device

Definition at line 74 of file usart.c.

◆ IN_CCM

usart_state u3state IN_CCM
static

Definition at line 18 of file usart.c.

◆ UARTS

const usart_dev* const UARTS[]
Initial value:
= {
NULL,
}
static const usart_dev usart3
Definition: usart.c:62
static const usart_dev usart1
Definition: usart.c:22
#define NULL
Definition: hal_types.h:59

Definition at line 136 of file usart.c.

Referenced by F4Light::UARTDriver::begin().

◆ us_ticks

uint32_t us_ticks

Definition at line 10 of file stopwatch.c.

Referenced by usart_foreach().

◆ usart1

const usart_dev usart1
static
Initial value:
= {
.USARTx = USART1,
.clk = RCC_APB2Periph_USART1,
.txrb = &usart1_txrb,
.rxrb = &usart1_rxrb,
.state = &u1state,
.irq = USART1_IRQn,
.gpio_af = GPIO_AF_USART1
}
#define BOARD_USART1_TX_PIN
Definition: board.h:43
#define BOARD_USART1_RX_PIN
Definition: board.h:44

Definition at line 22 of file usart.c.

◆ usart3

const usart_dev usart3
static
Initial value:
= {
.USARTx = USART3,
.clk = RCC_APB1Periph_USART3,
.txrb = &usart3_txrb,
.rxrb = &usart3_rxrb,
.state = &u3state,
.irq = USART3_IRQn,
.gpio_af = GPIO_AF_USART3
}
#define BOARD_USART3_TX_PIN
Definition: board.h:45
#define BOARD_USART3_RX_PIN
Definition: board.h:46

Definition at line 62 of file usart.c.