stm32-hal
stm32-hal copied to clipboard
STM32F4 - Flash.erase_page() never returns due to eop() never being set
It looks like there is a slight discrepancy between the implementation of the End Of Operation (eop) bit between the F3 and the F4 series, which prevents the erase_page() call from returning for the F4.
In RM0316 Rev 10 (for the F3x3/F3x8 series, I didn't check all of them) the EOP bit is set when the program / erase operation is completed.
However, in RM0090 Rev 21 (For the F4x5/F4x7/F4x9 series), the EOP bit is only set if the EOPIE interrupt is enabled:
I believe the fix will simply be removing the feature = "f4" from the following cfg_if. I haven't had the chance to make the change in the library, test, and submit a pull request - I worked around it by implementing erase_page() in a different way (The primary difference being I don't check eop - just bsy going low.)
https://github.com/David-OConnor/stm32-hal/blob/a728825cd38ac78d7d661be8ff199283becdaa42/src/flash/non_trustzone.rs#L307-L314
Also, for the following comment I can confirm the page as a u8 is passed into the register... very bizarre, but passing i in 1..12u8 does erase the proper areas of flash.
https://github.com/David-OConnor/stm32-hal/blob/a728825cd38ac78d7d661be8ff199283becdaa42/src/flash/non_trustzone.rs#L266