What protocol does the IDE use to upload sketches to a board?

I got a logic analyzer today, and was probing the RX/TX pins for UART when I noticed a lot of extra packets that appeared while I was uploading a sketch. They weren't compatible with the baud rates I tested them against. Therefore, I am not sure what protocol I am seeing. Any ideas? (Uno)

If you select File:Preferences and turn on Verbose Outputs, I expect what is shown there is what you would see.

The baud rate used for the Uno is 115200. You can determine that from the avrdude -b option you will see in the command revealed in the verbose output. If you run the same command from the command line but add -v -v -v to it then you will see even more details of the upload.

It's UART (TTL serial), baud rate varies by board - you can find it for your board from the verbose output when uploading through the IDE or from examining boards.txt. The protocol for communicating with the bootloader over UART is usually stk500 (when boards.txt calls it "arduino" or "stk500" that's what it is) - at least for the AVR's. The Mega2560 uses stk500v2, and non-avr boards use different protocols (unsurprisingly). stk500 is binary data (ie, not just printable ASCII characters). I think stk500 was designed by atmel; there's a spec detailing it somewhere.

1 Like

Thanks! So in PulseView, would I select UART or try to find a decoder for STK500? Because nothing I see for the decoder options says STK500. (I am working with a pro mini & uno)

You would select UART.

Is it transmitting in HEX, ASCII, BIN, or what?

The STK500 protocol is described here:

http://www.tuxgraphics.org/common/src2/article07052/stk500_spec_AVR068.pdf

Is there a particular reason other than academic curiosity or the "new toy effect" that you're trying to look at the upload process with the logic analyzer?

1 Like

Stk500 is not a very GOOD protocol. I wouldn't expect most logic analyzers to decode it any further than the byte-at-a-time UART display.

During uploading, the binary codes of a sketch are transmitted from PC to the target MCU (the Arduino) frame-by-frame. These frames are known as Intel-Hex formatted frames. Each frame could be viewed as one packet. There is no way to see extra packets except the last frame which the PC sends to mark the end-of-file.

Example:

void setup() 
{
  Serial.begin(9600);
  Serial.print("Hello!");
}

void loop() 
{

}

Before uploading, the above sketch is converted into the following frames. The frames are prepared from the object file which we can't see in the Arduino IDE (in MASM assembler of 80x86, we can see the object files). Each frame consists of 6 fields, and each field has its own meaning. Each and every symbol (say, :, 1, 0, ...) of the Intel-Hex frame is transmitted by the Virtual UART Port of the PC under asynchronous Protocol. In asynchronous data TX/RX Protocol, data are sent/received character-by-character called asynchronous data frame. Thus, : is sent as 00111010 (0x3A) which is an 8-bit ASCII code of :; 1 is sent as 00110001 (0x31) which is the ASCII code of 1, and so on. An asynchronous data frame is constructed by concatenating 1 start bit, 8 data bits, 1 parity bit (optional), and 1 stop bit.

:100000000C9435000C945D000C945D000C945D0024
:100010000C945D000C945D000C945D000C945D00EC
:100020000C945D000C945D000C945D000C945D00DC
:100030000C945D000C945D000C945D000C945D00CC
:100040000C9458010C945D000C94C8010C94A2010E
:100050000C945D000C945D000C945D000C945D00AC
:100060000C945D000C945D007D0211241FBECFEF47
:10007000D8E0DEBFCDBF11E0A0E0B1E0EEE6F5E0F4
:1000800002C005900D92A831B107D9F721E0A8E18F
:10009000B1E001C01D92AE3BB207E1F710E0C5E34D
:1000A000D0E004C02197FE010E94AA02C433D10708
:1000B000C9F70E94FA010C94B5020C940000CF928B
:1000C000DF92EF92FF920F931F93CF93DF936C0118
:1000D0007A018B01C0E0D0E0CE15DF0589F0D801B0
:1000E0006D918D01D601ED91FC910190F081E02D93
:1000F000C6010995892B11F47E0102C02196ECCF2F
:10010000C701DF91CF911F910F91FF90EF90DF908A
:10011000CF900895FC01918D828D981761F0828DAA
:10012000DF01A80FB11D5D968C91928D9F5F9F732B
:10013000928F90E008958FEF9FEF0895FC01918DCD
:10014000828D981731F0828DE80FF11D858D90E03A
:1001500008958FEF9FEF0895FC01918D228D892FD7
:1001600090E0805C9F4F821B91098F7399270895BF
:1001700088E191E00E94AC0021E0892B09F420E0A5
:10018000822F0895FC01848DDF01A80FB11DA35AB1
:10019000BF4F2C91848D90E001968F739927848FA7
:1001A000A689B7892C93A089B1898C9180648C939E
:1001B000938D848D981306C00288F389E02D808189
:1001C0008F7D80830895EF92FF920F931F93CF93BB
:1001D000DF93EC0181E0888F9B8D8C8D981305C097
:1001E000E889F989808185FD24C0F62E0B8D10E009
:1001F0000F5F1F4F0F731127E02E8C8DE8120CC07C
:100200000FB607FCFACFE889F989808185FFF5CF21
:10021000CE010E94C200F1CF8B8DFE01E80FF11DCF
:10022000E35AFF4FF0820B8FEA89FB89808180625D
:1002300007C0EE89FF896083E889F989808180643D
:10024000808381E090E0DF91CF911F910F91FF902B
:10025000EF900895CF93DF93EC01888D8823C9F048
:10026000EA89FB89808185FD05C0A889B9898C91BF
:1002700086FD0FC00FB607FCF5CF808185FFF2CF5A
:10028000A889B9898C9185FFEDCFCE010E94C2006B
:10029000E7CFDF91CF91089580E090E0892B29F09E
:1002A0000E94B80081110C94000008950E94B002D1
:1002B0001F920F920FB60F9211242F933F938F939B
:1002C0009F93AF93BF938091BA019091BB01A0918E
:1002D000BC01B091BD013091B90123E0230F2D374E
:1002E00020F40196A11DB11D05C026E8230F02963A
:1002F000A11DB11D2093B9018093BA019093BB0158
:10030000A093BC01B093BD018091B5019091B6015D
:10031000A091B701B091B8010196A11DB11D8093C4
:10032000B5019093B601A093B701B093B801BF9106
:10033000AF919F918F913F912F910F900FBE0F9092
:100340001F9018951F920F920FB60F9211242F93A2
:100350003F934F935F936F937F938F939F93AF934D
:10036000BF93EF93FF9388E191E00E94C200FF9159
:10037000EF91BF91AF919F918F917F916F915F911D
:100380004F913F912F910F900FBE0F901F90189596
:100390001F920F920FB60F9211242F938F939F935A
:1003A000EF93FF93E0912801F09129018081E09182
:1003B0002E01F0912F0182FD12C0908180913101B8
:1003C0008F5F8F7320913201821751F0E0913101DC
:1003D000F0E0E85EFE4F958F8093310101C080818F
:1003E000FF91EF919F918F912F910F900FBE0F90E2
:1003F0001F901895789484B5826084BD84B581601F
:1004000084BD85B5826085BD85B5816085BD8091DF
:100410006E00816080936E00109281008091810057
:10042000826080938100809181008160809381004F
:10043000809180008160809380008091B100846011
:100440008093B1008091B00081608093B000809172
:100450007A00846080937A0080917A008260809331
:100460007A0080917A00816080937A0080917A008E
:10047000806880937A001092C100E0912801F09189
:10048000290182E08083E0912401F091250110820E
:10049000E0912601F09127018FEC808310923001CA
:1004A000E0912C01F0912D0186E08083E0912A01FA
:1004B000F0912B01808180618083E0912A01F0918D
:1004C0002B01808188608083E0912A01F0912B01CB
:1004D000808180688083E0912A01F0912B018081E6
:1004E0008F7D808346E050E060E171E088E191E03B
:1004F0000E945F000E944C01FDCFE8E1F1E0138211
:10050000128288EE93E0A0E0B0E084839583A68316
:10051000B78384E091E09183808385EC90E09587B8
:10052000848784EC90E09787868780EC90E0918BBD
:10053000808B81EC90E0938B828B82EC90E0958BAA
:10054000848B86EC90E0978B868B118E128E138EA7
:10055000148E0895EE0FFF1F0590F491E02D09947D
:0E05600081E090E0F8940C94B502F894FFCF7F
:10056E0000000000E3005F00AC008A009E002A013C
:08057E0048656C6C6F21000060
:00000001FF

Stk500 does NOT send Intel-hex frames.