Skip to content

drivers: stm32: SPI: SPI nocache buffers can be in CONFIG_NOCACHE_MEMORY #61265

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 1 commit into from
Aug 24, 2023

Conversation

dgastonochoa
Copy link
Contributor

@dgastonochoa dgastonochoa commented Aug 8, 2023

The STM32 SPI driver checks buffers are within bounds of nocache memory regions, in case DMA is enabled, so that trying to use a buffer which is not in a nocache region returns an error. The only buffers that are considered nocache at the moment are those that are declared as so in devicetree.

As detected in the issue #60977, there is a problem with this: Zephyr has two different ways of declaring a new cache region. One is declaring such region in devicetree, and the other is using CONFIG_NOCACHE_REGION. Because of this, buffers that are located within these regions must be checked inside the STM32 SPI driver and considered valid.

This PR aims to solve the issue explained above.

Notice that #60977 also remarks another problem: the SPI API states that NULL buffers will be used to send/ignore dummy bytes. In order to pass the spi_loopback tests, this needs to be fixed as well.

Fixes the two problems mentioned in #60977 that make the SPI loopback tests to fail, that is, send zeroes if a tx null buffer is provided and consider buffers associated to CONFIG_NOCACHE_REGION as valid. However, it would be desirable to have loopback tests for buffers in nocache regions declared in devicetree, as mentioned in the above issue's comments. #61021 achieves this, but it would need to be rebased on top of this PR.

Note: I believe #52965 has the same problem in address_in_non_cacheable_sram

Test plan

Connect an STM32H7 board to the PC with pins D11 and D12 connected.

Open a minicom or equivalent terminal to read the test report.

Execute the following commands:

west build -p auto -b nucleo_h753zi tests/drivers/spi/spi_loopback/
west flash

And verify all tests pass. Then, do:

west build -p auto -b nucleo_h753zi -T tests/drivers/spi/spi_loopback/drivers.spi.stm32_spi_dma.loopback
west flash

And verify all pass again.

CONFIG_NOCACHE_MEMORY is a valid way of declaring buffers in
nocache regions. Consider them valid in the stm32 SPI driver
nocache check. Also, don't check NULL buffers as the SPI
interface states that such buffers will result in sending
zeroes.

Signed-off-by: Daniel Gaston Ochoa <[email protected]>
@carlescufi carlescufi merged commit 818aa2d into zephyrproject-rtos:main Aug 24, 2023
@dgastonochoa dgastonochoa deleted the fix-spi-dma branch August 25, 2023 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: SPI SPI bus platform: STM32 ST Micro STM32
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants