试验环境: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 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 variables ---------------------------------------------------------*/ ADC_InitTypeDef ADC_InitStructure; DMA_InitTypeDef DMA_InitStructure; TIM1_TimeBaseInitTypeDef TIM1_TimeBaseStructure; TIM1_OCInitTypeDef TIM1_OCInitStructure; TIM1_BDTRInitTypeDef TIM1_BDTRInitStructure; u16 ADC_RegularConvertedValueTab[32]; ErrorStatus HSEStartUpStatus; /* Private function prototypes -----------------------------------------------*/ 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 DEBUG debug(); #endif
/* System clocks configuration ---------------------------------------------*/ RCC_Configuration();
/* 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_TimeBaseStructure.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_OCInitStructure.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.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_InitStructure.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_PeripheralDataSize = 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_InitStructure);
/* 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_CC1; 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); /* Enable 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); /* 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_HSEConfig(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_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 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(RCC_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 * Output : 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); }
/******************************************************************************* * Function 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_FLASH */ /* Set the Vector Table base location at 0x08000000 */ NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); #endif }
/******************************************************************************/ 附录2:Debug Log
Thu Jan 03 20:00:46 2008: DLL version: V3.62a, compiled Feb 23 2007 17:06:09 Thu Jan 03 20:00:46 2008: Firmware: J-Link compiled Jun 14 2007 14:36:33 ARM Rev.5 Thu Jan 03 20:00:46 2008: JTAG speed is initially set to: 32 kHz Thu Jan 03 20:00:46 2008: Found Cortex-M3, Little endian. Thu Jan 03 20:00:46 2008: TPIU fitted. Thu Jan 03 20:00:46 2008: FPUnit: 6 code (BP) slots and 2 literal slots Thu Jan 03 20:00:46 2008: Software reset was performed Thu Jan 03 20:00:46 2008: Initial reset was performed Thu Jan 03 20:00:46 2008: J-Link found 2 JTAG devices. ARM core Id: 3BA00477(Cortex M3), ARM core Id: 00000000(ARM9) Thu Jan 03 20:00:46 2008: Device at TAP0 selected Thu Jan 03 20:00:47 2008: 3080 bytes downloaded and verified (5.20 Kbytes/sec) Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x2000007C, target byte: 0x42, byte in file: 0x01 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x2000007D, target byte: 0x08, byte in file: 0x80 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x2000007E, target byte: 0xCE, byte in file: 0x70 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x2000007F, target byte: 0x07, byte in file: 0x47 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000080, target byte: 0x42, byte in file: 0x50 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000081, target byte: 0x08, byte in file: 0xF0 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000082, target byte: 0xCF, byte in file: 0x00 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000083, target byte: 0x07, byte in file: 0x60 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000084, target byte: 0x43, byte in file: 0x81 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000085, target byte: 0x08, byte in file: 0x05 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000086, target byte: 0xCE, byte in file: 0x02 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000087, target byte: 0x07, byte in file: 0xD0 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000088, target byte: 0x42, byte in file: 0x5F Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000089, target byte: 0x08, byte in file: 0xF0 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x2000008A, target byte: 0xCE, byte in file: 0xFF Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x2000008B, target byte: 0x07, byte in file: 0x30 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x2000008C, target byte: 0x42, byte in file: 0x70 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x2000008D, target byte: 0x08, byte in file: 0x47 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x2000008E, target byte: 0xCF, byte in file: 0x2E Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x2000008F, target byte: 0x07, byte in file: 0x49 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000090, target byte: 0x41, byte in file: 0x0A Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000091, target byte: 0x08, byte in file: 0x68 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000092, target byte: 0xCE, byte in file: 0xD2 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000094, target byte: 0x41, byte in file: 0xFB Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000095, target byte: 0x08, byte in file: 0xD4 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000096, target byte: 0xCB, byte in file: 0x2D Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000097, target byte: 0x07, byte in file: 0x4A Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000098, target byte: 0x42, byte in file: 0x13 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000099, target byte: 0x08, byte in file: 0x68 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x2000009A, target byte: 0xCD, byte in file: 0x53 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x2000009B, target byte: 0x07, byte in file: 0xF0 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x2000005C, target byte: 0x40, byte in file: 0x15 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x2000005D, target byte: 0x08, byte in file: 0x00 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x2000005E, target byte: 0xC8, byte in file: 0x00 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x2000005F, target byte: 0x07, byte in file: 0x20 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000060, target byte: 0x3E, byte in file: 0x03 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000061, target byte: 0x08, byte in file: 0x4C Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000062, target byte: 0xD3, byte in file: 0x4F Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000063, target byte: 0x07, byte in file: 0xF0 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000064, target byte: 0x49, byte in file: 0x00 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000065, target byte: 0x08, byte in file: 0x00 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000066, target byte: 0xD2, byte in file: 0xA0 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000067, target byte: 0x07, byte in file: 0x47 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000068, target byte: 0x45, byte in file: 0x02 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000069, target byte: 0x08, byte in file: 0x4C Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x2000006A, target byte: 0xD1, byte in file: 0x03 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x2000006B, target byte: 0x07, byte in file: 0x4D Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x2000006C, target byte: 0x42, byte in file: 0xAE Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x2000006D, target byte: 0x08, byte in file: 0x46 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x2000006E, target byte: 0xCE, byte in file: 0x20 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x2000006F, target byte: 0x07, byte in file: 0x47 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000070, target byte: 0x41, byte in file: 0xC1 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000071, target byte: 0x08, byte in file: 0x05 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000072, target byte: 0xCA, byte in file: 0x00 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000073, target byte: 0x07, byte in file: 0x20 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000074, target byte: 0x40, byte in file: 0xC9 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000075, target byte: 0x08, byte in file: 0x06 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000076, target byte: 0xC9, byte in file: 0x00 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000077, target byte: 0x07, byte in file: 0x20 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x20000078, target byte: 0x3B, byte in file: 0x9D Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x2000007A, target byte: 0xD1, byte in file: 0x00 Thu Jan 03 20:00:47 2008: Warning: Verify error at address 0x2000007B, target byte: 0x07, byte in file: 0x20 Thu Jan 03 20:00:47 2008: There were warnings during download of FLASH loader, see Log Window Thu Jan 03 20:00:48 2008: Failed to load flash loader: C:Program FilesIAR SystemsEmbedded Workbench 4.0 EvaluationARMconfigflashloaderSTFlashSTM32F10x.d79
|
|