Skip to content

STM32 UART DRIVER : add support for buffer circular mode #80921

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 10, 2025

Conversation

djiatsaf-st
Copy link
Collaborator

@djiatsaf-st djiatsaf-st commented Nov 5, 2024

This PR introduces the implementation of the circular mode in the uart communication on the stm32 driver.

It is inspired by this commit 7275280#diff-54bdff4ff3a16e194201b66e24cada279fdfdd40dfd66b1df3df3a99d0f65cd0R1007 made by @fouge

The cyclic mode will be configured from the devicetree and will also have the management of the dma buffer with the integration of the half full and full irq .

This implementation is compatible with all STM32 series that have the CIRC bit at the 5th position of the DMA_CCRx register.

A sample driver has been made available and tested on the C0, F0 and G0 series with communication speeds reaching up to 500kbps.

Fixes #79831

@zephyrbot zephyrbot added area: Samples Samples area: UART Universal Asynchronous Receiver-Transmitter platform: STM32 ST Micro STM32 area: DMA Direct Memory Access labels Nov 5, 2024
@erwango erwango added this to the v4.1.0 milestone Nov 5, 2024
@djiatsaf-st djiatsaf-st marked this pull request as draft November 5, 2024 16:33
@erian747
Copy link
Contributor

erian747 commented Nov 7, 2024

I have not analyzed the PR in detail, but saw some fragments of code that could possibly touching a solution to discussion in:
#81104 which is about calling event callback in case of rx timeout (even with 0 bytes received)

@dcpleung dcpleung assigned erwango and unassigned dcpleung Nov 7, 2024
@djiatsaf-st djiatsaf-st marked this pull request as ready for review November 8, 2024 15:55
@djiatsaf-st djiatsaf-st force-pushed the uart_circular_mode branch 2 times, most recently from 28188de to 0c00ab2 Compare November 12, 2024 09:16
@djiatsaf-st djiatsaf-st force-pushed the uart_circular_mode branch 2 times, most recently from b2f4f3c to 3e3832b Compare November 12, 2024 12:02
@djiatsaf-st djiatsaf-st force-pushed the uart_circular_mode branch 2 times, most recently from 57ac9d1 to 1ed34bc Compare November 21, 2024 15:20
@djiatsaf-st djiatsaf-st force-pushed the uart_circular_mode branch 4 times, most recently from f10dc6c to 74b3e52 Compare November 26, 2024 16:41
Copy link
Member

@erwango erwango left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise LGTM

@djiatsaf-st djiatsaf-st force-pushed the uart_circular_mode branch 5 times, most recently from 7887fbe to 4d136e6 Compare December 13, 2024 14:13
djiatsaf-st and others added 3 commits January 8, 2025 16:22
This macro will help us to enable the 5th bit CIRC on the DMA_CCRx
register for all stm32 series having this configuration.
Thus the DMA will be able to handle the circular buffers.

Signed-off-by: Fabrice DJIATSA <[email protected]>
co-authored-by: Cyril Fougeray <[email protected]>
the following implementations are added:
- set cyclic variable to handle circular/normal mode :
  enable dest/source_reload_en variable to set CIRC bit to 1 for RX or TX.
- DMA_STATUS_COMPLETE(0), DMA_STATUS_BLOCK(1) macros to handle half
 and full irq
- add ASYNC_UART_STATUS_TIMEOUT(3)  macro to work with  default mode
- add status input in uart_stm32_dma_rx_flush function  to handle
 async events depending on the  mode we are in.

Signed-off-by: Fabrice DJIATSA <[email protected]>
co-authored-by: Cyril Fougeray <[email protected]>
This code example  will demonstrate how to use uart
circular mode on STM32 boards.

Signed-off-by: Fabrice DJIATSA <[email protected]>
@kartben kartben merged commit e0da2d9 into zephyrproject-rtos:main Jan 10, 2025
24 checks passed
@fouge
Copy link
Contributor

fouge commented Jan 10, 2025

will try that hopefully today!

EDIT: works first try by using same DTS as in overlay :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: DMA Direct Memory Access area: Samples Samples area: UART Universal Asynchronous Receiver-Transmitter platform: STM32 ST Micro STM32
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants