Safety-certified tools Tools for Automotive Applications C-STAT Static analysis C-RUN Runtime analysis Debugging and trace probes IAR Visual State
If you need to save memory and/or registers in your target to make debugging more efficient this tech note is for you. The example provided is for Freescale 6812, but with appropriate adaptations it should do the trick for other chips as well.
This example macro file shows how to save registers and a range of memory cells to a simple hex file. Here the file is named "c:\test.hex," but feel free to use whatever you like - Just remember to use the same file name saving and restoring. Also, for convenience, you should specify this file in "Project -> Options -> C-SPY -> Setup file" such that you get this loaded each time you start C-SPY. Then you can call the macros from the "Control -> Quick Watch" dialog - just give the name of the macro, for example memory_save() and push return or click "Recalculate." You probably do not want to "Add Watch," since that would mean executing the macro each time the watch is updated.
To give you some more detail, the file first defines some variables (you have access to these in the quick watch dialog too). The most interesting variables would be the mem_begin and mem_end - these are used to specify the range of memory that is to be saved and restored. Extending this to multiple ranges should be straighthforward.
Then we have the memory save function:
There are some lines commented out, starting with
// Optional register:
This is to allow you to save/restore the PP register only when needed (e.g., banking used). The memory read function is basically the inverse, it is really very straightforward.
The execUserSetup() finally, is where the values for mem_begin and mem_end are defined. If there is a macro by this name, it is automatically called once after the target program is downloaded. Please see C-SPY documentation for more info in other similar macros.
There is an additional example with macros where you can specify the name of the file, i.e. no need to update the macro source.
Example of a command to enter in the QuickWatch command line to dump the contents of a variable in a binary format:
DumpMem("dumpmem.bin", &trace_buffer, sizeof(trace_buffer))
Example of a command to enter in the QuickWatch command line to dump the contents of ARM registers in a readable format:
If size of int is too small for address(es) you are interested in, try casting to (long) instead of to (int).
All product names are trademarks or registered trademarks of their respective owners.