cancel
Showing results for 
Search instead for 
Did you mean: 

debugging keil uvision memory window

a105035x
Associate II
Posted on October 28, 2014 at 17:58

hi guys,

I know this isn't really the right forum for this because its more about an ide than a microcontroller, but the uvision forum is broken, and has been for a little while.

While I wait for keil's support to fix that, would someone here mind quickly helping me?

I basically don't understand the memory view windows for use when debugging in uvision4, and the documentation available isnt too clear to me. Just to try and play around with it, I've got a function in which I'm declaring some local variables and doing some arbitrary arithmetic with them, and adding these variables to 'memory 1' to try and see where in memory they are.

I was expecting the memory window to show a list of memory addresses, with the values stored in them next to them. Instead what I can see is the value I assign to the variable I'm putting in the memory window, suffixed with a colon, followed by loads of hex values which hold no particular relevance from visual inspection, to me. 

Can anyone kindly advise me on how to use and interpret the memory window constructively?

If it helps, the reason I want to use it is to try and see where exactly my stack and it's boundaries are (hence why I'm looking at the memory for local variables in a function). According to my cmsis startup.s file, the stack_size is 200 bytes , which I believe is the default. 

If anyone can help me I would appreciate it a lot, including pointers to documentation. 

Jonathan

#uvision-memory-window-debugging
5 REPLIES 5
Posted on October 28, 2014 at 18:28

You can tell the memory view to show you specific variables (in scope, or global), specific memory, or relative to a register, ie SP, or SP-0x100

The compiler gets to choose where in the stack frame it places local/auto variables, or if it just wants to hold them in registers.

It's a raw memory view, and you can choose if you want it in 8/16/32-bit formats.

You can have multiple tabs open, but I'd think the ''Call Stack + Locals'' tab might be more useful.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
a105035x
Associate II
Posted on October 30, 2014 at 10:40

Thanks Clive, the call stack+locals windows is helpful also. I didn't know function-local variables didn't necessarily get put on the stack. 

I'm also curious about the stack/stack frame itself. I'm trying to work out where its boundaries should be in memory. If I know this then surely if the stack pointer points to an address outside of this, I've got a stack overflow. Would that be right?

a105035x
Associate II
Posted on October 30, 2014 at 10:50

I believe I may be on the right lines for working this out:

In my startup_device.s (CMSIS) file, I've got the following lines:

Stack_Size      EQU     0x00000400

                AREA    STACK, NOINIT, READWRITE, ALIGN=3

Stack_Mem       SPACE   Stack_Size

__initial_sp

Which tells me my stack size is 0x400 bytes.

The device I'm using is cortex M3 based, and in the 'Cortex M3 Generic User Guide' (ARM, 2010) at section 2.1.3, it says

''On reset, the processor loads the MSP (main stack pointer) with the value from address 0x00000000.''

So therefore should I assume the stack starts at address 0x00000000, and goes up until 0x00000400 because thats my stack size?

a105035x
Associate II
Posted on October 30, 2014 at 12:15

Oops I've noticed a silly mistake I made. The start of the stack isn't 0x00000000 but the address stored at 0x00000000.

By typing in 0x00000000 to the one of the memory windows and having the register windows concurrently open I can see the value in R13(SP) (in the registers window) matches the value displayed in the memory window after the semi colon. The 'tricky' part in this is knowing the memory dump shown in the memory window is little endian... 

Therefore the end of my stack can be found at he address found at 0x00000000 in memory (or R13 immediatly after the program is stepped into) + the stack size define in my startup.s file.....right?

Posted on October 30, 2014 at 12:37

Yes, the address stored at zero, would expect something like 0x20001230, and followed by something line 0x080001C7 the PC for the ResetHandler

The stack of 1KB (0x400) tends to be a bit on the small side, depends what you're doing or if using things like printf()/scanf()

The stack descends downward, so say 0x20000E30[0x400] .. 0x20001230
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..