-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a generic AVR target: avr-none
This commit removes the `avr-unknown-gnu-atmega328` target and replaces it with a more generic `avr-none` variant that must be specialized with the `-C target-cpu` flag (e.g. `-C target-cpu=atmega328p`).
- Loading branch information
Showing
19 changed files
with
156 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 0 additions & 40 deletions
40
...ler/rustc_target/src/spec/base/avr_gnu.rs → compiler/rustc_target/src/spec/base/avr.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use crate::spec::{Cc, LinkerFlavor, Lld, RelocModel, Target, TargetOptions}; | ||
|
||
pub(crate) fn target() -> Target { | ||
Target { | ||
arch: "avr".into(), | ||
metadata: crate::spec::TargetMetadata { | ||
description: None, | ||
tier: None, | ||
host_tools: None, | ||
std: None, | ||
}, | ||
data_layout: "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8".into(), | ||
llvm_target: "avr-unknown-unknown".into(), | ||
pointer_width: 16, | ||
options: TargetOptions { | ||
c_int_width: "16".into(), | ||
exe_suffix: ".elf".into(), | ||
linker: Some("avr-gcc".into()), | ||
eh_frame_header: false, | ||
pre_link_args: TargetOptions::link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &[]), | ||
late_link_args: TargetOptions::link_args( | ||
LinkerFlavor::Gnu(Cc::Yes, Lld::No), | ||
&["-lgcc"], | ||
), | ||
max_atomic_width: Some(16), | ||
atomic_cas: false, | ||
relocation_model: RelocModel::Static, | ||
need_explicit_cpu: true, | ||
..TargetOptions::default() | ||
}, | ||
} | ||
} |
5 changes: 0 additions & 5 deletions
5
compiler/rustc_target/src/spec/targets/avr_unknown_gnu_atmega328.rs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# `avr-none` | ||
|
||
Series of microcontrollers from Atmel: ATmega8, ATmega328p etc. | ||
|
||
**Tier: 3** | ||
|
||
## Target maintainers | ||
|
||
- [Patryk Wychowaniec](https://github.com/Patryk27) <[email protected]> | ||
|
||
## Requirements | ||
|
||
This target is only cross-compiled; x86-64 Linux, x86-64 macOS and aarch64 macOS | ||
hosts are confirmed to work, but in principle any machine able to run rustc and | ||
avr-gcc should be good. | ||
|
||
Compiling for this target requires `avr-gcc` installed, because a couple of | ||
intrinsics (like 32-bit multiplication) rely on [`libgcc`](https://github.com/gcc-mirror/gcc/blob/3269a722b7a03613e9c4e2862bc5088c4a17cc11/libgcc/config/avr/lib1funcs.S) | ||
and can't be provided through `compiler-builtins` yet. This is a limitation that | ||
[we hope to lift in the future](https://github.com/rust-lang/compiler-builtins/issues/711). | ||
|
||
You'll also need to setup the `.cargo/config` file - see below for details. | ||
|
||
## Building the target | ||
|
||
Rust comes with AVR support enabled, you don't have to rebuild the compiler. | ||
|
||
## Building Rust programs | ||
|
||
Install `avr-gcc`: | ||
|
||
```console | ||
# Ubuntu: | ||
$ sudo apt-get install gcc-avr | ||
|
||
# Mac: | ||
$ brew tap osx-cross/avr && brew install avr-gcc | ||
|
||
# NixOS (takes a couple of minutes, since it's not provided through Hydra): | ||
$ nix shell nixpkgs#pkgsCross.avr.buildPackages.gcc11 | ||
``` | ||
|
||
... setup `.cargo/config` for your project: | ||
|
||
```toml | ||
[build] | ||
target = "avr-none" | ||
rustflags = ["-C", "target-cpu=atmega328p"] | ||
|
||
[unstable] | ||
build-std = ["core"] | ||
``` | ||
|
||
... and then simply run: | ||
|
||
```console | ||
$ cargo build --release | ||
``` | ||
|
||
The final binary will be placed into | ||
`./target/avr-none/release/your-project.elf`. | ||
|
||
Note that since AVRs have rather small amounts of registers, ROM and RAM, it's | ||
recommended to always use `--release` to avoid running out of space. | ||
|
||
Also, please note that specifying `-C target-cpu` is required - here's a list of | ||
the possible variants: | ||
|
||
https://github.com/llvm/llvm-project/blob/093d4db2f3c874d4683fb01194b00dbb20e5c713/clang/lib/Basic/Targets/AVR.cpp#L32 | ||
|
||
## Testing | ||
|
||
You can use [`simavr`](https://github.com/buserror/simavr) to emulate the | ||
resulting firmware on your machine: | ||
|
||
```console | ||
$ simavr -m atmega328p ./target/avr-none/release/your-project.elf | ||
``` | ||
|
||
Alternatively, if you want to write a couple of actual `#[test]`s, you can use | ||
[`avr-tester`](https://github.com/Patryk27/avr-tester). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters