avr-rust / delay

arduino-like delay routines based on busy-wait loops
Apache License 2.0
15 stars 11 forks source link

invalid register class `reg_iw` #20

Open stappersg opened 2 years ago

stappersg commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

Some information about my system:

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 commented 2 years ago

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 commented 2 years ago

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

stappersg commented 2 years ago

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.)