Hi all!
I was very interested in checking out what exactly happens during a sketch upload. I hooked up a logic analyzer to my board to check out what exactly occurs when the Arduino IDE uploads a sketch and I used the STK500 protocol docs (ver. 1) to decode the messages. Most of them are straightforward, but there was one set I could not find much information on: what are Universal Commands (command value 0x56) exactly? I've read the brief description and I've tried to decode the ones I see in my capture but I just don't get them
Specifically, after avrdude reads the device signature, it proceeds to execute the following Universal commands:
0x56 0x50 0x00 0x00 0x00 0x20 (3 times in a row)
0x56 0x58 0x08 0x00 0x00 0x20 (3 times in a row)
0x56 0x50 0x08 0x00 0x00 0x20 (3 times in a row)
It sends the same 9 commands after all memory pages have been updated too (for whatever reason).
So I dug around and tried to find something that could help decode the values 0x50, 0x58, 0x08. A couple posts online just say "Oh, those are just commands, the bootloader ignores them anyway", which... is fine, but completely useless. Skimming through the AVR datasheet and instruction set amounted to nothing (although I admit that I can easily overlook things).
I understand that the 4 bytes in every universal command are some sort of separate command, but... what, exactly ? What protocol does it belong to? What other command types exist? And, most importantly, what do they decode to? Are they important to the upload process? It has something to do with settings fuse and lock bits, but if someone could just break these commands into pieces and explain what they denote, I'll be really grateful!
Hi John! I must be really careless lately, because I honestly cannot find the source you're referring to . Once I'd posted my original question, I did notice the pseudocode in the STK500 comms protocol v1 doc appendix, where we can see the values 0x50 0x00 and 0x58 0x08 being used to read the low and high fuse bytes. But I can't find any place where these instructions are described in detail. Could you kindly provide a link to this instruction set you mention?
Additionally, I have 2 more questions:
why would avrdude read each fuse byte 3 times (seems a bit redundant)?
why would it do so before AND after uploading a sketch?
I think you will have to look at the edit history of avrdude to find out details like that. Perhaps some device didn't work right if you didn't check three times before and after.
Found it! Thanks a lot for the clarification!
So the multiple serial read instructions are probably historic at this point. Just for the fun of it, I will follow the trail you suggest and try to find out why they still exist in avrdude . Thanks again!
First, if you turn on additional debugging for avrdude (add "-vvvv" to the command line - each v increases the amount of debugging info), it will tell you what it's doing:
Then, armed with the info that this has something to do with "safemode", you can find avrdude documentation:
Ie - it's reading the fuses three times each to make sure that it's getting the same value each time. (I'm not aware of the history that apparently created the need for this. Seems weird.)
Amusingly (?) the bootloader doesn't actually "support" the commands to read the fuses (or any of the other "Universal" commands); it just eats the arguments and returns 0...
Interesting trivia indeed, thanks @westfw! If it were possible to mark 2 posts as solutions, I'd mark this one as well since it answers another one of my several questions. Maybe this particular bootloader is programmed to ignore these commands just to make the bootloader code smaller (i.e. more space for application code)?