Skip to content

Commit 97ca55d

Browse files
committed
devices: add basic support for ATtiny1626
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 <c.koehne@beckhoff.com>
1 parent 75993b0 commit 97ca55d

File tree

5 files changed

+5626
-0
lines changed

5 files changed

+5626
-0
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ attiny861 = ["device-selected"]
7777
attiny88 = ["device-selected"]
7878
attiny1606 = ["device-selected"]
7979
attiny1614 = ["device-selected"]
80+
attiny1626 = ["device-selected"]
8081
avr64du32 = ["device-selected"]
8182
avr64du28 = ["device-selected"]
8283
rt = ["avr-device-macros"]

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Via the feature you can select which chip you want the register specifications f
3535
| | | | | `attiny861` |
3636
| | | | | `attiny1606` |
3737
| | | | | `attiny1614` |
38+
| | | | | `attiny1626` |
3839
| | | | | `attiny2313` |
3940
| | | | | `attiny2313a` |
4041

src/devices.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@ pub mod attiny1614 {
183183
include!(concat!(env!("OUT_DIR"), "/pac/attiny1614.rs"));
184184
}
185185

186+
/// [ATtiny1626](https://www.microchip.com/wwwproducts/en/ATtiny1626)
187+
#[cfg(feature = "attiny1626")]
188+
pub mod attiny1626 {
189+
include!(concat!(env!("OUT_DIR"), "/pac/attiny1626.rs"));
190+
}
191+
186192
/// [ATtiny202](https://www.microchip.com/wwwproducts/en/ATtiny202)
187193
#[cfg(feature = "attiny202")]
188194
pub mod attiny202 {

src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#![cfg_attr(feature = "attiny167", doc = "**attiny167**,")]
3131
#![cfg_attr(feature = "attiny1606", doc = "**attiny1606**,")]
3232
#![cfg_attr(feature = "attiny1614", doc = "**attiny1614**,")]
33+
#![cfg_attr(feature = "attiny1626", doc = "**attiny1626**,")]
3334
#![cfg_attr(feature = "attiny202", doc = "**attiny202**,")]
3435
#![cfg_attr(feature = "attiny212", doc = "**attiny212**,")]
3536
#![cfg_attr(feature = "attiny214", doc = "**attiny214**,")]
@@ -89,6 +90,7 @@
8990
//! `attiny13a`,
9091
//! `attiny167`,
9192
//! `attiny1614`,
93+
//! `attiny1626`,
9294
//! `attiny202`,
9395
//! `attiny212`,
9496
//! `attiny214`,
@@ -264,6 +266,7 @@ compile_error!(
264266
* attiny167
265267
* attiny1606
266268
* attiny1614
269+
* attiny1626
267270
* attiny202
268271
* attiny212
269272
* attiny214
@@ -351,6 +354,8 @@ pub use crate::devices::attiny13a;
351354
pub use crate::devices::attiny1606;
352355
#[cfg(feature = "attiny1614")]
353356
pub use crate::devices::attiny1614;
357+
#[cfg(feature = "attiny1626")]
358+
pub use crate::devices::attiny1626;
354359
#[cfg(feature = "attiny167")]
355360
pub use crate::devices::attiny167;
356361
#[cfg(feature = "attiny202")]

0 commit comments

Comments
 (0)