Problems with my own Project based on Arduino Zero

I am playing with my own developed board, based on the Arduino Zero schematic, I tried to make it as similar as the Arduino Zero, searching for the highest compatibility with the Arduino Libraries, except that there is no EDBG Debugger.

The SAMD21 MCU is coming directly from Atmel, that means has not been configured yet, no FUSE bits, no bootloader, etc.

I connected my board using an ATMEL ICE programmer in the SWD pins, flashed succesfully the Arduino bootloader and started downloading my first programs playing with Digital I/O successfully.

I am trying now to test all the hardware piece by piece (Digital I/O, Analog I/O, Communications Serial, etc), using small sketches that I can easily debug. I have still not jumped into the Atmel Studio, because I feel myself very comfortable using the Arduino IDE.

I am having two kind of problems so far:

  • first, the board does not boot automatically, I have to unplug-plug the power supply, and it still doesn´t boot, it seems that I have to RESET some pin, it takes me an effort to start the board playing with some pins, I don´t know still the combination that boots the program.
  • Second issue is regarding the native USB, I can not see it altogether. I plug an USB cable but I can´t see it in my Linux computer (lsusb command), and the program itself does not go further than the SETUP. It can be a hardware issue, or some missed configuration in the MCU itself

Can you give any idea or advice?.

This is the program I am using to check USB activity:

const int ledPin =  9;             // number of the LED pin
const int speakerPin = 8;          // bumber of Buzzer Pin
const int DIPin = 5;               // bumber of Digital Input Pin  <- Entrada Digital a chequear!!

int ledState = LOW;                // ledState used to set the LED
unsigned long previousMillis = 0;  // will store last time LED was updated
const long interval = 2000;        // interval at which to blink (milliseconds)

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(speakerPin, OUTPUT);
  pinMode(DIPin, INPUT);
}  ///// FIN DE SETUP /////

void loop() {

  // BEEP CADA 5 SG PARA ENTERARME POGRAMA ACTIVO ---------------------------------------
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;
    
    // Make a Beep in each transition
    for (int i=0; i<500; i++) {  // generate a 1KHz tone for 1/2 second
       digitalWrite(speakerPin, HIGH);
       delayMicroseconds(50);
       digitalWrite(speakerPin, LOW);
       delayMicroseconds(50);
    }
  }

  // COMPROBACION ENTRADAS DIGITALES    --------------------------------------- 
  bool DI;
  DI = digitalRead(DIPin);
  if (DI) {
      if (ledState == LOW) {
      ledState = HIGH;
    } else {
      ledState = LOW;
    }
    digitalWrite(ledPin, ledState);      
  }
  
} ///// FIN DE LOOP /////

OK, I have identified that there was a hardware error, USB + and - pins were shortcuted.

I can see that a raw SAMD21 MCU (coming from ATMEL factory) can not be identified by the computer through the native USB port, but as soon as you flash the arduino bootloader, the computer sees the USB connection as an "Arduino S.A." device. This makes perfect sense.

So my problem/issue can be redefined in the following way: How does the arduino bootloader starts a flasehd program sketch?, what combination of pins (Reset, USB, whatsoever), is the arduino bootloader expecting to start the program?

Or better, where can I find information aobut the functionality of this arduino bootloader?. in addition to github of course. ArduinoCore-samd/board_startup.c at master · arduino/ArduinoCore-samd · GitHub

The workflow is in the main.c file. As you can see, the CPU first check if the RESET button has been pressed twice : if yes, it stay in bootloader and wait for a code to be uploaded via USB. If not : it checks is a program is already flashed. If not, it stays in the bootloader and wait for an upload. If there is already a program : it checks for the alignment of vector table (I'm unsure about this). In other case, it execute the application Reset_Handler : it starts the program uploaded.