16#if defined(STM32F407xx)
17#define TOTAL_NUM_UART 8
20#define USART1_ACTIVE_IDX 0
21#define USART2_ACTIVE_IDX 1
22#define USART3_ACTIVE_IDX 2
23#define USART4_ACTIVE_IDX 3
24#define USART5_ACTIVE_IDX 4
25#define USART6_ACTIVE_IDX 5
26#define USART7_ACTIVE_IDX 6
27#define USART8_ACTIVE_IDX 7
29#elif defined(STM32F732xx)
30#define TOTAL_NUM_UART 8
33#define USART1_ACTIVE_IDX 0
34#define USART2_ACTIVE_IDX 1
35#define USART3_ACTIVE_IDX 2
36#define USART4_ACTIVE_IDX 3
37#define USART5_ACTIVE_IDX 4
38#define USART6_ACTIVE_IDX 5
39#define USART7_ACTIVE_IDX 6
40#define USART8_ACTIVE_IDX 7
43#define USART_BRR_DIV_Fraction_Pos USART_BRR_DIV_FRACTION_Pos
44#define USART_BRR_DIV_Mantissa_Pos USART_BRR_DIV_MANTISSA_Pos
48#include "common/phal_F4_F7/phal_F4_F7.h"
50typedef uint32_t ptr_int;
222#define PHAL_USART1_RXDMA_STREAM DMA2_Stream5
223#define PHAL_USART1_TXDMA_STREAM DMA2_Stream7
225#define PHAL_USART2_RXDMA_STREAM DMA1_Stream5
226#define PHAL_USART2_TXDMA_STREAM DMA1_Stream6
228#define PHAL_USART3_RXDMA_STREAM DMA1_Stream1
229#define PHAL_USART3_TXDMA_STREAM DMA1_Stream3
231#define PHAL_USART4_RXDMA_STREAM DMA1_Stream2
232#define PHAL_USART4_TXDMA_STREAM DMA1_Stream4
234#define PHAL_USART5_RXDMA_STREAM DMA1_Stream0
235#define PHAL_USART5_TXDMA_STREAM DMA1_Stream7
237#define PHAL_USART6_RXDMA_STREAM DMA2_Stream1
238#define PHAL_USART6_TXDMA_STREAM DMA2_Stream6
240#define PHAL_USART7_RXDMA_STREAM DMA1_Stream3
241#define PHAL_USART7_TXDMA_STREAM DMA1_Stream1
243#define PHAL_USART8_RXDMA_STREAM DMA1_Stream6
244#define PHAL_USART8_TXDMA_STREAM DMA1_Stream0
246#define _DEF_USART_RXDMA_CONFIG(rx_addr_, priority_, UXART, dmanum, streamnum, channum) \
248 .periph_addr = (uint32_t)&((UXART)->DR), \
249 .mem_addr = (uint32_t)(rx_addr_), \
251 .increment = false, \
255 .periph_inc = false, \
256 .mem_to_mem = false, \
257 .priority = (priority_), \
259 .periph_size = 0b00, \
261 .dma_chan_request = channum, \
262 .stream_idx = streamnum, \
263 .periph = DMA##dmanum, \
264 .stream = DMA##dmanum##_Stream##streamnum, \
267#define _DEF_USART_TXDMA_CONFIG(tx_addr_, priority_, UXART, dmanum, streamnum, channum) \
269 .periph_addr = (uint32_t)&((UXART)->DR), \
270 .mem_addr = (uint32_t)(tx_addr_), \
272 .increment = false, \
276 .periph_inc = false, \
277 .mem_to_mem = false, \
278 .priority = (priority_), \
280 .periph_size = 0b00, \
282 .dma_chan_request = channum, \
283 .stream_idx = streamnum, \
284 .periph = DMA##dmanum, \
285 .stream = DMA##dmanum##_Stream##streamnum, \
288#define USART1_RXDMA_CONT_CONFIG(a, p) _DEF_USART_RXDMA_CONFIG(a, p, USART1, 2, 5, 4)
289#define USART1_TXDMA_CONT_CONFIG(a, p) _DEF_USART_TXDMA_CONFIG(a, p, USART1, 2, 7, 4)
290#define USART2_RXDMA_CONT_CONFIG(a, p) _DEF_USART_RXDMA_CONFIG(a, p, USART2, 1, 5, 4)
291#define USART2_TXDMA_CONT_CONFIG(a, p) _DEF_USART_TXDMA_CONFIG(a, p, USART2, 1, 6, 4)
292#define USART3_RXDMA_CONT_CONFIG(a, p) _DEF_USART_RXDMA_CONFIG(a, p, USART3, 1, 1, 4)
293#define USART3_TXDMA_CONT_CONFIG(a, p) _DEF_USART_TXDMA_CONFIG(a, p, USART3, 1, 3, 4)
294#define USART4_RXDMA_CONT_CONFIG(a, p) _DEF_USART_RXDMA_CONFIG(a, p, UART4, 1, 2, 4)
295#define USART4_TXDMA_CONT_CONFIG(a, p) _DEF_USART_TXDMA_CONFIG(a, p, UART4, 1, 4, 4)
296#define USART5_RXDMA_CONT_CONFIG(a, p) _DEF_USART_RXDMA_CONFIG(a, p, UART5, 1, 0, 4)
297#define USART5_TXDMA_CONT_CONFIG(a, p) _DEF_USART_TXDMA_CONFIG(a, p, UART5, 1, 7, 4)
298#define USART6_RXDMA_CONT_CONFIG(a, p) _DEF_USART_RXDMA_CONFIG(a, p, USART6, 2, 1, 5)
299#define USART6_TXDMA_CONT_CONFIG(a, p) _DEF_USART_TXDMA_CONFIG(a, p, USART6, 2, 6, 5)
303#define USART1_RXDMA_CONT_CONFIG(rx_addr_, priority_) \
305 .periph_addr = (uint32_t)&(USART1->RDR), \
306 .mem_addr = (uint32_t)(rx_addr_), \
308 .increment = false, \
312 .periph_inc = false, \
313 .mem_to_mem = false, \
314 .priority = (priority_), \
316 .periph_size = 0b00, \
318 .dma_chan_request = 0b0100, \
321 .stream = DMA2_Stream5}
323#define USART1_TXDMA_CONT_CONFIG(tx_addr_, priority_) \
325 .periph_addr = (uint32_t)&(USART1->TDR), \
326 .mem_addr = (uint32_t)(tx_addr_), \
328 .increment = false, \
332 .periph_inc = false, \
333 .mem_to_mem = false, \
334 .priority = (priority_), \
336 .periph_size = 0b00, \
338 .dma_chan_request = 0b0100, \
341 .stream = DMA2_Stream7}
343#define USART4_RXDMA_CONT_CONFIG(rx_addr_, priority_) \
345 .periph_addr = (uint32_t)&(UART4->RDR), \
346 .mem_addr = (uint32_t)(rx_addr_), \
348 .increment = false, \
352 .periph_inc = false, \
353 .mem_to_mem = false, \
354 .priority = (priority_), \
356 .periph_size = 0b00, \
358 .dma_chan_request = 0b0100, \
361 .stream = DMA1_Stream2}
363#define USART4_TXDMA_CONT_CONFIG(tx_addr_, priority_) \
365 .periph_addr = (uint32_t)&(UART4->TDR), \
366 .mem_addr = (uint32_t)(tx_addr_), \
368 .increment = false, \
372 .periph_inc = false, \
373 .mem_to_mem = false, \
374 .priority = (priority_), \
376 .periph_size = 0b00, \
378 .dma_chan_request = 0b0100, \
381 .stream = DMA1_Stream4}
383#define UART5_RXDMA_CONT_CONFIG(rx_addr_, priority_) \
385 .periph_addr = (uint32_t)&(UART5->RDR), \
386 .mem_addr = (uint32_t)(rx_addr_), \
388 .increment = false, \
392 .periph_inc = false, \
393 .mem_to_mem = false, \
394 .priority = (priority_), \
396 .periph_size = 0b00, \
398 .dma_chan_request = 0b0100, \
401 .stream = DMA1_Stream0}
402#define UART5_TXDMA_CONT_CONFIG(tx_addr_, priority_) \
404 .periph_addr = (uint32_t)&(UART5->TDR), \
405 .mem_addr = (uint32_t)(tx_addr_), \
407 .increment = false, \
411 .periph_inc = false, \
412 .mem_to_mem = false, \
413 .priority = (priority_), \
415 .periph_size = 0b00, \
417 .dma_chan_request = 0b0100, \
420 .stream = DMA1_Stream7}
void PHAL_usartTxBl(usart_init_t *handle, uint8_t *data, uint32_t len)
TX using no DMA (blocks until complete)
Definition usart.c:150
word_length_t
Definition usart.h:64
@ WORD_8
8-Bit word length
Definition usart.h:65
@ WORD_9
9-Bit word length
Definition usart.h:66
bool PHAL_initUSART(usart_init_t *handle, const uint32_t fck)
Initialize a USART Peripheral with desired settings.
Definition usart.c:34
bool PHAL_disableContinousRxDMA(usart_init_t *handle)
Disables the Continous RX that was previously used.
Definition usart.c:337
bool PHAL_usartRxBusy(usart_init_t *handle)
Returns whether USART peripheral is currently receiving data.
Definition usart.c:396
void PHAL_usartRxBl(usart_init_t *handle, uint8_t *data, uint32_t len)
RX using no DMA (blocks until complete)
Definition usart.c:182
bool PHAL_usartTxBusy(usart_init_t *handle)
Returns whether USART peripheral is currently transmitting data.
Definition usart.c:273
void usart_recieve_complete_callback(usart_init_t *handle)
Callback function called immediately after reception of a USART RX message Uses USART IDLE line inter...
Definition usart.c:723
bool PHAL_usartRxDma(usart_init_t *handle, uint16_t *data, uint32_t len, bool cont)
Starts an rx using dma of a specific length.
Definition usart.c:277
hw_flow_ctl_t
Definition usart.h:76
@ CTS_RTS
Enable both CTS and RTS.
Definition usart.h:80
@ HW_DISABLE
Hardware flow control disable.
Definition usart.h:77
@ CTS
Enable Clear to send control.
Definition usart.h:78
@ RTS
Enable Request to send control.
Definition usart.h:79
obsample_t
Definition usart.h:88
@ OB_ENABLE
Enable one bit sampling.
Definition usart.h:90
@ OB_DISABLE
Disable one bit sampling.
Definition usart.h:89
parity_t
Definition usart.h:58
@ PT_ODD
Odd Parity.
Definition usart.h:60
@ PT_EVEN
Even Parity.
Definition usart.h:59
@ PT_NONE
Disable Parity bits.
Definition usart.h:61
stop_bits_t
Definition usart.h:69
@ SB_ONE_HALF
1.5 Stop bits
Definition usart.h:73
@ SB_TWO
Two Stop bits.
Definition usart.h:71
@ SB_HALF
One half stop bit.
Definition usart.h:72
@ SB_ONE
One Stop bit.
Definition usart.h:70
ovsample_t
Definition usart.h:83
@ OV_16
Oversample by 16.
Definition usart.h:84
@ OV_8
Oversample by 8.
Definition usart.h:85
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.
Definition usart.c:207
uint32_t baud_rate
Baud rate for communication.
Definition usart.h:117
word_length_t word_length
Word length for tx/rx (8 default)
Definition usart.h:118
volatile usart_tx_errors_t tx_errors
Any TX error flags set during transmission.
Definition usart.h:134
uint8_t usart_active_num
Index of USART in active array (see USARTx_ACTIVE_IDX)
Definition usart.h:126
dma_init_t * tx_dma_cfg
TX configuration.
Definition usart.h:129
stop_bits_t stop_bits
Number of stop bits to use (1 default)
Definition usart.h:119
volatile usart_rx_errors_t rx_errors
Any RX error flags set during reception.
Definition usart.h:135
ovsample_t ovsample
8x or 16x oversample (16x default)
Definition usart.h:122
bool wake_addr
Wake up when given a specific address.
Definition usart.h:124
USART_TypeDef * periph
USART Peripheral to be used.
Definition usart.h:131
uint8_t address
Address to wake up to when addr_mode is enabled.
Definition usart.h:125
obsample_t obsample
One bit sampling enable (off default)
Definition usart.h:123
hw_flow_ctl_t hw_flow_ctl
Special hardware modes (none default)
Definition usart.h:121
dma_init_t * rx_dma_cfg
RX configuration.
Definition usart.h:130
parity_t parity
Parity of communication (none default)
Definition usart.h:120
bool dma_direct_mode_error
DMA error while attempting to operate in direct mode.
Definition usart.h:102
bool framing_error
Unable to understand USART frame.
Definition usart.h:97
bool dma_transfer_error
DMA transfer error.
Definition usart.h:101
bool dma_fifo_overrun
DMA FIFO has been overrun - apparently this can be ignored on USART peripherals AS LONG AS YOU AREN'T...
Definition usart.h:103
bool noise_detected
Oversampling detected a possible bit flip due to noise in usart frame.
Definition usart.h:96
bool parity_error
USART Parity bit incorrect (Only when parity is enabled)
Definition usart.h:98
bool overrun
USART unable to parse data in time.
Definition usart.h:95
bool dma_direct_mode_error
DMA error while attempting to operate in direct mode.
Definition usart.h:109
bool dma_fifo_overrun
DMA FIFO has been overrun - apparently this can be ignored on USART peripherals AS LONG AS YOU AREN'T...
Definition usart.h:110
bool dma_transfer_error
DMA transfer error.
Definition usart.h:108