28 #include <libopencm3/stm32/rcc.h> 29 #include <libopencm3/stm32/gpio.h> 30 #include <libopencm3/stm32/usart.h> 31 #include <libopencm3/cm3/nvic.h> 32 #include <libopencmsis/core_cm3.h> 43 #define USART_BAUDRATE 1500000 47 static volatile uint8_t
rx_i = 0;
50 static volatile uint8_t
tx_i = 0;
60 rcc_periph_clock_enable(RCC_AFIO);
71 usart_set_flow_control(
USART(
USART_ID), USART_FLOWCONTROL_NONE);
128 if (usart_get_interrupt_source(
USART(
USART_ID), USART_SR_TXE)) {
137 if (usart_get_interrupt_source(
USART(
USART_ID), USART_SR_RXNE)) {
static uint8_t rx_buffer[USART_BUFFER]
ring buffer for received data
volatile bool usart_received
how many bytes available in the received buffer since last read
#define USART_ISR(x)
get interrupt service routine for USART based on USART identifier
static uint8_t tx_buffer[USART_BUFFER]
ring buffer for data to transmit
#define USART_ID
USART peripheral.
global definitions and methods (API)
#define USART_BUFFER
transmit and receive buffer sizes
static volatile uint8_t rx_i
current position of read received data
static volatile uint8_t tx_used
how much data needs to be transmitted
#define USART_IRQ(x)
get NVIC IRQ for USART based on USART identifier
#define USART(x)
get USART based on USART identifier
#define USART_PORT(x)
get port for USART based on USART identifier
#define USART_PORT_RCC(x)
get RCC for USART port based on USART identifier
void usart_putchar_nonblocking(char c)
send character over USART (non-blocking)
static volatile uint8_t tx_i
current position of transmitted data
library for USART communication (API)
static volatile uint8_t rx_used
how much data has been received and not red
void usart_flush(void)
ensure all data has been transmitted (blocking)
#define USART_BAUDRATE
serial baudrate, in bits per second (with 8N1 8 bits, no parity bit, 1 stop bit settings) ...
char usart_getchar(void)
get character received over USART (blocking)
#define LENGTH(x)
get the length of an array
#define USART_RCC(x)
get RCC for USART based on USART identifier
#define USART_PIN_RX(x)
get receive pin for USART based on USART identifier
void usart_putchar_blocking(char c)
send character over USART (blocking)
#define USART_PIN_TX(x)
get transmit pin for USART based on USART identifier
void usart_setup(void)
setup USART peripheral