Skip to content

Run arduino mega 2560 elfs in qemu #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
lucasw opened this issue Mar 26, 2021 · 6 comments
Open

Run arduino mega 2560 elfs in qemu #1

lucasw opened this issue Mar 26, 2021 · 6 comments

Comments

@lucasw
Copy link
Owner

lucasw commented Mar 26, 2021

Use qemu 5.2.0 or later

https://www.qemu.org/

Install ninja

sudo apt install ninja-build
mkdir build_qemu_5.2.0
cd build_qemu_5.2.0
../configure --prefix=$HOME/other/install --target-list=avr-softmmu,arm-softmmu
make

(arm-softmmu also of interest, add it to the target list, comma no spaces)

2557 files to build including arm-softmmu, 1931 without.

@lucasw
Copy link
Owner Author

lucasw commented Mar 26, 2021

qemu-system-avr -machine help
Supported machines are:
2009                 Arduino Duemilanove (ATmega168) (alias of arduino-duemilanove)
arduino-duemilanove  Arduino Duemilanove (ATmega168)
mega2560             Arduino Mega 2560 (ATmega2560) (alias of arduino-mega-2560-v3)
arduino-mega-2560-v3 Arduino Mega 2560 (ATmega2560)
mega                 Arduino Mega (ATmega1280) (alias of arduino-mega)
arduino-mega         Arduino Mega (ATmega1280)
uno                  Arduino UNO (ATmega328P) (alias of arduino-uno)
arduino-uno          Arduino UNO (ATmega328P)
none                 empty machine

@lucasw
Copy link
Owner Author

lucasw commented Mar 26, 2021

Now run the arduino ide, build a sample project.

ide doesn't respect the 200% scaling, it's tiny.

arduino/Arduino#6472

built files go into /tmp/build1703114282366706709.tmp and similar.

qemu-system-avr -machine mega -bios DigitalReadSerial.cpp.elf 

A new window opens, can set it to serial0 and see a single loop of output from the example code that I added:

FOO

but the delay doesn't work, or the system is stopped?

Try out -serial dev and use gtkterm.

Figure out how to build arduino project from command line.

@lucasw
Copy link
Owner Author

lucasw commented Mar 27, 2021

qemu-system-avr -M mega2560 -bios test.elf -nographic -serial tcp::5678,server=on,wait=off
telnet localhost 5678

https://qemu.readthedocs.io/en/latest/system/target-avr.html

But want to leave serial monitor running in another window, automatically reconnect when server goes up and down

Thought udp would work, but locks up qemu sometimes, doesn't like recycling the server

qemu-system-avr -M mega2560 -bios test.elf -nographic -serial udp::5678
nc -u -l -p 5678

@lucasw
Copy link
Owner Author

lucasw commented Mar 27, 2021

-S to pause on start, c to continue, stop to pause again

@lucasw
Copy link
Owner Author

lucasw commented Mar 27, 2021

The arduino delay() locks up, while delayMicroseconds() may not be delaying at all, but util/delay.h + delay_ms() runs ~10x faster than real time

#include <util/delay.h>

_delay_ms(1000);

(also millis() just returns 0- some clock on the arduino isn't getting emulated?)

@lucasw
Copy link
Owner Author

lucasw commented Mar 28, 2021

Want to slow down the emulator, cpulimit looks to work:

cpulimit -l 2 -- qemu-system-avr -M mega2560 -bios test.elf -nographic -serial tcp::5678,server=on,wait=off

But this crashes hard on typing exit into qemu, the terminal tab goes down.

May need to free up the port if cycling rapidly:

fuser -k 5678/tcp

Actually can do ctrl-c instead of quit, then fuser will close the process that is using that port, presserving the terminal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant