what should DMA_MemoryBaseAddr be pointing to?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2008-09-04 10:50 AM
what should DMA_MemoryBaseAddr be pointing to?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2011-05-17 3:43 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2011-05-17 3:43 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2011-05-17 3:43 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2011-05-17 3:43 AM
Thanks for reply
I've tried both and surprisingly both seemed to work! (i.e with and without &), which boggles my mind.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2011-05-17 3:43 AM
> 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.