Page 1 of 1

[STM32F407VGT6] How to erase flash fs?

Posted: Thu Sep 05, 2019 6:24 pm
by vbolshakov
I compile micropython to DIY MORE STM32-407 board (with STM32F407VGT6 MCU) using STM32F4DISC as starting point.
My mpconfigboard.h available at https://pastebin.com/A6J2XcLb

Almost all works without problem, but content of flash filesystem is garbage. I can format it from PC and all OK till next firmware update.

What wrong with my config?

Re: [STM32F407VGT6] How to erase flash fs?

Posted: Thu Sep 05, 2019 6:46 pm
by Roberthh
You must not write the file system both from the PC and from MicroPython at the same time. The PC caches the FS is not awayr of changes made by MicroPython. And if you write from the PC, take care to unmount (eject) it before you unplug the device.
You can format the flash from Micropython at the REPL prompt by:

import uos
uos.VfsFat.mkfs("/flash")

Unmount (eject) the flash drive from the PC before you do that.
P.S.: Because of this continuous risk of damaging the file system I do not enable the device a flash drive. Instead I use tools like pyboard.py, rshell or ampy to transfer files. In case of a LAN connection, you can use Webrepl, rshell of ftp.

Re: [STM32F407VGT6] How to erase flash fs?

Posted: Thu Sep 05, 2019 6:48 pm
by vbolshakov
There is garbage after flashing.
Also noted that after flashing STM32F4DISC-20190529-v1.11.dfu to STM32F4DISC i got same problems - there is filenames on FS, but content is garbage.

Re: [STM32F407VGT6] How to erase flash fs?

Posted: Thu Sep 05, 2019 6:59 pm
by vbolshakov
And flash formatting not working...

>>> import uos
>>> uos.VfsFat.mkfs("/flash")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'readblocks'

Re: [STM32F407VGT6] How to erase flash fs?

Posted: Thu Sep 05, 2019 7:33 pm
by Roberthh
Your're right. Looks Like I'm lost in versions an dialects. Then you can still erase flash with make erase and re-flash the firmware. That's the crowbar method.

Re: [STM32F407VGT6] How to erase flash fs?

Posted: Thu Sep 05, 2019 7:45 pm
by vbolshakov
There is a note somewhere about flash fs part not erased on firmware upgrade to save it content...

Finaly found solution - USER button press and hold while reseting board cleared flash fs. Tried this method before, but able may be not holding long enough or released in wrong moment.

Re: [STM32F407VGT6] How to erase flash fs?

Posted: Thu Sep 05, 2019 8:06 pm
by vbolshakov
Boot modes are:
...
3. Green and orange LED together, *filesystem reset*: resets the flash
filesystem to its factory state, then boots in safe mode.

So with only one LED with invers controll very hard to get this mode...

Re: [STM32F407VGT6] How to erase flash fs?

Posted: Thu Sep 05, 2019 10:09 pm
by dhylands
If your mpconfigboard.h file only defines LED1 and doesn't define LED2, then the code will use a slightly different behaviour. Instead it will flash the LED 1, 2, or 3 times.

See: https://github.com/micropython/micropyt ... ain.c#L328

Re: [STM32F407VGT6] How to erase flash fs?

Posted: Fri Sep 06, 2019 10:21 am
by vbolshakov
Thank you. I already found this part, but don't understand why i can't catch right moment.
For one STM32F4DISCOVERY, that work strange i plan to build firmware with explicitly format flash fs on boot.