Hi - For years I've been using Proteus to simulate PIC firmware and hardware by using the MPLAB/MPLABX Proteus plugin. It's been a useful tool in my development workflow. Proteus simulation isn't perfect, but it's saved me a lot of time and solder...
I recently started doing the same with the Arduino IDE and the AVR processors in Proteus. Since there is no plugin to tie the Arduino IDE (or any other Arduino IDEs, like VSCode, PlatformIO, etc.) to Proteus, I generate .elf files from the GCC-AVR compiler and load them directly into the AVR processor on Proteus.
I encountered a number of frustrating issues doing this, but eventually worked through them. I'd like to share my workflow to assist others who may want to do the same, perhaps save someone time or trouble.
Proteus has the ability to set up a firmware project itself. However, I encountered a number of issues when using this. You can set up Proteus to directly use the Arduino IDE compiIer toolchain but I found sometimes sketches would compile in the Arduino IDE but not the Proteus IDE, and I was not able to figure out why (sometimes Proteus couldn't find libraries that were right there). The Proteus system compiles to a hard-to-locate temp directory unless the project settings "Embed Files" box is unchecked, which dumps all the compiler output into the project folder. I also found the Proteus editor and IDE user interface to be awkward. I prefer to develop code in the Arduino IDE, VSCode, or more sophisticated editor suites, and let Proteus do the simulation, not the code building.
Because of these issues, I decided to avoid using the Proteus firmware development environment, and to use the Arduino IDE toolchain directly. Here is the way I've set up my system:
1) Create the hardware schematic in Proteus, using one of the AVR processors.
2) Create the firmware project in the IDE of choice. I prefer to write code using VSCode as my editor and to use the VSCode Arduino Extension to compile the code using the Arduino IDE toolchain. That way I can easily switch from the Arduino IDE to VSCode as desired for different purposes. Some prefer to use the PlatformIO extension in VSCode or Eclipse, that's fine, but I prefer to avoid creating a separate toolchain from the default Arduino IDE toolchain.
3) Edit the Arduino preferences.txt file. This text file is referenced in the Arduino IDE preferences window. Add the line "build.path=(path)", setting the path to wherever you prefer the Arduino build output to be placed (* if anyone knows how to make this path dynamic rather than static so you could place the output in the project folder, I'd appreciate a how-to...*)
4) If you are using VSCode to edit and build the Arduino firmware, edit the arduino.json project file to include the line, "output": "../VSCode_output", to place the Arduino build output into the specified VSCode_output folder.
5) When building for Proteus simulation, instruct the compiler to turn off optimization. If this isn't done, the resulting .elf file will display incomplete code addresses in Proteus, and sometimes even fail to provide a .ino file for debugging purposes.
To do this, preface the Arduino sketch with:
#pragma GCC optimize ("-O0")
#pragma GCC push_options
...and terminate the Arduino sketch with:
This will tell the compiler not to perform any optimization. This will result in larger firmware files, so these #pragma lines can be commented out when building and uploading the firmware to the actual hardware.
6) Build the file in the Arduino IDE, VSCode or (
your choice). The .elf file will be written to the output folder specifed in item #3 or #4 above.
7) In Proteus, add the .elf file to the processor properties (control-i, "Properties"). Simulate using the Proteus system debugger, as described in the Proteus documentation.
Works well for me. Hope it's helpful for someone else too.
Now if only there were a similar firmware/hardware simulation environment for the ESP8266/ESP32...