STM32F10x library
Data Structures | Functions | Variables
serialq.c File Reference

Buffered USART routines. More...

#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include "stm32f10x.h"
#include "circbuf8.h"
#include "itoa.h"

Functions

void ser_init (const uint8_t devnum, const uint32_t br, uint8_t *txb, uint16_t txs, uint8_t *rxb, uint16_t rxs)
 Init USART. More...
 
void ser_shutdown (const uint8_t devnum)
 Deinit USART. More...
 
void ser_flush_rxbuf (const uint8_t devnum)
 Flush rx buffer. More...
 
void ser_wait_txe (const uint8_t devnum)
 Wait for output queue to be transmitted. More...
 
uint8_t ser_getc (const uint8_t devnum, uint8_t *const d)
 Get a byte from the serial queue. More...
 
void ser_putc (const uint8_t devnum, const char a)
 Enqueue a byte to the serial queue for transmission. More...
 
void ser_puts (const uint8_t devnum, const char *s)
 Send a string. More...
 
void ser_putsn (const uint8_t devnum, const char *s, uint8_t n)
 Send n chars of string. More...
 
void ser_puti_lc (const uint8_t devnum, const int32_t a, const uint8_t r, uint8_t w, char c)
 Send int in the specified radix r of minlen w prepended by char c. More...
 
void ser_putf (const uint8_t devnum, float f, uint8_t prec)
 Send float with specified precision. More...
 
int ser_printf (const char *s,...)
 Simplified implementation of printf (without dynamic malloc). More...
 

Variables

struct USART_DevDef USART1_PinDef = {2, USART1, RCC_APB2Periph_USART1, USART1_IRQn, GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_9}
 
struct USART_DevDef USART2_PinDef = {1, USART2, RCC_APB1Periph_USART2, USART2_IRQn, GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_2}
 
struct USART_DevDef USART3_PinDef = {1, USART3, RCC_APB1Periph_USART3, USART3_IRQn, GPIOB, RCC_APB2Periph_GPIOB, GPIO_Pin_10}
 
volatile struct cbuf8_t uart_rxq [3]
 
volatile struct cbuf8_t uart_txq [3]
 
uint8_t ser_printf_devnum = 1
 

Detailed Description

Buffered USART routines.

All USART data transmission is interrupt driven. Received data is put into a FIFO (provided by circbuf8.c). Data to be transmitted is likewise put into a FIFO. Memory for both FIFOs is provided by the caller on init.

Author
Matej Kogovsek (matej.nosp@m.@ham.nosp@m.radio.nosp@m..si)
Note
This file is part of mat-stm32f1-lib

Function Documentation

void ser_flush_rxbuf ( const uint8_t  devnum)

Flush rx buffer.

Parameters
[in]devnumUSART peripheral number (1..3)
uint8_t ser_getc ( const uint8_t  devnum,
uint8_t *const  d 
)

Get a byte from the serial queue.

Parameters
[in]devnumUSART peripheral number (1..3)
[out]dPointer to uint8_t where received data is put
Returns
Same as cbuf8_get
void ser_init ( const uint8_t  devnum,
const uint32_t  br,
uint8_t *  txb,
uint16_t  txs,
uint8_t *  rxb,
uint16_t  rxs 
)

Init USART.

Parameters
[in]devnumUSART peripheral number (1..3)
[in]brBaudrate (i.e. 115200 for 115.2k), F_CPU independent
[in]txbPointer to caller allocated TX buffer
[in]txssizeof(txb)
[in]rxbPointer to caller allocated RX buffer
[in]rxssizeof(rxs)
int ser_printf ( const char *  s,
  ... 
)

Simplified implementation of printf (without dynamic malloc).

Returns
Always returns 1.

Variable ser_printf_devnum has to be set to the wanted USART peripheral number (1..3) prior to calling.

void ser_putc ( const uint8_t  devnum,
const char  a 
)

Enqueue a byte to the serial queue for transmission.

Parameters
[in]devnumUSART peripheral number (1..3)
[in]aByte to transmit
void ser_putf ( const uint8_t  devnum,
float  f,
uint8_t  prec 
)

Send float with specified precision.

Parameters
[in]devnumUSART peripheral number (1..3)
[in]ffloat
[in]precNumber of decimals
void ser_puti_lc ( const uint8_t  devnum,
const int32_t  a,
const uint8_t  r,
uint8_t  w,
char  c 
)

Send int in the specified radix r of minlen w prepended by char c.

Parameters
[in]devnumUSART peripheral number (1..3)
[in]aint
[in]rRadix
[in]wMin width
[in]cPrepending char to achieve min width
void ser_puts ( const uint8_t  devnum,
const char *  s 
)

Send a string.

Parameters
[in]devnumUSART peripheral number (1..3)
[in]sZero terminated string to send
void ser_putsn ( const uint8_t  devnum,
const char *  s,
uint8_t  n 
)

Send n chars of string.

Parameters
[in]devnumUSART peripheral number (1..3)
[in]sString, zeros are sent as spaces
[in]nNumber of chars to send
void ser_shutdown ( const uint8_t  devnum)

Deinit USART.

Parameters
[in]devnumUSART peripheral number (1..3)
void ser_wait_txe ( const uint8_t  devnum)

Wait for output queue to be transmitted.

Parameters
[in]devnumUSART peripheral number (1..3)

Variable Documentation

uint8_t ser_printf_devnum = 1

USART peripheral number used by ser_printf

volatile struct cbuf8_t uart_rxq[3]

RX circbuf defs for all 3 USARTs

volatile struct cbuf8_t uart_txq[3]

TX circbuf defs for all 3 USARTs

struct USART_DevDef USART1_PinDef = {2, USART1, RCC_APB2Periph_USART1, USART1_IRQn, GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_9}

Register and pin defs for USART1

struct USART_DevDef USART2_PinDef = {1, USART2, RCC_APB1Periph_USART2, USART2_IRQn, GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_2}

Register and pin defs for USART2

struct USART_DevDef USART3_PinDef = {1, USART3, RCC_APB1Periph_USART3, USART3_IRQn, GPIOB, RCC_APB2Periph_GPIOB, GPIO_Pin_10}

Register and pin defs for USART3