AnsweredAssumed Answered

Bug in HAL_DMA_Init()?

Question asked by HarjitS on Nov 6, 2016

Part: STM32F411

I've got a SPI transmit buffer that is 16 bytes long and I send SPI messages that are 16 bytes long.

The SPI bus runs at 50MHz, so I want to use DMA and the FIFO. In addition, I want to use the FIFO to read data from memory in Word mode and write data to the SPI peripheral in Byte mode - I believe this is called unpacking (Table 31 of RM0383, Figure 28 of RM0383).

So, I program the DMA as follows:

    /* Peripheral DMA init*/
 
    hdma_spi1_tx.Instance = DMA2_Stream3;
    hdma_spi1_tx.Init.Channel = DMA_CHANNEL_3;
    hdma_spi1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
    hdma_spi1_tx.Init.PeriphInc = DMA_PINC_DISABLE;
    hdma_spi1_tx.Init.MemInc = DMA_MINC_ENABLE;
    hdma_spi1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
    hdma_spi1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
    hdma_spi1_tx.Init.Mode = DMA_NORMAL;
    hdma_spi1_tx.Init.Priority = DMA_PRIORITY_MEDIUM;
    hdma_spi1_tx.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
    hdma_spi1_tx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_HALFFULL;
    hdma_spi1_tx.Init.MemBurst = DMA_MBURST_SINGLE;
    hdma_spi1_tx.Init.PeriphBurst = DMA_PBURST_SINGLE;
    if (HAL_DMA_Init(&hdma_spi1_tx) != HAL_OK)
    {
      Error_Handler();
    }

When this snippet of code is executed, Error_Handler() ends up getting called. When I dig into why, it seems that DMA_CheckFifoParam() is looking for the FIFOThreshold to be DMA_FIFO_THRESHOLD_FULL.

From reading the reference manual (RM0383), there is no such requirement. I think the code in DMA_CheckFifoParam() is mapping the requirement for burst transfers.

Thanks in advance.

Outcomes