Developing AVR code usually involves a lot of simulation, by using programs such as:
- simavr, an excellent all-round option, http://github.com/buserror/simavr/
- μsim, aimed strictly at testing crypto protocols https://github.com/hberntsen/usim
fastavr is like these, but with the main design goals of raw speed and simplicity of use.
- Supports all common AVR instructions (see below)
- Optional user-definable behaviour of all AVR I/O ports
- Interrupts and single-stepping
- Possibility of simulating components using multi-threading
- Much faster than a physical AVR
See the file
tester.c; this reads an AVR program (in IHEX8 format) and executes it on a emulated Atmega2560, causing bytes
written to USART0 to be written to the console. It also defines a watchdog timer that can be used to auto-reset/kill a program
that is in a run-away condition (as described in Atmel's datasheets). Also emulated are the programmable timers TIMER0 and
TIMER1, as well as EEPROM memory (for handling non-volatile data).
To build this project, you will need to have support for developing 32-bit programs installed. E.g. by installing libc6-dev-i386 on Debian.
Once you have that, this is likely to work:
Configuration options are found in
A quick test can be performed by running
The S flag is always stuck at V⊕O due to the way fastavr handles the flags. This should only be noticeable when using SES/SEV/SEO/CLS/CLV/CLO or writing SREG via I/O-space
SPM and DES instructions are supported as hooks for C functions; see the
des-supportbranch for a AVR-compatible emulation of the DES instruction.
No support for Reduced Core AVR; cycle count not correct for XMEGA microcontrollers.
Not all illegal opcodes will result in an error. Neither will out-of-bounds SRAM accesses.
The core has not yet been ported to x86-64.
Writing this pet project couldn't have been possible without Michel Pollet's excellent simavr.
Without the μNaCl project, testing this simulator wouldn't have been possible as well: http://munacl.cryptojedi.org/atmega.shtml