Hardware Abstraction Layer for AVR microcontrollers and common boards

Overview

avr-hal Continuous Integration arduino-hal docs atmega-hal docs attiny-hal docs

Hardware Abstraction Layer for AVR microcontrollers and common boards (for example Arduino). Based on the avr-device crate.

This is a new version of avr-hal! Older versions can be found in the old branch but will no longer get support.

Quickstart

You need a nightly Rust compiler for compiling Rust code for AVR. Note: Due to a regression, versions after nightly-2021-01-07 are currently broken (see #124). Please use that version of the compiler for now. The correct version will be installed automatically.

Next, install "ravedude", a tool which seamlessly integrates flashing your board into the usual cargo workflow:

cargo +stable install ravedude

Go into ./examples/arduino-uno (or the directory for whatever board you want), and run the following commands:

cd examples/arduino-uno

# Build and run it on a connected board
cargo run --bin uno-blink

Starting your own project

The best way to start your own project is via the avr-hal-template which you can easily use with cargo-generate:

cargo generate --git https://github.com/Rahix/avr-hal-template.git

Repository Structure

The avr-hal repository is a workspace containing all components making up the HAL. Here is an overview:

arduino-hal arduino-hal docs

arduino-hal is the batteries-included HAL for all Arduino & similar boards. This is what you probably want to use for your projects. It is intentionally built to abstract away the differences between boards as much as possible.

examples/*

The examples directory contains lots of examples for common hardware. Do note that not all examples were ported to all boards, but there is a good chance that you can still use the code. Currently, the Arduino Uno crate contains the most examples.

mcu/atmega-hal atmega-hal docs , mcu/attiny-hal attiny-hal docs

HAL crates for AVR microcontroller families. If you have a custom board, you'll want to work with these crates. Please check their documentation for a list of supported MCUs.

avr-hal-generic avr-hal-generic docs

This is a generic crate containing most of the HAL implementaions in the form of macros which are instanciated in each HAL crate for the specific MCUs. If you intend to write drivers that work with any AVR chip, targeting avr-hal-generic is probably the best route.

avr-specs/

The avr-specs/ directory contains rustc target definitions for all supported microcontrollers. You will need these for compiling rust code for AVR. The avr-hal-template already includes them for convenience.

ravedude crates.io page

ravedude is a utility for seamlessly integrating avrdude and a serial console into the cargo workflow. With a bit of configuration (check its README!) you can then upload your code to your board and view its output over the serial console by just using cargo run as you would normally.

Disclaimer

This project is not affiliated with either Microchip (former Atmel) nor any of the Vendors that created the boards supported in this repository.

License

avr-hal is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Comments
  • Add a HAL implementation for SPI master

    Add a HAL implementation for SPI master

    In an attempt to execute #5 , I've begun on this skeleton of a SPI-implementing macro. I've only written a few lines of Rust, and never a macro, so this is based on reading the relevant documentation and following the examples of the other macros in the directory (namely serial.rs). I haven't even tried to compile it yet. It's a Work in Progress, and not yet ready to merge.

    Please give any and all feedback. I will continue to work on fleshing out the details.

    Note that I've intentionally substituted the original "master"/"slave" terminology for the alternate "primary"/"secondary" terminology. Hence "piso" and "posi" instead of "miso" and "mosi" respectively.

    opened by jonahbron 62
  • Added support for atmega1280 and bigavr6

    Added support for atmega1280 and bigavr6

    ~~do not merge this yet~~

    ~~This addition does not work yet and crashes the compiler.~~

    Both examples work now. The port definitions are not at all complete though.]

    Also I don't have any idea yet on how to add stuff like a display that can occupy exactly one set of pins (because it is hardwired there) and is easy to create.

    mcu-support 
    opened by peacememories 40
  • LLVM ERROR: Not supported instr

    LLVM ERROR: Not supported instr

    I am using this example: https://github.com/Rahix/avr-hal/tree/d17a441a667dd65e5a9be75b0e71d1beadf93e84/boards/arduino-uno

    I have also executed rustup component add rust-src

    And it fails to compile with this error:

    » cargo +nightly build --example uno-blink
       Compiling compiler_builtins v0.1.39
       Compiling nb v1.0.0
       Compiling cfg-if v0.1.10
       Compiling bare-metal v0.2.5
       Compiling void v1.0.2
       Compiling vcell v0.1.3
       Compiling ufmt-write v0.1.0 (https://github.com/Rahix/ufmt.git?rev=12225dc1678e42fecb0e8635bf80f501e24817d9#12225dc1)
       Compiling panic-halt v0.2.0
       Compiling nb v0.1.3
       Compiling avr-device v0.2.3
       Compiling ufmt v0.1.0 (https://github.com/Rahix/ufmt.git?rev=12225dc1678e42fecb0e8635bf80f501e24817d9#12225dc1)
       Compiling embedded-hal v0.2.4
    LLVM ERROR: Not supported instr: <MCInst 258 <MCOperand Reg:1> <MCOperand Imm:15> <MCOperand Reg:40>>
    error: could not compile `compiler_builtins`
    
    To learn more, run the command again with --verbose.
    warning: build failed, waiting for other jobs to finish...
    error: build failed
    

    My versions:

    • rust
    » rustup --version
    rustup 1.23.1 (2020-12-03)
    info: This is the version for the rustup toolchain manager, not the rustc compiler.
    info: The currently active `rustc` version is `rustc 1.51.0-nightly (c8915eebe 2021-01-07)`
    
    • avr
    » avr-gcc --version
    avr-gcc (Homebrew AVR GCC 9.3.0) 9.3.0
    Copyright (C) 2019 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    
    • And macos 10.14
    compiler-bug 
    opened by sobolevn 23
  • SPI: CS must be configured before SPI peripheral

    SPI: CS must be configured before SPI peripheral

    I'm trying to use the SPI library but it's not working as expected. The send method works fine and returns without incident, but the read method blocks forever.

        let byte = block!(spi.send(5u8).and_then(|_| spi.read()));
        if let Ok(byte) = byte {
            ufmt::uwriteln!(&mut serial, "wrote read {}\r", byte).unwrap();
        } else {
            ufmt::uwriteln!(&mut serial, "not wrote read\r").unwrap();
        }
    

    It never makes it past the block macro, it seems that it's returning WouldBlock forever. All read does is try to flush, code here:

    https://github.com/Rahix/avr-hal/blob/master/avr-hal-generic/src/spi.rs#L125

    The is_write_in_progress is obviously true as expected, since a send was just executed. But it seems that the write complete status register is not being set.

    https://github.com/Rahix/avr-hal/blob/master/avr-hal-generic/src/spi.rs#L127

    Documentation for the SPI interrupt flag is in section 18.5.2 of this document:

    http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7810-Automotive-Microcontrollers-ATmega328P_Datasheet.pdf

    I'm trying to debug this but any suggestions are welcome.

    bug hal-api 
    opened by jonahbron 20
  • uno-runner for Windows Subsystom for Linux

    uno-runner for Windows Subsystom for Linux

    This is a post on how to connect serial devices to WSL: https://www.scivision.dev/usb-tty-windows-subsystem-for-linux/

    On Linux, the Arduino doesn't show up as /dev/ttyACM0 but as for example /dev/ttyS3 when it's connected to Port 3.

    This would perhaps conclude that changing this: SERIAL_PORT="/dev/ttyACM0" in uno-runner.sh to SERIAL_PORT="/dev/ttyS3" would do the trick but that's not the case I think because I get Inappropriate ioctl for device instead.

    How can I make this work?

    windows 
    opened by Septias 18
  • Analog output for Arduino Uno

    Analog output for Arduino Uno

    The Arduino supports PWM on a few ports, yet looking through ports.rs, the HAL only seems to allow digital outputs. Is there an example of doing analog writes? Does this require including a lower level implementation?

    hal-api hal-generic 
    opened by jeroenvlek 16
  • Some uncommon baudrates might be unstable

    Some uncommon baudrates might be unstable

    Following PR #88, some (uncommon!) baudrates seem to be unstable: Namely 14400, 28800, and 76800 seem to be problematic. Further analysis of the generated waveform is needed to determine what is the problem.

    Relevant comment from the PR.

    Cc: @explicite

    bug help wanted 
    opened by Rahix 13
  • SparkFun Qwiic Pro Micro USB-C Atmega32u4

    SparkFun Qwiic Pro Micro USB-C Atmega32u4

    Hello @Rahix

    I just started making the sparkfun-pro-micro crate by copying and renaming everything from the arduino-leonardo one (26698a0a191).

    @cecton, for the pins, just reference the schematic for your board. It shows quite well which MCU pin is named what on the PCB.

    It honestly took me some time to see it on the schematics :sweat_smile: I used the right most diagram.

    It doesn't really show D11 to D13 but I supposed this is assumed because of the order? So I did the same with A4-A5 (Please double check that b66921e87)

    Closes #52

    mcu-support 
    opened by cecton 13
  • Need examples showing how to use timer interrupts : ISR : OCR: interrupt service routine: output compare register

    Need examples showing how to use timer interrupts : ISR : OCR: interrupt service routine: output compare register

    BACKGROUND

    I'm attempting to follow various examples for writing timer driven interrupt service routines in rust targeting the AVR...similar to these examples in arduino c:

    https://www.instructables.com/id/Arduino-Timer-Interrupts/ https://circuitdigest.com/microcontroller-projects/arduino-timer-tutorial

    EXAMPLE c CODE

    In these examples, there is a stanza for setting the various registers to set this up. Here's an extract:

    //set timer1 interrupt at 1Hz
      TCCR1A = 0;// set entire TCCR1A register to 0
      TCCR1B = 0;// same for TCCR1B
      TCNT1  = 0;//initialize counter value to 0
      // set compare match register for 1hz increments
      OCR1A = 15624;// = (16*10^6) / (1*1024) - 1 (must be <65536)
      // turn on CTC mode
      TCCR1B |= (1 << WGM12);
      // Set CS10 and CS12 bits for 1024 prescaler
      TCCR1B |= (1 << CS12) | (1 << CS10);  
      // enable timer compare interrupt
      TIMSK1 |= (1 << OCIE1A);
    

    Then these c examples show how to wire up an ISR:

    ISR(TIMER1_COMPA_vect){...}
    

    AVR-HAL rust CODE

    In the avr-hal repo's various examples, I only see reference to the timer registers of tccr1b and tcnt1. Is this an oversight or is this because of some limitation on the platform? It would be really useful to see an example that included the other registers such as compare ocr1a and especially an example showing the use of an interrupt service routine like the common c ISR above.

    Links: Here's the example code I am following, though I've looked at all the avr-hal examples that include a timer:

    1. Create the timer
    2. Configure prescaling (TCCR1B)
    3. Reset/clear the timer (TCNT1)
    4. Is this TCNT1 read the equivalent of an output compare register (OCR)?

    REQUEST

    An example that sets up 2 different timers, say timer0 and timer1, and instantiates an ISR. I assume this would mean properly setting the ocr0a and ocr1a registers...h

    I am happy to assist with documentation and more examples, but I need some direction/guidance here.

    question 
    opened by ToddG 12
  • Serial port setup: baud_rate/8/N/1 doesn't work when uploading examples to Arduino Uno rev2

    Serial port setup: baud_rate/8/N/1 doesn't work when uploading examples to Arduino Uno rev2

    I'm getting gibberish on serial port. I've uploaded examples to my Arduino Uno rev2 board via cargo +nightly run --example uno-serial and cargo +nightly run --example uno-adc. I've played with several baud_rates (switched uno-serial.rs example from 57600 to 9600). I cannot get the correct setup to retrieve the data. The upload process is correct and other examples (uno-blink.rs) are working correctly.

    Also, code from Arduino IDE behaves correctly in terms of Serial port communication.

    bug 
    opened by kosciej 12
  • Windows build fails because of symlinked target files

    Windows build fails because of symlinked target files

    Heya,

    just checked this out on Windows 10 with rust 1.47.0-nightly and tried to run the uno-blink example but got:

    $ cargo build --example uno-blink
       Compiling arduino-uno v0.1.0 (C:\Users\grego\code\avr-hal\boards\arduino-uno)
    error: unknown use of instruction mnemonic without a size suffix
      |
    note: instantiated into assembly here
     --> <inline asm>:1:2
      |
    1 |     in %al,0x35
      |     ^
    
    error: invalid instruction mnemonic 'sei'
      |
    note: instantiated into assembly here
     --> <inline asm>:1:2
      |
    1 |     sei
      |     ^^^
    
    error: aborting due to 2 previous errors
    
    error: could not compile `arduino-uno`.
    

    Same problem in WSL 2 Ubuntu with the same rust version. Any pointers would be appreciated, maybe it's something I could look at myself.

    bug windows 
    opened by Gregoor 12
  • NixOS: Linker errors when compiling for ATmega2560 with recent rust compiler

    NixOS: Linker errors when compiling for ATmega2560 with recent rust compiler

    Hello!

    I'm pretty new to cross-compiling.

    I created a nix environment in which i can compile the .ELF file for some targets.

    For example, the target avr-atmega328p.json works:

    bash-5.1$ cargo build --target avr-specs/avr-atmega328p.json 
       Compiling compiler_builtins v0.1.85
       Compiling core v0.0.0 (/nix/store/r9ns07w4z808rpysvg4z84bx3q525yv7-rust-mixed/lib/rustlib/src/rust/library/core)
       Compiling avr-hal-generic v0.1.0 (https://github.com/rahix/avr-hal?rev=4170a773d4d76cc93433d2455ed8b14e573ebe70#4170a7
       [..... i am skipping some lines ....]
       Compiling helloworld v0.1.0 (/home/arne/Projects/hobby/rust-arduino-led-blink)
        Finished dev [optimized + debuginfo] target(s) in 20.01s
    

    And i get target/avr-atmega328p/debug/helloworld.elf.

    But the arduino that i have at my disposal is the atmega2560, i get the following output:

    bash-5.1$ cargo build --target avr-specs/avr-atmega2560.json --verbose
           Fresh core v0.0.0 (/nix/store/r9ns07w4z808rpysvg4z84bx3q525yv7-rust-mixed/lib/rustlib/src/rust/library/core)
           Fresh rustc-std-workspace-core v1.99.0 (/nix/store/r9ns07w4z808rpysvg4z84bx3q525yv7-rust-mixed/lib/rustlib/src/rust/library/rustc-std-workspace-core)
           Fresh unicode-ident v1.0.6
           Fresh compiler_builtins v0.1.85
           Fresh proc-macro2 v1.0.49
           Fresh quote v1.0.23
           Fresh nb v1.0.0
           Fresh syn v1.0.107
           Fresh proc-macro-hack v0.5.20+deprecated
           Fresh rustversion v1.0.11
           Fresh ufmt-macros v0.2.0
           Fresh avr-device-macros v0.4.0
           Fresh nb v0.1.3
           Fresh ufmt-write v0.1.0
           Fresh bare-metal v1.0.0
           Fresh cfg-if v0.1.10
           Fresh void v1.0.2
           Fresh vcell v0.1.3
           Fresh ufmt v0.1.2
           Fresh paste v1.0.11
           Fresh embedded-hal v0.2.7
           Fresh avr-device v0.4.0
           Fresh cfg-if v1.0.0
           Fresh avr-hal-generic v0.1.0 (https://github.com/rahix/avr-hal?rev=4170a773d4d76cc93433d2455ed8b14e573ebe70#4170a773)
           Fresh panic-halt v0.2.0
           Fresh atmega-hal v0.1.0 (https://github.com/rahix/avr-hal?rev=4170a773d4d76cc93433d2455ed8b14e573ebe70#4170a773)
           Fresh arduino-hal v0.1.0 (https://github.com/rahix/avr-hal?rev=4170a773d4d76cc93433d2455ed8b14e573ebe70#4170a773)
       Compiling helloworld v0.1.0 (/home/arne/Projects/hobby/rust-arduino-led-blink)
         Running `rustc --crate-name helloworld --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=149 --crate-type bin --emit=dep-info,link -C opt-level=s -C panic=abort -C lto -C debuginfo=2 -C debug-assertions=on -C metadata=fbe7e5f7c81a8527 -C extra-filename=-fbe7e5f7c81a8527 --out-dir /home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps --target /home/arne/Projects/hobby/rust-arduino-led-blink/avr-specs/avr-atmega2560.json -C incremental=/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/incremental -L dependency=/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps -L dependency=/home/arne/Projects/hobby/rust-arduino-led-blink/target/debug/deps --extern arduino_hal=/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps/libarduino_hal-b20db3fb6d901e6a.rlib --extern 'noprelude:compiler_builtins=/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps/libcompiler_builtins-03a22ee3553a16ba.rlib' --extern 'noprelude:core=/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps/libcore-8e43a845006832d0.rlib' --extern embedded_hal=/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps/libembedded_hal-2eda8d6ea831d148.rlib --extern nb=/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps/libnb-1af58d0fb3475ee9.rlib --extern panic_halt=/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps/libpanic_halt-d2460f22359f919f.rlib --extern ufmt=/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps/libufmt-a9534496297e0ed1.rlib -Z unstable-options`
    error: linking with `avr-gcc` failed: exit status: 1
      |
      = note: LC_ALL="C" PATH="/nix/store/r9ns07w4z808rpysvg4z84bx3q525yv7-rust-mixed/lib/rustlib/x86_64-unknown-linux-gnu/bin:/nix/store/g2nfbpind37b3v3y6zbszmcgfmrj5v7x-patchelf-0.15.0/bin:/nix/store/wn31i3dzwahz6ccws8bs1nwyqrpgsvj7-gcc-wrapper-11.3.0/bin:/nix/store/sxdx80lmk4zkhb51f4x5dgqvxgmx55wl-gcc-11.3.0/bin:/nix/store/s7ip867mrpnnjlppbnxlcsq10gv13x2x-glibc-2.35-224-bin/bin:/nix/store/h8gvq6r4hgpa71h44dmg9qfx03mj81sv-coreutils-9.1/bin:/nix/store/62fb427ncxaaksa2k59rhbilfg68v20x-binutils-wrapper-2.39/bin:/nix/store/frh9l9nrdysasdi2gs7i241s241ngjw2-binutils-2.39/bin:/nix/store/bzc9c4x9fqwjaxs0g45qkahabc0gv75f-avrdude-7.0/bin:/nix/store/fznym4mxp2q5r0bg6zdpska27xcq1iv3-ravedude-0.1.5/bin:/nix/store/r9ns07w4z808rpysvg4z84bx3q525yv7-rust-mixed/bin:/nix/store/88awvrn16car4z5xx516drhpbl2sp5h8-avr-stage-final-gcc-wrapper-11.3.0/bin:/nix/store/7zlcl5m0vq5cl5kcl1swb67wczms78al-avr-stage-final-gcc-11.3.0/bin:/nix/store/5kh0ddszrd1d04z61kw1b2302z7mbnkp-avr-libc-avr-2.1.0/bin:/nix/store/qyrv5scy0pda6cm10mdn66nd6shh907a-avr-binutils-wrapper-2.39/bin:/nix/store/kzjyiw72pi5d7hgyrs0l1fgqq31zj6cs-avr-binutils-2.39/bin:/nix/store/h8gvq6r4hgpa71h44dmg9qfx03mj81sv-coreutils-9.1/bin:/nix/store/zml88vnkpm8if114qkbbqd1q7n3ypqqy-findutils-4.9.0/bin:/nix/store/49y3r0gr9m6k20d91kl6dgp4b9a6m72v-diffutils-3.8/bin:/nix/store/5dv5cq1lwvsijr9p16p2kp79g1dbajk3-gnused-4.8/bin:/nix/store/bcvccw6y9bfil6xrl5j7psza7hnd16ry-gnugrep-3.7/bin:/nix/store/l1fp0hyca54xbb85vfhppd16bskzx8dg-gawk-5.1.1/bin:/nix/store/89zbjdkb48ma61k76l2mzn3s0ra0wn2c-gnutar-1.34/bin:/nix/store/qs8qb1swpivkfq7i9yd52n0mw6z4ij81-gzip-1.12/bin:/nix/store/wwkyfg8b34xy16zzc9p6rkh59p4q37qx-bzip2-1.0.8-bin/bin:/nix/store/i0x4pzj96qwvkrm94317l6jbi53a2rdj-gnumake-4.4/bin:/nix/store/4xw8n979xpivdc46a9ndcvyhwgif00hz-bash-5.1-p16/bin:/nix/store/793iwfbjvg7wgpqq7r83a1qjl1yg02sf-patch-2.7.6/bin:/nix/store/a3mwv26f99ycsv9w6hrx0jjjjywvcb1n-xz-5.2.9-bin/bin:/nix/store/camlh5laf1wsklghk0vcaw7gvx4rpzd1-file-5.43/bin:/home/arne/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/home/arne/.cargo/bin:/home/arne/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/home/arne/.cabal/bin:/home/arne/.ghcup/bin:/home/arne/.yarn/bin:/home/arne/.emacs.d/bin:/home/arne/.yarn/bin:/home/arne/.emacs.d/bin" VSLANG="1033" "avr-gcc" "-mmcu=atmega2560" "-Wl,--as-needed" "/tmp/nix-shell.pCNOuF/rustcaIPZ4U/symbols.o" "/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps/helloworld-fbe7e5f7c81a8527.arduino_hal-b20db3fb6d901e6a.arduino_hal.4ff7873c-cgu.0.rcgu.o.rcgu.o" "-Wl,--as-needed" "-L" "/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps" "-L" "/home/arne/Projects/hobby/rust-arduino-led-blink/target/debug/deps" "-L" "/nix/store/r9ns07w4z808rpysvg4z84bx3q525yv7-rust-mixed/lib/rustlib/avr-atmega2560/lib" "-Wl,-Bstatic" "/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps/libcompiler_builtins-03a22ee3553a16ba.rlib" "-Wl,-Bdynamic" "-lgcc" "-Wl,-znoexecstack" "-L" "/nix/store/r9ns07w4z808rpysvg4z84bx3q525yv7-rust-mixed/lib/rustlib/avr-atmega2560/lib" "-o" "/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps/helloworld-fbe7e5f7c81a8527.elf" "-Wl,--gc-sections" "-no-pie"
      = note: /nix/store/kzjyiw72pi5d7hgyrs0l1fgqq31zj6cs-avr-binutils-2.39/bin/avr-ld: skipping incompatible /nix/store/5kh0ddszrd1d04z61kw1b2302z7mbnkp-avr-libc-avr-2.1.0/avr/lib/avr5/libm.a when searching for -lm
              /nix/store/kzjyiw72pi5d7hgyrs0l1fgqq31zj6cs-avr-binutils-2.39/bin/avr-ld: skipping incompatible /nix/store/5kh0ddszrd1d04z61kw1b2302z7mbnkp-avr-libc-avr-2.1.0/avr/lib/avr3/libm.a when searching for -lm
              /nix/store/kzjyiw72pi5d7hgyrs0l1fgqq31zj6cs-avr-binutils-2.39/bin/avr-ld: skipping incompatible /nix/store/5kh0ddszrd1d04z61kw1b2302z7mbnkp-avr-libc-avr-2.1.0/avr/lib/avr4/libm.a when searching for -lm
              /nix/store/kzjyiw72pi5d7hgyrs0l1fgqq31zj6cs-avr-binutils-2.39/bin/avr-ld: skipping incompatible /nix/store/5kh0ddszrd1d04z61kw1b2302z7mbnkp-avr-libc-avr-2.1.0/avr/lib/avr5/libc.a when searching for -lc
              /nix/store/kzjyiw72pi5d7hgyrs0l1fgqq31zj6cs-avr-binutils-2.39/bin/avr-ld: skipping incompatible /nix/store/5kh0ddszrd1d04z61kw1b2302z7mbnkp-avr-libc-avr-2.1.0/avr/lib/avr3/libc.a when searching for -lc
              /nix/store/kzjyiw72pi5d7hgyrs0l1fgqq31zj6cs-avr-binutils-2.39/bin/avr-ld: skipping incompatible /nix/store/5kh0ddszrd1d04z61kw1b2302z7mbnkp-avr-libc-avr-2.1.0/avr/lib/avr4/libc.a when searching for -lc
              /nix/store/kzjyiw72pi5d7hgyrs0l1fgqq31zj6cs-avr-binutils-2.39/bin/avr-ld: avr architecture of input file `/tmp/nix-shell.pCNOuF/rustcaIPZ4U/symbols.o' is incompatible with avr:6 output
              collect2: error: ld returned 1 exit status
              
    
    error: could not compile `helloworld` due to previous error
    
    Caused by:
      process didn't exit successfully: `rustc --crate-name helloworld --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=149 --crate-type bin --emit=dep-info,link -C opt-level=s -C panic=abort -C lto -C debuginfo=2 -C debug-assertions=on -C metadata=fbe7e5f7c81a8527 -C extra-filename=-fbe7e5f7c81a8527 --out-dir /home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps --target /home/arne/Projects/hobby/rust-arduino-led-blink/avr-specs/avr-atmega2560.json -C incremental=/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/incremental -L dependency=/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps -L dependency=/home/arne/Projects/hobby/rust-arduino-led-blink/target/debug/deps --extern arduino_hal=/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps/libarduino_hal-b20db3fb6d901e6a.rlib --extern 'noprelude:compiler_builtins=/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps/libcompiler_builtins-03a22ee3553a16ba.rlib' --extern 'noprelude:core=/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps/libcore-8e43a845006832d0.rlib' --extern embedded_hal=/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps/libembedded_hal-2eda8d6ea831d148.rlib --extern nb=/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps/libnb-1af58d0fb3475ee9.rlib --extern panic_halt=/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps/libpanic_halt-d2460f22359f919f.rlib --extern ufmt=/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps/libufmt-a9534496297e0ed1.rlib -Z unstable-options` (exit status: 1)
    

    I don't understand why it doesn't work for the latter target.

    The repository is here: https://github.com/arnemileswinter/rust-arduino-cross-compile-nix-blinking-led and is based on the cargo template.

    Thanks in advance!

    compiler-bug 
    opened by arnemileswinter 4
  • Hmm, I also found this [Stackoverflow Answer](https://electronics.stackexchange.com/a/390541) which might give a good base:

    Hmm, I also found this [Stackoverflow Answer](https://electronics.stackexchange.com/a/390541) which might give a good base:

        Hmm, I also found this [Stackoverflow Answer](https://electronics.stackexchange.com/a/390541) which might give a good base:
    

    "4" The last digit marks the series of chips. Within a series they are often pin-compatible and share a similar set of features. Some prominent series are:

    • 'no digit' - these are the first generation chips with 8 to 128 kiB Flash
    • '8' - a series from 4 to 32 kiB Flash, all in the same housing. More or less an improved version of the original chips
    • '4' similar to '8', but in larger packages with more pins (~40 instead of ~30) and up to 128 kiB Flash
    • '5' similar to '4', but with more timers and PWM channels
    • '0','1' rather old family with large packages (60 - 100 pins) and up to 256 kiB Flash.
    • '9' with integrated LCD controller
    • 'U2', 'U4' are the two sizes of USB-enabled controllers
    • '08', '09' newest family with additional configurable logic and more CPU-bypassing features
    • '50', '90' the largest chips with 100 pins, but few peripherals

    I think we can group some of them even more. For a start, I'd (without looking deeper) group the ATmega devices like this:

    • no digit
    • 8, 4, 5
    • 0, 1
    • U*

    for the others, we don't currently have any devices supported, so we can take care of them later. For the ATtiny devices, I think we can try to merge the info from your link with this kind of 'generation' numbering scheme, to derive a sensible partitioning.

    What also needs to be evaluated is how to name those crates ... Not sure what would be intuitive.

    Originally posted by @Rahix in https://github.com/Rahix/avr-hal/issues/94#issuecomment-736545626

    opened by lemurcina 1
  • Add support for ATmega8

    Add support for ATmega8

    Adds support for ATmega8 (https://github.com/Rahix/avr-device/pull/112 has to be resolved first for this to work correctly).

    ATmega8 is more challenging, because it does not work like the atmegas that were already implemented in some ways

    1. EEPROM does not have modes (erase, erase and write), completely different mechanism is required.

    2. WDT registers have different names "s" is missing from wdtcsr.

    3. Does not have DIDR for ADCs

    4. USART does not have "0" at end. It's just USART, not USART0. It has registers UBRRL, UBRRH instead of just one UBRR. I don't think it's possible to merge into just one register using patches as the UBRRH is shared with UCSRC and it's not directly next to UBRRL.

    5. WDT does not have the same prescalers. It also does not support 4k ms and 8k ms. The rest of the prescalers does not exactly match the values.

    6. I implemented a new macro that is named impl_eeprom_atmega_old. I am not sure if this name fits.

    7. I added paste macro and passed in a string name of the register

    8. I created a no_didr macro that does not contain anything in the relevant method. I don't think there is anything else to be done in that method, but I may be wrong here. I have not used ADCs that much.

    9. as ATmega8 looks very specific regarding USART, I decided to not even create a macro, but instead implement it directly in atmega-hal/wdt.rs. There is a few differences to usart macro, namely UCSRC and UBRRH are functions, UCSRC has to have set URSEL to one (that says UCSRC should be set instead of UBRRH as they share the same location in memory). UBRR is set by UBRRH and UBRRL instead of just UBRR.

    10. I have used the closest values and put panic!() to 4k ms and 8k ms. I think there should be a better solution than this...

    What do you think about these changes? Do you have better idea how to implement ATmega8?

    I have tested EEPROM, USART, ADCs (and using ports of course) so far. I will try to test the rest in short time.

    opened by Rutherther 0
  • Can't Compile error E0635

    Can't Compile error E0635

    When running cargo build I get the following error:

       Compiling proc-macro2 v1.0.47
    error[E0635]: unknown feature `proc_macro_span_shrink`
      --> .cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-1.0.47/src/lib.rs:92:30
       |
    92 |     feature(proc_macro_span, proc_macro_span_shrink)
       |                              ^^^^^^^^^^^^^^^^^^^^^^
    
    error: aborting due to previous error
    
    For more information about this error, try `rustc --explain E0635`.
    error: could not compile `proc-macro2`
    
    To learn more, run the command again with --verbose.
    
    opened by StormTrooper720 1
  • Support ATMega644/A

    Support ATMega644/A

    Currently, ATMega644 is supported in avr-devices but not in avr-hal and, if a meaningful difference exists, neither supports ATMega644A. It would be nice to see these supported.

    help wanted mcu-support 
    opened by enderger 0
  • Support Arduino Uno Wifi (rev 2)

    Support Arduino Uno Wifi (rev 2)

    Hello,

    I followed your guide on generating a new project with avr-hal-template and chose 'Arduino Uno' in the template menu.

    When I execute cargo run, I get:

    Finished dev [optimized + debuginfo] target(s) in 7.65s
         Running `ravedude uno -cb 57600 -P /dev/ttyACM0 target/avr-atmega328p/debug/sensor.elf`
           Board Arduino Uno
     Programming target/avr-atmega328p/debug/environment-sensor.elf => /dev/ttyACM0
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
    

    The Arduino IDE gives exactly the same error.

    However, after some investigation with arduino-cli, I found out I need the megaAVR core rather than the (I think) non-mega avr core that is used by ravedude:

    $ ./arduino-cli board list
    Port         Protocol Type              Board Name            FQBN                    Core
    /dev/ttyACM0 serial   Serial Port (USB) Arduino Uno WiFi Rev2 arduino:megaavr:uno2018 arduino:megaavr
    

    Using the listed FQBN with arduino-cli on the 'blink' example sketch, the sketch gets successfully uploaded and starts running on the target:

    $ ./arduino-cli compile --fqbn arduino:megaavr:uno2018 blink
    $ ./arduino-cli upload -p /dev/ttyACM0 --fqbn arduino:megaavr:uno2018 blink
    avrdude: usbdev_open(): WARNING: failed to set configuration 1: Device or resource busy
    

    It seems the warning can be ignored in this case, although I can't say what other process is actually using the device while doing this.

    My questions for you:

    • Is this a known issue and do you have pointers to solutions?
    • If not, can I configure ravedude to use the above FQBN?
    • If not, can you point me where I need to extend the ravedude code to support this? I don't seem to be able to locate the core setting in the generated config for avrdude.
    opened by bverhagen 0
Owner
Rahix
Rahix
Rust Hardware Abstraction Layer (HAL) crate for the Vorago VA108xx family of MCUs

HAL for the Vorago VA108xx MCU family This repository contains the Hardware Abstraction Layer (HAL), which is an additional hardware abstraction on to

Institute of Space Systems 0 Dec 22, 2021
Hardware Abstraction Layer for ATmega32U4

Deprecation Note: This crate will soon be deprecated in favor of avr-hal. avr-hal is a new approach to writing the HAL crate, that was designed with s

Rahix 3 May 16, 2021
An asynchronous Hardware Abstraction Layer (HAL) for embedded systems

embedded-hal-async An asynchronous Hardware Abstraction Layer (HAL) for embedded systems. This crate contains asynchronous versions of the embedded-ha

Diego Barrios Romero 3 Jan 22, 2022
Register access crate for AVR microcontrollers

avr-device Auto-generated wrappers around registers for AVR microcontrollers. Usage Add the following to Cargo.toml: [dependencies.avr-device] version

Rahix 103 Dec 23, 2022
Garden monitoring system using m328p and m2560 Arduino Uno boards

Garden monitoring system using m328p and m2560 Arduino Uno boards. 100% Rust [no_std] using the avr hardware abstraction layer (avr-hal)

Ethan Gallucci 1 May 4, 2022
Progmem utility for the AVR architecture

avr-progmem Progmem utilities for the AVR architectures. This crate provides unsafe utilities for working with data stored in the program memory of an

null 15 Nov 20, 2022
AVR device definitions

avrd AVR device definitons in Rust. Documentation This crate exposes information about different AVR microcontrollers so it can be used pragmatically.

The AVR-Rust project 32 Dec 28, 2022
Functional testing framework for AVR binaries, powered by simavr.

Functional testing framework for AVR binaries, powered by simavr. tl;dr get your microcontroller's firmware black-box-tested in seconds!

Patryk Wychowaniec 14 Nov 16, 2022
ICSP (2-wire) dongle for flashing PIC32 microcontrollers

Pic32Probe This is an ICSP (2-wire) dongle for flashing PIC32 microcontrollers implemented on an Raspberry Pi RP2040 microcontroller. Use a simple RP2

Stephan 3 Sep 26, 2022
HAL for the CH58x family of microcontrollers. BLE 5.3, RISC-V Qingke V4.

ch58x-hal HAL for the CH58x RISC-V BLE microcotrollers from WCH. This crate is under random and active development. DO NOT USE in production. This sho

WCH MCU for Rust 3 Oct 24, 2023
Common utilities code used across Fulcrum Genomics Rust projects

fgoxide Common utilities code used across Fulcrum Genomics Rust projects. Why? There are many helper functions that are used repeatedly across project

Fulcrum Genomics 2 Nov 2, 2022
Tracing layer to quickly inspect spans and events

tracing-texray First, a word of warning: This is alpha software. Don't run this in prod or anywhere where a panic would ruin your day. tracing-texray

Russell Cohen 23 Dec 3, 2022
The classic game Pong, written in lambda calculus, and a thin layer of Rust.

What? The good old game Pong, written in lambda calculus, and a thin layer of Rust. Why? I was bored. No, seriously, why? Everyone keeps saying that l

null 2 Aug 14, 2022
A tracing layer for macOS/iOS's `oslog`

tracing_oslog This is a tracing layer for the Apple OS logging framework. Activities are used to handle spans, Example use tracing_oslog::OsLogger; l

Lucy 12 Dec 6, 2022
A compatibility layer to smooth the transition between different versions of embedded-hal

Embedded HAL Compatibility Layer A compatibility layer to smooth the transition between different versions of embedded-hal (specifically 0.2.x and 1.0

Ryan 7 Sep 11, 2022
AWS Cloudwatch layer for tracing-subscriber

tracing-cloudwatch tracing-cloudwatch is a custom tracing-subscriber layer that sends your application's tracing events(logs) to AWS CloudWatch Logs.

ymgyt 7 May 14, 2023
A crate providing a tracing-subscriber layer for formatting events so Datadog can parse them

Datadog Formatting Layer A crate providing a tracing-subscriber layer for formatting events so Datadog can parse them. Features Provides a layer for t

Open Schnick 4 Jun 22, 2023
Fusion is a cross-platform App Dev ToolKit build on Rust . Fusion lets you create Beautiful and Fast apps for mobile and desktop platform.

Fusion is a cross-platform App Dev ToolKit build on Rust . Fusion lets you create Beautiful and Fast apps for mobile and desktop platform.

Fusion 1 Oct 19, 2021
List of Persian Colors and hex colors for CSS, SCSS, PHP, JS, Python, and Ruby.

Persian Colors (Iranian colors) List of Persian Colors and hex colors for CSS, SCSS, PHP, C++, QML, JS, Python, Ruby and CSharp. Persian colors Name H

Max Base 12 Sep 3, 2022