Photon 2 STARTUP() time

How fast can I get user code running on the Photon 2? I have the following lines of code for a quick test,

void startupFunc(void) {
  lt1a = millis();
  pinMode(D7, OUTPUT);
  digitalWrite(D7, 0);
}

STARTUP(startupFunc());

When I print the value of millis() that was gotten during startup, it shows at 1139 ms.

However, when looking at the board from when the blue LED on D7 turns on when power is applied to when the startupFunc() gets called and turns off the blue LED, is about 2.65 seconds total.

I'm working with a bootloader that currently just waits for a timeout, but it prolongs my startup sequence between the Photon 2 and the co processor by starting them in series rather than parallel. I can probably work something else out but I was curious if there was still a way to get things going more quickly.

@jettonj, I was actually just discussing this with @rickkas7 yesterday. The "boot" time for the Photon2/P2 to get to the STARTUP function is 2.3 seconds and is not changeable. The RTL8721D used in the Photon2/P2 has a low power core (KM0) and a regular core (KM4). It seems the KM0 processor is used to validate the user firmware image prior to being run on the KM4 and this is what causes the boot delay.

BTW, to get an accurate time, you should use System.ticks() and System.ticksPerMicrosecond() to calculate the microseconds it takes to get to STARTUP.

Using System.ticks() and printing with lt1a/System.ticksPerMicrosecond()/1000 I get 1135 ms, so still about the same.

Are you saying the 2.3 second overhead includes the KM0 validating the ~256KB user image at 20 MHz, or that it happens after? I'm sure you've already looked into it but is there not a way for the KM4 to be validating instead?

The longest delay I see on (what I think is) the RTL8721D datasheet is Tboot of 200 ms.

I'm not positive that's the reason why it takes 2 seconds to boot; I vaguely remember hearing that but I may be mistaken. However, I do know that there is little chance of it being made faster because there is some good reason it can't be changed, I'm just not positive what that reason is.

@jettonj, to clarify, in my case, with my scope I measured the time between the hardware RESET line going high (button released) to pinMode()/digitalWriteFast() code setting a pin HIGH in a STARTUP function.

Understood. I would be interested to see what the KM0's systick timer looks like at this point.

Also from what I can tell the HAL provided systick just points to timer 4 of the RTL8721D, so there's probably some delay between power on and that timer getting initialized. That would explain some of the difference between the power on boot time and the printed time.

1 Like