Skip to main content
SMali.3
Associate II
July 3, 2024
Solved

Problems with pointers on STM32H725ZGT6

  • July 3, 2024
  • 6 replies
  • 1516 views

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)

 

    This topic has been closed for replies.
    Best answer by SMali.3

    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

    6 replies

    SMali.3
    SMali.3AuthorBest answer
    Associate II
    July 3, 2024

    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

    Andrew Neil
    Super User
    July 4, 2024

    @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

     

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    SMali.3
    SMali.3Author
    Associate II
    July 4, 2024

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

    SMali.3
    SMali.3Author
    Associate II
    July 4, 2024

    Done!

    Andrew Neil
    Super User
    July 4, 2024

    It's not showing ...

     

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

    AndrewNeil_0-1720131337511.png

     

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.