what should DMA_MemoryBaseAddr be pointing to?
Company  
ST Home | Microcontrollers

Index  »  ARM Cortex-M3 STM32  »  what should DMA_MemoryBaseAddr be pointing to?
     
   what should DMA_MemoryBaseAddr be pointing to?
 Moderated by :   »  STOne-32

Author
beginning argument    ( Replies received: 4 )
pandoraems   Posted 03-09-2008 at 23:32   



Registered on :
09-03-2008

Messages : 19

 OFF-Line


following is a snip from STm's example of using DMA with ADC:


u16 ADC_ConvertedValue[512];
...
...
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&ADC_ConvertedValue;


I am wondering about why it needs the ampersand in front of ADC_ConvertedValue ? I would think that DMA_MemoryBaseAddr should contain the address of the first element of the array , which what ADC_ConvertedValue is. And not the address to a pointer to the first member of ADC_ConvertedValue[] (which seems like what the example code does and is quite unintuitive)

am i confused? or is the example incorrect?

Thanks



 Profile   Quote  
lanchon   Posted 04-09-2008 at 05:40   



Registered on :
11-02-2008

Messages : 367

 OFF-Line

well, *ADC_ConvertedValue is the first u16, and I guess ADC_ConvertedValue is a const pointer to u16 and since it's const it needn't be allocated in memory at all. I think the result of taking the address of such a const should at lest be undefined and might be illegal (maybe only in C++). so I'd say it's a bug. the horrible structure of the lib which require casts all over may be hiding the error until runtime.




 Profile   Quote  
andreas1   Posted 04-09-2008 at 16:22   



Registered on :
01-07-2008

Messages : 22

 OFF-Line

In ANSI C, &ADC_ConvertedValue is valid and is a pointer of type pointer-to-512-element-array-of-u16, as opposed to using ADC_ConvertedValue without the ampersand, which decays into a pointer of type pointer-to-u16. Both point to the same location, the first element of the array. In this example, the type of the pointer is irrelevant since it is immediately cast to u32 anyway.



 Profile   Quote  
pandoraems   Posted 04-09-2008 at 16:23   



Registered on :
09-03-2008

Messages : 19

 OFF-Line

Thanks for reply

I've tried both and surprisingly both seemed to work! (i.e with and without &),
which boggles my mind.





 Profile   Quote  
lanchon   Posted 04-09-2008 at 23:20   



Registered on :
11-02-2008

Messages : 367

 OFF-Line

> In ANSI C, &ADC_ConvertedValue is valid and is a pointer of type pointer-to-512-element-array-of-u16

thanks. so I guess a pointer-to-512-element-array-of-u16 autoconverts to pointer-to-u16, but size of *pointer-to-512-element-array-of-u16 covers all the array.




 Profile   Quote  
On Top

Search in the forums
 
Jump To