cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with pointers on STM32H725ZGT6

SMali.3
Associate III

Hello

Global definition of pointers:

unsigned int *uIntUtilityTmpP;
unsigned int *uIntP_2_UtilityTmp;

In a function I would like to initialize them with absolute values:

*uIntP_2_UtilityTmp=0x15;
*uIntUtilityTmpP=455;
uCharUtilityTmp=62;
sprintf(print_string,"1 -> *uIntP_2_UtilityTmp: 0x%x, *uIntUtilityTmpP: %d, uCharUtilityTmp: %d\n", *uIntP_2_UtilityTmp, *uIntUtilityTmpP, uCharUtilityTmp);
writeMessageRS232(PRIMARY_COM_PORT, (uint8_t *)print_string, strlen(print_string));

The printout on COM port shows following:

1 -> *uIntP_2_UtilityTmp: 0x1c7, *uIntUtilityTmpP: 455, uCharUtilityTmp: 62

Problem which I have here is that both pointer have the same value. When I write to *uIntP_2_UtilityTmp=0x15 I can see in debugger that also *uIntUtilityTmpP was refreshed with the same value. The same is the case in the next step when I write *uIntUtilityTmpP=455; and then variable *uIntP_2_UtilityTmp gets the same value in this case 455 which is 0x1c7.

Why this is so? What to set in compiler or in microcontroler that this works properly? I am using

STM32CubeIDE, Version: 1.13.0, Build: 17399_20230707_0829 (UTC)

 

1 ACCEPTED SOLUTION

Accepted Solutions
SMali.3
Associate III

Ok, problem solved.

Both pointers have to be referenced to something. In this case to another unsigned int like this:

uIntUtilityTmp=455:
uIntUtilityTmpP=&uIntUtilityTmp; //reference the pointer to variable

Readout in debugger:

*uIntUtilityTmpP  equals to 455

View solution in original post

6 REPLIES 6
SMali.3
Associate III

Ok, problem solved.

Both pointers have to be referenced to something. In this case to another unsigned int like this:

uIntUtilityTmp=455:
uIntUtilityTmpP=&uIntUtilityTmp; //reference the pointer to variable

Readout in debugger:

*uIntUtilityTmpP  equals to 455


@SMali.3 wrote:

Ok, problem solved.


Good to know - please mark the solution.

Please note the </> button for posting code - see:

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/ta-p/575228

 

Thank you very much. I will do that next time.

Please mark the solution now.

SMali.3
Associate III

Done!

It's not showing ...

 

It should get a tick and green background - like this:

AndrewNeil_0-1720131337511.png