Skip to content
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

Updated 003.0 Building a crate for AVR #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/003-building-a-crate-for-avr.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,40 @@ After setting up the compiler, you may use it to generate assembly or machine co

## Choosing a `--target`

The Rust nightly compiler includes a built-in target for ATmega328 named `avr-unknown-gnu-atmega328`
The Rust nightly compiler includes a built-in target for ATmega328 named `avr-unknown-gnu-atmega328`.

If you wish to target a microcontroller other than ATmega328, or you want to change any of the
default builtin options like the linking parameters, then you will need to export the builtin
default built-in options like the linking parameters, then you will need to export the built-in
`avr-unknown-gnu-atmega328` target to a custom target specification JSON file and modify
it to suit your needs.

This target can be adapted to other microcontrollers as per the instructions in [3.1. The built-in `avr-unknown-gnu-atmega328` target](./003.1-the-avr-unknown-gnu-atmega328-target.md).

In summary, there are two options:

* Use `rustc --target=avr-unknown-gnu-atmega328` to use the default, builtin GCC based target for ATmega328
* Or use `rustc --target=my-custom-avr-target.json` with either a JSON file adapted from the builtin
* Use `rustc --target=avr-unknown-gnu-atmega328` to use the default, built-in GCC based target for ATmega328
* Or use `rustc --target=my-custom-avr-target.json` with either a JSON file adapted from the built-in
`avr-unknown-gnu-atmega328` target above, or otherwise build the file you wish manually to avoid the
default path entirely.

## Make sure you use the nightly version of Rust, not the default stable channel
## Using the right Rust compiler

The best way to ensure a crate is using the Nightly compiler is to run `rustup override set nightly` inside a terminal
within the root directory of the crate. After this is done, `cargo` will by-default use the AVR-enabled Nightly compiler
Make sure you use the `nightly` version of Rust, not the default stable channel.
The best way to ensure a crate is using the `nightly` compiler is to run `rustup override set nightly` inside a terminal
within the root directory of the crate. After this is done, `cargo` will by default use the AVR-enabled Nightly compiler
any time `cargo` is used within the directory tree of the crate.

## Compiling a crate

To compile and link an executable crate for AVR, run the following:
Depending on the option you selected from above, you can compile and link the executable crate for AVR with either of the commands below.

Using the builtin `avr-unknown-gnu-atmega328` target:
If you used the builtin `avr-unknown-gnu-atmega328` target, run:

```bash
cargo build -Z build-std=core --target avr-unknown-gnu-atmega328 --release
```

Using a custom target specification JSON:

If you used a custom target specification JSON, run:

```bash
cargo build -Z build-std=core --target /path/to/my-custom-avr-target.json --release
Expand Down