0.4.7 Setup block and crash on photon with 0.4.7 (core ok)

@mdma
I have the same behaviour than this issue, I’ve got an application used by a number of users and today I got a new user that is unable to run it (it block), so I tried updating my core and photon and reproduce the issue since 0.4.7. It works with core and block with photon.
To be honest, each time a new firmware, each time pain and I need to investigate in the code because it breaks something. Last time was a too long setup time before calling cloud setup variable function from setup(), now it’s blocking for a reason I ignore and I have ton of other things to do instead debugging a application that worked fine since 1 year.

So to avoid spending time now on this issue, one dirty fix is to keep 0.4.5, so is there any option from spark dev to select firmware used (such as 0.4.5) (like in web ide ?)

Anyway I do not block in my setup() because I’m calling delay and yield in my potential loop. But I need to wait from a serial frame to come in setup() that can take up to 2/3 sec, so how can I achieve this ? Here the code I call from setup(). Tere are other before and after but this one blocks.

bool tinfo_setup(bool wait_data)
{
  bool ret = false;

  Serial.print("Initializing Teleinfo...");
  Serial.flush();

  #ifdef SPARK
  Serial1.begin(1200);  // Port série RX/TX on serial1 for Spark
  #endif

  // reset du timeout de detection de la teleinfo
  tinfo_last_frame = millis();

  // Init teleinfo
  tinfo.init();

  // Attacher les callback donc nous avons besoin
  tinfo.attachADPS(ADPSCallback);
  tinfo.attachData(DataCallback);
  tinfo.attachNewFrame(NewFrame);
  tinfo.attachUpdatedFrame(UpdatedFrame);

  // Doit-on attendre une ligne valide
  if (wait_data) {
    // ici on attend une trame complete ou le time out
    while ( !(status & STATUS_TINFO) && (millis()-tinfo_last_frame<TINFO_FRAME_TIMEOUT*1000)) {
      char c;
      // Envoyer le contenu de la serial au process teleinfo
      // les callback mettront le status à jour
      #ifdef SPARK
        while ( Serial1.available()) {
          c = Serial1.read();
          Serial.print(c);
          Serial.flush();
          tinfo.process(c);
          _yield();
          delay(5);
        }
      #else
        while (Serial.available()) {
          c = Serial1.read();
          Serial.print(c);
          Serial.flush();
          tinfo.process(c);
          _yield();
          delay(5);
        }
      #endif
      delay(5);
      _yield();
    }
  }

  ret = (status & STATUS_TINFO)?true:false;
  Serial.print("Init Teleinfo ");
  Serial.println(ret?"OK!":"Erreur!");

  return ret;

Here the serial output and after photo is blocked until I push reset button

Core Network settings
IP   : 192.168.1.208
Mask : 255.255.255.0
GW   : 192.168.1.254
SSDI : HOME-HOTSPOT
RSSI : -62dB
Compile avec les fonctions : BOARD V1.2  MCP23017 OLED TELEINFO RFM69 
Initializing MCP23017...Searching...Setup...OK!
Initializing OLED...Searching...Setup...OK!
Initializing RFM69...OK!
Initializing Teleinfo...|
ISOUS.15 <
HCH.000400294 Y
HCHP 000000000 S
PTE.HC.. S
IINST 001 X
IMAX 001 @
PAPP 00180 *
HHPH.3 ^
MOTDETAT 000000 B
.
ADCO 031428067147 B
OPTARIF HC.. <
ISOUS.15 <
HCH.000400294 Y
HCHP 000000000 S
PTE.HC.. S
IINST 001 X
IMAX 001 @
PAPP 00180 *
HHPH.3 ^
MOTDETAT 000000 B
.
ADCO 031428067

It’s like there Is a maximum duration time for setup() to execute ? Any what do do/not to do in setup() would be appreciated.

All source code is public and released here (lot of files)

Any idea ?