adafruit / circuitpython

CircuitPython - a Python implementation for teaching coding with microcontrollers
https://circuitpython.org
Other
4.1k stars 1.22k forks source link

STM32: Move NVM into filesystem region #3059

Open hierophect opened 4 years ago

hierophect commented 4 years ago

Currently, enabling the NVM module for STM32 requires an entire sector of memory, which is at minimum 16kB on the STM32. This section should be reworked to use a small amount of memory after the filesystem through the existing internal flash manager, rather than an entire linker-defined sector.

dhalbert commented 4 years ago

If the filesystem and NVM share a single erase sector, then a write to either the filesystem or NVM will erase the page temporarily and will cause data in the other functionality to be wrong temporarily. So the writes will have to be atomic from the other functionality's point of view.

hierophect commented 4 years ago

@dhalbert the filesystem is cached, but I guess NVM cannot be since the user counts on anything they write being saved right away. So I think the implementation would need to flush the filesystem cache every time NVM writes, but not vice versa.

dhalbert commented 4 years ago

The scenario I am thinking of is:

  1. User writes to nvm
  2. page erase happens
  3. host computer fetches filesystem data; this must be locked out until 4.
  4. nvm write completes
hierophect commented 4 years ago

@dhalbert yeah that's why I suggested putting it in the internal_flash module, it should just be alongside the rest of the flash operations where everything is guaranteed to be sequential.