[riot-notifications] [RIOT-OS/RIOT] cpu/stm32_common: add DMA implementation for F2/F4/F7 (#7658)

Vincent Dupont notifications at github.com
Thu Sep 28 18:13:15 CEST 2017


This is a try to add a generic DMA implementation for f2/f4/f7.

I tested with a stm32f413, UART and SPI drivers seems to work.
If this is accepted, I'll need help to adapt boards configuration and to test.

A `static const dma_conf_t dma_config[]` array is needed in board's `periph_conf.h` to declare which 'physical' streams will be used. Then UART and SPI drivers point to the 'logical' stream (index in `dma_config`).

The DMA API becomes:
```C
/**
 * @brief   Initialize DMA
 */
void dma_init(void);

/**
 * @brief   Execute a DMA transfer
 *
 * This function blocks until the transfer is completed
 *
 * @param[in]  dma     logical DMA stream
 * @param[in]  chan    DMA channel
 * @param[in]  src     source buffer
 * @param[out] dst     destination buffer
 * @param[in]  len     length to transfer
 * @param[in]  mode    DMA mode
 * @param[in]  flags   DMA configuration
 *
 * @return < 0 on error, the number of transfered bytes otherwise
 */
int dma_transfer(dma_t dma, int chan, const void *src, void *dst, size_t len,
                 dma_mode_t mode, uint8_t flags);

/**
 * @brief   Acquire a DMA stream
 *
 * @param[in] dma     logical DMA stream
 */
void dma_acquire(dma_t dma);

/**
 * @brief   Release a DMA stream
 *
 * @param[in] dma     logical DMA stream
 */
void dma_release(dma_t dma);

/**
 * @brief   Start a DMA transfer on a stream
 *
 * @param[in] dma     logical DMA stream
 */
void dma_start(dma_t dma);

/**
 * @brief   Suspend a DMA transfer on a stream
 *
 * @param[in] dma     logical DMA stream
 *
 * @return the remaining number of bytes to transfer
 */
uint16_t dma_suspend(dma_t dma);

/**
 * @brief   Resume a suspended DMA transfer on a stream
 *
 * @param[in] dma     logical DMA stream
 * @param[in] todo    the remaining number of bytes to tranfer
 */
void dma_resume(dma_t dma, uint16_t todo);

/**
 * @brief   Stop a DMA transfer on a stream
 *
 * @param[in] dma     logical DMA stream
 */
void dma_stop(dma_t dma);

/**
 * @brief   Wait for the end of a transfer
 *
 * @param[in] dma     logical DMA stream
 */
void dma_wait_for_end(dma_t dma);

/**
 * @brief   Configure a DMA stream for a new transfer
 *
 * @param[in]  dma     logical DMA stream
 * @param[in]  chan    DMA channel
 * @param[in]  src     source buffer
 * @param[out] dst     destination buffer
 * @param[in]  len     length to transfer
 * @param[in]  mode    DMA mode
 * @param[in]  flags   DMA configuration
 *
 * @return < 0 on error, 0 on success
 */
int dma_configure(dma_t dma, int chan, const void *src, void *dst, size_t len,
                  dma_mode_t mode, uint8_t flags);
```
where `dma_transfer` is a helper function using the other ones when a single transfer is needed.

I wonder whether we could make that API generic for all cpu or not.


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

  https://github.com/RIOT-OS/RIOT/pull/7658

-- Commit Summary --

  * cpu/stm32_common: add DMA implementation for F2/F4/F7
  * cpu/stm32_common: adapt SPI driver to use DMA
  * cpu/stm32_common: adapt UART driver to use DMA
  * boards/nucleo144-f413: adapt board config to use DMA

-- File Changes --

    M boards/nucleo144-f413/include/periph_conf.h (55)
    M cpu/stm32_common/include/periph_cpu_common.h (288)
    A cpu/stm32_common/periph/dma.c (306)
    M cpu/stm32_common/periph/spi.c (39)
    M cpu/stm32_common/periph/uart.c (53)
    M cpu/stm32f2/cpu.c (5)
    M cpu/stm32f2/include/periph_cpu.h (95)
    M cpu/stm32f4/cpu.c (6)
    M cpu/stm32f4/include/periph_cpu.h (92)
    M cpu/stm32f7/cpu.c (5)

-- Patch Links --

https://github.com/RIOT-OS/RIOT/pull/7658.patch
https://github.com/RIOT-OS/RIOT/pull/7658.diff

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/7658
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20170928/ba013807/attachment-0001.html>


More information about the notifications mailing list