Skip to content
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

svd2rust: update to v0.35.0 #176

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 38 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ jobs:
id: cache-cargo
with:
path: ~/cargo-bin
key: rust-tools-20250106-001
key: rust-tools-20250111-001
- name: Install svd2rust
if: steps.cache-cargo.outputs.cache-hit != 'true'
run: cargo install svd2rust --version 0.28.0 --locked
run: cargo install svd2rust --version 0.35.0 --locked
- name: Install cargo-form
if: steps.cache-cargo.outputs.cache-hit != 'true'
run: cargo install form --version 0.8.0 --locked
Expand All @@ -53,12 +53,12 @@ jobs:
- name: Install Nightly Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly-2023-08-08
toolchain: nightly-2025-01-10
components: rustfmt

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

Expand Down Expand Up @@ -86,10 +86,43 @@ jobs:
- name: Install Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly-2023-12-28
toolchain: nightly-2025-01-10
components: rust-src,rustfmt

# Rust Dependencies
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The duplication here feels pretty dirty, but maybe there's a better way for the jobs to depend on a separate job that builds the cache.

- name: Cache Cargo installed binaries
uses: actions/cache@v4
id: cache-cargo
with:
path: ~/cargo-bin
key: rust-tools-20250111-001
- name: Install svd2rust
if: steps.cache-cargo.outputs.cache-hit != 'true'
run: cargo install svd2rust --version 0.35.0 --locked
- name: Install cargo-form
if: steps.cache-cargo.outputs.cache-hit != 'true'
run: cargo install form --version 0.8.0 --locked
- name: Install atdf2svd
if: steps.cache-cargo.outputs.cache-hit != 'true'
run: cargo install atdf2svd --version 0.5.0 --locked
- name: Install svdtools
if: steps.cache-cargo.outputs.cache-hit != 'true'
run: cargo install svdtools --version 0.4.0 --locked
- name: Copy tools to cache directory
if: steps.cache-cargo.outputs.cache-hit != 'true'
run: |
mkdir ~/cargo-bin
cp ~/.cargo/bin/svd2rust ~/cargo-bin
cp ~/.cargo/bin/form ~/cargo-bin
cp ~/.cargo/bin/atdf2svd ~/cargo-bin
cp ~/.cargo/bin/svdtools ~/cargo-bin
- name: Put new cargo binary directory into path
run: echo "$HOME/cargo-bin" >> $GITHUB_PATH

- name: Install AVR gcc, binutils, and libc
run: sudo apt-get install -y avr-libc binutils-avr gcc-avr
- name: Generate ATmega328P PAC files
run: make atmega328p
- name: Build ATmega328P example
run: cd examples/atmega328p && cargo build
- name: Check ATmega328P formatting
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ Via the feature you can select which chip you want the register specifications f
## Build Instructions
The version on `crates.io` is pre-built. The following is only necessary when trying to build this crate from source.

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:
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:
```bash
cargo install atdf2svd --version 0.5.0 --locked
cargo install svd2rust --version 0.28.0 --locked
cargo install svd2rust --version 0.35.0 --locked
cargo install form
rustup component add --toolchain nightly rustfmt
cargo install svdtools --version 0.4.0 --locked
Expand Down
5 changes: 2 additions & 3 deletions examples/atmega328p/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ embedded-hal = "0.2.3"


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

# Configure the build for minimal size - AVRs have very little program memory
Expand Down
2 changes: 1 addition & 1 deletion examples/atmega328p/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "nightly-2023-12-28"
channel = "nightly-2025-01-10"
components = ["rust-src"]
profile = "minimal"
29 changes: 16 additions & 13 deletions examples/atmega328p/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,28 @@ fn panic(_info: &core::panic::PanicInfo) -> ! {

loop {
avr_device::asm::delay_cycles(1_000_000);
dp.PORTD.portd.write(|w| w.pd3().set_bit());
dp.portd.portd().write(|w| w.pd3().set_bit());
avr_device::asm::delay_cycles(1_000_000);
dp.PORTD.portd.write(|w| w.pd3().clear_bit());
dp.portd.portd().write(|w| w.pd3().clear_bit());
}
}

#[avr_device::interrupt(atmega328p)]
fn TIMER0_OVF() {
use core::sync::atomic::{AtomicU8, Ordering::Relaxed};

// This interrupt should raise every (1024*255)/16MHz s ≈ 0.01s
// We then count 61 times to approximate 1s.
// XXX: this is a really bad way to count time

static mut OVF_COUNTER: u16 = 0;
const ROLLOVER: u16 = 61;

*OVF_COUNTER = OVF_COUNTER.wrapping_add(1);
if *OVF_COUNTER > ROLLOVER {
*OVF_COUNTER = 0;
static OVF_COUNTER: AtomicU8 = AtomicU8::new(0);
const ROLLOVER: u8 = 61;

let ovf = OVF_COUNTER.load(Relaxed);
if ovf < ROLLOVER {
OVF_COUNTER.store(ovf + 1, Relaxed);
} else {
OVF_COUNTER.store(0, Relaxed);
interrupt::free(|cs| {
LED_STATE.borrow(cs).set(!LED_STATE.borrow(cs).get());
});
Expand All @@ -59,14 +62,14 @@ fn main() -> ! {
// will be written value + the modified bits

// Divide by 1024 -> 16MHz/1024 = 15.6kHz
dp.TC0.tccr0b.write(|w| w.cs0().prescale_1024());
dp.tc0.tccr0b().write(|w| w.cs0().prescale_1024());
// Enable overflow interrupts
dp.TC0.timsk0.write(|w| w.toie0().set_bit());
dp.tc0.timsk0().write(|w| w.toie0().set_bit());

// Make pd2 and pd3 outputs
// We use .modify() in order not to change the other bits
dp.PORTD.ddrd.modify(|_, w| w.pd2().set_bit());
dp.PORTD.ddrd.modify(|_, w| w.pd3().set_bit());
dp.portd.ddrd().modify(|_, w| w.pd2().set_bit());
dp.portd.ddrd().modify(|_, w| w.pd3().set_bit());

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

dp.PORTD.portd.modify(|_, w| w.pd2().bit(led_state));
dp.portd.portd().modify(|_, w| w.pd2().bit(led_state));

// We want to make the program crash after 9 blinks
if previous_state != led_state {
Expand Down
Loading