stm32f3xx-hal icon indicating copy to clipboard operation
stm32f3xx-hal copied to clipboard

UART DMA improvements and refactoring

Open robamu opened this issue 2 years ago • 1 comments

Some preparation to allow variable sized DMA transfers as specified in https://github.com/stm32-rs/stm32f3xx-hal/issues/325 . I did not have to change anything in the serial_dma example, but this is unfortunately still a breaking change because of the DMA transfer wrappers which are now returned for DMA transactions. I re-tested the serial_dma example on a STM32F3-Disco. In the process of reading a it about DMA, I also saw that the datasheet recommends checking the UART TC flag for transmission completeness. I am not sure whether this was not done on purpose or simply overlooked, but the changes ensure the TC flag is now checked as well.

Copied from CHANGELOG:

Changed

  • serial: The DMA functions write_all and read_exact now returns the wrapper structs SerialDmaTx and SerialDmaRx instead of the direct DMA transfer struct. These allow checking the USART ISR events with is_event_triggered as well.

Fixed

  • serial: The previous DMA write_all implementation did use the DMA transfer completion event to check for transfer completion, but MCU datasheet specifies that the TC flag of the USART peripheral should be checked for transfer completion to avoid corruption of the last transfer. This is now done by the new SerialDmaTx wrapper.

Added

  • serial: Public is_event_triggered method which allows to check for events given an event and a USART reference.

If you consider this mergeable (with adaptions/changes), I also have some other branches which build on top of these changes, for example the splitting of RX and TX events. :)

robamu avatar Dec 29 '22 13:12 robamu

Looking at this again as I am updating another application. This probably needs to be re-worked now that the split has been removed. Then again, using DMA requires TX and RX to be different entities.

robamu avatar Mar 23 '24 11:03 robamu