read the data stack contents

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
User16627
Level 1
Level 1
I just bought the TFT Aurix_TC277 microcontroller and started programming with Hightec.
I am beginner with the aurix.

so I need your help,
I have to read the contents of the memory after running a program.
for example, I work on the CUP0, I know that all the data is stored in the DMI and I also know the size of this memory, which is 120 KB.

I want to know if it is possible with Aurix to read the contents of this memory after running a program?

and i want to know if he can read the contents of the memory using another kernel not to touch the program running on the core0?

the need is to trace all values written in memory of program execution

if you have documents or an example, send it to me.
0 Likes
8 Replies
lock attach
Attachments are accessible only for community members.
User13290
Level 5
Level 5
First like received First solution authored
Hi Rihab,

I have created the attached example. To run it click the tiny down arrow within the build button, and build the tsim target from here. You can also enable the "Make Target" view and double-click the tsim target. The expected output (console-TAB) should be:

Lowest: 0xd0000890
Highest: 0xd0001890
F(20) = 4181
Stack Usage: 1228 bytes


Let me know if you have questions.

Best regards,

Henk-Piet Glas

Principal Technical Specialist
Embedded Software
0 Likes
User16627
Level 1
Level 1
Thank you for your answer,
can you explain it more please, does the code you created, allows to display the contents of the stack, during the execution of the program?
I am studying and understanding the functionality of TSIM.
can you tell me how I can install TSIM

best regards
0 Likes
User13290
Level 5
Level 5
First like received First solution authored

Hi Rihab,

can you explain it more please


Sure. Have a look at this recording (password: Blomkamp). I'm going relatively fast, but the aim is to give you a quick overview. Note first of all TSIM is part of the product. No need to install it. The Makefile.targets pulls it from the correct location. This makefile itself is being pulled by the master makefile that is created when you build the project for the first time.

Next note functions init_stack() (line #20) and stack_usage() (line #27). The former initialises the stack with a predefined value 0xBADDCAFE. The latter reads it back after some stack usage. Based on the values that were overwritten through this usage I make a ballpark estimate. Be sure to check the mapfile (read_stack.map, also created after your initial build) as well. In here you can cross-reference the results of the output console.

Stack labels __lc_b_ustack and __lc_e_ustack are created in the hightec.ld linker script. They are derived from existing system symbols __USTACK and __USTACK_SIZE that are declared in memory-tc27xx.x. This system script is pulled from /lib/gcc/tricore/4.9.4 which itself implicitly (through the INSERT command) pulls elf32tricore.x which resides in /tricore/lib/ldscripts. As a whole they create your entire memory map.

My first build breaks in the example. I'm not sure why, but removing the dot character solves the issue and produces the build as I predicated it. Note that the recording purposely has a limited lifetime. It will last you 1 week so be sure to download it.

If you have any further questions, just let me know.

Best regards,


Henk-Piet Glas
Principal Technical Specialist
Embedded Software

0 Likes
User16627
Level 1
Level 1
thank you so much
it's clear to me,
I just have related questions:
- I did not understand the stack_usage function why return 4 * (__lc_e_ustack - p); what does it mean 4

- is the stack_usage function used to count the number of bytes used in the stack?
0 Likes
User13290
Level 5
Level 5
First like received First solution authored

Hi Rihab,

Concerning your followup questions. When you subtract two integer pointers you will get the number of integer indexes between those two pointers. Since the aim is to find out how many bytes have been used, I then multiply it by four. Your second question is correct; it calculates how much stack was used by the following statement:

printf("F(20) = %d\n", F(20));


This statement emulates a specific user application. I used a recursive function to force off some stack activity.

Henk-Piet Glas


Principal Technical Specialist
Embedded Software

0 Likes
User16627
Level 1
Level 1
Hello Henk.

K, thanks,
it helped me too much.
just last question please,
since now I know the highest and lowest address of the stack so the number of bytes used in the stack, I created a function that reads what is written in this address range to see what which is written in the stack, so I did that :

int pile_start =0xd0000890;
int size =0x1890;
void read_stack()
{
ptrdiff_t i;
for ( i = pile_start; i < size; i++)
{
printf("pile = %d \n", *( unsigned char * )(pile_start+i));
}
}

and after I had on the consol values like that :
stack = 217
stack = 173
stack = 0
stack = 48
stack = 128
stack = 242
stack = 139
stack = 2
stack = 40
stack = 66
stack = 223
stack = 4
.....
...
..


like that, I think that it does not make sense this display there,
Normally it must have values, symbols and addresses in the stack
* is my way of displaying the stack is not correct?
0 Likes
User13290
Level 5
Level 5
First like received First solution authored

Hi Rihab,

Stack allocation is a dynamic process, managed by the compiler. Automatics such as you describe have a certain lifetime. They move into focus and after a while they disappear again. As an end-user you're really not that interested for as long as things are running smooth and efficiently.

If you want to dump what's physically being allocated onto the stack at any point in time, it's probably best to inspect the disassembly instead. Your own dump is just an integer dump of whatever has been placed onto the stack, but you can't tell what's what from that. You also can't tell from that, what's life and what isn't.

Best regards,

Henk-Piet Glas


Principal Technical Specialist
Embedded Software

0 Likes
DSRnathan
Level 3
Level 3
50 sign-ins 25 replies posted 25 sign-ins
Hello Henk , please can you upload the recording for understanding the content.

Thank you,

Kind Regards,
Deepak
0 Likes