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

invalid register class reg_iw #20

Open
stappersg opened this issue May 21, 2022 · 5 comments
Open

invalid register class reg_iw #20

stappersg opened this issue May 21, 2022 · 5 comments

Comments

@stappersg
Copy link
Member

Hi,

Over here is this seen:

$ cargo +nightly publish
    Updating crates.io index
   Packaging avr_delay v0.4.0 (/home/gs0604/src/rust/RustAVR/delay)
   Verifying avr_delay v0.4.0 (/home/gs0604/src/rust/RustAVR/delay)
   Compiling proc-macro2 v1.0.39
   Compiling unicode-ident v1.0.0
   Compiling syn v1.0.95
   Compiling quote v1.0.18
   Compiling const_env_impl--value v0.1.2
   Compiling const_env--value v0.1.2
   Compiling avr-config v2.0.1
   Compiling avr_delay v0.4.0 (/home/stappers/src/rust/RustAVR/delay/target/package/avr_delay-0.4.0)
error: invalid register class `reg_iw`: unknown register class
  --> src/lib.rs:40:18
   |
40 |                  i = inout(reg_iw) zero => _,
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: invalid register class `reg_iw`: unknown register class
  --> src/lib.rs:47:14
   |
47 |              i = inout(reg_iw) last_count => _,
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: could not compile `avr_delay` due to 2 previous errors
error: failed to verify package tarball

What would be the correct register class?

@stappersg
Copy link
Member Author

When adding --target ./avr-atmega328p.json is there a complete other error, which is earlier, it comes from avr-config:

   Compiling avr-config v2.0.1
warning: target json file contains unused fields: no-compiler-rt

error[E0463]: can't find crate for `core`
  |
  = note: the `avr-atmega328p-9922596273948483120` target may not be installed
  = help: consider downloading the target with `rustup target add avr-atmega328p-9922596273948483120`
  = help: consider building the standard library from source with `cargo build -Zbuild-std`

error[E0463]: can't find crate for `compiler_builtins`

error: proc macro panicked
  --> /home/stappers/.cargo/registry/src/github.com-1ecc6299db9ec823/avr-config-2.0.1/src/cpu_frequency.rs:22:36
   |
22 | const CPU_FREQUENCY_HZ_IMPL: u32 = value_from_env!("AVR_CPU_FREQUENCY_HZ": u32); // Must be set whenever AVR is being targeted.
   |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: message: no value available for environment variable 'AVR_CPU_FREQUENCY_HZ'

error: requires `sized` lang_item

For more information about this error, try `rustc --explain E0463`.
warning: `avr-config` (lib) generated 1 warning
error: could not compile `avr-config` due to 4 previous errors; 1 warning emitted
$

So adding a target doesn't seem the correct way to set the correct register class.
Yes, help is wanted.

@stappersg
Copy link
Member Author

Some information about my system:

  • It is rustup-to-date
  • It is aware of ARM targets
  • Not aware of AVR targets

In detail

$ rustup update
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
info: syncing channel updates for 'nightly-x86_64-unknown-linux-gnu'
info: checking for self-updates

   stable-x86_64-unknown-linux-gnu unchanged - rustc 1.61.0 (fe5b13d68 2022-05-18)
  nightly-x86_64-unknown-linux-gnu unchanged - rustc 1.63.0-nightly (e6a4afc3a 2022-05-20)

info: cleaning up downloads & tmp directories
$ rustup target list | grep -i -e aRm | wc
     17      17     428
$ rustup target list | grep -i -e aVr | wc
      0       0       0
$ 

Asking @mbuesch, author of #18, how system looks there.

@mbuesch
Copy link
Contributor

mbuesch commented May 21, 2022

I have installed the nightly toolchain into a separate directory:

$ cat rust-unstable-activate 
export RUSTUP_HOME="$HOME/.rust-unstable/rustup"
export CARGO_HOME="$HOME/.rust-unstable/cargo"
export PATH="$CARGO_HOME/bin:$PATH"
PS1="rust-unstable/$PS1"
$ . rust-unstable-activate 
rust-unstable$ rustup show
Default host: x86_64-unknown-linux-gnu
rustup home:  $HOME/.rust-unstable/rustup

installed toolchains
--------------------

nightly-2022-03-18-x86_64-unknown-linux-gnu
nightly-x86_64-unknown-linux-gnu (default)

active toolchain
----------------

nightly-x86_64-unknown-linux-gnu (default)
rustc 1.63.0-nightly (cd282d7f7 2022-05-18)

With that environment I build the project with:

rust-unstable$ cargo build --target avr-atmega328p.json -Z build-std=core --release
rust-unstable$ cat avr-atmega328p.json 
{
  "arch": "avr",
  "cpu": "atmega328p",
  "data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
  "env": "",
  "executables": true,
  "linker": "avr-gcc",
  "linker-flavor": "gcc",
  "linker-is-gnu": true,
  "llvm-target": "avr-unknown-unknown",
  "no-compiler-rt": true,
  "os": "unknown",
  "position-independent-executables": false,
  "exe-suffix": ".elf",
  "eh-frame-header": false,
  "pre-link-args": {
    "gcc": ["-mmcu=atmega328p"]
  },
  "late-link-args": {
    "gcc": ["-lgcc", "-lc"]
  },
  "target-c-int-width": "16",
  "target-endian": "little",
  "target-pointer-width": "16",
  "vendor": "unknown"
}

@mbuesch
Copy link
Contributor

mbuesch commented May 21, 2022

Also see this documentation for reg constraints:
https://doc.rust-lang.org/stable/unstable-book/language-features/asm-experimental-arch.html

@stappersg
Copy link
Member Author

Yes, progress. Thanks mbuesh. With commit cfe9848f8 and command line

AVR_CPU_FREQUENCY_HZ=8_000_000 cargo +nightly build --target ./avr-atmega328p.json -Z build-std=core --release

do I get a clean compile.

Issue is solved and left open for documentation purposes.
(The long term goal is that avr rust book has the documentation.)

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

No branches or pull requests

2 participants