Question
DMA1 Not Working at 2 kHz Frequency, BDMA Works Fine (STM32H7, SPI)
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;
}
}
