From 536616d42443799790e60d3da3e355613e41b2d0 Mon Sep 17 00:00:00 2001 From: Werner <26710260+GuilhermeWerner@users.noreply.github.com> Date: Sat, 25 Dec 2021 08:13:42 -0300 Subject: [PATCH] Basic arduino blink --- .cargo/config.toml | 6 ++++++ Cargo.toml | 29 +++++++++++++++++++++++++++++ Source/Main.rs | 19 +++++++++++++++++++ avr-atmega328p.json | 29 +++++++++++++++++++++++++++++ rust-toolchain | 1 + 5 files changed, 84 insertions(+) create mode 100644 .cargo/config.toml create mode 100644 Cargo.toml create mode 100644 Source/Main.rs create mode 100644 avr-atmega328p.json create mode 100644 rust-toolchain diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..3b07943 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,6 @@ +[build] +target-dir = "Binaries" +target = "avr-atmega328p.json" + +[unstable] +build-std = ["core"] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..46f71ca --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "rust-avr" +version = "0.1.0" +edition = "2018" + +[[bin]] +name = "RustAVR" +path = "Source/Main.rs" +bench = false +test = false + +[dependencies] +arduino-hal = { git = "https://github.com/Rahix/avr-hal", rev = "f84c0dff774c2292bc932b670955165161ecc7d1", features = ["arduino-uno"] } +embedded-hal = "0.2.3" +nb = "0.1.2" +panic-halt = "0.2.0" +ufmt = "0.1.0" + +[profile.dev] +panic = "abort" +lto = true +opt-level = "s" + +[profile.release] +panic = "abort" +codegen-units = 1 +debug = true +lto = true +opt-level = "s" diff --git a/Source/Main.rs b/Source/Main.rs new file mode 100644 index 0000000..7a92e19 --- /dev/null +++ b/Source/Main.rs @@ -0,0 +1,19 @@ +#![no_std] +#![no_main] +#![allow(non_snake_case)] +#![allow(unused_imports)] + +use panic_halt as _; + +#[arduino_hal::entry] +fn main() -> ! { + let peripherals = arduino_hal::Peripherals::take().unwrap(); + let pins = arduino_hal::pins!(peripherals); + + let mut led = pins.d13.into_output(); + + loop { + led.toggle(); + arduino_hal::delay_ms(1000); + } +} diff --git a/avr-atmega328p.json b/avr-atmega328p.json new file mode 100644 index 0000000..c9bcdb8 --- /dev/null +++ b/avr-atmega328p.json @@ -0,0 +1,29 @@ +{ + "llvm-target": "avr-unknown-unknown", + "cpu": "atmega328p", + "target-endian": "little", + "target-pointer-width": "16", + "target-c-int-width": "16", + "os": "unknown", + "arch": "avr", + "data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8", + "executables": true, + "linker": "avr-gcc", + "linker-flavor": "gcc", + "pre-link-args": { + "gcc": [ + "-Os", + "-mmcu=atmega328p" + ] + }, + "exe-suffix": ".elf", + "post-link-args": { + "gcc": [ + "-Wl,--gc-sections" + ] + }, + "singlethread": false, + "no-builtins": false, + "no-default-libraries": false, + "eh-frame-header": false +} diff --git a/rust-toolchain b/rust-toolchain new file mode 100644 index 0000000..cef4e16 --- /dev/null +++ b/rust-toolchain @@ -0,0 +1 @@ +nightly-2021-01-07