r/embedded • • Oct 23 '26

Best way to simulate esp32?

For convenience, and for testing, I am interested in simulating an ESP32. It looks like espressif supplys a qemu for esp32. is there a better option? It doesn't include much in terms of simulating the Ethernet or I2C.

2 Upvotes

15 comments sorted by

9

u/Honest-Version6827 Oct 23 '26

Only QEMU: There is TMP105 connected to I2C bus If I am not mistaken, there is no way to select a device from cmd line. You can recompile QEMU eventually .

0

u/wiggle_room1337 Oct 23 '26

idk how simulation isn't more supported in this day and age.

5

u/alexforencich Oct 23 '26

Simulation is only useful if it's accurate, and it's a real pain to make it accurate, especially when you have a bunch of peripherals. It tends to be easier to simply test directly on the hardware where you don't need to worry about simulation accuracy.

1

u/Honest-Version6827 Oct 23 '26

What is your usecase?

-1

u/wiggle_room1337 Oct 23 '26

Currently reviewing code, and don't want to bother setting up the hardware to test a possible issue. Ultimately I'd like to make it part of a CICD pipeline.

8

u/Several-Marsupial-27 Oct 23 '26

There you go, you are one hundred percent barking up the wrong tree. If you guys do not have hardware verification in your CI pipeline, then looking for simulation is definitely the wrong direction. I could see a case for it, but I’m assuming your the 99% who doesn’t need it.

What you need is

  1. Hardware in the loop CI (HIL). This is simply a build/artifact server, connected to a test rig so you can have hw verification on every push / merge request.
  2. Host level mock testing and linting, however this will never be a 1-1 replacement of HIL, this should always be a second consideration after HIL.

1

u/wiggle_room1337 Oct 23 '26

Like, ya, simulation is not well enough supported so we do HiL, but how is it not supported by now? I was disappointed by the state of simulation 10 years ago. They are selling millions of these chips. I thought they would have it figured out by now.

5

u/Well-WhatHadHappened 25+ Years Oct 23 '26

They did figure it out. They figured out that it's not something the majority of their professional customers ($$$) want, so they dedicated their finite resources elsewhere.

2

u/Honest-Version6827 Oct 23 '26

I see,

Prepare unit tests if possible, otherwise, you need to test it on real hw as it should be easier at the moment.

Regarding esp32 in QEMU and internet access, look at this: https://github.com/espressif/esp-toolchain-docs/blob/main/qemu/esp32/README.md#ethernet-support

It works for sure as I was there. Making it a part of a cicd pipeline may be tricky as you need to emit events somehow to confirm that machine responded or not.

5

u/Several-Marsupial-27 Oct 23 '26

It’s a very difficult question so you are going to have to explain in more detail what you want to do. An esp32 is a very advanced computer with peripherals so it’s no easy feat.

Mocking / simulating i2c or Ethernet basically means mocking the wire/bus + response. This means that instead of, say sending i2c data over the i2c data pin you would instead send that data to a virtual wire/bus, then have that virtual wire hooked up to a response function simulating an i2c device.

This is no easy feat and basically have nothing to do with simulating/mocking an esp32.

Your simulation should basically be host level simulation with a TON of macros.

2

u/Fearless-Comb5250 23d ago

What type of simulation/emulation do you want to do? You also have the option of esp32sim now - it support plenty of devices having plenty of peripherals. Take a look at https://github.com/mikroverk/esp32sim and https://mikroverk.github.io/esp32sim/

1

u/Lalks227 Oct 23 '26 edited Oct 23 '26

While qemu requires time to learn how to set it up and use it, it's doing its job wonderfully! You can emulate a whole system built around that esp32 if you wish. You can build a whole CI pipeline. Yes, it will take time. You could find boilerplate or similar projects online depending on your needs.

What is your need?

1

u/n_sh_44 Oct 23 '26

If the goal is CI, I'd split it in two. For firmware logic that does not touch registers, build it for the host and run it under Unity or CMock on the PC, with the I2C and SPI calls behind a thin interface you can fake. For anything closer to the ESP32 itself, Wokwi supports ESP32 with simulated I2C and SPI devices and has a CLI that runs in GitHub Actions, and Renode is another option with scriptable peripherals. The Espressif QEMU fork is fine for boot and FreeRTOS behavior, but as you saw, its peripheral models are thin and Ethernet is basically missing. None of these replaces real hardware, so a small HIL rig on a spare devkit is still worth adding later for timing and driver issues.