Skip to main content
Graduate II
August 1, 2020
Question

USE_HAL_***_REGISTER_CALLBACKS and HAL_SPI_xxxCpltCallback not called

  • August 1, 2020
  • 0 replies
  • 633 views

After each project update, CubeMX 5x/6x changes the values of all USE_HAL_***_REGISTER_CALLBACKS definitions in stm32h7xx_hal_conf.h header file. This makes it extremely difficult to use the callback functions.

PS:

Hi, today I lost the whole day to find out why the H743 doesn't work

void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi)

and other Callback related SPIs do not work with H743.

This is the function that sends the data but does not call the callback

void test()
{
 uint8_t buffer[] = {1,2,3,4};
 HAL_SPI_Transmit_IT (&hspi1,buffer, sizeof (buffer) );
}

I want to ask if this is a mistake or has another idea.

at F7xxx it works normally and at the end of the transmission the function is called

SPI_CloseTx_ISR (hspi);

and it is in it that this callback is called.

STM32H7xx_HAL_Driver\Src\stm32h7xx_hal_spi

static void SPI_TxISR_8BIT(SPI_HandleTypeDef hspi)
 
{
 
 / Transmit data in 8 Bit mode */
 
 *(__IO uint8_t *)&hspi->Instance->TXDR = *((uint8_t *)hspi->pTxBuffPtr);
 
 hspi->pTxBuffPtr += sizeof(uint8_t);
 
 hspi->TxXferCount--;
 
 /* Disable IT if no more data excepted /
 
 if (hspi->TxXferCount == 0UL)
 
 {
 
#if defined(USE_SPI_RELOAD_TRANSFER)
 
 / Check if there is any request to reload /
 
 if (hspi->Reload.Requested == 1UL)
 
 {
 
 hspi->TxXferSize = hspi->Reload.TxXferSize;
 
 hspi->TxXferCount = hspi->Reload.TxXferSize;
 
 hspi->pTxBuffPtr = hspi->Reload.pTxBuffPtr;
 
 }
 
 else
 
 {
 
 / Disable TXP interrupts /
 
 __HAL_SPI_DISABLE_IT(hspi, SPI_IT_TXP);
 
 }
 
#else 
 
 / Disable TXP interrupts /
 
 __HAL_SPI_DISABLE_IT(hspi, SPI_IT_TXP);
 
#endif / USE_HSPI_RELOAD_TRANSFER */
 
 }
 
}

STM32F7xx_HAL_Driver\Src\stm32f7xx_hal_spi.c

/**
 
@brief Handle the data 8-bit transmit in Interrupt mode.
@param hspi pointer to a SPI_HandleTypeDef structure that contains
the configuration information for SPI module.
@retval None
*/
static void SPI_TxISR_8BIT(struct __SPI_HandleTypeDef *hspi)
{
 *(__IO uint8_t )&hspi->Instance->DR = (hspi->pTxBuffPtr);
 hspi->pTxBuffPtr++;
 hspi->TxXferCount--;
 if (hspi->TxXferCount == 0U)
 
 {
 
#if (USE_SPI_CRC != 0U)
 
 if (hspi->Init.CRCCalculation == SPI_CRCCALCULATION_ENABLE)
 
 {
 
 /* Enable CRC Transmission /
 
 SET_BIT(hspi->Instance->CR1, SPI_CR1_CRCNEXT);
 
 }
 
#endif / USE_SPI_CRC */
 
 SPI_CloseTx_ISR(hspi);
 
 }
 
}

This happens in versions V1.6.0, V1.7.0 and V1.8.0,

/* SPI in mode Transmitter -------------------------------------------------*/
 if (HAL_IS_BIT_CLR(trigger, SPI_FLAG_UDR) && HAL_IS_BIT_SET(trigger, SPI_FLAG_TXP) && HAL_IS_BIT_CLR(trigger, SPI_FLAG_DXP))
 {
 hspi->TxISR(hspi);
 handled = 1UL;
 }
 
#if defined(USE_SPI_RELOAD_TRANSFER)
 /* SPI Reload -------------------------------------------------*/
 if (HAL_IS_BIT_SET(trigger, SPI_FLAG_TSERF))
 {
 hspi->Reload.Requested = 0UL;
 __HAL_SPI_CLEAR_TSERFFLAG(hspi);
 }
#endif /* USE_HSPI_RELOAD_TRANSFER */
 
 if (handled != 0UL)
 {
 return;
 }
 
 /* SPI End Of Transfer: DMA or IT based transfer */
 if (HAL_IS_BIT_SET(trigger, SPI_FLAG_EOT))

as far as I understand the function is merged into the above function, but `handled` is always `handled = 1UL; `

here is solution from me

 /* SPI in mode Transmitter -------------------------------------------------*/
 if (HAL_IS_BIT_CLR(trigger, SPI_FLAG_UDR) && HAL_IS_BIT_SET(trigger, SPI_FLAG_TXP) && HAL_IS_BIT_CLR(trigger, SPI_FLAG_DXP))
 {
 hspi->TxISR(hspi);
// handled = 1 ; //-bobby
 handled = hspi->TxXferCount ; //+bobby
 }
 
#if defined(USE_SPI_RELOAD_TRANSFER)
 /* SPI Reload -------------------------------------------------*/
 if (HAL_IS_BIT_SET(trigger, SPI_FLAG_TSERF))
 {
 hspi->Reload.Requested = 0UL;
 __HAL_SPI_CLEAR_TSERFFLAG(hspi);
 }
#endif /* USE_HSPI_RELOAD_TRANSFER */
 
 if (handled != 0UL)
 {
 return;
 }
 /* SPI End Of Transfer: DMA or IT based transfer */
//	if (HAL_IS_BIT_SET(trigger, SPI_FLAG_EOT)) // -bobby
	if ((HAL_IS_BIT_SET(trigger, SPI_FLAG_EOT))||(HAL_IS_BIT_SET(hspi->Instance->SR, SPI_FLAG_TXTF)))	//+bobby
 {
 /* Clear EOT/TXTF/SUSP flag */
 __HAL_SPI_CLEAR_EOTFLAG(hspi);
 __HAL_SPI_CLEAR_TXTFFLAG(hspi);
 __HAL_SPI_CLEAR_SUSPFLAG(hspi);

    This topic has been closed for replies.