Skip to main content
Visitor II
February 28, 2025
Question

32bit SPI DMA, not triger SPI interrupt hold busy state

  • February 28, 2025
  • 1 reply
  • 475 views
Controller: STM32H750XBH6 
Development Environment: CubeMX + MDK V5.27
Issue Background: The DAC chip requires the use of 32-bit SPI. Currently, it works normally with a polling method. There is a need to use hardware SPI + DMA to increase the speed.
  • When only the following three items are changed to 8-bit mode, the single-byte DMA transmission can be sent multiple times, and the function is normal.

 

 

hspi2.Init.DataSize = SPI_DATASIZE_32BIT;---------------->8BIT
hdma_spi2_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;------->BYTE
hdma_spi2_tx.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;------>BYTE

 

 

  • In the current code, when using the HAL_SPI_Transmit_DMA() function for the first transmission, the waveform can be seen on the logic analyzer (it can enter the DMA interrupt), but it does not enter the SPI interrupt, causing SPI_Busy.

Jack_member_0-1740709851575.png

  • The current code, due to being in a Bus state, causes all subsequent DMA transmissions to return directly.
    Jack_member_1-1740710183529.png

    SPI Configure:

 

/* SPI2 init function */
void MX_SPI2_Init(void)
{

 /* USER CODE BEGIN SPI2_Init 0 */

 /* USER CODE END SPI2_Init 0 */

 /* USER CODE BEGIN SPI2_Init 1 */

 /* USER CODE END SPI2_Init 1 */
 hspi2.Instance = SPI2;
 hspi2.Init.Mode = SPI_MODE_MASTER;
 hspi2.Init.Direction = SPI_DIRECTION_2LINES;
 hspi2.Init.DataSize = SPI_DATASIZE_32BIT;
 hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
 hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
 hspi2.Init.NSS = SPI_NSS_SOFT;
 hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
 hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
 hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
 hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
 hspi2.Init.CRCPolynomial = 0x0;
 hspi2.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
 hspi2.Init.NSSPolarity = SPI_NSS_POLARITY_LOW;
 hspi2.Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;
 hspi2.Init.TxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
 hspi2.Init.RxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
 hspi2.Init.MasterSSIdleness = SPI_MASTER_SS_IDLENESS_00CYCLE;
 hspi2.Init.MasterInterDataIdleness = SPI_MASTER_INTERDATA_IDLENESS_00CYCLE;
 hspi2.Init.MasterReceiverAutoSusp = SPI_MASTER_RX_AUTOSUSP_DISABLE;
 hspi2.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_DISABLE;
 hspi2.Init.IOSwap = SPI_IO_SWAP_DISABLE;
 if (HAL_SPI_Init(&hspi2) != HAL_OK)
 {
 Error_Handler();
 }
 /* USER CODE BEGIN SPI2_Init 2 */

 /* USER CODE END SPI2_Init 2 */

}

 


DMA Configure:

 

void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle)
{

 GPIO_InitTypeDef GPIO_InitStruct = {0};
 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
 if(spiHandle->Instance==SPI2)
 {
 /* USER CODE BEGIN SPI2_MspInit 0 */

 /* USER CODE END SPI2_MspInit 0 */

 /** Initializes the peripherals clock
 */
 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_SPI2;
 PeriphClkInitStruct.Spi123ClockSelection = RCC_SPI123CLKSOURCE_PLL;
 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
 {
 Error_Handler();
 }

 /* SPI2 clock enable */
 __HAL_RCC_SPI2_CLK_ENABLE();

 __HAL_RCC_GPIOI_CLK_ENABLE();
 /**SPI2 GPIO Configuration
 PI1 ------> SPI2_SCK
 PI2 ------> SPI2_MISO
 PI3 ------> SPI2_MOSI
 */
 GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3;
 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
 GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
 HAL_GPIO_Init(GPIOI, &GPIO_InitStruct);

 /* SPI2 DMA Init */
 /* SPI2_TX Init */
 hdma_spi2_tx.Instance = DMA1_Stream0;
 hdma_spi2_tx.Init.Request = DMA_REQUEST_SPI2_TX;
 hdma_spi2_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
 hdma_spi2_tx.Init.PeriphInc = DMA_PINC_DISABLE;
 hdma_spi2_tx.Init.MemInc = DMA_MINC_ENABLE;
 hdma_spi2_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
 hdma_spi2_tx.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
 hdma_spi2_tx.Init.Mode = DMA_NORMAL;
 hdma_spi2_tx.Init.Priority = DMA_PRIORITY_LOW;
 hdma_spi2_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
 hdma_spi2_tx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
 hdma_spi2_tx.Init.MemBurst = DMA_MBURST_SINGLE;
 hdma_spi2_tx.Init.PeriphBurst = DMA_PBURST_SINGLE;
 if (HAL_DMA_Init(&hdma_spi2_tx) != HAL_OK)
 {
 Error_Handler();
 }

 __HAL_LINKDMA(spiHandle,hdmatx,hdma_spi2_tx);

 /* SPI2 interrupt Init */
 HAL_NVIC_SetPriority(SPI2_IRQn, 0, 0);
 HAL_NVIC_EnableIRQ(SPI2_IRQn);
 /* USER CODE BEGIN SPI2_MspInit 1 */

 /* USER CODE END SPI2_MspInit 1 */
 }
}​

 

 

    This topic has been closed for replies.

    1 reply

    Visitor II
    March 4, 2025

    maybe a misunderstanding of Polling vs. INT-mode, vs. DMA-mode?

    If you use SPI in DMA mode: you should only use DMA related interrupts, such as DMA done.
    INT-mode related interrupts are not needed - and I think, not enabled, not used anymore.
    If you configure SPI in DMA mode -potentially the INT-mode related interrupts are not enabled, not configured (and not needed).

    Just in INT-mode, you get interrupts related to SPI busy, empty etc. In DMA-mode - and if you get DMA INTs - these are the only hooks to synchronize. You cannot mix INT and DMA-mode (and their interrupts).