Skip to content

Commit 6375284

Browse files
committed
svd2rust: update to v0.35.0
1 parent 95f5810 commit 6375284

File tree

5 files changed

+59
-24
lines changed

5 files changed

+59
-24
lines changed

.github/workflows/ci.yml

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ jobs:
2626
id: cache-cargo
2727
with:
2828
path: ~/cargo-bin
29-
key: rust-tools-20250106-001
29+
key: rust-tools-20250111-001
3030
- name: Install svd2rust
3131
if: steps.cache-cargo.outputs.cache-hit != 'true'
32-
run: cargo install svd2rust --version 0.28.0 --locked
32+
run: cargo install svd2rust --version 0.35.0 --locked
3333
- name: Install cargo-form
3434
if: steps.cache-cargo.outputs.cache-hit != 'true'
3535
run: cargo install form --version 0.8.0 --locked
@@ -53,12 +53,12 @@ jobs:
5353
- name: Install Nightly Rust
5454
uses: actions-rust-lang/setup-rust-toolchain@v1
5555
with:
56-
toolchain: nightly-2023-08-08
56+
toolchain: nightly-2025-01-10
5757
components: rustfmt
5858

5959
# Actual test run
6060
- name: Generate chip description sources
61-
run: make RUSTUP_TOOLCHAIN=nightly-2023-08-08
61+
run: make RUSTUP_TOOLCHAIN=nightly-2025-01-10
6262
- name: Test-compile the crate
6363
run: cargo check --all-features
6464

@@ -86,10 +86,43 @@ jobs:
8686
- name: Install Rust
8787
uses: actions-rust-lang/setup-rust-toolchain@v1
8888
with:
89-
toolchain: nightly-2023-12-28
89+
toolchain: nightly-2025-01-10
9090
components: rust-src,rustfmt
91+
92+
# Rust Dependencies
93+
- name: Cache Cargo installed binaries
94+
uses: actions/cache@v4
95+
id: cache-cargo
96+
with:
97+
path: ~/cargo-bin
98+
key: rust-tools-20250111-001
99+
- name: Install svd2rust
100+
if: steps.cache-cargo.outputs.cache-hit != 'true'
101+
run: cargo install svd2rust --version 0.35.0 --locked
102+
- name: Install cargo-form
103+
if: steps.cache-cargo.outputs.cache-hit != 'true'
104+
run: cargo install form --version 0.8.0 --locked
105+
- name: Install atdf2svd
106+
if: steps.cache-cargo.outputs.cache-hit != 'true'
107+
run: cargo install atdf2svd --version 0.5.0 --locked
108+
- name: Install svdtools
109+
if: steps.cache-cargo.outputs.cache-hit != 'true'
110+
run: cargo install svdtools --version 0.4.0 --locked
111+
- name: Copy tools to cache directory
112+
if: steps.cache-cargo.outputs.cache-hit != 'true'
113+
run: |
114+
mkdir ~/cargo-bin
115+
cp ~/.cargo/bin/svd2rust ~/cargo-bin
116+
cp ~/.cargo/bin/form ~/cargo-bin
117+
cp ~/.cargo/bin/atdf2svd ~/cargo-bin
118+
cp ~/.cargo/bin/svdtools ~/cargo-bin
119+
- name: Put new cargo binary directory into path
120+
run: echo "$HOME/cargo-bin" >> $GITHUB_PATH
121+
91122
- name: Install AVR gcc, binutils, and libc
92123
run: sudo apt-get install -y avr-libc binutils-avr gcc-avr
124+
- name: Generate ATmega328P PAC files
125+
run: make atmega328p
93126
- name: Build ATmega328P example
94127
run: cd examples/atmega328p && cargo build
95128
- name: Check ATmega328P formatting

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ Via the feature you can select which chip you want the register specifications f
4040
## Build Instructions
4141
The version on `crates.io` is pre-built. The following is only necessary when trying to build this crate from source.
4242

43-
You need to have [atdf2svd][] (= 0.5.0), [svd2rust][] (= 0.28), [form][] (>= 0.8), [rustfmt][](for the *nightly* toolchain) and [svdtools][] (= 0.4.0) installed:
43+
You need to have [atdf2svd][] (= 0.5.0), [svd2rust][] (= 0.35.0), [form][] (>= 0.8), [rustfmt][](for the *nightly* toolchain) and [svdtools][] (= 0.4.0) installed:
4444
```bash
4545
cargo install atdf2svd --version 0.5.0 --locked
46-
cargo install svd2rust --version 0.28.0 --locked
46+
cargo install svd2rust --version 0.35.0 --locked
4747
cargo install form
4848
rustup component add --toolchain nightly rustfmt
4949
cargo install svdtools --version 0.4.0 --locked

examples/atmega328p/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ embedded-hal = "0.2.3"
1818

1919

2020
[dependencies.avr-device]
21-
version = "0.5.3"
22-
# To use the local version of avr-device instead, uncomment the following line:
21+
version = "0.7"
2322
# NB: make sure to build this crate first by running `make` at the root of the project
24-
# path = "../.."
23+
path = "../.."
2524
features = ["atmega328p", "rt"]
2625

2726
# Configure the build for minimal size - AVRs have very little program memory
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[toolchain]
2-
channel = "nightly-2023-12-28"
2+
channel = "nightly-2025-01-10"
33
components = ["rust-src"]
44
profile = "minimal"

examples/atmega328p/src/main.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,28 @@ fn panic(_info: &core::panic::PanicInfo) -> ! {
2626

2727
loop {
2828
avr_device::asm::delay_cycles(1_000_000);
29-
dp.PORTD.portd.write(|w| w.pd3().set_bit());
29+
dp.portd.portd().write(|w| w.pd3().set_bit());
3030
avr_device::asm::delay_cycles(1_000_000);
31-
dp.PORTD.portd.write(|w| w.pd3().clear_bit());
31+
dp.portd.portd().write(|w| w.pd3().clear_bit());
3232
}
3333
}
3434

3535
#[avr_device::interrupt(atmega328p)]
3636
fn TIMER0_OVF() {
37+
use core::sync::atomic::{AtomicU8, Ordering::Relaxed};
38+
3739
// This interrupt should raise every (1024*255)/16MHz s ≈ 0.01s
3840
// We then count 61 times to approximate 1s.
3941
// XXX: this is a really bad way to count time
4042

41-
static mut OVF_COUNTER: u16 = 0;
42-
const ROLLOVER: u16 = 61;
43-
44-
*OVF_COUNTER = OVF_COUNTER.wrapping_add(1);
45-
if *OVF_COUNTER > ROLLOVER {
46-
*OVF_COUNTER = 0;
43+
static OVF_COUNTER: AtomicU8 = AtomicU8::new(0);
44+
const ROLLOVER: u8 = 61;
4745

46+
let ovf = OVF_COUNTER.load(Relaxed);
47+
if ovf < ROLLOVER {
48+
OVF_COUNTER.store(ovf + 1, Relaxed);
49+
} else {
50+
OVF_COUNTER.store(0, Relaxed);
4851
interrupt::free(|cs| {
4952
LED_STATE.borrow(cs).set(!LED_STATE.borrow(cs).get());
5053
});
@@ -59,14 +62,14 @@ fn main() -> ! {
5962
// will be written value + the modified bits
6063

6164
// Divide by 1024 -> 16MHz/1024 = 15.6kHz
62-
dp.TC0.tccr0b.write(|w| w.cs0().prescale_1024());
65+
dp.tc0.tccr0b().write(|w| w.cs0().prescale_1024());
6366
// Enable overflow interrupts
64-
dp.TC0.timsk0.write(|w| w.toie0().set_bit());
67+
dp.tc0.timsk0().write(|w| w.toie0().set_bit());
6568

6669
// Make pd2 and pd3 outputs
6770
// We use .modify() in order not to change the other bits
68-
dp.PORTD.ddrd.modify(|_, w| w.pd2().set_bit());
69-
dp.PORTD.ddrd.modify(|_, w| w.pd3().set_bit());
71+
dp.portd.ddrd().modify(|_, w| w.pd2().set_bit());
72+
dp.portd.ddrd().modify(|_, w| w.pd3().set_bit());
7073

7174
// SAFETY: We can enable the interrupts here as we are not inside
7275
// a critical section.
@@ -82,7 +85,7 @@ fn main() -> ! {
8285
led_state = LED_STATE.borrow(cs).get();
8386
});
8487

85-
dp.PORTD.portd.modify(|_, w| w.pd2().bit(led_state));
88+
dp.portd.portd().modify(|_, w| w.pd2().bit(led_state));
8689

8790
// We want to make the program crash after 9 blinks
8891
if previous_state != led_state {

0 commit comments

Comments
 (0)