Enable factory reset boot mode without a user switch
The documentation at https://docs.micropython.org/en/latest/pyboard/general.html describes a "filesystem reset" boot mode which can be triggered by holding down the user switch during the power up boot sequence:
filesystem reset: resets the flash filesystem to its factory state, then boots in safe mode.
For supported MicroPython boards that do not have a user switch (e.g. SparkFun MicroMod STM32 Processor), is there any way to trigger a "filesystem reset" from software?
If not, would it be possible to add a new machine.factory_reset() function to enable this? (similar to the machine.reset() and machine.soft_reset() functions described in https://docs.micropython.org/en/latest/library/machine.html?highlight=reset#machine.reset)
For the sake of completeness, it would also be nice to support resetting into the "safe boot" boot mode from software as well through something like a machine.safe_reset() function.
stm32: Move factory reset files and code to separate source file.
The new function factory_reset_make_files() populates the given filesystem with the default factory files. It is defined with weak linkage so it can be overridden by a board.
This commit also brings some minor user-facing changes:
-
boot.py is now no longer created unconditionally if it doesn't exist, it is now only created when the filesystem is formatted and the other files are populated (so, before, if the user deleted boot.py it would be recreated at next boot; now it won't be).
-
pybcdc.inf and README.txt are only created if the board has USB, because they only really make sense if the filesystem is exposed via USB.