Atmega32U4 cheatsheet summary

Go To Last Post
12 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

After some months of work, I would like to share with you a little project I was playing with.

There are still mistakes but its mostly done.

 

All the data was gathered from the datasheet and some from public infromation on the OCD registers, which I don't yet know if correct for this chip.

Plus I noticed that JTAG flash programming interface is in essence the same as the HVPP just without the 'HV' part, so I documented it as such.

 

 

Attachment(s): 

Last Edited: Mon. Feb 26, 2018 - 09:28 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Note that Atmel/Microchip already have a document called, "ATmega16U4/32U4 - Summary Datasheet"

 

http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7766-8-bit-AVR-ATmega16U4-32U4_Summary.pdf

 

So it would be helpful to give your document - and the thread - a different name.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oops, didn't notice that.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I wanted some community feedback on this summary, especially if I missed something important.

Where else should I share it?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

maximlevitsky wrote:
Where else should I share it?
Here is just fine. Anyone interested will likely read the tiny/mega forum in their travels.

 

Moderator

 

PS personally I thought it looked like a fairly amazing piece of work. Not sure of the point in recounting the AVR opcode summary. For one that is in every datasheet anyway but also, anyone writing Asm (presumably the intended author?) will be using a copy of the full opcode manual anyway. (and how many 32U4 users would write in Asm?). But the rest of the stuff looked like an amazing amount of work . Of course the 32U4 is not going to be everyone's cup of tea. The majority of posts we see here tend to be about the 48/88/168/328 family (the latter especially because it is the chip at the heart of most Arduino) or they are about the 164/324/644/1284 family (and most recently these all signing, all dancing tiny817 things!). We don't see many posts from 32U4 users (or really many about any of the mega-USB chips, which is a shame) so your audience could be fairly limited.

 

BTW to keep this "alive" you might want to consider making a more formal introduction to it and posting in the Tutorial Forum (follow thread naming and so on that you see in other threads there). The entire Tutorial Forum spreads across just 6 pages of thread titles so that way it will remain visible for all time (here in tiny/mega it will slowly make its way off the first page and into oblivion)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The optcode summary is mostly about various non obvious limitations of the instruction set which are only documented in the ISA manual which is fairly long and lacks an summary.

(stuff like say LDI being able to only work on high 16 registers,  being unable to use X register with an offset, etc)

 

Also some instructions are just aliases, which I also pointed out.

My goal I think, is to create a toy GUI debugger for this chip using JTAG/OCD interface and 2nd Arduino acting as a JTAGICE replacement. Might as well do some reverse engineering if the information I have is not up to date.

 

Atmega32U4 is used in Arduino micro, and various arduino derived products, so I made a focus on it, plus it has very nice USB controller, which is even nicer that I thought initially.

 

Good idea to make the tutorial post about this. I will also share this soon in editable format so anybody could make its own additions/adapt to other AVR chips (of which, lot of data in this summary would be very similar)

 

Thanks!!

Best regards,

         Maxim Levitsky

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

my guess is that the clk count for calls and ret are wrong (the counts are for chips with more than 16 bit PC)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The Atmega32U4 datasheet insists that this part has the 22 bit PC, it lists the extended jmp/call instructions, it mentions this in programming part, etc.

This is one of the things that I guess that I need to verify on the real chip.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do you mean this in the datasheet?

 

 

That does look like a copy/paste error from the datasheet of a larger device.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This and various other places. I thought that maybe this chip indeed uses 22 bit PC and ISA, and just sets upper bits to 0. I'll check this soon.

Last Edited: Tue. Feb 27, 2018 - 01:37 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

 

The "Instruction Set Summary" table in the ATmega32U4's datasheet [ref. 7766J, 04/2016] appears to be wrong !

 

I've tested the CALL and RET instructions' behaviour, and:

- the CALL instruction only pushes 2 bytes on the stack,

- the CALL and RET only take 4 cycles each -- instead of 5 cycles.

Of course, I've checked I was testing the 4-byte absolute call CALL instruction, not the 2-byte relative call RCALL instruction.

 

Actually, this corresponds to the data in the "AVR Instruction Set Manual" [ref. 0856L, 11/2016] since the PC register is only 16-bit wide.

 

Moreover, in the datasheet one can read: "The device Program Counter (PC) is 16 bits wide, thus addressing the 32K program memory locations" [§ 5.1 "In-System Reprogrammable Flash Program Memory"].

Last Edited: Fri. Jul 12, 2019 - 01:52 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There's a sticky thread for posting this kind of thing:

 

https://www.avrfreaks.net/forum/...

 

(it looks like you are right - they've done the classic copy/paste thing and used the instruction summary from an AVR with > 128K flash)