4 years, 8 months ago.

Very strange error, some code which does not execute seem to crash the MCU unless commented out

I have a very strange error.

I have a function which never gets called in my code. However, despite this it causes my board to crash if certain lines are uncommented. The function is as follows:

include the mbed library with this snippet

bool readConnectBlocks(){  
  string info;  
  while (true){
    int size = 0;
    char s[64];
    //if (!(KWPReceiveBlock(s, 64, size))) return false;
    //if (size == 0) return false;
    if (s[2] == '\x09') break;
    if (s[2] != '\xF6') {
      //return false;
    //string text = string(s);
    //info += text.substr(3, size-2);
    //if (!KWPSendAckBlock()) return false;
  return true;

If I uncomment any one of those commented lines, my code seems to crash. I should mention the code compiles without any errors, even with all the above lines uncommented.

I do not understand why this is happening, especially since this function is never called in the rest of my code...

I should mention I am using an STM32F413ZH (Nucleo-F413ZH) for which I have (successfully) manually modified the mbed-dev source to add this board as a new target.

Thanks, James

Be the first to answer this question.