Expand description
Avr Boot
This crate contains functions to write to the program memory of AVR MCUs, using the spm
instruction.
It could be considered a reimagining of the macros in boot.h from avr-libc, but in Rust, plus some artisanal, hand-crafted asm. If you’re looking to create a bootloader, this crate should be useful.
It is hal independent, and optimised for code size.
Regular and extended (>64k) addressing modes are supported.
Getting started
Add the module to your Cargo.toml:
[dependencies]
avr-boot = "0.1.0"
Pick from the high level API:
use avr_boot::PageBuffer;
let address: u16 = 0x1000;
let data = [0xffff; PageBuffer::LENGTH];
let buff = PageBuffer::new(address);
buff.copy_from(&data);
buff.store();
Or the low level one:
use avr_boot::{spm, SPM_PAGESIZE_WORDS, Address};
let page_address: u16 = 0x1000;
for w in 0..SPM_PAGESIZE_WORDS {
spm::fill_page((page_address + (w * 2) as u16), 0x1234);
}
spm::erase_page(page_address);
spm::write_page(page_address);
spm::rww_enable();
Check out the examples module for more usage examples
Modules
Low level API for calling bootloader functions
Structs
16 or 24 bit program memory address
NewType, an array of memory the same size as the page buffer
Representation of the spm page buffer.
Constants
Total size of the SPM page buffer, for the current MCU target
Total length in 16 but words of the SPM page buffer, for the current MCU target