I’m working on some bare metal Cortex-M4 code. It usually runs on a dev board, but to run unit tests I emulate it under QEMU. However, some hardware configurations are done differently depending on whether it’s running on the board or QEMU — for instance, stdout
is redirected to SWO if running on the board, and to USART if running under QEMU.
Currently I have a build-time flag that determines whether to run it under QEMU or not. However to make the user experience a little better I would like to avoid that. As such I’m wondering whether there’s a way to check, at runtime, if the code is running on the board or under QEMU. Say, reading a memory address which will give different outputs for QEMU and the board. I know if emulation is bug-free it should behave exactly like the board, but maybe the QEMU developers hid something somewhere that I could check.