othane/mos — pull request #4 by othane (2014-06-05 04:21:35+00:00)
Title: disable interrupts during flash erase/writes

according to the datasheet for the stm32f373:
"On the contrary, during a program/erase operation
to the Flash memory, any attempt to read the Flash
memory will stall the bus. The read operation will
proceed correctly once the program/erase operation
has completed. This means that code or data fetches
cannot be made while a program/erase operation is
ongoing"

and according to the stm32f107 datasheet:
"if a read/write operation is initiated during
programming, (BSY bit set), the CPU stalls until
the ongoing main Flash memory programming is over"

so that coupled with the fact that the unlocking and locking of flash
should all be done with interrupts disabled so we can guarantee we write
the unlock registers back to back (else unlock will fail along with
flash erase) means we might as well wrap the erase and writes to flash
in a critical section, otherwise a interrupt might run but will be
stalled until the flash becomes free and god knows what will happen
then.