This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

can't change struct values

Hello

I've one struct in a header file - but I'm not able to change the values of the struct members.

typedef struct  {
    unsigned int   Addr;                                              //
    unsigned int   status;                                            //
} *p_Descriptor;
#define RxPacket (0x21000000 + (8 * NB_PACKETS))

0x21000000 is the start addr of a external SRAM.

In the c-file I define a global struct ptr:

volatile p_Descriptor const p_rxBD = (p_Descriptor)0x21000000;

In a local function I want to fill the struct array.

char *pPacket =(char *)RxPacket;

for(i=0; i< NB_PACKETS; i++)
    {
           p_rxBD[i].Addr = (unsigned int)pPacket; //
                  p_rxBD[i].status = 0;
        pPacket +=SIZE;
    }

but I'm not able to do this. If i watch the values of the struct (with the watch window) - the value of the ptr is 0x21000000 (which is ok and his addr is 0x20000010 (internal sram) which is also ok)

But the values of Addr is 0xFFFFFFFF and the value of status is 0x6000FFFF - and these values didn't change during the for loop. I step through the programm but this values are always the same value.

I don't no if it is correct that the value of *p_RxBD is 0x21000010 and the ptr **p_rxBD is 0x21000D90 --> because this area is only for the buffers of the peripherial and not for a ptr. Therefore I installed this ptr in the internal RAM and p_rxBD has the addr 0x20000010 which is correct...

Johannes

Parents
  • It seems that you have uncovered a bug in the uVision/ARM
    elf/dwarf loader which causes some incorrect types when
    const, volatile and typedef defining struct pointers
    are involved. This will be corrected with the next
    version of SARM.DLL and SarmCM3.DLL for Cortex-M.

    If you need SARM.dll more quickly, then please contact
    KeilSupportIntl@arm.com. Otherwise, you might use the
    following precedure to watch the array at the absolute address:

    typedef struct dsc  {
      unsigned int    Addr;
      unsigned int  status;
    } DSC;
    typedef DSC        *pDSC;
    typedef    DSC tRxB[256];   // Array[256] of 'DSC'
    tRxB                 RxB;   // used for RxB buffer.
    
    //#define RxPacket (0x21000000 + (8 * NB_PACKETS))
    volatile pDSC const p_rxBD = (pDSC) &RxB[0];
    
    void Filler (void)  {
      int      i;
    
      for ( i = 0 ; i < 256 ; ++i )  {
        p_rxBD[i].Addr   = (i << 24) | i;
        p_rxBD[i].status = i | 0x8000;
      }
    }
    


    Assuming the array 'RxB' is located at address 0x400000A4 (0x21000000 in your example) you can use
    the above array typedef type 'tRxB' to show the complete array in the watch window. The watch is entered in the watch window as:

       ((tRxB) 0x400000A4)
    


    this is the same as '((tRxB) &RxB[0])'.

    When stepping within Filler() it can be seen that the members of each struct in the array are setup correctly. Each of the individual structures from the array can be expanded and viewed.

Reply
  • It seems that you have uncovered a bug in the uVision/ARM
    elf/dwarf loader which causes some incorrect types when
    const, volatile and typedef defining struct pointers
    are involved. This will be corrected with the next
    version of SARM.DLL and SarmCM3.DLL for Cortex-M.

    If you need SARM.dll more quickly, then please contact
    KeilSupportIntl@arm.com. Otherwise, you might use the
    following precedure to watch the array at the absolute address:

    typedef struct dsc  {
      unsigned int    Addr;
      unsigned int  status;
    } DSC;
    typedef DSC        *pDSC;
    typedef    DSC tRxB[256];   // Array[256] of 'DSC'
    tRxB                 RxB;   // used for RxB buffer.
    
    //#define RxPacket (0x21000000 + (8 * NB_PACKETS))
    volatile pDSC const p_rxBD = (pDSC) &RxB[0];
    
    void Filler (void)  {
      int      i;
    
      for ( i = 0 ; i < 256 ; ++i )  {
        p_rxBD[i].Addr   = (i << 24) | i;
        p_rxBD[i].status = i | 0x8000;
      }
    }
    


    Assuming the array 'RxB' is located at address 0x400000A4 (0x21000000 in your example) you can use
    the above array typedef type 'tRxB' to show the complete array in the watch window. The watch is entered in the watch window as:

       ((tRxB) 0x400000A4)
    


    this is the same as '((tRxB) &RxB[0])'.

    When stepping within Filler() it can be seen that the members of each struct in the array are setup correctly. Each of the individual structures from the array can be expanded and viewed.

Children
No data