Simple ZephyrOS device driver using UART3 and the DMA1 (channel 4 & 7).
Main features:
- getting bursts of uart bytes without knowing the amount of data to be received before.
- sending uart data via DMA to reduce MCU load
The RX is received via DMA into a ring buffer. After the finish of the message burst or when the ringbuffer is half full(HTC)/full(TC) the rx callback is called. This callback is not blocking the rx/tx.
The TX is done via DMA transfer. The write function sets up the DMA transfer and waits for the complete semaphore. This semaphore is given in the DMA transfer complete(TC) interrupt.
Keeping in mind that vector based processing is the most efficent way, the RX ring buffer is set to 512 Bytes. Means that in the worst case the rx callback has to process 256 Bytes. But processing 256 Bytes than having 256 uart tx interrupts is much more efficent.
sources:
- The core rx idea is from Tilen Majerle and can be found here: uart3 rx dma
- stm32f412 datasheet(RM0402)
- stm32HAL LL documentation (UM1725)