cancel
Showing results for 
Search instead for 
Did you mean: 

H743 SPI slave receive not working in circular DMA mode

CKosa
Associate II

I try to make two H743 boards communicate each other. The master board sends a chunk (~300Bytes) unregularly and the slave board shall receive it and write it to memory via DMA.

  • Interrupt mode working correctly.
  • DMA Normal mode working correctly.
  • DMA Circular mode returns only zeros.

Is it restricted at all? The source code says:

/*   Circular mode restriction:
 
   (+) The DMA circular mode cannot be used when the SPI is configured in these modes:
 
     (++) Master 2Lines RxOnly
 
     (++) Master 1Line Rx
 */

So "slave mode" should work. But the HAL_SPI_Receive_DMA() function has following condition:

/* Set the number if data at current transfer */
  if (hspi->hdmarx->Init.Mode == DMA_CIRCULAR)
  {
    MODIFY_REG(hspi->Instance->CR2, SPI_CR2_TSIZE, 0);
  }
  else
  {
    MODIFY_REG(hspi->Instance->CR2, SPI_CR2_TSIZE, Size);
  }

Removing the condition doesn't help either.

The performance is a very important issue for me. So I don't always want to trigger a HAL_SPI_Receive_IT()

Snippets from my code:

stm32h7xx_hal_msp.c:

hdma_spi3_rx.Instance = DMA1_Stream0;
        hdma_spi3_rx.Init.Request = DMA_REQUEST_SPI3_RX;
        hdma_spi3_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
        hdma_spi3_rx.Init.PeriphInc = DMA_PINC_DISABLE;
        hdma_spi3_rx.Init.MemInc = DMA_MINC_ENABLE;
        hdma_spi3_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
        hdma_spi3_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
        hdma_spi3_rx.Init.Mode = DMA_NORMAL; //DMA_CIRCULAR NOT WORKING
        hdma_spi3_rx.Init.Priority = DMA_PRIORITY_LOW;
        hdma_spi3_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
        HAL_DMA_Init(&hdma_spi3_rx);

Can anybody help me?

  • How to make circular DMA Receive in slave mode work?
  • If it's not possible, how to trigger another single DMA receive after one transfer is complete? (Once the DMA started, it's busy also in normal mode.

Thanks for responses

1 REPLY 1
S.Ma
Principal

Not a H7 user, as for SPI, it might be the latest IP version.

From the 2nd gen SPI (with programmable bit length and FIFO), SPI Slave works with DMA in Cyclic mode if you take care of specifics

  • SPI 4 wire mode (1 TX and 1 RX DMA streams both in circular mode)
  • In your app, you want to set DMA start address to buffer beginning address, for example at NSS fall and.or rise edge (EXTI)
    • Flush or reset the SPI FIFO. The Tx one will be filled with old data. Either the SPI had FIFO reset bit, or you'll have to SW reset the whole SPI
    • Don't put IT on DMA nor SPI, just on NSS edge.

Maybe this will help. I was told H7 has xtra memory buses, restrictions etc... which I'm no xpert...