cancel
Showing results for 
Search instead for 
Did you mean: 

DMA1 Not Working at 2 kHz Frequency, BDMA Works Fine (STM32H7, SPI)

eds
Associate III

Hi everyone,

I'm facing an issue with using DMA1 for SPI communication in my project. I'm trying to achieve a 2 kHz frequency, but DMA1 doesn't seem to work at this rate, whereas BDMA functions without any problems.

 This is my sampling task that is called with a timer interrupt,

 

if (!g_xGxStatus.txOngoing) {
    g_xGxStatus.sampleReady = IsDataReady(&pxHandler->s1);
    if (g_xGxStatus.sampleReady) {
        g_xGxStatus.txOngoing = true;
        HAL_GPIO_WritePin(pxHandler->s1.csPort, pxHandler->s1.csPin, GPIO_PIN_RESET);
        HAL_SPI_TransmitReceive_DMA(pxHandler->s1.pxSpi, (uint8_t*) DMA_TxBuffer1, (uint8_t*) DMA_RxBufferGyro1, 6);
    }
}

if (!g_xGyStatus.txOngoing && !g_xGzStatus.txOngoing) {
    if (Sel == 2) {
        g_xGyStatus.sampleReady = IsDataReady(&pxHandler->s3);
        if (g_xGyStatus.sampleReady) {
            g_xGyStatus.txOngoing = true;
            HAL_GPIO_WritePin(pxHandler->s2.csPort, pxHandler->s2.csPin, GPIO_PIN_RESET);
            HAL_SPI_TransmitReceive_DMA(pxHandler->s2.pxSpi, (uint8_t*) DMA_TxBuffer2, (uint8_t*) DMA_RxBufferGyro2, 6);
        }
    } else if (Sel == 3) {
        g_xGzStatus.sampleReady = IsDataReady(&pxHandler->s3);
        if (g_xGzStatus.sampleReady) {
            g_xGzStatus.txOngoing = true;
            HAL_GPIO_WritePin(pxHandler->s3.csPort, pxHandler->s3.csPin, GPIO_PIN_RESET);
            HAL_SPI_TransmitReceive_DMA(pxHandler->s3.pxSpi, (uint8_t*) DMA_TxBuffer3, (uint8_t*) DMA_RxBufferGyro3, 6);
        }
    }
}

 

and also my the callback function for SPI Transmit-Receive:

 

void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi) {

    if (hspi->Instance == SPI2) {
        HAL_GPIO_WritePin(g_xImuHandle.s1.csPort, g_xImuHandle.s1.csPin, GPIO_PIN_SET);
        g_xGxStatus.sampleReady = false;
        g_xGxStatus.txOngoing = false;
    }

}

 

5 REPLIES 5

Which 'H7?

> DMA1 doesn't seem to work at this rate

What are the symptoms?

Read out and check/post content of SPI and relevant DMA/DMAMUX registers, compare them to the working case, while figuring out differences using respective chapters in Reference Manual.

> BDMA functions without any problems.

I wonder, how could BDMA possibly work with SPI2, since there's no connectivity from SPI2 to DMAMUX2/BDMA.

JW

Moritz1
Associate III

Maybe it is the same issue I have?

Does your DMA maybe transfers no Data to the SPI peripheral?

https://community.st.com/t5/stm32-mcus-products/stm32h753-dma-sometimes-does-not-transfer-data/td-p/681583 

Hi JW,

>Which 'H7?

It is STM32H735RGV.

>What are the symptoms? 

I am getting either a 255 or 0 every 2-3 seconds. The data is also corrupted as well as the frequency. 

>I wonder, how could BDMA possibly work with SPI2, since there's no connectivity from SPI2 to DMAMUX2/BDMA.

I am using BDMA via SPI6, I am simply configuring both SPIs and DMAs with the same configuration but I have connected 2 sensors to SPI6 so I use one of the sensors' CS in every cycle. Other than that the procedure is the same. 

eds
Associate III

Hi,

I do not think so, as when I slow down my timer interrupt the DMA seems to be working fine. 

eds
Associate III

I have realized that the data I have been sending through DMA was corrupted. I put the data to be sent at the address 0x30000000 for the SPI2 using DMA1 and for some reason the data I put in to the buffer changes at start up. I do not know how to place the buffer so that the data is not corrupted. I am also not using cache for that very same reason.7