cancel
Showing results for 
Search instead for 
Did you mean: 

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

Pevy.Andy
Associate III
Posted on June 16, 2017 at 09:36

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

    }

}

#stm32l4-hal-spi-and-rtc-bugs.
3 REPLIES 3
Imen.D
ST Employee
Posted on June 16, 2017 at 13:18

Hi

Pevy.Andy

,

Thank you again for your report issues and your contribution to improve our products.

I will check then report internally these issues if confirmed.

Best Regards

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Imen.D
ST Employee
Posted on June 22, 2017 at 14:31

Hi

Pevy.Andy

,

After investigation on your SPI issue,

your problem is not related to the HAL_SPIEx_FlushRxFifo function.

Indeed, the SPI_FLAG_FRLVL is not used to track the number of bytes stored in the FIFO but to track if the FIFO (that can be able to store 32bit) is Full(32bit), quater (8bit) or half(16bit).

On top of that, if you are escaping from a 8bit transfer, SPI_RXFIFO_THRESHOLD is already set in CR2 register. Concerning your point 'it reads out data that was left over from a previous transfer before the new data.', This is the specific to a FIFO, and indicated in the STM32L4 reference manual:

A read access to the SPIx_DR register returns the oldest value stored in RXFIFO that has not been read yet.

So, your problem is not related to function HAL_SPIEx_FlushRxFifo. Maybe you should to check SPI distant and be sure that SPI master and slave are stopped before call this function.

Regards

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Imen.D
ST Employee
Posted on December 18, 2017 at 11:25

Hello

,

About

RTC issue and m

issing clear of WUTF flagwhen it is about enabling the wakeup interrupt service.

I think

there is a wrong usage of the HAL that leads to flag not being cleared.

The WTUF Falg is cleared when enabling the service.

HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock){.... /* Clear flag Wake-Up */ __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF);....}The flag is also cleared in IRQHandlervoid HAL_RTCEx_WakeUpTimerIRQHandler(RTC_HandleTypeDef *hrtc){... /* Clear the WAKEUPTIMER interrupt pending bit */ __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF);}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

All RTC API starting WakeUp Timer do clear the flag internally. So, there should be not need to add addition clear.

In case of several HAL_RTC_Init() during the application lifetime, there shall be always a HAL_RTC_DeInit() call prior to new HAL_RTC_Init().

Best Regards

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen