2012-10-12 05:59 PM
I've been scratching my head for the past few days as I try to
understand why and what is going on... So here it goes:
Current config: stm32f407VG (same as stm32f4 discovery)
I set up a project using the default linker and startup files from
Init the ADC & DMA's ADC_CommonInitStructure.ADC_Mode = ADC_DualMode_RegSimult; ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2; ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_1; DMA_InitTypeDef DMA_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; DMA_InitStructure.DMA_Channel = DMA_Channel_0; DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t) &RawADCData.adcRaw1; DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t) ADC_CCR_ADDRESS; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory; DMA_InitStructure.DMA_BufferSize = ADC_SAMPLE_NUM * ADC_NUM * ADC_BUFFER_MULTIPLIER; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; DMA_InitStructure.DMA_Priority = DMA_Priority_High; DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable; DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull; DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; DMA_Init(DMA2_Stream0, &DMA_InitStructure); /*Interrupt when half of DMA is done, so we do not overwrite our values when processing*/ DMA_ITConfig(DMA2_Stream0, DMA_IT_HT | DMA_IT_TC, ENABLE); DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_TEIF0 | DMA_IT_DMEIF0 | DMA_IT_FEIF0 | DMA_IT_TCIF0 | DMA_IT_HTIF0); // Enable the DMA2_Stream0 global Interrupt NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream0_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* DMA2_Stream0 enable */ DMA_Cmd(DMA2_Stream0, ENABLE);--Symptom A:
Compile on GCC with CooCox as IDE, the DMA values are all garbled, after
looking at the memory, it seems like the DMA values were sometimes
offset by 1 word.
--Symptom B: Floats do not print correctly, printf works, but they are
not passed on VA_ARGS correctly, offset by x bytes, x is pretty random.
--Sympton C: I add a struct into my file somewhere, say
struct b
{ float z[40];}Everything begins to work, prints are correct, DMA is correct.
I add anther struct into anther file
struct b
{ float z[80]; int z[3];}DMA is correct, but printf does not work again. If i twitter around with
the structs, DMA can be broken, but printf works, or they all can be
broken.
I have a feeling that it is a linker error or alignment error, but do
not know where else to look.
The entire codebase is here
(http://code.google.com/p/narwhalroboticsquad/source/browse/?r=25#svn%2Ftrunk%2FNarwhalQuad)
built with the GNU ARM toolchain.