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

Support/avr platform #12

Merged
merged 12 commits into from
Apr 8, 2022
Merged

Conversation

mutantbob
Copy link

torrancew's pull request #6 seems to have stalled. I picked up where it left off and performed the changes to the CI system you requested. Let me know if there is anything else you would like adjusted.

torrancew and others added 5 commits November 14, 2021 09:02
This commit adds support for AVR (Arduino) platforms via direct
implementation of interrupt enable/disable functionality via AVR
assembly.

The underlying motivation for this support is to enable further
integration with the greater Embedded Rust ecosystem. As an example,
`embedded-nal` depends upon `heapless`, which in turn depends upon
atomic support, either natively or via `atomic-polyfill`.
`atomic-polyfill` uses `critical-section`, and so enabling AVR support
in this crate has great benefits to the downstream packages that hvae
come to depend upon `critical-section`.
…and feature(llvm_asm). Also had to disable #![doc because the AVR compiler can't handle it
@mutantbob
Copy link
Author

The CI check appears to have choked because nightly-2021-01-07 (the version of Rust that works for AVR) is not installed. I am not familiar enough with git's CI system for rust to know how to get it to use that.

ci.sh Outdated
@@ -7,3 +7,4 @@ cargo build --target thumbv6m-none-eabi
cargo build --target thumbv7em-none-eabi
cargo build --target riscv32imc-unknown-none-elf
cargo build --target riscv32imac-unknown-none-elf
cargo +nightly-2021-01-07 build -Zbuild-std=core --target avr-specs/avr-atmega328p.json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to use such an old nightly?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Attempting to use a modern version of rust fails with
error: ran out of registers during register allocation
It may be covered by rust-lang/rust#88252 , but Rust on AVR has been waiting for a fix for a long time and has to muddle along with old tools.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, I see. No problem then, was just curious :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it is possible to just rustup install nightly-2021-01-07 in the ci.sh, but I don't know how to test it without pushing another commit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment in the main thread. also feel free to push as many commits as you need! you can squash/amend later.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found a way to make ci.sh work. I just did a rustup toolchain install nightly-2021-01-07 --component rust-src before I compile for AVR. There might be a more elegant way to do it, but I do not know what it would be.

#[no_mangle]
unsafe fn _critical_section_acquire() -> u8 {
let mut sreg: u8;
llvm_asm!(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to use the newer asm!, or is it not supported on AVR?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last I checked asm! was not supported by Rust for AVR target.

Also, the last time I dealt with assembly language was 1987 on an 8086.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, just wanted to confirm!

Also, the last time I dealt with assembly language was 1987 on an 8086.

😂

@Dirbaio
Copy link
Member

Dirbaio commented Apr 7, 2022

The CI check appears to have choked because nightly-2021-01-07 (the version of Rust that works for AVR) is not installed. I am not familiar enough with git's CI system for rust to know how to get it to use that.

It's standard rustup. If you set it through the envvar instead it autodownloads it: RUSTUP_TOOLCHAIN=nightly-2021-01-07 cargo build ...

Copy link
Member

@Dirbaio Dirbaio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, Thank you!

@Dirbaio Dirbaio merged commit b2a9d9f into rust-embedded:main Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants