2019-02-22 07:58 AM
I'm trying to use HAL_SPI_Abort() os SPI2 interface in DMA mode for STM32F769NI MCU and program hangs in it in loop:
while (hspi->State != HAL_SPI_STATE_ABORT)
So it seams that State should be changed in interrupts, I think that in SPI2_IRQn interrupt, which is not trigerred in DMA mode.
Could you please advice.
BR,
Krystian
2019-02-26 05:01 AM
Issue is still not resolved on my side - please advice.
I'm including my SPI configuration:
SpiHandle.Instance = SPI2;
SpiHandle.Init.Mode = SPI_MODE_MASTER;
SpiHandle.Init.Direction = SPI_DIRECTION_2LINES;
SpiHandle.Init.NSS = SPI_NSS_SOFT;
SpiHandle.Init.CLKPolarity = SPI_POLARITY_LOW;
SpiHandle.Init.CLKPhase = SPI_PHASE_1EDGE;
SpiHandle.Init.TIMode = SPI_TIMODE_DISABLE;
SpiHandle.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
SpiHandle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;
SpiHandle.Init.DataSize = SPI_DATASIZE_8BIT;
SpiHandle.Init.FirstBit = SPI_FIRSTBIT_MSB;
SpiHandle.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
SpiHandle.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
SpiHandle.Init.CRCPolynomial = 7;
GPIO_InitStruct.Pin = GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF5_SPI;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
//MISO
GPIO_InitStruct.Pin = GPIO_PIN_14;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF5_SPI;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
//MOSI
GPIO_InitStruct.Pin = GPIO_PIN_15;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF5_SPI;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
hdma_rx.Instance = DMA1_Stream3;
hdma_rx.Init.Channel = DMA_CHANNEL_0;
hdma_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
hdma_rx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
hdma_rx.Init.MemBurst = DMA_MBURST_SINGLE;
hdma_rx.Init.PeriphBurst = DMA_MBURST_SINGLE;
hdma_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
hdma_rx.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_rx.Init.MemInc = DMA_MINC_ENABLE;
hdma_rx.Init.Mode = DMA_NORMAL;
hdma_rx.Init.Priority = DMA_PRIORITY_HIGH;
if ( SpiHandle.Init.DataSize > SPI_DATASIZE_8BIT )
{
hdma_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
hdma_rx.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
}else{
hdma_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
hdma_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
}
if ( HAL_OK != HAL_DMA_Init(hdma_rx) ) { return (-1); }
__HAL_LINKDMA(SpiHandle, hdmarx, hdma_rx);
hdma_tx.Instance = DMA1_Stream4;
hdma_tx.Init.Channel = DMA_CHANNEL_0;
hdma_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
hdma_tx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
hdma_tx.Init.MemBurst = DMA_MBURST_SINGLE;
hdma_tx.Init.PeriphBurst = DMA_MBURST_SINGLE;
hdma_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
hdma_tx.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_tx.Init.MemInc = DMA_MINC_ENABLE;
hdma_tx.Init.Mode = DMA_NORMAL;
hdma_tx.Init.Priority = DMA_PRIORITY_LOW;
if ( pSpiHandler->pHalHandler->Init.DataSize > SPI_DATASIZE_8BIT )
{
hdma_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
hdma_tx.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
}else{
hdma_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
hdma_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
}
if ( HAL_OK != HAL_DMA_Init(hdma_tx) ) { return (-1); }
// Associate the initialized DMA handle to the the SPI handle
__HAL_LINKDMA(SpiHandle, hdmatx, hdma_tx);
// rx
HAL_NVIC_SetPriority(DMA1_Stream3_IRQn, 1, 0);
HAL_NVIC_ClearPendingIRQ(DMA1_Stream3_IRQno);
HAL_NVIC_EnableIRQ(DMA1_Stream3_IRQn);
// tx
HAL_NVIC_SetPriority(DMA1_Stream4_IRQn, 1, 0);
HAL_NVIC_ClearPendingIRQ(DMA1_Stream4_IRQn);
HAL_NVIC_EnableIRQ(DMA1_Stream4_IRQn);