[riot-notifications] [RIOT-OS/RIOT] STM32_common/SPI: Reduce the overhead in the DMA hot path (#14097)

Koen Zandberg notifications at github.com
Mon May 18 14:03:34 CEST 2020

### Contribution description

This PR reduces the number of instructions required for DMA-based SPI transfers and moves a number of setup calls from the spi_transfer_bytes to the acquire/release function. This reduces the overhead. 

1. Add a define for the always-on settings in the CR2 registers removing some of the volatile register read-modify-write sequences.
2. Use the define from the first commit to further reduce the number of read-modify-writes to the CR2 register.
3. Moves the DMA acquire inside the SPI acquire, it is overkill to acquire/release for every single SPI transfer.
4. Removes the DMA stop function call. The DMA stream is automatically stopped as soon as the transfer is finished and doesn't need to be manually stopped.
5. Refactor to use the new setup and prepare functions from #14096. A single setup is done during the SPI acquire. This reduces a few unnecessary register writes every transfer.

Together with #14096 this reduces the overhead with a single byte SPI transfer (not counting acquire/release overhead) using DMA from 17μs to 6.4μs, measured using the bench command in `tests/periph_spi`.

### Testing procedure

This probably needs testing with all affected stm32 devices.

`tests/periph_spi` can be used to verify the decrease in overhead on SPI DMA enabled boards. The test needs a `FEATURES_REQUIRED += periph_dma` in order to force DMA usage. 

### Issues/PRs references

Depends on #14096 
You can view, comment on, or merge this pull request online at:


-- Commit Summary --

  * tests/periph_spi: Add thread runtime stats
  * fixup! tests/periph_spi: Add thread runtime stats
  * fixup! tests/periph_spi: Add thread runtime stats
  * stm32/dma: Move one-time config to init function
  * stm32/dma: Move FCR configuration to acquire function
  * stm32/dma: Move clear flags to acquire
  * stm32/dma: add setup and prepare functions
  * stm32/dma: Remove superfluous asserts from DMA hot path
  * stm32/spi: Add define for default CR2 settings
  * stm32/spi: Reduce register writes in hot path
  * stm32/spi: Acquire/release the DMA during the SPI acquire/release
  * stm32/dma: Cache DMA stream base address
  * stm32/spi: Remove superfluous DMA stop call
  * stm32/spi: Use new DMA setup/prepare functions

-- File Changes --

    M cpu/stm32_common/include/periph_cpu_common.h (45)
    M cpu/stm32_common/periph/dma.c (155)
    M cpu/stm32_common/periph/spi.c (98)
    M tests/periph_spi/Makefile (1)
    M tests/periph_spi/main.c (130)

-- Patch Links --


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20200518/ecf7dd94/attachment.htm>

More information about the notifications mailing list