digitalWrite() -> Hard Fault ZeroMKR

Hello,

I have an issue with digital write, when I call try to set a state of a pin the micro hard faults, I lose USB programming and I need to double press reset to force enter bootloader mode to program it again.

I have extracted this code from a larger program of mine as an example only. I did anyone else have his issue with the M0 core boards?

expected result: code runs to print line “Bank Done”
**Actual result **: code prints “In Loop” and hard faults at for loop.

work arraound : insert delay(1); after digital write

Arduino IDE 1.8.8 and SamD21 M0 lib 1.6.20

The code

const uint8_t bankPins[]    = {2, 3, 4, 5};         //2  3  4  5 

const uint8_t SW1Button     = 6;
const uint8_t SW2Button     = 7;

// the setup function runs once when you press reset or power the board
void setup() {

  Serial.begin(9600);
  while (!Serial);    // wait for the serial port to open
  Serial.println("Hello Tester V0.1.1");
  // Set up inputs
  pinMode(SW1Button, INPUT_PULLUP);
  pinMode(SW2Button, INPUT_PULLUP);
  
  // Set up outputs
  pinMode(LED_BUILTIN, OUTPUT);
  for(int i = 0; i<=3; i++)pinMode(bankPins[i],  OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  Serial.println("In Loop");
  for(int i = 0; i<=3; i++) 
  {
    digitalWrite(bankPins[i], HIGH);                    // wait for a second
    //delay(1);
  }
  Serial.println("Bank Done");
  
}

Try removing this line :

 while (!Serial);    // wait for the serial port to open

I have read that the MKRZero controller hangs if the while loop is used and the application never runs.