Skip to content

AVR section support for variables - feature

ccrause requested to merge ccrause/fpc-source:avr-section-support-var into main

Compiler support for the data memory sections .progmem (flash memory) and .eeprom was added. The compiler will generate the required low level instructions to access the respective memory section automatically. The support covers both classic AVR architecture and the newer unified memory architecture.

The section support is combined with type checking to ensure consistent and predictable behaviour. The following rules and behaviour have been implemented:

  • A variable, constant or type can be associated with a section. If the section name is not recognized the current behaviour is followed.
  • Read/write access to .eeprom space is supported, but only read access for the .progmem space is provided (due to the paged erase/write semantics).
  • The .progmem access is strictly enforced at declaration time, so only true constants, string literals and typed constants (if writeableconst is off) are allowed to be in .progmem space. Any typed const variables could also be allowed if required, since another access check is done in the code generator step to catch write operations to .progmem.
  • A local switch literalStringsInProgmem can be used to indicate storage of string literals in code in .progmem space.
  • Parameters to functions/procedures can also refer to sections, on the callee side the appropriate access code will be generated.
  • Type checking of parameters is extended to also compare section types.
  • Some build-in conversions from a sectioned type to a regular type is provided. This is used when a sectioned type is passed to a procedure with a regular parameter type (if a conversion is possible). This conversion doesn't apply when passing pointers or references.
  • A local switch convertSectionedStringsToTemp can be specified to preconvert sectioned shortstrings to regular temporary shortstrings before further processing. This reduces the dependence of section specific helper routines and may lead to smaller executable size in certain cases. When this switch is active, the only time a sectioned shortstring will not be converted is when it is passed as a parameter to a procedure with a matching sectioned parameter type.
  • Section information is added to symbols stored in ppu files so that sectioned types work across unit boundaries.
  • Helper code has been added to the AVR controller units to provide the low level access in the include files sectionhelpersh.inc and sectionhelpers.inc.
    • These include files provide low level EEPROM access and shortstring conversion and handling helpers for section specific data.
    • Added extra I/O registers and bit definitions required for EEPROM simulation to avrsim unit. Simulation of EEPROM access requires an updated version of fp-avrsim.

Merge request reports