-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add documentation for the new builtin 'avr-unknown-gnu-atmega328' target
This was added to Rust in rust-lang/rust#74941
- Loading branch information
1 parent
33bd7bc
commit 9fa5566
Showing
3 changed files
with
106 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# 3.1. The built-in `avr-unknown-gnu-atmega328` target | ||
|
||
The Rust nightly compiler contains a built-in target, `avr-unknown-gnu-atmega328`, that | ||
generates code for the AVR [ATmega328](https://en.wikipedia.org/wiki/ATmega328) using the | ||
GNU AVR-GCC toolchain for linking support. | ||
|
||
## Targeting custom microcontrollers by adapting 'avr-unkonwn-gnu-atmega328' | ||
|
||
See the section [./005.1-the-target-specification-json-file.md](5.1. The Target Specification JSON File) for | ||
more information about how Rust target specification JSON files work. | ||
|
||
To generate a Rust target specification JSON file from the builtin: | ||
|
||
|
||
```bash | ||
rustc --print target-spec-json -Z unstable-options --target avr-unknown-gnu-atmega328 > my-custom-avr-unknown-gnu-atmega328.json | ||
``` | ||
|
||
This prints the target specification JSON file `my-custom-avr-unknown-gnu-atmega328.json`: | ||
|
||
```json | ||
{ | ||
"arch": "avr", | ||
"cpu": "atmega328", | ||
"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, | ||
"env": "", | ||
"exe-suffix": ".elf", | ||
"executables": true, | ||
"is-builtin": true, | ||
"late-link-args": { | ||
"gcc": [ | ||
"-lgcc" | ||
] | ||
}, | ||
"linker": "avr-gcc", | ||
"linker-flavor": "gcc", | ||
"linker-is-gnu": true, | ||
"llvm-target": "avr-unknown-unknown", | ||
"os": "unknown", | ||
"pre-link-args": { | ||
"gcc": [ | ||
"-mmcu=atmega328", | ||
"-Wl,--as-needed" | ||
] | ||
}, | ||
"target-c-int-width": "16", | ||
"target-endian": "little", | ||
"target-pointer-width": "16", | ||
"vendor": "unknown" | ||
} | ||
``` | ||
|
||
To adapt this file to target a different microcontroller: | ||
|
||
* Replace the top-level `"cpu": "atmega328"` with `"cpu": "YOUR-AVR-VARIANT-NAME"` | ||
* Replace `"-mmcu=atmega328"` with `"-mmcu=YOUR-AVR-VARIANT-NAME"` | ||
|
||
The file can then be passed to Rust via the `rustc --target <JSON FILE PATH>` instead of | ||
`rustc --target avr-unknown-gnu-atmega328`, which will tailor the generated code to your | ||
desired microcontroller. | ||
|
||
It is also possible to customize link parameters if desired by modifying the JSON file. | ||
|
||
## Compiling for AVR without the GNU toolchain | ||
|
||
At the moment, the only builtin AVR target `avr-unknown-gnu-atmega328` always requires | ||
AVR-GCC, AVR-libc and AVR-binutils from the GNU project. | ||
|
||
The LLVM LLD linker has some limited support for AVR which in the future could be leveraged | ||
to allow compiling AVR Rust binaries without the dependency on the GNU toolchain. Some work | ||
on `compiler-builtins` and others would also be required. At the moment, the GNU toolchain | ||
is a hard dependency. | ||
no t |
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