cancel
Showing results for 
Search instead for 
Did you mean: 

L4R7 prefetch enabling and disabling

NArnd
Associate III

Hello,

Does anybody know if there is any prerequisite when enabling or disabling the prefetch buffer?

More specifically, in the Nucleo L4R5ZI sleep example the prefetch buffer is disabled in main() just before the main loop. It is never re-enabled after this. (Bit FLASH_ACR_PRFTEN.)

   __HAL_FLASH_PREFETCH_BUFFER_DISABLE();

   __HAL_FLASH_PREFETCH_BUFFER_ENABLE();

Since the prefetch buffer is enabled at reset / power up, the existence of an ENABLE macro suggests that it can be re-enabled, but I haven't been able to find out if this is done in the background by the MCU HW or if you must give the MCU some clock cycles to adjust itself.

Greatful for your input.

Best regards

Niclas

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

> Does anybody know if there is any prerequisite when enabling or disabling the prefetch buffer?

The RM just says to set/reset the bit, and that's all the ST examples do.

> Since the prefetch buffer is enabled at reset 

PRFTEN = 0 at reset, at least per the RM.

0693W00000BdaA4QAJ.png

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

3 REPLIES 3
TDK
Guru

> Does anybody know if there is any prerequisite when enabling or disabling the prefetch buffer?

The RM just says to set/reset the bit, and that's all the ST examples do.

> Since the prefetch buffer is enabled at reset 

PRFTEN = 0 at reset, at least per the RM.

0693W00000BdaA4QAJ.png

If you feel a post has answered your question, please click "Accept as Solution".
NArnd
Associate III

Thank you.

And thank you for pointing out that I had got the PRFTEN reset state wrong.

In comment to "... that's all the ST examples do.":

Why does only the sleep mode example disable the prefetch buffer and why does none of the no-sleep mode examples even mention it?

Also, why does the sleep mode example disable a setting that is already disabled by reset state?

It blanket sets all GPIO to very high speed analog. (The stop1 mode example sets all to (implicitly) low speed analog which is more reasonable. Also there are probably a number of pins that should not be set to floating on the Nucleo board as it might break other components' inputs.)

My point is that at least the sleep mode example is rather a selection of more or less sloppy hints than a consistent, well commented, reference solution.

BR /Niclas

TDK
Guru

> Why does only the sleep mode example disable the prefetch buffer and why does none of the no-sleep mode examples even mention it?

The prefetch is enabled based on the PREFETCH_ENABLE define in the HAL configuration file. It's disabled in all the examples I saw.

https://github.com/STMicroelectronics/STM32CubeL4/blob/5e1553e07706491bd11f4edd304e093b6e4b83a4/Projects/NUCLEO-L4R5ZI/Examples/PWR/PWR_SLEEP/Inc/stm32l4xx_hal_conf.h#L168

Presumably, no other examples mention it because it's not relevant to what the examples are doing. For example, using UART doesn't care if it's enabled or disabled.

> Also, why does the sleep mode example disable a setting that is already disabled by reset state?

I didn't write the example so I can only guess. One reason would be to ensure it's disabled regardless of what is done prior to entering sleep. Another would be to call explicit attention to it rather than hiding it in HAL somewhere so the user is more likely to understand it should be off to decrease power consumption.

> It blanket sets all GPIO to very high speed analog.

Not sure if OSPEED setting matters if the pin is in analog mode. The RM says that in analog mode "The Schmitt trigger input is deactivated, providing zero consumption for every analog value of the I/O pin."

If you feel a post has answered your question, please click "Accept as Solution".