diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d81ac61..f22815b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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 @@ -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 + - 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 diff --git a/README.md b/README.md index 64f036a..cebfbd6 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/examples/atmega328p/Cargo.toml b/examples/atmega328p/Cargo.toml index b9a532e..4694de0 100644 --- a/examples/atmega328p/Cargo.toml +++ b/examples/atmega328p/Cargo.toml @@ -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 diff --git a/examples/atmega328p/rust-toolchain.toml b/examples/atmega328p/rust-toolchain.toml index 5e363e2..b325113 100644 --- a/examples/atmega328p/rust-toolchain.toml +++ b/examples/atmega328p/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2023-12-28" +channel = "nightly-2025-01-10" components = ["rust-src"] profile = "minimal" diff --git a/examples/atmega328p/src/main.rs b/examples/atmega328p/src/main.rs index 147b7e7..9cc4fa1 100644 --- a/examples/atmega328p/src/main.rs +++ b/examples/atmega328p/src/main.rs @@ -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()); }); @@ -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. @@ -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 {