1
\$\begingroup\$

I want to store calibration data on a microcontroller (namely the STM32 line) however with a large amount of flash memory available to ustilise, I wondered if there is a standard area of memory that is typicaly cordoned off for such hardcoded user constants.

My initial thought is to put the data in the last page of the flash memory. This is the furthest from the programming code which starts in the first page and thus unlikely to corrupt the programming code.

Is there a generic rule of thumb for location of writing such constants into flash? (like in the last pages of Flash)

\$\endgroup\$
  • 2
    \$\begingroup\$ Wherever you place it, you can remove that region from your linker script to ensure that the program code, and space you left for constants won't collide. \$\endgroup\$ – Colin Aug 6 at 12:20
  • \$\begingroup\$ I typically use Keil when using arm devices, so im unfamiliar with how to alter this here (linker script), but appreciate the tip. I'll do some digging in this regard but i think it centres around the scatter file. \$\endgroup\$ – Pop24 Aug 6 at 14:24
  • \$\begingroup\$ It's unclear if you plan to change this at runtime. If you do, beware erase block boundaries, and ideally pick a region that is exactly an erase block. Also note some flash memories permit overwriting further from the erase state but those with ECC typically do not, and often the minimum write size would be an ECC unit of perhaps a double word. \$\endgroup\$ – Chris Stratton Aug 6 at 14:31
  • \$\begingroup\$ @ChrisStratton Its changing at run time only if the device is in calibration mode, this is well controlled and only I have the ability to so. Once calibrated it will write the calibration data to flash and then resume normal operation. Ill make sure in these regards to read the reference manual thouroughly thanks for the heads up! \$\endgroup\$ – Pop24 Aug 6 at 14:37
  • 1
    \$\begingroup\$ @Pop24 if you're using the arm compiler within keil it's known as a scatter file, and found via the project properties. \$\endgroup\$ – Colin Aug 6 at 14:39
4
\$\begingroup\$

Some micro-controllers have protected areas, which require additional steps to program and erase. Calibration parameters are usually stored in such areas, as they usually survive a firmware update. Other micro-controllers have areas of the flash that behave as EEPROM (single byte erase instead of sector erase). Parameters can be stored in such areas. If neither option is available to you, where ever is convenient is OK, as long as the programmer that comes after you knows the convention.

\$\endgroup\$
  • \$\begingroup\$ +1 for the tip on protecting data, its not something I'd need at the moment for this particular device but its definitely worth knowing for future projects! \$\endgroup\$ – Pop24 Aug 6 at 14:26
  • \$\begingroup\$ I suppose that really it is just a matter of convenience and as microcontrollers differ so much there is no generic place to put this data. \$\endgroup\$ – Pop24 Aug 6 at 14:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.