-
Notifications
You must be signed in to change notification settings - Fork 79
devices: add basic support for ATtiny1626 #185
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
Conversation
Hi, thanks a lot for your contribution! Just a heads-up, I am holding off merging new chips right now until #157 is merged, which quite significantly changes the way the register definitions are generated. I will ping you once this change has landed so you can rebase your changes ontop of it.
Hm, probably means that some patches are necessary. Check the generated SVD file for the register in question to see whether the definitions looks good. If not, you'll need to write a patch to fix it. If you need help with that, don't hesitate asking! |
Thanks.
The generated SVD file looks sane (see below). The baseAddress of VPORTA is 0 and the addressOffset of DIR is 0 too, so VPORTA.DIR has address 0, which is indeed correct. It looks like rust is unable to access memory address 0 [1]. [1] https://users.rust-lang.org/t/reading-from-physical-address-0x0/117408/2
|
Here's the notification: #157 was merged 🎉 Please rebase your work ontop of the new code-generation. You should be able to make out the new structure in |
I just checked the datasheet for the MCU, and it seems address 0x0 is correct; contrary to usual (old?) AVR chips, this one seems to have IO space mapped to data space at 0x0 instead of 0x20 like the other ones. I think the issue may be that Rust inserts a panic check for address 0x0 before actually dereferencing, if so we will probably require assembly in some form, or some fix in the compiler. I would have thought |
Maybe svd2rust can learn to special case address 0 and somehow interface with a library provided symbol for read/write access to address 0? I think hardcoding platform-specific assembly in |
Thanks for the notification! Regarding the address 0x0 issue. I've compiled the following code and used avr-objdump to check the output binary:
As you can see, the code immediately panics instead of even trying to access address 0x0. When using e.g. VPORTB instead of VPORTA, the resulting binary looks good:
|
5885a55
to
a1a99cd
Compare
Okay, as the |
In the meantime, I asked about this on Zulip, and it seems the access to 0 issue could be fixed via the compiler, with a small addition. It will require an RFC, so it may take a moment to arrive, but then we'd solve the issue for all MCUs, and without loosing access to anything. Edit: it appears an RFC is unneeded, so it can be fixed relatively fast. I'll write a proper PR soon. |
Thanks a lot for your help and fast response! How should we continue? Should I opt out VPORTA.DIR to get this merged or do you prefer waiting for your PR to get merged? |
I'd remove VPORTA.DIR for now and then add it back later once the compiler supports it. Adding it back is not a breaking change, so we can do this at any time. |
97ca55d
to
11750a5
Compare
Pull in the ATDF file from Microchip and add all the necessary plumbing around the code-base to make it compile. It hasn't been tested much yet. So far, I've tested some accesses to the PORTx register on hardware. The common patches for the xmega series seem reasonable, so I've applied them. Additionally, VPORTA.DIR was patched out for 2 series devices because it doesn't work. VPORTA.DIR is mapped to memory address 0x0. This address is commonly used as NULL pointer and it looks like rust isn't able to handle accesses to that address [1]. To check that, I've created a short example programm accessing VPORTA.DIR [2] and checking the resulting binary with avr-objdump [3]. The produced binary panics as soon as I'm trying to access VPORTA.DIR [4]. By changing the code to access a different register of VPORTA like OUT, the code produces a sane binary [5]. [1] https://users.rust-lang.org/t/reading-from-physical-address-0x0/117408/2 [2] ``` #![no_std] #![no_main] use panic_halt as _; pub extern "C" fn main() -> ! { let dp = unsafe { avr_device::attiny1626::Peripherals::steal() }; dp.vporta.dir().write(|w| w.set(1 << 7)); loop {} } ``` [3] `avr-objdump -D -m tinyavr2 target/avr-none/debug/test.elf` [4] ``` 000000a0 <main>: a0: 81 e0 ldi r24, 0x01 ; 1 a2: 80 93 00 38 sts 0x3800, r24 ; 0x803800 <DEVICE_PERIPHERALS> a6: 0e 94 59 00 call 0xb2 ; 0xb2 <_ZN4core9panicking14panic_nounwind17h63d81beb9bde1088E> ``` [5] ``` 000000a0 <main>: a0: 81 e0 ldi r24, 0x01 ; 1 a2: 80 93 00 38 sts 0x3800, r24 ; 0x803800 <DEVICE_PERIPHERALS> a6: 80 e8 ldi r24, 0x80 ; 128 a8: 81 b9 out 0x01, r24 ; 1 aa: ff cf rjmp .-2 ; 0xaa <.Luint32_t_name+0x3> ``` Signed-off-by: Corvin Köhne <[email protected]>
11750a5
to
deb3651
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot! Please open an issue to track the fix for VPORTA.DIR
so it doesn't get lost.
Pull in the ATDF file from Microchip and add all the necessary plumbing around the code-base to make it compile.
It hasn't been tested much yet and no device specific patches are included. So far, I've tested some accesses to the PORTx register on hardware. It seems to work expect for VPORTA.DIR. VPORTA.DIR resolves to address 0 which causes rust to panic on access by default.