Skip to main content
GG.2
Associate II
October 15, 2023
Solved

Enabling instruction prefetch in the HAL (potential bug)

  • October 15, 2023
  • 5 replies
  • 2932 views

Hello,

According to the reference manual RM0456 7.3.3:

"Prefetch is enabled by setting PRFTEN in FLASH_ACR.
PRFTEN must be set only if at least one wait state is needed to access the flash memory"

 

Compared to that I've seen that in the U5 HAL, in the function HAL_Init() there is a call to `__HAL_FLASH_PREFETCH_BUFFER_ENABLE()` (when `PREFETCH_ENABLE` is defined).

This means that prefetch might be enabled even when there are 0 wait states to access flash memory (because this is not enforced), contradicting what the reference manual says.

 

Is it intentional? or might cause undefined behavior?

Thank you

 

 

 

This topic has been closed for replies.
Best answer by mƎALLEm

Hello,

That' true the macro is called in the HAL: 

HAL_StatusTypeDef HAL_Init(void)
{
/* Configure Flash prefetch */
#if (PREFETCH_ENABLE != 0U)
__HAL_FLASH_PREFETCH_BUFFER_ENABLE();
#endif /* PREFETCH_ENABLE */

But the software flag is activated in the example itself in stm32u5xx_hal_conf.h file:

#define PREFETCH_ENABLE 1U /*!< Enable prefetch */

stm32u5xx_hal_conf.h file is not part of the HAL but part of your example or project.

So you need to set it to 0 in your case.

5 replies

Tesla DeLorean
Guru
October 15, 2023

Probably less consequential if the Flash can service with no delay, but yes language here seems awkward and could.be explained more clearly and reasoned. @Sarra.S 

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
ST Employee
October 16, 2023

Hello @GG.2, @Tesla DeLorean, 

Thank you for bringing this question to my attention! 

>>This means that prefetch might be enabled even when there are 0 wait states to access flash memory 

This case is not applicable in U5 Flash examples, in fact, all the examples run at 160MHz, according to this frequency, there are 4 wait states (Check RM) : 

SarraS_1-1697451396583.png

So prefetch has to be enabled, and PRFTEN must be set since there is more than 1 wait state needed. 

I hope this is much more clear.  

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
GG.2
GG.2Author
Associate II
October 16, 2023

The problem is that I'm running my own code, not the examples, and the HAL should not assume the HCLK frequency... In my case I run at 12MHZ range 4 with 0 WS

mƎALLEm
mƎALLEmBest answer
ST Technical Moderator
October 16, 2023

Hello,

That' true the macro is called in the HAL: 

HAL_StatusTypeDef HAL_Init(void)
{
/* Configure Flash prefetch */
#if (PREFETCH_ENABLE != 0U)
__HAL_FLASH_PREFETCH_BUFFER_ENABLE();
#endif /* PREFETCH_ENABLE */

But the software flag is activated in the example itself in stm32u5xx_hal_conf.h file:

#define PREFETCH_ENABLE 1U /*!< Enable prefetch */

stm32u5xx_hal_conf.h file is not part of the HAL but part of your example or project.

So you need to set it to 0 in your case.

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.