close-circle
Close
0%
0%

Arduino ATmega 328 Emulator

This will emulate the AVR code right out of the .ELF file

Similar projects worth following
This is a Arduino ATmega 328 (UNO) emulator I wrote for Linux. It loads the .ELF files directly, so you only need to compile your sketch with the Arduino IDE, then click reload and execute image in the emulator.

I built this cause I wanted a emulator for the Arduino UNO, not a simulator that doesn't tell me why and where thing crash. I've semi bricked many Arduino units, but always got them back up and running with another UNO. With this emulator, I can properly debug my system step by step, see the registers/memory, and see when memory writes go out of bounds.

For decoding the opcodes, I used a vector table of 65536 entries.

There are 107 opcode groups, 131 total instruction variants.

Right now I have 90 more opcodes to complete.

This emulator will be cycle accurate, support virtual GPIO, and console printing.

For the moment, I'm skipping working with the boot loaders, but it's a option for the future.

  • I2C function in progress.

    tehaxor6905/09/2017 at 00:37 0 comments

    Debugging the I2C registers is a bit more chalenging than the other periferals.

  • USART with printing now working.

    tehaxor6904/26/2017 at 21:38 0 comments

    USART without the RX part, now works. Messages are printed to the terminal window.

    This is the Arduino code I used for the sketch.

     void setup() {
       Serial.begin(9600); 
     }
     
     void loop() {
       Serial.print("Test UART Message " );
       Serial.println("0123456789");
       
       delay(2);                     
     }
    

    IRQ USART, UDRE "__vector_19" is responsible for writing out the TX buffer to I/O 0xC6

    "_ZN5Print5printEPKc" Is the subroutine that gets called to update the TX buffer.

  • Fade Sketch + PWM now working.

    tehaxor6904/25/2017 at 22:54 0 comments

    Register 0x88 OCR1AL and 0x89 OCR1AH comtrols the PWM duty rate.


  • Blink sketch is now working.

    tehaxor6904/22/2017 at 23:51 0 comments

    I finally got the blink sketch running.

    To get the blink sketch up and running in the Emulator, I had to get the CPU, Memory Mapper, GPIOs, and the timer overflow/compare IRQs working.

    The IRQ and "micros" function use SRAM 0x0007~0x000A as a 32bit timer.

    After all that fun stuff, I had an alternating bit in the PORTB register.

View all 4 project logs

Enjoy this project?

Share

Discussions

tehaxor69 wrote 04/16/2017 at 17:33 point

I will have a console window for that.

It will report invalid opcodes, memory / IO access errors. FLASH and EEPROM over use.

I'm not sure about flash fuses, if they are in the ELF, I can report on those too.

I hope to have a working CPU core within a few weeks.

  Are you sure? yes | no

DEC0 wrote 04/15/2017 at 22:00 point

that is just awesome!

How does emulation present errors and such ? Would definitely want to try this out

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates