-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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-unknown-unknown
This commit removes the `avr-unknown-gnu-atmega328` target and replaces it with a more generic `avr-unknown-unknown` variant that can be specialized using `-C target-cpu` (e.g. `-C target-cpu=atmega328p`). I've decided to go with the `-unknown` tag (i.e. `avr-unknown-unknown` instead of `avr-unknown-gnu`), because that's the name LLVM already uses - I see no reason to diverge here. Seizing the day, I'm adding myself as the maintainer of this target - I've been already fixing the bugs anyway, might as well make it official. Related discussion: #131171
- Loading branch information
Showing
16 changed files
with
132 additions
and
59 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
39 changes: 0 additions & 39 deletions
39
...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
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.
30 changes: 30 additions & 0 deletions
30
compiler/rustc_target/src/spec/targets/avr_unknown_unknown.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
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, | ||
..TargetOptions::default() | ||
}, | ||
} | ||
} |
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,75 @@ | ||
# `avr-unknown-unknown` | ||
|
||
Series of microcontrollers from Atmel: ATmega8, ATmega328p etc. | ||
|
||
**Tier: 3** | ||
|
||
## Target maintainers | ||
|
||
-[Patryk Wychowaniec](https://github.com/Patryk27) <pwychowaniec@pm.me> | ||
|
||
## Requirements | ||
|
||
This target is only cross-compiled - x86_64 / aarch64 x Lixux / 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`, 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, see https://github.com/rust-lang/compiler-builtins/issues/711. | ||
|
||
## Building the target | ||
|
||
Rust comes with AVR support enabled, you don't have to rebuild the compiler | ||
itself. | ||
|
||
## 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 Hydra doesn't build it): | ||
$ nix shell nixpkgs#pkgsCross.avr.buildPackages.gcc11 | ||
``` | ||
|
||
... setup `.cargo/config` for your project: | ||
|
||
```toml | ||
[build] | ||
target = "avr-unknown-unknown" | ||
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-unknown-unknown/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. | ||
|
||
## Testing | ||
|
||
You can use [`simavr`](https://github.com/buserror/simavr) to emulate the | ||
resulting firmware on your machine: | ||
|
||
``` | ||
simavr -m atmega328p ./target/avr-unknown-unknown/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