Correct. Opening the serial port with standard settings will make the USB-UART adapter (which is ATmega8u2 on the mega2560 board) assert the DTR (data terminal ready) line, which is connected to the nreset of the Mega2560 via a capacitor (AC-coupled signal). See schematics.
So opening the serial port with standard settings (assert DTR on port open) will reset the Mega2560.
When it is reset, oscillator will be started according to its fuse settings (this may take a tiny time). The first piece of code that will execute is the bootloader. The Mega2560 is flashed with the STK500v2 bootloader.
It has a timeout for acceping UART bootloader commands for flashing. If no flashing commands are coming in, the MCU will boot your actual application after the timeout.
The value for this timeout is 1 second.
Once the application is booted, it will start execution by running the reset vector (provided by avr-gcc) and then it finally enters the main function of the Arduino core, which after some initialization goes into your
setup() function. So, there’s a lot of time that passes until you get the chance to execute your first command in
setup() – if
Serial.begin(..) isn’t the first one, more time will pass until the serial is initialized and ready to accept commands (at least writing them in the serial RX buffer, processing them is then up to your application).
You can exactly measure how much time is passing by using a oscilloscope or a logic analyzer and tracing the RESET signal (available on header) and an arbitrary GPIO pin which you
pinMode(..,OUTPUT); digitalWrite(..,HIGH); high as the first commands in your
setup(). The time passing between reset being activated and the GPIO pin going high is then the time it takes to enter the