build at attiny85-blink project

This commit is contained in:
Savanni D'Gerinel 2023-10-29 11:55:35 -04:00
parent 48113d6ccb
commit 6167bdf428
11 changed files with 238 additions and 1 deletions

44
Cargo.lock generated
View File

@ -128,6 +128,13 @@ dependencies = [
"num-traits", "num-traits",
] ]
[[package]]
name = "attiny85-blink"
version = "0.1.0"
dependencies = [
"avr_delay",
]
[[package]] [[package]]
name = "autocfg" name = "autocfg"
version = "0.1.8" version = "0.1.8"
@ -143,6 +150,23 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "avr-config"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "abb2276df19ea0f25741658d218861b8a24d78eaf926127eb2384f0927f9ab9f"
dependencies = [
"const_env--value",
]
[[package]]
name = "avr_delay"
version = "0.4.2"
source = "git+https://github.com/avr-rust/delay/?rev=0.4.2#849918a8dfb2f6211787bd8ff69c4083d685cf54"
dependencies = [
"avr-config",
]
[[package]] [[package]]
name = "backtrace" name = "backtrace"
version = "0.3.69" version = "0.3.69"
@ -436,6 +460,26 @@ version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28c122c3980598d243d63d9a704629a2d748d101f278052ff068be5a4423ab6f" checksum = "28c122c3980598d243d63d9a704629a2d748d101f278052ff068be5a4423ab6f"
[[package]]
name = "const_env--value"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ade503a5095050a5bf3feb8ae71842fb49dfc4af01dd613beb4f00bb7144645"
dependencies = [
"const_env_impl--value",
]
[[package]]
name = "const_env_impl--value"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a046e06596453266c54d3eb790813fd047494fc1d04d5077fba628bf84e1b83a"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]] [[package]]
name = "cookie" name = "cookie"
version = "0.17.0" version = "0.17.0"

View File

@ -1,5 +1,6 @@
[workspace] [workspace]
members = [ members = [
"attiny85-blink",
"changeset", "changeset",
"config", "config",
"config-derive", "config-derive",

View File

@ -0,0 +1,5 @@
[build]
target = "../avr-attiny85.json"
[unstable]
build-std = ["core"]

10
attiny85-blink/Cargo.toml Normal file
View File

@ -0,0 +1,10 @@
[package]
name = "attiny85-blink"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
avr_delay = { git = "https://github.com/avr-rust/delay/", rev = "0.4.2" }

View File

@ -0,0 +1,3 @@
[toolchain]
channel = "nightly"
profile = "minimal"

View File

@ -0,0 +1,65 @@
#![no_std]
#![no_main]
use avr_delay::delay_ms;
// PORTB address is 0x38 (documentation says 0x18)
// DDRB address is 0x37 (documentation says 0x17)
// PINB address is 0x36 (documentation says 0x16)
//
// Whenever accessing a pin/port via the LD and ST instructions, add 0x20 to each address. This is
// hidden in the attiny85 datasheet in section 5.4. Section 5.2 shows a memory map in which the I/O
// registers start at address 0x20. Before that are the normal general purpose registers.
//
// Writing to a bit to a register means setting up a write mask, then using
// `core::ptr::write_volatile`. Watch for the `ops::Bit...` traits to help outwith bit operations.
trait Register {
type T;
const ADDRESS: *mut Self::T;
fn write(value: Self::T) {
unsafe {
core::ptr::write_volatile(Self::ADDRESS, value);
}
}
fn read() -> Self::T {
unsafe { core::ptr::read_volatile(Self::ADDRESS) }
}
}
#[allow(non_camel_case_types)]
pub struct PINB;
impl Register for PINB {
type T = u8;
const ADDRESS: *mut u8 = 0x36 as *mut u8;
}
#[allow(non_camel_case_types)]
pub struct DDRB;
impl Register for DDRB {
type T = u8;
const ADDRESS: *mut u8 = 0x37 as *mut u8;
}
#[allow(non_camel_case_types)]
pub struct PORTB;
impl Register for PORTB {
type T = u8;
const ADDRESS: *mut u8 = 0x38 as *mut u8;
}
#[no_mangle]
pub extern "C" fn main() {
DDRB::write(0x01);
loop {
PORTB::write(0x01);
delay_ms(500);
PORTB::write(0x00);
delay_ms(500);
}
}

31
avr-atmega328p.json Normal file
View File

@ -0,0 +1,31 @@
{
"arch": "avr",
"cpu": "atmega328p",
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
"env": "",
"executables": true,
"linker": "avr-gcc",
"linker-flavor": "gcc",
"linker-is-gnu": true,
"llvm-target": "avr-unknown-unknown",
"os": "unknown",
"position-independent-executables": false,
"exe-suffix": ".elf",
"eh-frame-header": false,
"pre-link-args": {
"gcc": [
"-Os",
"-mmcu=atmega328p"
]
},
"late-link-args": {
"gcc": [
"-lc",
"-lgcc"
]
},
"target-c-int-width": "16",
"target-endian": "little",
"target-pointer-width": "16",
"vendor": "unknown"
}

31
avr-atmega32u4.json Normal file
View File

@ -0,0 +1,31 @@
{
"arch": "avr",
"cpu": "atmega32u4",
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
"env": "",
"executables": true,
"linker": "avr-gcc",
"linker-flavor": "gcc",
"linker-is-gnu": true,
"llvm-target": "avr-unknown-unknown",
"os": "unknown",
"position-independent-executables": false,
"exe-suffix": ".elf",
"eh-frame-header": false,
"pre-link-args": {
"gcc": [
"-Os",
"-mmcu=atmega32u4"
]
},
"late-link-args": {
"gcc": [
"-lc",
"-lgcc"
]
},
"target-c-int-width": "16",
"target-endian": "little",
"target-pointer-width": "16",
"vendor": "unknown"
}

25
avr-attiny85.json Normal file
View File

@ -0,0 +1,25 @@
{
"arch": "avr",
"atomic-cas": false,
"cpu": "attiny85",
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
"eh-frame-header": false,
"exe-suffix": ".elf",
"executables": true,
"late-link-args": {
"gcc": [
"-lgcc"
]
},
"linker": "avr-gcc",
"llvm-target": "avr-unknown-unknown",
"max-atomic-width": 8,
"no-default-libraries": false,
"pre-link-args": {
"gcc": [
"-mmcu=attiny85"
]
},
"target-c-int-width": "16",
"target-pointer-width": "16"
}

View File

@ -64,6 +64,21 @@
"type": "indirect" "type": "indirect"
} }
}, },
"nixpkgs-22-11": {
"locked": {
"lastModified": 1688392541,
"narHash": "sha256-lHrKvEkCPTUO+7tPfjIcb7Trk6k31rz18vkyqmkeJfY=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "ea4c80b39be4c09702b0cb3b42eab59e2ba4f24b",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "nixos-22.11",
"type": "indirect"
}
},
"nixpkgs_2": { "nixpkgs_2": {
"locked": { "locked": {
"lastModified": 1654275867, "lastModified": 1654275867,
@ -119,6 +134,7 @@
"root": { "root": {
"inputs": { "inputs": {
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"nixpkgs-22-11": "nixpkgs-22-11",
"pkgs-cargo2nix": "pkgs-cargo2nix", "pkgs-cargo2nix": "pkgs-cargo2nix",
"typeshare": "typeshare", "typeshare": "typeshare",
"unstable": "unstable" "unstable": "unstable"

View File

@ -3,12 +3,13 @@
inputs = { inputs = {
nixpkgs.url = "nixpkgs/nixos-23.05"; nixpkgs.url = "nixpkgs/nixos-23.05";
nixpkgs-22-11.url = "nixpkgs/nixos-22.11";
unstable.url = "nixpkgs/nixos-unstable"; unstable.url = "nixpkgs/nixos-unstable";
pkgs-cargo2nix.url = "github:cargo2nix/cargo2nix"; pkgs-cargo2nix.url = "github:cargo2nix/cargo2nix";
typeshare.url = "github:1Password/typeshare"; typeshare.url = "github:1Password/typeshare";
}; };
outputs = { self, nixpkgs, unstable, pkgs-cargo2nix, typeshare, ... }: outputs = { self, nixpkgs, nixpkgs-22-11, unstable, pkgs-cargo2nix, typeshare, ... }:
let let
version = builtins.string 0 8 self.lastModifiedDate; version = builtins.string 0 8 self.lastModifiedDate;
supportedSystems = [ "x86_64-linux" ]; supportedSystems = [ "x86_64-linux" ];
@ -17,12 +18,17 @@
devShell."x86_64-linux" = devShell."x86_64-linux" =
let let
pkgs = import nixpkgs { system = "x86_64-linux"; }; pkgs = import nixpkgs { system = "x86_64-linux"; };
pkgs-22-11 = import nixpkgs-22-11 { system = "x86_64-linux"; };
pkgs-unstable = import unstable { system = "x86_64-linux"; }; pkgs-unstable = import unstable { system = "x86_64-linux"; };
cargo2nix = pkgs-cargo2nix.packages."x86_64-linux"; cargo2nix = pkgs-cargo2nix.packages."x86_64-linux";
avr = pkgs-22-11.pkgsCross.avr;
in in
pkgs.mkShell { pkgs.mkShell {
name = "ld-tools-devshell"; name = "ld-tools-devshell";
buildInputs = [ buildInputs = [
avr.buildPackages.gcc
avr.buildPackages.avrdude
avr.avrlibc
pkgs.libadwaita pkgs.libadwaita
pkgs.clang pkgs.clang
pkgs.entr pkgs.entr