How to convert __flash to PROGMEM

I've converted a mixed Arduino Mega 2560 C,C++ to C++. My last holdout is storing a struct with default values in Flash Memory.

The Struct:

typedef struct
{
  uint8_t pulseMicroSeconds;
  uint8_t stepperIdleLockTime; 
  ...
  uint8_t  flags;
  float stepsPerMm[NabAxes];
  ...
}       settings_s;

Original flash code:

const __flash settings_s defaults = {\
    .pulseMicroSeconds = DefStepPulseMicroSeconds,
    .stepperIdleLockTime = DefStepperLockTime,
    ...
    .flags = DefFlags,
    .stepsPerMm[NabAxisX] = DefStepsPerMmX,
    .stepsPerMm[NabAxisY] = DefStepsPerMmY,
    .stepsPerMm[NabAxisZ] = DefStepsPerMmZ,
    ...
  };

New PROGMEM code:

const  settings_s defaults PROGMEM = {\
    .pulseMicroSeconds = DefStepPulseMicroSeconds,
    .stepperIdleLockTime = DefStepperLockTime,
    ...
    .flags = DefFlags,
    .stepsPerMm[NabAxisX] = DefStepsPerMmX,
    .stepsPerMm[NabAxisY] = DefStepsPerMmY,
    .stepsPerMm[NabAxisZ] = DefStepsPerMmZ,
    ...
  };

I'm getting an error for each of the array items: error: expected primary-expression before '.' token

What are the necessary steps to convert __flash to PROGMEM?

this compiles for me

const uint8_t NabAxisX = 0;
const uint8_t NabAxisY = 1;
const uint8_t NabAxisZ = 2;

const uint8_t DefStepPulseMicroSeconds = 10;
const uint8_t DefStepperLockTime = 11;
const uint8_t DefFlags = 1;

const uint8_t DefStepsPerMmX = 1;
const uint8_t DefStepsPerMmY = 1;
const uint8_t DefStepsPerMmZ = 1;

struct Settings_s {
    uint8_t  pulseMicroSeconds;
    uint8_t  stepperIdleLockTime;

    uint8_t  flags;
    uint8_t  stepsPerMm [3];
};

const PROGMEM Settings_s defaults = {
    .pulseMicroSeconds    = DefStepPulseMicroSeconds,
    .stepperIdleLockTime  = DefStepperLockTime,

    .flags                = DefFlags,
    .stepsPerMm = { DefStepsPerMmX, DefStepsPerMmY, DefStepsPerMmZ },
};

OK! Thanks.
I converted my code and that error is solved, however, I'm getting three (3)

sorry, unimplemented: non-trivial designated initializers not supported
};
^
sorry, unimplemented: non-trivial designated initializers not supported
sorry, unimplemented: non-trivial designated initializers not supported

I thought it might be the .flags, I commented that line and then there are an additional (4)

sorry, unimplemented: non-trivial designated initializers not supported
sorry, unimplemented: non-trivial designated initializers not supported
sorry, unimplemented: non-trivial designated initializers not supported
sorry, unimplemented: non-trivial designated initializers not supported

The Defxxx items are #define

    #define DefStepPulseMicroSeconds 10
    #define DefStepperLockTime 255 
    ...
  #define DefFlags  ((DefReportInches << StgBitReportInches)    \
                   | (DefLaserMode << StgBitLaserMode)                    \
                   | (DefInvertStepEnable << StgBitInvertStepEnable)  \
                   | (DefHardLimitEnable << StgBitHardLimitEnable)     \
                   | (DefHomingEnable << StgBitHomingEnable)          \
                   | (DefSoftLimitEnable << StgBitSoftLimitEnable)      \
                   | (DefInvertLimitPins << StgBitInvertLimitPins)        \
                   | (DefInvertProbePin << StgBitInvertProbePin))

    ...
    #define DefStepsPerMmX 80.0
    #define DefStepsPerMmY 80.0
    #define DefStepsPerMmZ 80.0

I've not ever have seen this message before. Any suggestions?

I converted the #define to const 'type'. Still getting the same 'sorry' messages.

Research on this 'sorry' message found another difference between C & C++, namely that the order if initialization must be the same as the struct! Once I fixed the order of items, it compiles.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.