ESP8266 / pinmode strangeness

I have a piece of code like so:

const int PINS[] PROGMEM = {
  D1,   //GPIO5
  D2,   //GPIO4 
  D3,   //GPIO0
  D5,   //GPIO14
  D6,   //GPIO12
  D7    //GPIO13
};

Serial.begin(115200);
for(int i=0; i<MAX_INPUTS; i++){
  Serial.print(PINS[i]);
  pinMode(PINS[i], INPUT_PULLUP);
}

This runs ok, but I don’t need Serial.print() for troubleshooting anymore…so I remove it.
Now I’m getting stack errors and endless reboot cycles:
Decoding stack results
0x40209e54: loop_wrapper() at C:\Users\Dazed\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266\core_esp8266_main.cpp line 180

I think Serial.print() is perhaps casting the variable in some way that causes pinMode to accept it.
inserting a delay(10) or delay(200) instead does not fix the crash. Commenting out the pinmode line fixes the crash.

I have also tried the following (which worked):

const int PINS[] PROGMEM = {
  D1,   //GPIO5
  D2,   //GPIO4 
  D3,   //GPIO0
  D5,   //GPIO14
  D6,   //GPIO12
  D7    //GPIO13
};

Serial.begin(115200);
for(int i=0; i<MAX_INPUTS; i++){
  //Serial.print(PINS[i]);
  //pinMode(PINS[i], INPUT_PULLUP);
}

int i = 0;
pinMode(PINS[i], INPUT_PULLUP);
pinMode(PINS[1], INPUT_PULLUP);
pinMode(PINS[2], INPUT_PULLUP);

It may seem strange to reference pins through an array object, but this makes it very easy to:
A) configure which pins or how many to read via web interface
B) indicate whether they are meant to be normally closed or normally open
C) iterate through them and apply de-bounce filtering before triggering a response

I’d like to understand what Serial.print() might be doing that causes looped pinmode to say “Yup, looks good” or how that’s different from the later code. I’m guessing this relates to pointer handling or maybe type casting somewhere along the way…but I don’t actually understand what’s really happening.

Those are not Arduino programs, those are snippets. Please show an ENTIRE program that illustrates the problem.
(It could be just a sample, it does not have to be YOUR program).

By the way, it is not unusual to reference pins through an array.

I'd bet a coffee that you just miscalculated the value of MAX_INPUTS and overflowed the array bounds.

pinMode(PINS[i], INPUT_PULLUP);

Since when is that the way to read data from 'PROGMEM" ?
also really there can hardly be a need to use progmem for something like that.

const int PINS[]  = {
  D1,   //GPIO5
  D2,   //GPIO4
  D3,   //GPIO0
  D5,   //GPIO14
  D6,   //GPIO12
  D7    //GPIO13
};


for(int i=0; i<6; i++){
  pinMode(PINS[i], INPUT_PULLUP);
}

This should work though.

I'm a little behind on follow-up.

Deva_Rishi, you are correct.
It was foolish to use progmem. I'm not really sure where I got the idea that it made sense.
There is plenty of memory for variables....so... I don't know what I was thinking.

Your other comment about how I was reading data out of progmem is probably more to the point though. That would seem to be the issue.

Thanks for the help.

:sunglasses: