AnsweredAssumed Answered

Two problems that I have identified in the L4 HAL code that you should be interested in....

Question asked by pevy.andy on Jun 16, 2017
Latest reply on Dec 18, 2017 by Imen D

Two problems that I have identified in the L4 HAL code that you should probably be interested in....

 

Firstly in the SPI FIFO Flush code:

The FIFO can operate in 8 or 16 bit mode, but the 2 bits that are used to track the number of bytes stored in the FIFO can get out of step with the actual content, if the FIFO is set to 16 bit mode.

 

This means that when you next get data on the channel, it reads out  data that was left over from a previous transfer before the new data.

 

To fix this I have had to force the relevant interface into 8 bit mode before doing the flush.


/**
* @brief Flush the RX fifo.
* @param hspi: pointer to a SPI_HandleTypeDef structure that contains
* the configuration information for the specified SPI module.
* @retval HAL status
*/
HAL_StatusTypeDef PPT_HAL_SPIEx_FlushRxFifo(SPI_HandleTypeDef *hspi)
{
__IO uint32_t tmpreg;

uint8_t count = 0;

 

// Added.....
/* set fifo rx thresold according the reception data length: 8 bit */
SET_BIT(hspi->Instance->CR2, SPI_RXFIFO_THRESHOLD);
// /Added

 

while((hspi->Instance->SR & SPI_FLAG_FRLVL) != SPI_FRLVL_EMPTY)
{
count++;
tmpreg = hspi->Instance->DR;


UNUSED(tmpreg); /* To avoid GCC warning */


if(count == SPI_FIFO_SIZE)
{
   return HAL_TIMEOUT;
}
}
   return HAL_OK;
}

 

Next, to make the RTC issue a wakeup interrupt the wakeup timer (RTC_FLAG_WUTF) flag must be cleared when enabling the RTC.

 

If this is not done, the wakeup happens but no interrupt is generated.

 

void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
{

    if(hrtc->Instance==RTC)
    {
        /* Peripheral clock enable */
       __HAL_RCC_RTC_ENABLE();

 

    /* Peripheral interrupt init*/
    HAL_NVIC_SetPriority(RTC_WKUP_IRQn, 5, 0);
    HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn);

// Added
// Need this here until Cube is fixed. [AP] [BUGFIX]
    __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF);
// /Added

    }
}

Outcomes