Skip to content

Latest commit

 

History

History
144 lines (122 loc) · 5.1 KB

README.md

File metadata and controls

144 lines (122 loc) · 5.1 KB

avr-hal Build Status

embedded-hal implementations for AVR microcontrollers. Based on the register definitions from avr-device.

Quickstart

You need nightly rust for compiling rust code for AVR. Go into ./boards/arduino-leonardo (or the directory for whatever board you want), and run the following commands:

# Now you are ready to build your first avr blink example!
cargo +nightly build --example leonardo-blink

# Finally, convert it into a .hex file that you can flash using avr-dude
../../mkhex.sh --debug leonardo-blink

ls -l ../../target/leonardo-blink.hex

Starting your own project

This is a step-by-step guide for creating a new project targeting Arduino Leonardo (ATmega32U4). You can of course apply the same steps for any other microcontroller.

  1. Start by creating a new project:
    cargo new --bin avr-example
    cd avr-example
  2. Copy the target description for your MCU (e.g. boards/arduino-leonardo/avr-atmega32u4.json) into your project.
  3. Create a file .cargo/config.toml with the following content:
    [build]
    target = "avr-atmega32u4.json"
    
    [unstable]
    build-std = ["core"]
  4. Fill Cargo.toml with these additional directives:
    [dependencies]
    # A panic handler is needed.  This is a crate with the most basic one.
    # The `leonardo-panic` example shows a more elaborate version.
    panic-halt = "0.2.0"
    
    [dependencies.arduino-leonardo]
    git = "https://github.com/Rahix/avr-hal"
    
    # Configure the build for minimal size
    [profile.dev]
    panic = "abort"
    lto = true
    opt-level = "s"
    
    [profile.release]
    panic = "abort"
    codegen-units = 1
    debug = true
    lto = true
    opt-level = "s"
  5. Start your project with this basic template:
    #![no_std]
    #![no_main]
    
    // Pull in the panic handler from panic-halt
    extern crate panic_halt;
    
    use arduino_leonardo::prelude::*;
    
    #[arduino_leonardo::entry]
    fn main() -> ! {
        let dp = arduino_leonardo::Peripherals::take().unwrap();
    
        unimplemented!()
    }
  6. Build with
    cargo +nightly build
    # or
    cargo +nightly build --release
    and find your binary in .

Structure

This repository contains the following components:

  • A generic crate containing implementations that can be used chip-independently and macros to create chip-dependent instances of peripheral abstractions. This crate is named avr-hal-generic.
  • HAL crates for each chip in chips/. These make use of avr-hal-generic to create chip-specific definitions.
  • Board Support Crates for popular hardware in boards/. They, for the most part, just re-export functionality from the chip-HAL, with the names that are printed on the PCB.

Status

The following peripherals are supported in avr-hal-generic:

  • A spinning delay implementation
  • PORTx peripherals as digital IO (v2)
  • A TWI based I2C implementation
  • SPI primary-mode implementation

HAL Status

The chip-HAL crates currently support the following peripherals:

  • atmega2560-hal
    • Spinning Delay
    • PORTA, PORTB, PORTC, PORTD, PORTE, PORTF, PORTG, PORTH, PORTJ, PORTK, PORTL as digital IO
    • USART0, USART1, USART2, USART3 for serial communication
    • I2C using TWI
    • SPI
    • ADC (no differential channels yet)
  • atmega328p-hal
    • Spinning Delay
    • PORTB, PORTC, PORTD as digital IO (v2)
    • USART0 for serial communication
    • I2C using TWI
    • SPI
    • ADC
  • atmega32u4-hal
    • Spinning Delay
    • PORTB, PORTC, PORTD, PORTE, PORTF as digital IO (v2)
    • USART1 for serial communication
    • I2C using TWI
    • SPI
    • ADC (no differential channels yet)
  • attiny85-hal
    • Spinning Delay
    • PORTB as digital IO (v2)

Supported Hardware

In boards/ there are crates for the following hardware. Please note that this project is in no way affiliated with any of the vendors.

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.