-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[AVR] Microchip changed the semantics of 16 bit register writes on newer cores #58395
Comments
I did some poking a the avr-gcc code to figure out which devices are affected by this change. Apparently all XMEGA cores require the low byte to be written first. Here are a few functions in gcc responsible for this: And here is a list of all the XMEGA cores. Maybe that helps a bit. |
fixed by https://reviews.llvm.org/D141752 |
Not completely, take for example volatile int* stv (int volatile *p, int volatile *q)
{
*q = 0;
*p++ = 0;
return p;
} compiled with
I didn't try all addressing modes, but at least the above two (indirect and post-increment) are not correct, because we have to obey the following access orders for multi-byte volatile data:
For an explanation, see for example Does avr-gcc properly work with 16-bit AVR I/O registers? on stackoverflow. A device is Xmega iff
|
I have uploaded a new version of my patch https://reviews.llvm.org/D141752, your new test is correctly
|
For 16-bit ports, the normal devices reqiure writing high byte first and then low byte. But the XMEGA devices require the reverse order. Fixes llvm#58395 Reviewed By: aykevl, jacquesguan Differential Revision: https://reviews.llvm.org/D141752
For 16-bit ports, the normal devices reqiure writing high byte first and then low byte. But the XMEGA devices require the reverse order. Fixes llvm/llvm-project#58395 Reviewed By: aykevl, jacquesguan Differential Revision: https://reviews.llvm.org/D141752
When accessing 16 bit registers like counters on an 8 bit AVR core, these accesses have to be split into two 8 bit register writes. To do this, the peripherals have a TEMP register that the CPU automatically writes to on the first write and a write to the other half of the target register yields a write of this temporary register and the currently written value into the 16 bit target register in the same cycle.
On old cores like an ATmega8, the datasheet states that you need to write the high byte first and then the low byte. See ATmega8 datasheet, page 78.. LLVM takes care of this here for writes and here for reads.
However, newer cores like the tinyAVR 1-series like an ATtiny817 require these writes to happen with the LOW byte first, followed by the high byte. See ATtiny817 datasheet, page 55. I didn't check any other datasheets yet about which other cores might be affected by this change.
I just ran into this when trying to use Rust on an ATtiny817. Writing to the counter register with a
u16
seemingly caused the low byte to be ignored or otherwise wrong all the time. Once I converted my writes manually to twou8
writes in the order specified by the datasheet, things started to work. Flipping them once more showed the same broken results as the singleu16
write.I also confirmed the wrong order by disassembling the resulting Rust program and comparing it to an equivalent C program compiled by
avr-gcc
. Theavr-gcc
compiled program was equivalent except for the write order of the two register halves.The text was updated successfully, but these errors were encountered: