Opportunity for Faster Boot?

Hi,

Once again, excuse my ignorance on this one… I figured I would create a stand alone thread on this topic since it may be relevant to others. The boot time on the M2 is slower than my other systems in the vehicle causing some issues, and I am wondering if there is any way that could be sped up. What bootloader is used, and can any Arduino Due compatible bootloader be used? I think I read others have achieved something like 25-50ms with Optiboot. I’m not familiar with how to set that up, but before I dive into learning, I thought I would ask if something like this is even possible.

There is not really any bootloader on an Arduino Due. It boots directly to your code instantly upon start up. When you want to flash a new program there is a loader of sorts but it is in ROM. Since the bootloader isn’t called on start up it doesn’t take any time. And, since it’s in ROM you can’t change it even if you wanted to.

However, a quirk with the processor used in the Due and M2 is that the USB stack is hosted in code and built as part of your program. That means, while the processor boots instantly, the USB stack probably takes a bit of time to initialize and be ready to go.

Are you running your own Arduino sketch on the M2 or something pre-built like M2RET? Prebuilt binaries could have a delay on start up to allow things to settle before the program continues. You certainly need to be sure you have no delays upon start up.

I have a different design based around the Arduino Due processor (SAM3X) and it’s a vehicle control unit for electric cars. It boots very rapidly, faster than needed to start talking to drive train systems and other components. So, I know it’s possible.

I am running my own sketch. Mainly starting with one of your sketches that was designed to show traffic on both CAN ports.

This is my variable defs and startup. Does waiting for the USB stack interfere with running the rest of the code?

// Required libraries
#include “variant.h”
#include <due_can.h>
#include <M2_12VIO.h>
#include <pins_arduino.h>
#include <Arduino.h>
#include “M2_IO.h”
#include <pwm_lib.h>
M2_12VIO M2IO;

//Leave defined if you use native port, comment if using programming port
//This sketch could provide a lot of traffic so it might be best to use the
//native port
#define Serial SerialUSB

byte rpm1 = 0;
byte rpm2 = 0;
byte APP = 0;
byte Mux1 = 0;
byte Mux2 = 0;
byte RadFan = 0; //Porsche Radiator Fan signal - 7 bits long. Bit 8 is engine run status
byte RadFanUnCnvrt = 0; //GM Radiator Fan Signal is 8 bits long
byte TPS = 0; //Maybe GM Controller does not transmit - send APP instead, close enough
byte Coolant = 0; //Eng Coolant Temp
byte OilLvl = 0; //Eng Oil Level
byte OilPress = 0; //Oil Pressure
byte OilTemp = 0; //Oil Temperature
byte VehSpeed1 = 0; //Vehicle Speed
byte VehSpeed2 = 0; //Other Half Veh Speed
byte SpdL = 0;
byte SpdH = 0;
byte Cnt2 = 0;
byte EngTorqH = 0;
byte EngTorqL = 0;
byte CmndTorqH = 0;
byte CmndTorqL = 0;
byte Baro = 0;
byte PRNDL = 0x50;

uint16_t EngTorq = 0;
uint16_t CmndTorq = 0;
uint16_t TOS_TmTx = 0;
uint16_t TOS_Cnt = 0;
uint16_t TOS_TmMax = 65534;
uint16_t TOS_CntMax = 1023;

int Rvr_Input = 1; //Sets Analog Input 1 to be the input for reverse.
int TOS_Tm = 0;
int Timer = 0;
int value = 0;
int test = 0;
int Spd = 0;
int test2 = 0;
int RvrSwitch = 1;
int RPM = 0;
int VSS = 0;
unsigned long PrevTime=0;
unsigned long PreCntTm=0;
unsigned long LoopRate_17ms = 0;
unsigned long LoopRate_1000ms = 0;
unsigned long LoopRate_100ms = 0;
unsigned long LoopRate_13ms = 0;
unsigned long time_now = 0;

void setup()
{

M2IO.Init_12VIO(); // Initialize the M2I/O library
//M2IO.Setpin_12VIO(2, ON, SOURCE, PWM_PIN, 2, 20);
//M2IO.Setpin_12VIO(1, ON, SOURCE);

pinMode(Led5, OUTPUT); // Set the Green LED PIN as an OUTPUT
//pinMode(Led4, OUTPUT); // Set the Yellow LED PIN as an OUTPUT
//pinMode(Led3, OUTPUT); // Set the Yellow LED PIN as an OUTPUT
digitalWrite(Led5, LOW); // turn the Green LED ON by making the PIN LOW
// digitalWrite(Led4, HIGH); // turn the Yellow LED OFF by making the PIN HIGH
// digitalWrite(Led3, HIGH); // turn the Yellow LED OFF by making the PIN HIGH
M2IO.InitButton_12VIO(Rvr_Input); //Inits the input as a digital input for a button. Looks for voltage to set true. Use pullup resistor to use a ground input (ground will set false, so invert the logic)

//Serial.begin(115200);

// Initialize CAN0 and CAN1, Set the proper baud rates here
Can0.begin(CAN_BPS_500K);
Can1.begin(CAN_BPS_500K);

//By default there are 7 mailboxes for each device that are RX boxes
//This sets each mailbox to have an open filter that will accept extended
//or standard frames
//Ignore this bit - Unsure what it means. Copied from setup
int filter;
//extended
for (filter = 0; filter < 3; filter++) {
Can0.setRXFilter(filter, 0, 0, true);
Can1.setRXFilter(filter, 0, 0, true);
}
//standard
for (int filter = 3; filter < 7; filter++) {
Can0.setRXFilter(filter, 0, 0, false);
Can1.setRXFilter(filter, 0, 0, false);
}