Skip to content
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

drivers: uart_stm32: add DCache support in async DMA mode by using nocache memory regions #70503

Merged

Conversation

ajarmouni-st
Copy link
Collaborator

Adapt the stm32 uart driver to verify if DMA buffers, used in async mode, are located in noncacheable memory when DCache is activated, in order to avoid cache coherency issues.
Modify tests/drivers/uart_async_api test to run with DCache enabled by putting DMA buffers in a nocache memory region.

@ajarmouni-st ajarmouni-st force-pushed the dev_async_uart_nocachemem branch 2 times, most recently from 57f2a21 to 85f7ad8 Compare March 20, 2024 16:13
@ajarmouni-st ajarmouni-st added area: UART Universal Asynchronous Receiver-Transmitter area: DMA Direct Memory Access platform: STM32 ST Micro STM32 area: Cache labels Mar 20, 2024
@ajarmouni-st ajarmouni-st marked this pull request as ready for review March 20, 2024 16:29
@dcpleung dcpleung assigned erwango and unassigned dcpleung Mar 20, 2024
@ajarmouni-st ajarmouni-st marked this pull request as draft March 20, 2024 18:12

if DCACHE

config DT_DEFINED_NOCACHE
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps it's time to generalize the DT NOCACHE? Considering its usage here, in the SPI tests, and potentially by applications.

For example, by introducing related configs in

config NOCACHE_MEMORY

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I already thought about it, it will simplify things. Thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Perhaps it's time to generalize the DT NOCACHE? Considering its usage here, in the SPI tests, and potentially by applications.

@GeorgeCGV Will do it in another PR for all drivers as soon as this one is merged.

@ajarmouni-st ajarmouni-st force-pushed the dev_async_uart_nocachemem branch 3 times, most recently from 393ade6 to f8d5a71 Compare March 21, 2024 15:45
@ajarmouni-st ajarmouni-st marked this pull request as ready for review March 22, 2024 10:38
@ajarmouni-st ajarmouni-st added the area: Tests Issues related to a particular existing or missing test label Mar 22, 2024
drivers/serial/uart_stm32.c Show resolved Hide resolved
drivers/serial/uart_stm32.c Show resolved Hide resolved
tests/drivers/uart/uart_async_api/Kconfig Outdated Show resolved Hide resolved
Comment on lines 10 to 18
#if defined(CONFIG_DCACHE) && defined(CONFIG_NOCACHE_MEMORY)
#define __NOCACHE __attribute__ ((__section__(".nocache")))
#define NOCACHE_MEM 1
#elif defined(CONFIG_DCACHE) && defined(CONFIG_DT_DEFINED_NOCACHE)
#define __NOCACHE __attribute__ ((__section__(CONFIG_DT_DEFINED_NOCACHE_NAME)))
#define NOCACHE_MEM 1
#else
#define NOCACHE_MEM 0
#endif /* CONFIG_NOCACHE_MEMORY */
Copy link
Member

Choose a reason for hiding this comment

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

Open point, instead of modifiying the code, what about using the code relocation feature which will do the same operation behind the scene. For instance see: https://github.com/zephyrproject-rtos/zephyr/pull/65234/files.
Though, this solution doesn't seem to be compatible with use of ".nocache", so it could be a blocker

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

interesting, will investigate.

harness: ztest
harness_config:
fixture: gpio_loopback
depends_on: gpio
Copy link
Member

Choose a reason for hiding this comment

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

@dcpleung I'm surprise about this depends_on: gpio but I can see it all over this file. Is that expected ?

tests/drivers/uart/uart_async_api/testcase.yaml Outdated Show resolved Hide resolved
tests/drivers/uart/uart_async_api/testcase.yaml Outdated Show resolved Hide resolved
Adapt the driver to verify if DMA buffers are located in noncacheable
memory when DCache is activated, in order to avoid cache coherency issues.
This is required until manual cache coherency management is implemented.

Signed-off-by: Abderrahmane Jarmouni <abderrahmane.jarmouni-ext@st.com>
Add support for running tests with DCache enabled & put DMA buffers
in a nocache memory region to avoid coherency issues.

Signed-off-by: Abderrahmane Jarmouni <abderrahmane.jarmouni-ext@st.com>
Add test cases/configs for async DMA uart with DCache on STM32F7/H7 boards

Signed-off-by: Abderrahmane Jarmouni <abderrahmane.jarmouni-ext@st.com>
Add the possibility to flash nucleo-f746zg board using west
STM32CubeProgrammer runner.

Signed-off-by: Abderrahmane Jarmouni <abderrahmane.jarmouni-ext@st.com>
@erwango erwango assigned dcpleung and unassigned erwango May 7, 2024
@erwango
Copy link
Member

erwango commented May 7, 2024

@dcpleung I'd like your opinion, specially on the test part, as this part is generic.

@nashif nashif merged commit cd6c948 into zephyrproject-rtos:main May 13, 2024
25 checks passed
@ajarmouni-st ajarmouni-st deleted the dev_async_uart_nocachemem branch May 14, 2024 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Cache area: DMA Direct Memory Access area: Tests Issues related to a particular existing or missing test area: UART Universal Asynchronous Receiver-Transmitter platform: STM32 ST Micro STM32
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants