-
Notifications
You must be signed in to change notification settings - Fork 18
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
Changes from 5 commits
928471f
af9a351
9c4aa28
780cebf
c9b6ff4
3973306
7b2111a
1569ee4
4fe1867
1266d6d
e933171
7f915c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"arch": "avr", | ||
"atomic-cas": false, | ||
"cpu": "atmega328p", | ||
"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, | ||
"exe-suffix": ".elf", | ||
"executables": true, | ||
"late-link-args": { | ||
"gcc": [ | ||
"-lgcc" | ||
] | ||
}, | ||
"linker": "avr-gcc", | ||
"linker-is-gnu": true, | ||
"llvm-target": "avr-unknown-unknown", | ||
"max-atomic-width": 8, | ||
"no-default-libraries": false, | ||
"pre-link-args": { | ||
"gcc": [ | ||
"-mmcu=atmega328p", | ||
"-Wl,--as-needed" | ||
] | ||
}, | ||
"target-c-int-width": "16", | ||
"target-pointer-width": "16" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
#![cfg_attr(docsrs, feature(doc_cfg))] | ||
#![no_std] | ||
#![cfg_attr(target_arch = "avr", feature(llvm_asm))] | ||
#![cfg_attr(target_arch = "avr", feature(extended_key_value_attributes))] | ||
#![doc = include_str!("../README.md")] | ||
|
||
pub use bare_metal::CriticalSection; | ||
|
@@ -118,6 +120,25 @@ cfg_if::cfg_if! { | |
cortex_m::interrupt::enable() | ||
} | ||
} | ||
} else if #[cfg(target_arch = "avr")] { | ||
#[no_mangle] | ||
unsafe fn _critical_section_acquire() -> u8 { | ||
let mut sreg: u8; | ||
llvm_asm!( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to use the newer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Last I checked
Also, the last time I dealt with assembly language was 1987 on an 8086. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, just wanted to confirm!
😂 |
||
"in $0, 0x3F | ||
cli" | ||
: "=r"(sreg) | ||
::: "volatile" | ||
); | ||
sreg | ||
} | ||
|
||
#[no_mangle] | ||
unsafe fn _critical_section_release(token: u8) { | ||
if token & 0x80 == 0x80 { | ||
llvm_asm!("sei" :::: "volatile"); | ||
} | ||
} | ||
} else if #[cfg(target_arch = "riscv32")] { | ||
#[no_mangle] | ||
unsafe fn _critical_section_acquire() -> u8 { | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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 theci.sh
, but I don't know how to test it without pushing another commit.There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 arustup 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.