stm32f3xx-hal
stm32f3xx-hal copied to clipboard
UART DMA improvements and refactoring
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_allandread_exactnow returns the wrapper structsSerialDmaTxandSerialDmaRxinstead of the direct DMA transfer struct. These allow checking the USART ISR events withis_event_triggeredas well.
Fixed
- serial: The previous DMA
write_allimplementation 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 newSerialDmaTxwrapper.
Added
- serial: Public
is_event_triggeredmethod 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. :)
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.