Please explain how program is loaded to Arduino

I have two questions - I'm trying to understand how program is loaded into Arduino when I use virtual serial port. Basically I want to understand how it is implemented in Arduino Environment. How program code is distinguished from just simple data transfered to Arduino through serial port? (The question is about technical explanation, not about how it is doable through Arduino IDE)

  • Second question is what is done inside Duemilanove bootloader? I haven't succeeded to find any good description of that. Could you please point me to any?

Thanks in advance

Second question is what is done inside Duemilanove bootloader? I haven't succeeded to find any good description of that

You can see exactly what it does - the source code is in the distribution in hardware/bootloaders/atmega/ATmegaBOOT_168.c

AWOL, thanks for pointing to the source. It really explains a lot.

So, what I was able to figure out from the code that Bootloader does the following:

  1. Initializes some processor parameters

  2. Reads characters from UART (USB/COM port in our case) in case there is 'd' character command sent to UART it reads subsequent bytes which contain program code to be loaded into flash memory. (There are also some other commands could be sent to bootloader on startup)

  3. Executes app_start function (which I guess is loaded user program)

As I understand a kind of RESET signal is sent to CPU when UART communication is started, is it? Please correct me if I'm wrong somewhere.

As I understand a kind of RESET signal is sent to CPU when UART communication is started, is it? Please correct me if I'm wrong somewhere.

Yes, When you click on upload the Arduino IDE toggles the DTR control signal on the virtual comm port just before handing off control to AVRDUDE program in the PC for performing the actual upload. On the Arduino board the USB serial conveter chip's (FTDI) DTR signal is wired through a capacitor to cause a hardware reset of the AVR chip, which then starts the bootloader program to become active.

Lefty

Yes, When you click on upload the Arduino IDE toggles the DTR control signal on the virtual comm port just before handing off control to AVRDUDE program in the PC for performing the actual upload. On the Arduino board the USB serial conveter chip’s (FTDI) DTR signal is wired through a capacitor to cause a hardware reset of the AVR chip, which then starts the bootloader program to become active.

Wow, sounds good :slight_smile: It means that I can restart AVR from USB
host by calling serialPort.setDTR(true);

BTW why this capacitor is used? I found it on the Duemillanove circuit
diagram. There is also some strange for me thing which is called RESET-EN coming from DRT. What does it mean?

(now I’m talking about this one http://arduino.cc/en/uploads/Main/arduino-duemilanove-schematic.pdf)

The reset-en is a link that can be cut to disable the serial DTR reset. It gets in the way sometimes (everytime a serial link is established it flags DTR which then resets the Arduino, often not a desired behaviour.)