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
205#define PHAL_USART1_RXDMA_STREAM DMA2_Stream5
206#define PHAL_USART1_TXDMA_STREAM DMA2_Stream7
208#define PHAL_USART2_RXDMA_STREAM DMA1_Stream5
209#define PHAL_USART2_TXDMA_STREAM DMA1_Stream6
211#define PHAL_USART3_RXDMA_STREAM DMA1_Stream1
212#define PHAL_USART3_TXDMA_STREAM DMA1_Stream3
214#define PHAL_USART4_RXDMA_STREAM DMA1_Stream2
215#define PHAL_USART4_TXDMA_STREAM DMA1_Stream4
217#define PHAL_USART5_RXDMA_STREAM DMA1_Stream0
218#define PHAL_USART5_TXDMA_STREAM DMA1_Stream7
220#define PHAL_USART6_RXDMA_STREAM DMA2_Stream1
221#define PHAL_USART6_TXDMA_STREAM DMA2_Stream6
223#define PHAL_USART7_RXDMA_STREAM DMA1_Stream3
224#define PHAL_USART7_TXDMA_STREAM DMA1_Stream1
226#define PHAL_USART8_RXDMA_STREAM DMA1_Stream6
227#define PHAL_USART8_TXDMA_STREAM DMA1_Stream0
229#define _DEF_USART_RXDMA_CONFIG(rx_addr_, priority_, UXART, dmanum, streamnum, channum) \
231 .periph_addr = (uint32_t)&((UXART)->DR), \
232 .mem_addr = (uint32_t)(rx_addr_), \
234 .increment = false, \
238 .periph_inc = false, \
239 .mem_to_mem = false, \
240 .priority = (priority_), \
242 .periph_size = 0b00, \
244 .dma_chan_request = channum, \
245 .stream_idx = streamnum, \
246 .periph = DMA##dmanum, \
247 .stream = DMA##dmanum##_Stream##streamnum, \
250#define _DEF_USART_TXDMA_CONFIG(tx_addr_, priority_, UXART, dmanum, streamnum, channum) \
252 .periph_addr = (uint32_t)&((UXART)->DR), \
253 .mem_addr = (uint32_t)(tx_addr_), \
255 .increment = false, \
259 .periph_inc = false, \
260 .mem_to_mem = false, \
261 .priority = (priority_), \
263 .periph_size = 0b00, \
265 .dma_chan_request = channum, \
266 .stream_idx = streamnum, \
267 .periph = DMA##dmanum, \
268 .stream = DMA##dmanum##_Stream##streamnum, \
271#define USART1_RXDMA_CONT_CONFIG(a, p) _DEF_USART_RXDMA_CONFIG(a, p, USART1, 2, 5, 4)
272#define USART1_TXDMA_CONT_CONFIG(a, p) _DEF_USART_TXDMA_CONFIG(a, p, USART1, 2, 7, 4)
273#define USART2_RXDMA_CONT_CONFIG(a, p) _DEF_USART_RXDMA_CONFIG(a, p, USART2, 1, 5, 4)
274#define USART2_TXDMA_CONT_CONFIG(a, p) _DEF_USART_TXDMA_CONFIG(a, p, USART2, 1, 6, 4)
275#define USART3_RXDMA_CONT_CONFIG(a, p) _DEF_USART_RXDMA_CONFIG(a, p, USART3, 1, 1, 4)
276#define USART3_TXDMA_CONT_CONFIG(a, p) _DEF_USART_TXDMA_CONFIG(a, p, USART3, 1, 3, 4)
277#define USART4_RXDMA_CONT_CONFIG(a, p) _DEF_USART_RXDMA_CONFIG(a, p, UART4, 1, 2, 4)
278#define USART4_TXDMA_CONT_CONFIG(a, p) _DEF_USART_TXDMA_CONFIG(a, p, UART4, 1, 4, 4)
279#define USART5_RXDMA_CONT_CONFIG(a, p) _DEF_USART_RXDMA_CONFIG(a, p, UART5, 1, 0, 4)
280#define USART5_TXDMA_CONT_CONFIG(a, p) _DEF_USART_TXDMA_CONFIG(a, p, UART5, 1, 7, 4)
281#define USART6_RXDMA_CONT_CONFIG(a, p) _DEF_USART_RXDMA_CONFIG(a, p, USART6, 2, 1, 5)
282#define USART6_TXDMA_CONT_CONFIG(a, p) _DEF_USART_TXDMA_CONFIG(a, p, USART6, 2, 6, 5)
286#define USART1_RXDMA_CONT_CONFIG(rx_addr_, priority_) \
288 .periph_addr = (uint32_t)&(USART1->RDR), \
289 .mem_addr = (uint32_t)(rx_addr_), \
291 .increment = false, \
295 .periph_inc = false, \
296 .mem_to_mem = false, \
297 .priority = (priority_), \
299 .periph_size = 0b00, \
301 .dma_chan_request = 0b0100, \
304 .stream = DMA2_Stream5}
306#define USART1_TXDMA_CONT_CONFIG(tx_addr_, priority_) \
308 .periph_addr = (uint32_t)&(USART1->TDR), \
309 .mem_addr = (uint32_t)(tx_addr_), \
311 .increment = false, \
315 .periph_inc = false, \
316 .mem_to_mem = false, \
317 .priority = (priority_), \
319 .periph_size = 0b00, \
321 .dma_chan_request = 0b0100, \
324 .stream = DMA2_Stream7}
326#define USART4_RXDMA_CONT_CONFIG(rx_addr_, priority_) \
328 .periph_addr = (uint32_t)&(UART4->RDR), \
329 .mem_addr = (uint32_t)(rx_addr_), \
331 .increment = false, \
335 .periph_inc = false, \
336 .mem_to_mem = false, \
337 .priority = (priority_), \
339 .periph_size = 0b00, \
341 .dma_chan_request = 0b0100, \
344 .stream = DMA1_Stream2}
346#define USART4_TXDMA_CONT_CONFIG(tx_addr_, priority_) \
348 .periph_addr = (uint32_t)&(UART4->TDR), \
349 .mem_addr = (uint32_t)(tx_addr_), \
351 .increment = false, \
355 .periph_inc = false, \
356 .mem_to_mem = false, \
357 .priority = (priority_), \
359 .periph_size = 0b00, \
361 .dma_chan_request = 0b0100, \
364 .stream = DMA1_Stream4}
366#define UART5_RXDMA_CONT_CONFIG(rx_addr_, priority_) \
368 .periph_addr = (uint32_t)&(UART5->RDR), \
369 .mem_addr = (uint32_t)(rx_addr_), \
371 .increment = false, \
375 .periph_inc = false, \
376 .mem_to_mem = false, \
377 .priority = (priority_), \
379 .periph_size = 0b00, \
381 .dma_chan_request = 0b0100, \
384 .stream = DMA1_Stream0}
385#define UART5_TXDMA_CONT_CONFIG(tx_addr_, priority_) \
387 .periph_addr = (uint32_t)&(UART5->TDR), \
388 .mem_addr = (uint32_t)(tx_addr_), \
390 .increment = false, \
394 .periph_inc = false, \
395 .mem_to_mem = false, \
396 .priority = (priority_), \
398 .periph_size = 0b00, \
400 .dma_chan_request = 0b0100, \
403 .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:143
word_length_t
Definition usart.h:47
@ WORD_8
8-Bit word length
Definition usart.h:48
@ WORD_9
9-Bit word length
Definition usart.h:49
bool PHAL_initUSART(usart_init_t *handle, const uint32_t fck)
Initialize a USART Peripheral with desired settings.
Definition usart.c:39
bool PHAL_disableContinousRxDMA(usart_init_t *handle)
Disables the Continous RX that was previously used.
Definition usart.c:278
uint32_t ptr_int
Definition usart.h:33
bool PHAL_usartRxBusy(usart_init_t *handle)
Returns whether USART peripheral is currently receiving data.
Definition usart.c:323
void PHAL_usartRxBl(usart_init_t *handle, uint8_t *data, uint32_t len)
RX using no DMA (blocks until complete)
Definition usart.c:163
bool PHAL_usartTxBusy(usart_init_t *handle)
Returns whether USART peripheral is currently transmitting data.
Definition usart.c:228
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:650
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:232
hw_flow_ctl_t
Definition usart.h:59
@ CTS_RTS
Enable both CTS and RTS.
Definition usart.h:63
@ HW_DISABLE
Hardware flow control disable.
Definition usart.h:60
@ CTS
Enable Clear to send control.
Definition usart.h:61
@ RTS
Enable Request to send control.
Definition usart.h:62
obsample_t
Definition usart.h:71
@ OB_ENABLE
Enable one bit sampling.
Definition usart.h:73
@ OB_DISABLE
Disable one bit sampling.
Definition usart.h:72
parity_t
Definition usart.h:41
@ PT_ODD
Odd Parity.
Definition usart.h:43
@ PT_EVEN
Even Parity.
Definition usart.h:42
@ PT_NONE
Disable Parity bits.
Definition usart.h:44
stop_bits_t
Definition usart.h:52
@ SB_ONE_HALF
1.5 Stop bits
Definition usart.h:56
@ SB_TWO
Two Stop bits.
Definition usart.h:54
@ SB_HALF
One half stop bit.
Definition usart.h:55
@ SB_ONE
One Stop bit.
Definition usart.h:53
ovsample_t
Definition usart.h:66
@ OV_16
Oversample by 16.
Definition usart.h:67
@ OV_8
Oversample by 8.
Definition usart.h:68
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:179
uint32_t baud_rate
Baud rate for communication.
Definition usart.h:100
word_length_t word_length
Word length for tx/rx (8 default)
Definition usart.h:101
volatile usart_tx_errors_t tx_errors
Any TX error flags set during transmission.
Definition usart.h:117
uint8_t usart_active_num
Index of USART in active array (see USARTx_ACTIVE_IDX)
Definition usart.h:109
stop_bits_t stop_bits
Number of stop bits to use (1 default)
Definition usart.h:102
volatile usart_rx_errors_t rx_errors
Any RX error flags set during reception.
Definition usart.h:118
ovsample_t ovsample
8x or 16x oversample (16x default)
Definition usart.h:105
dma_init_t * rx_dma_cfg
RX configuration.
Definition usart.h:113
bool wake_addr
Wake up when given a specific address.
Definition usart.h:107
uint8_t address
Address to wake up to when addr_mode is enabled.
Definition usart.h:108
obsample_t obsample
One bit sampling enable (off default)
Definition usart.h:106
USART_TypeDef * periph
USART Peripheral to be used.
Definition usart.h:114
dma_init_t * tx_dma_cfg
TX configuration.
Definition usart.h:112
hw_flow_ctl_t hw_flow_ctl
Special hardware modes (none default)
Definition usart.h:104
parity_t parity
Parity of communication (none default)
Definition usart.h:103
bool dma_direct_mode_error
DMA error while attempting to operate in direct mode.
Definition usart.h:85
bool framing_error
Unable to understand USART frame.
Definition usart.h:80
bool dma_transfer_error
DMA transfer error.
Definition usart.h:84
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:86
bool noise_detected
Oversampling detected a possible bit flip due to noise in usart frame.
Definition usart.h:79
bool parity_error
USART Parity bit incorrect (Only when parity is enabled)
Definition usart.h:81
bool overrun
USART unable to parse data in time.
Definition usart.h:78
bool dma_direct_mode_error
DMA error while attempting to operate in direct mode.
Definition usart.h:92
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:93
bool dma_transfer_error
DMA transfer error.
Definition usart.h:91