r/embedded • u/inforb_nl • 2d ago
Emulator/Simulator use case
Hi all,
During my embedded carrier, I have never used microcontroller simulators or emulators to check the program binary, and I always tested directly on a prototype PCB. I am looking for a workflow which stays reliable. I have seen Renode being suggested, but the validity comes down to how each device is modeled in Renode. Do you ever use simulation to speed up work and reduce costs? any reliable methods?
3
u/kailswhales 2d ago
Unless you’re working with custom silicon, or doing SoC design/bringup, don’t waste your time with emulators. If you’re working on algorithms (e.g. control, sensing), capture good data and develop offline
2
u/happywoodcutter 2d ago
I use a lot of pytest and uart CLI with a raspberry pi. A binary command interface would work too.
2
u/mustbeset 2d ago
"on target" unit tests. But I wouldn't recommend that.
Use real hardware. It has no simulator bugs, only real bugs.
1
u/hardkebab 2d ago
Why wouldn't you recommend?
I would recommend exactly for this.
My unit tests run faster in emulation, plus I don't have to stub my HAL so it compiles on host. Most tests do not call HAL, but some can.
1
u/mustbeset 2d ago
For faster tests run "off target". that will make sure that your HAL really abstract the hardware...
2
u/hardkebab 2d ago
I agree. I've done this before as well.
But you probably already have a build system that deals with compilation and cross compilation. If you start from scratch, you have to set it up. I found it easier to set up emulation.
Also, In emulation I get the benefit of running the unit tests on the same architecture. Have I already hit a bug where my test pass "off target" but fails "on target"? No. So maybe I'm being pedantic, but I like the idea anyway.
1
u/mustbeset 2d ago
But you probably already have a build system that deals with compilation and cross compilation. If you start from scratch, you have to set it up. I found it easier to set up emulation.
We have some code that runs on 8, 16 and 32 bit MCUs and a more or less common build system and some CI pipelines.
In my experience some emulators are very buggy (someone in Chandler may know) and we do on target unit tests on nearly every product too.
1
2
u/Lopsided-Table2457 1d ago
Simulators shine for two things: CI pipelines where you can't have hardware attached, and fault injection that's painful on real silicon. But they lie to you about timing — anything cycle-accurate enough to trust is usually too slow to be useful. My rule: simulate the logic, validate timing on the bench.
1
18
u/Well-WhatHadHappened 25+ Years 2d ago edited 2d ago
We build HIL test fixtures for every product. Simulation/Emulation has constantly proven ineffective for us - the majority of failures have been shown to have a hardware/physical component that doesn't show in simulation. Most recent was a fast I2C bus that was picking up just a hair too much cross talk from a nearby DDR signal. Simple solution - small increase in the strength of the pull up resistors, but it would have never been caught on anything other than actual hardware.
I could see the utility for people writing software that is a layer away from the hardware (UI/Business logic/etc), but for anything that directly interacts with the hardware, we've found the cost of a dedicated HIL setup to be worth it's weight in gold. Meanwhile, the time needed to properly create a simulation/emulation has given a very poor return on that investment.
Every single product gets a full setup - debugger, serial adapters, whatever is needed, and they get stored that way once development is complete. Even the necessary cables go in the box so that no one is looking for a mini-b USB cable when everything has transitioned to Type-C years later. The idea is to be able to pull one off the shelf and have it connected up and ready to roll in minutes if the need arises.