发 帖  
原厂入驻New
[问答] 想用DMA传输和普通搬移数据对比使用的时间?
66 DMA
分享
我想用DMA传输和普通搬移数据对比使用的时间,程序中时间输布出来,好像没有计时,请帮帮我看看
main.c中
#include "STM32f10x.h"#include "stdio.h"#include "string.h"
void Delay(__IO uint32_t ntime);void TimingDelay_Decrement(void);
#define BufferSize 32
static __IO uint32_t TimingDelay; vu32 SystickTime;vu16 CurrDataCounter = 0;
uc32 SRC_Const_Buffer[BufferSize] ={0x01020304, 0x05060708, 0x090A0B0C, 0X0D0E0F10,0X11121314, 0X15161718, 0X191A1B1C, 0X1D1E1F20,0X21222324, 0X25262728, 0X292A2B2C, 0X2D2E2F30,0X31323334, 0X35363738, 0X394A4B4C, 0X4D4E4F50,0X51525354, 0X55565758, 0X595A5B5C, 0X5D5E5F60,0X61626364, 0X65666768, 0X696A6B6C, 0X6D6E6F70,0X71727374, 0X75767778, 0X797A7B7C, 0X7D7E7F80, };
u32 DST_Buffer[BufferSize];
void RCC_Configuration(void);void NVIC_Configuration(void);void GPIO_Configuration(void);void USART_Configuration(void);void DMA_Configuration(void);//void Systick_Configuration(void);
void SystickInit(void){SystemInit();IF(SysTick_Config(SystemCoreclock / 1000000))   //时基 1US  {     while (1);  }}
int main(void){u8 i=0;u8 TickCntDMA = 0;u8 TickCntCPU = 0;
RCC_Configuration( );NVIC_Configuration( );GPIO_Configuration( );USART_Configuration( );DMA_Configuration( );
SystickTime = 0;
printf(" \r\n A  \n");
for(i = 0; i<BufferSize; i++){DST_Buffer = SRC_Const_Buffer;}TickCntCPU = SystickTime;
printf(" \r\n  B  \n");

for(i = 0; i<BufferSize; i++){DST_Buffer = 0;}
printf(" \r\n TEST1  %dus  \n",TickCntCPU);
SystickTime = 0;
DMA_Cmd(DMA1_Channel6 , ENABLE);while(CurrDataCounter != 0);
TickCntDMA = SystickTime;printf("\r\n     %d", TickCntDMA);
if(strncmp((const char *)SRC_Const_Buffer , (const char *)DST_Buffer , BufferSize) == 0)  {      printf("\r\n Transmit Success! \r\n");  }else   printf("\r\n Transmit Fault! \r\n");printf("\r\n CPU transfer , time : %dus\n\r" , TickCntCPU);printf("\r\n DMA transfer , time : %dus\n\r" , TickCntDMA);    while(1);}
void RCC_Configuration(void){ErrorStatus  HSEStartUpStatus;RCC_DeInit( );RCC_HSEConfig(RCC_HSE_ON);HSEStartUpStatus = RCC_WaitForHSEStartUp();if(HSEStartUpStatus == SUCCESS){RCC_HCLKConfig(RCC_SYSCLK_Div1);RCC_PCLK1Config(RCC_HCLK_Div2);RCC_PCLK2Config(RCC_HCLK_Div1);FLASH_SetLatency(FLASH_Latency_2);FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);RCC_PLLConfig(RCC_PLLSource_HSE_Div1 , RCC_PLLMul_9);RCC_PLLCmd(ENABLE);while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);while(RCC_GetSYSCLKSource() !=0x08);}RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA , ENABLE);RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1 , ENABLE);}
void GPIO_Configuration(void){GPIO_InitTypeDef  GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_Init(GPIOA , &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;GPIO_Init(GPIOA , &GPIO_InitStructure);}
void NVIC_Configuration(void){NVIC_InitTypeDef NVIC_InitStructure;
#ifdef VECT_TAB_RAM    NVIC_SetVectorTable(NVIC_VectTab_RAM , 0x0);#elseNVIC_SetVectorTable(NVIC_VectTab_FLASH , 0x0);#endifNVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel6_IRQn;NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;NVIC_Init(&NVIC_InitStructure);}
void DMA_Configuration(void){DMA_InitTypeDef  DMA_InitStructure;
DMA_DeInit(DMA1_Channel6);
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)SRC_Const_Buffer;//定义DMA外设基址DMA_InitStructure.DMA_MemoryBaseAddr =  (u32)DST_Buffer;   //定义DMA内存基地址DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;//外设作为数据传输的来源DMA_InitStructure.DMA_BufferSize = BufferSize;  //定义DMA缓存大小DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Enable;//外设地址寄存器递增DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;   //内存地址寄存器递增DMA_InitStructure.DMA_PeripheralDataSize = DMA_MemoryDataSize_Word;//数据宽度为32位DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;  //工作在正常缓存模式DMA_InitStructure.DMA_Priority = DMA_Priority_High; //DMA通道具有高优先级DMA_InitStructure.DMA_M2M = DMA_M2M_Enable; //DMA设置为内存到内存传输DMA_Init(DMA1_Channel6 , &DMA_InitStructure);//DMA_ITConfig(DMA1_Channel6 , DMA_IT_TC , ENABLE);//传输完成中断CurrDataCounter = DMA_GetCurrDataCounter(DMA1_Channel6);//读取当前数据量计数值}
void USART_Configuration(void){USART_InitTypeDef USART_InitStructure;USART_ClockInitTypeDef USART_ClockInitStructure;// 波特率9600  // 8为数据长度// 1个停止位,无效验// 禁止硬件流控制// 禁止usart时钟// 时钟极性低// 在第二个边沿捕捉数据// 最后1位数据的时钟脉冲不从SCLK输出USART_ClockInitStructure.USART_Clock = USART_Clock_Disable;USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;USART_ClockInit(USART1 , &USART_ClockInitStructure);
USART_InitStructure.USART_BaudRate = 9600;USART_InitStructure.USART_WordLength = USART_WordLength_8b;USART_InitStructure.USART_StopBits = USART_StopBits_1;USART_InitStructure.USART_Parity = USART_Parity_No;USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;USART_Init(USART1 , &USART_InitStructure);USART_Cmd(USART1 , ENABLE);
}
int fputc(int ch , FILE  *f){USART_SendData(USART1 , (u8) ch);while(USART_GetFlagStatus(USART1 , USART_FLAG_TC) == RESET);return ch;}
void Delay(__IO uint32_t nTime){     TimingDelay = nTime;    while(TimingDelay != 0);}
void TimingDelay_Decrement(void){  if(TimingDelay != 0x00)     {        TimingDelay--;     }}
stm32f10x_it.C下
/**  ******************************************************************************  * @file    GPIO/IOToggle/stm32f10x_it.c   * @author  MCD Application Team  * @version V3.5.0  * @date    08-April-2011  * @brief   Main Interrupt Service Routines.  *          This file provides template for all exceptions handler and peripherals  *          interrupt service routine.  ******************************************************************************  * @attention  *  * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS  * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE  * TIME. AS A RESULT, STmicroELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY  * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING  * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE  * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.  *  * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>  ******************************************************************************  */
/* Includes ------------------------------------------------------------------*/#include "stm32f10x_it.h"
extern vu32 SystickTime;extern vu16 CurrDataCounter;/** @addtogroup STM32F10x_StdPeriph_Examples  * @{  */
/** @addtogroup GPIO_IOToggle  * @{  */
/* Private typedef -----------------------------------------------------------*//* Private define ------------------------------------------------------------*//* Private macro -------------------------------------------------------------*//* Private variables ---------------------------------------------------------*//* Private function prototypes -----------------------------------------------*//* Private functions ---------------------------------------------------------*/
/******************************************************************************//*            Cortex-M3 Processor Exceptions Handlers                         *//******************************************************************************/
/**  * @brief  This function handles NMI exception.  * @param  None  * @retval None  */void NMI_Handler(void){}
/**  * @brief  This function handles Hard Fault exception.  * @param  None  * @retval None  */void HardFault_Handler(void){  /* Go to infinite loop when Hard Fault exception occurs */  while (1)  {  }}
/**  * @brief  This function handles Memory Manage exception.  * @param  None  * @retval None  */void MemManage_Handler(void){  /* Go to infinite loop when Memory Manage exception occurs */  while (1)  {  }}
/**  * @brief  This function handles Bus Fault exception.  * @param  None  * @retval None  */void BusFault_Handler(void){  /* Go to infinite loop when Bus Fault exception occurs */  while (1)  {  }}
/**  * @brief  This function handles Usage Fault exception.  * @param  None  * @retval None  */void UsageFault_Handler(void){  /* Go to infinite loop when Usage Fault exception occurs */  while (1)  {  }}
/**  * @brief  This function handles SVCall exception.  * @param  None  * @retval None  */void SVC_Handler(void){}
/**  * @brief  This function handles debug Monitor exception.  * @param  None  * @retval None  */void DebugMon_Handler(void){}
/**  * @brief  This function handles PendSV_Handler exception.  * @param  None  * @retval None  */void PendSV_Handler(void){}
/**  * @brief  This function handles SysTick Handler.  * @param  None  * @retval None  */
extern TimingDelay_Decrement(void);
void SysTick_Handler(void){SystickTime++;TimingDelay_Decrement( );}
void DMA1_Channel6_IRQhandler(void){CurrDataCounter = DMA_GetCurrDataCounter(DMA1_Channel6);DMA_ClearITPendingBit(DMA1_IT_GL6);}
/******************************************************************************//*                 STM32F10x Peripherals Interrupt Handlers                   *//*  Add here the Interrupt Handler for the used peripheral(s) (PPP), for the  *//*  available peripheral interrupt handler's name please refer to the startup *//*  file (startup_stm32f10x_xx.s).                                            *//******************************************************************************/
/**  * @brief  This function handles PPP interrupt request.  * @param  None  * @retval None  *//*void PPP_IRQHandler(void){}*/
/**  * @}  */
/**  * @}  */
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
请帮我看看哪里有问题谢谢,我用的V3.5的固件库
DMA.rar (4.23 MB )
0
2020-8-6 02:53:15   评论 分享淘帖 邀请回答
6个回答
2020-8-6 08:17:23 评论

举报

我先开辟一片区域,把数据通过普通CPU传输,和DMA中断传输,分别用Systick进行计时,然后通过串口把时间分别打印到助手上,进行对比下,看看传输时间,,我现在Systick好像不计数
if(strncmp((const char *)SRC_Const_Buffer , (const char *)DST_Buffer , BufferSize) == 0)
  {   
   printf("\r\n Transmit Success! \r\n");
  }
else
   printf("\r\n Transmit Fault! \r\n");
printf("\r\n CPU transfer , time: %dus\n\r" , TickCntCPU);
printf("\r\n DMA transfer , time: %dus\n\r" , TickCntDMA);
这两句话也进不去
我实在不知道怎么回事了
2020-8-6 08:33:54 评论

举报

问题就在定位到你的systick设置了,撇开其他两个,你单独看systick的运行,是否正常?
比如中断能否进入?计数是否有累加?
2020-8-6 08:52:01 评论

举报

确实不计数啊,版主帮我看看,怎么样操作固件库让systick计数,
2020-8-6 09:00:45 评论

举报

2020-8-6 09:19:30 评论

举报

2020-8-6 09:37:56 评论

举报

只有小组成员才能发言,加入小组>>

83个成员聚集在这个小组

加入小组

创建小组步骤

关闭

站长推荐 上一条 /8 下一条

快速回复 返回顶部 返回列表