2021-07-13 09:14 AM
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
Solved! Go to Solution.
2021-07-13 09:41 AM
> 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.
2021-07-13 09:41 AM
> 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.
2021-07-13 10:51 AM
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
2021-07-13 11:14 AM
> 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.
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."