-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Create a generic AVR target: avr-none #131651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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) <pwychowaniec@pm.me> | ||
|
||
## 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 | ||
Patryk27 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.