Skip to main content
Visitor II
September 25, 2019
Question

Is there a way to tell the Cosmic compiler *not* to initialize EEPROM?

  • September 25, 2019
  • 1 reply
  • 708 views

In a project I'm working on, I am using the internal EEPROM of the STM8L151.

I do not initialize the variables (of course), but the compiler automatically set them all to 0. This is a bit of a problem because my code looks for 0xFF to see whether or not the variables have been previously written. And with 0 being a valid value for most of them, this distinction cannot be made.

Now, I realise that in production this is no big deal, because I can simply just not program the EEPROM, but in debugging it is a right royal pain in the neck.

I have gone through the Cosmic documentation, but couldn't find anything.

So, does anyone have a solution?

Best regards,

Rob

    This topic has been closed for replies.

    1 reply

    Explorer
    September 25, 2019

    I don't know Cosmic compiler specific, but according to the C standards, a value of 0 is assumed if you do not initialize global/static variables.

    That means, outside of function scope,

    int myVariable;

    is equivalent to

    int myVariable = 0;