Is there a way for a program to know if it's executed under the simulator and not on an actual CPU?
Alright, here's my solution for LPC2xxx chips, in case anyone is interested. It is based on the fact that most flash programming tools modify the program image in such a way that the sum of all interrupt vectors in the boot block will be 0, whereas under the simulator the program is executed "as is", without any modification.
#include <stdint.h> #include <stdbool.h> bool in_simulator(void) { uint32_t sum = 0; uint32_t * p; for (p = 0; p < (uint32_t *)0x20; p++) sum += *p; return sum != 0; }
I doubt that anyone cares, but any criticism and suggestions are welcome :)
Hi, Very nice solution...
Do you have a trick also to know if the Ulink is connected(Debug) or when the CPU is stand alone (No Ulink)?
Thanks, Doron
In Cortex-M3
if(CoreDebug->DHCSR & 1) { // Debugging with ULIK or similar ! } else { // No debugging tool }
View all questions in Keil forum