《STM32定时器触发AD采样DMA传输问题.doc》由会员分享,可在线阅读,更多相关《STM32定时器触发AD采样DMA传输问题.doc(23页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、STM32定时器触发AD采样+DMA传输问题试验环境:EWARM 4.41A + J-link + 目标板试验内容:TIM1-CC1触发ADC采样,单通道,采样结果使用DMA传输到SRAM中。问 题:下载程序提示SRAM校验错误,拔下J-link一端的USB口再插上,下载OK -停止程序,再下载,提示错误,再拔下J-link USB口,再下载,OK- .如此反复。仔细看了下Debuglog,发现存放DMA传输到的目标内存数据校验错误(IAR debugger选项中的verify download选上),如下:Verify error at address 0x2000007C, target
2、byte: 0x3F, byte in file: 0x01分析:可能是停止程序的时候,TIM1和ADC,DMA都没有停下来,下载的时候,DMA一直写数据到开辟的内存中,导致那部分内存数据校验错误。以上只是个人的一些看法,不知道不否正确,有没有哪位帮分析下。/*/附录1:试验程序源码:/* Includes -*/#include stm32f10x_lib.h/* Private typedef -*/* Private define -*/#define ADC1_DR_Address (u32)0x4001244C)/* Private macro -*/* Private variab
3、les -*/ADC_InitTypeDef ADC_InitStructure;DMA_InitTypeDef DMA_InitStructure;TIM1_TimeBaseInitTypeDef TIM1_TimeBaseStructure;TIM1_OCInitTypeDef TIM1_OCInitStructure;TIM1_BDTRInitTypeDef TIM1_BDTRInitStructure;u16 ADC_RegularConvertedValueTab32;ErrorStatus HSEStartUpStatus;/* Private function prototype
4、s -*/void RCC_Configuration(void);void GPIO_Configuration(void);void NVIC_Configuration(void);/* Private functions -*/* Function Name : main* Description : Main program* Input : None* Output : None* Return : None*/int main(void)#ifdef DEBUGdebug();#endif/* System clocks configuration -*/RCC_Configur
5、ation();/* NVIC configuration -*/NVIC_Configuration();/* GPIO configuration -*/GPIO_Configuration();TIM1_DeInit();/* Time Base configuration */TIM1_TimeBaseStructure.TIM1_Prescaler = 0x00;TIM1_TimeBaseStructure.TIM1_CounterMode = TIM1_CounterMode_Up;TIM1_TimeBaseStructure.TIM1_Period = 3599;TIM1_Tim
6、eBaseStructure.TIM1_ClockDivision = 0x00;TIM1_TimeBaseStructure.TIM1_RepetitionCounter = 0x00;TIM1_TimeBaseInit(&TIM1_TimeBaseStructure);/* Channel1 Configuration in PWM mode */TIM1_OCInitStructure.TIM1_OCMode = TIM1_OCMode_PWM1;TIM1_OCInitStructure.TIM1_OutputState = TIM1_OutputState_Enable;TIM1_OC
7、InitStructure.TIM1_OutputNState = TIM1_OutputNState_Enable;TIM1_OCInitStructure.TIM1_Pulse = 100;TIM1_OCInitStructure.TIM1_OCPolarity = TIM1_OCPolarity_Low;TIM1_OCInitStructure.TIM1_OCNPolarity = TIM1_OCNPolarity_High;TIM1_OCInitStructure.TIM1_OCIdleState = TIM1_OCIdleState_Set;TIM1_OCInitStructure.
8、TIM1_OCNIdleState = TIM1_OCIdleState_Reset;TIM1_OC1Init(&TIM1_OCInitStructure);/* TIM1 main Output Enable */TIM1_CtrlPWMOutputs(ENABLE);/* TIM1 counter enable */TIM1_Cmd(ENABLE);/* DMA Channel1 Configuration -*/DMA_DeInit(DMA_Channel1);DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;DMA_I
9、nitStructure.DMA_MemoryBaseAddr = (u32)&ADC_RegularConvertedValueTab;DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;DMA_InitStructure.DMA_BufferSize = 32;DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;DMA_InitStructure.DMA_Pe
10、ripheralDataSize = DMA_PeripheralDataSize_HalfWord;DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;DMA_Init(DMA_Channel1, &DMA_InitStru
11、cture);/* Enable DMA channel1 */DMA_Cmd(DMA_Channel1, ENABLE);/* ADC1 configuration -*/ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;ADC_InitStructure.ADC_ScanConvMode = DISABLE;ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC
12、1;ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;ADC_InitStructure.ADC_NbrOfChannel = 1;ADC_Init(ADC1, &ADC_InitStructure);/* ADC1 regular channel14 configuration */ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_13Cycles5);/* Enable ADC1 DMA */ADC_DMACmd(ADC1, ENABLE);/* Enab
13、le ADC1 external trigger */ADC_ExternalTrigConvCmd(ADC1, ENABLE);/* Enable ADC1 */ADC_Cmd(ADC1, ENABLE);/* TIM1 counter enable */TIM1_Cmd(ENABLE);/* Test on channel1 transfer complete flag */while(!DMA_GetFlagStatus(DMA_FLAG_TC1);/* Clear channel1 transfer complete flag */DMA_ClearFlag(DMA_FLAG_TC1)
14、;/* TIM1 counter disable */TIM1_Cmd(DISABLE);while (1)/* Function Name : RCC_Configuration* Description : Configures the different system clocks.* Input : None* Output : None* Return : None*/void RCC_Configuration(void)/* RCC system reset(for debug purpose) */RCC_DeInit();/* Enable HSE */RCC_HSEConf
15、ig(RCC_HSE_ON);/* Wait till HSE is ready */HSEStartUpStatus = RCC_WaitForHSEStartUp();if(HSEStartUpStatus = SUCCESS)/* Enable Prefetch Buffer */FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);/* Flash 2 wait state */FLASH_SetLatency(FLASH_Latency_2);/* HCLK = SYSCLK */RCC_HCLKConfig(RCC_SYSCLK_
16、Div1);/* PCLK2 = HCLK */RCC_PCLK2Config(RCC_HCLK_Div1);/* PCLK1 = HCLK/2 */RCC_PCLK1Config(RCC_HCLK_Div2);/* ADCCLK = PCLK2/4 */RCC_ADCCLKConfig(RCC_PCLK2_Div4);/* PLLCLK = 8MHz * 7 = 56 MHz */RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_7);/* Enable PLL */RCC_PLLCmd(ENABLE);/* Wait till PLL is
17、ready */while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) = RESET)/* Select PLL as system clock source */RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);/* Wait till PLL is used as system clock source */while(RCC_GetSYSCLKSource() != 0x08)/* Enable peripheral clocks -*/* Enable DMA clock */RCC_AHBPeriphClockCmd(RC
18、C_AHBPeriph_DMA, ENABLE);/* Enable GPIOA, GPIOC, ADC1 and TIM1 clock */RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC |RCC_APB2Periph_ADC1 | RCC_APB2Periph_TIM1, ENABLE);/* Function Name : GPIO_Configuration* Description : Configures the different GPIO ports.* Input : None* Outpu
19、t : None* Return : None*/void GPIO_Configuration(void)GPIO_InitTypeDef GPIO_InitStructure;/* Configure PC.01 and PC.04 (ADC Channel11 and Channel14) as analog input */GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;GPIO_Init(GPIOC, &GPIO_InitStructure);/* Functi
20、on Name : NVIC_Configuration* Description : Configures NVIC and Vector Table base location.* Input : None* Output : None* Return : None*/void NVIC_Configuration(void)#ifdef VECT_TAB_RAM/* Set the Vector Table base location at 0x20000000 */NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);#else /* VECT_TAB_
21、FLASH */* Set the Vector Table base location at 0x08000000 */NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);#endif/*/附录2:Debug LogThu Jan 03 20:00:46 2019: DLL version: V3.62a, compiled Feb 23 2019 17:06:09Thu Jan 03 20:00:46 2019: Firmware: J-Link compiled Jun 14 2019 14:36:33 ARM Rev.5Thu Jan 03 20:
22、00:46 2019: JTAG speed is initially set to: 32 kHzThu Jan 03 20:00:46 2019: Found Cortex-M3, Little endian.Thu Jan 03 20:00:46 2019: TPIU fitted.Thu Jan 03 20:00:46 2019: FPUnit: 6 code (BP) slots and 2 literal slotsThu Jan 03 20:00:46 2019: Software reset was performedThu Jan 03 20:00:46 2019: Init
23、ial reset was performedThu Jan 03 20:00:46 2019: J-Link found 2 JTAG devices. ARM core Id: 3BA00477(Cortex M3), ARM core Id: 00000000(ARM9)Thu Jan 03 20:00:46 2019: Device at TAP0 selectedThu Jan 03 20:00:47 2019: 3080 bytes downloaded and verified (5.20 Kbytes/sec)Thu Jan 03 20:00:47 2019: Warning:
24、Verify error at address 0x2000007C, target byte: 0x42, byte in file: 0x01Thu Jan 03 20:00:47 2019: Warning:Verify error at address 0x2000007D, target byte: 0x08, byte in file: 0x80Thu Jan 03 20:00:47 2019: Warning:Verify error at address 0x2000007E, target byte: 0xCE, byte in file: 0x70Thu Jan 03 20
25、:00:47 2019: Warning:Verify error at address 0x2000007F, target byte: 0x07, byte in file: 0x47Thu Jan 03 20:00:47 2019: Warning:Verify error at address 0x20000080, target byte: 0x42, byte in file: 0x50Thu Jan 03 20:00:47 2019: Warning:Verify error at address 0x20000081, target byte: 0x08, byte in fi
26、le: 0xF0Thu Jan 03 20:00:47 2019: Warning:Verify error at address 0x20000082, target byte: 0xCF, byte in file: 0x00Thu Jan 03 20:00:47 2019: Warning:Verify error at address 0x20000083, target byte: 0x07, byte in file: 0x60Thu Jan 03 20:00:47 2019: Warning:Verify error at address 0x20000084, target b
27、yte: 0x43, byte in file: 0x81Thu Jan 03 20:00:47 2019: Warning:Verify error at address 0x20000085, target byte: 0x08, byte in file: 0x05Thu Jan 03 20:00:47 2019: Warning:Verify error at address 0x20000086, target byte: 0xCE, byte in file: 0x02Thu Jan 03 20:00:47 2019: Warning:Verify error at address
28、 0x20000087, target byte: 0x07, byte in file: 0xD0Thu Jan 03 20:00:47 2019: Warning:Verify error at address 0x20000088, target byte: 0x42, byte in file: 0x5FThu Jan 03 20:00:47 2019: Warning:Verify error at address 0x20000089, target byte: 0x08, byte in file: 0xF0Thu Jan 03 20:00:47 2019: Warning:Ve
29、rify error at address 0x2000008A, target byte: 0xCE, byte in file: 0xFFThu Jan 03 20:00:47 2019: Warning:Verify error at address 0x2000008B, target byte: 0x07, byte in file: 0x30Thu Jan 03 20:00:47 2019: Warning:Verify error at address 0x2000008C, target byte: 0x42, byte in file: 0x70Thu Jan 03 20:0
30、0:47 2019: Warning:Verify error at address 0x2000008D, target byte: 0x08, byte in file: 0x47Thu Jan 03 20:00:47 2019: Warning:Verify error at address 0x2000008E, target byte: 0xCF, byte in file: 0x2EThu Jan 03 20:00:47 2019: Warning:Verify error at address 0x2000008F, target byte: 0x07, byte in file
31、: 0x49Thu Jan 03 20:00:47 2019: Warning:Verify error at address 0x20000090, target byte: 0x41, byte in file: 0x0AThu Jan 03 20:00:47 2019: Warning:Verify error at address 0x20000091, target byte: 0x08, byte in file: 0x68Thu Jan 03 20:00:47 2019: Warning:Verify error at address 0x20000092, target byt
32、e: 0xCE, byte in file: 0xD2Thu Jan 03 20:00:47 2019: Warning:Verify error at address 0x20000094, target byte: 0x41, byte in file: 0xFBThu Jan 03 20:00:47 2019: Warning:Verify error at address 0x20000095, target byte: 0x08, byte in file: 0xD4Thu Jan 03 20:00:47 2019: Warning:Verify error at address 0
33、x20000096, target byte: 0xCB, byte in file: 0x2DThu Jan 03 20:00:47 2019: Warning:Verify error at address 0x20000097, target byte: 0x07, byte in file: 0x4AThu Jan 03 20:00:47 2019: Warning:Verify error at address 0x20000098, target byte: 0x42, byte in file: 0x13Thu Jan 03 20:00:47 2019: Warning:Veri
34、fy error at address 0x20000099, target byte: 0x08, byte in file: 0x68Thu Jan 03 20:00:47 2019: Warning:Verify error at address 0x2000009A, target byte: 0xCD, byte in file: 0x53Thu Jan 03 20:00:47 2019: Warning:Verify error at address 0x2000009B, target byte: 0x07, byte in file: 0xF0Thu Jan 03 20:00:
35、47 2019: Warning:Verify error at address 0x2000005C, target byte: 0x40, byte in file: 0x15Thu Jan 03 20:00:47 2019: Warning:Verify error at address 0x2000005D, target byte: 0x08, byte in file: 0x00Thu Jan 03 20:00:47 2019: Warning:Verify error at address 0x2000005E, target byte: 0xC8, byte in file:
36、0x00Thu Jan 03 20:00:47 2019: Warning:Verify error at address 0x2000005F, target byte: 0x07, byte in file: 0x20Thu Jan 03 20:00:47 2019: Warning:Verify error at address 0x20000060, target byte: 0x3E, byte in file: 0x03Thu Jan 03 20:00:47 2019: Warning:Verify error at address 0x20000061, target byte:
37、 0x08, byte in file: 0x4CThu Jan 03 20:00:47 2019: Warning:Verify error at address 0x20000062, target byte: 0xD3, byte in file: 0x4FThu Jan 03 20:00:47 2019: Warning:Verify error at address 0x20000063, target byte: 0x07, byte in file: 0xF0Thu Jan 03 20:00:47 2019: Warning:Verify error at address 0x2
38、0000064, target byte: 0x49, byte in file: 0x00Thu Jan 03 20:00:47 2019: Warning:Verify error at address 0x20000065, target byte: 0x08, byte in file: 0x00Thu Jan 03 20:00:47 2019: Warning:Verify error at address 0x20000066, target byte: 0xD2, byte in file: 0xA0Thu Jan 03 20:00:47 2019: Warning:Verify
39、 error at address 0x20000067, target byte: 0x07, byte in file: 0x47Thu Jan 03 20:00:47 2019: Warning:Verify error at address 0x20000068, target byte: 0x45, byte in file: 0x02Thu Jan 03 20:00:47 2019: Warning:Verify error at address 0x20000069, target byte: 0x08, byte in file: 0x4CThu Jan 03 20:00:47
40、 2019: Warning:Verify error at address 0x2000006A, target byte: 0xD1, byte in file: 0x03Thu Jan 03 20:00:47 2019: Warning:Verify error at address 0x2000006B, target byte: 0x07, byte in file: 0x4DThu Jan 03 20:00:47 2019: Warning:Verify error at address 0x2000006C, target byte: 0x42, byte in file: 0x
41、AEThu Jan 03 20:00:47 2019: Warning:Verify error at address 0x2000006D, target byte: 0x08, byte in file: 0x46Thu Jan 03 20:00:47 2019: Warning:Verify error at address 0x2000006E, target byte: 0xCE, byte in file: 0x20Thu Jan 03 20:00:47 2019: Warning:Verify error at address 0x2000006F, target byte: 0
42、x07, byte in file: 0x47Thu Jan 03 20:00:47 2019: Warning:Verify error at address 0x20000070, target byte: 0x41, byte in file: 0xC1Thu Jan 03 20:00:47 2019: Warning:Verify error at address 0x20000071, target byte: 0x08, byte in file: 0x05Thu Jan 03 20:00:47 2019: Warning:Verify error at address 0x20000072, target byte: 0xCA, byte in file: 0x00Thu Jan 03 20:00:47 2019: Warning:Verify error at address 0x20000073, target byte: 0x07, byte in file: 0x20Thu Jan 03 20:00:47 2019: Warning:Verify error at address 0