Search code examples
armbenchmarkingkeilcortex-m

Benchmarking memory use in the Keil uVision 5 simulator


I have a Keil uVision project that I would like to benchmark extensively. The code is currently running in simulator mode. To visualize results we simply store characters in a memory region and display said region as ASCII.

This approach works pretty well to obtain timings using the Cortex-M system ticks. However, I don't have an idea for the ram usage of the code:

  • Ideally I would the simulator to stop the execution when the maximum amount of ram was used.
  • I would also like to see maximum heap usage (or even per function).

Is there a way to do obtain these values? I'm aware of the maximum stack size reported by the build system.

Is there a way to limit the amount of ram available in the uVision simulator?

Thanks


Solution

  • There is a fairly obvious solution: Just count the ram in the memory window. First find the memory regions allocated for the heap and the stack (this can usually be found in the startup assembly file). Then go through the memory window in the debugger and just look where the memory didn't get changed.

    Keil usually initializes the memory with 0 so the stack boundaries can easily be seen. The total stack usage can be computed in the following way

    $TOTAL = $TOP - $BOTTOM
    

    If the boundary can't be seen it might make sense to first initialize the memory with a pattern (see here).