完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
我想用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(" rn A n"); for(i = 0; i printf(" rn B n"); for(i = 0; i printf(" rn TEST1 %dus n",TickCntCPU); SystickTime = 0; DMA_Cmd(DMA1_Channel6 , ENABLE);while(CurrDataCounter != 0); TickCntDMA = SystickTime;printf("rn %d", TickCntDMA); if(strncmp((const char *)SRC_Const_Buffer , (const char *)DST_Buffer , BufferSize) == 0) { printf("rn Transmit Success! rn"); }else printf("rn Transmit Fault! rn");printf("rn CPU transfer , time : %dusnr" , TickCntCPU);printf("rn DMA transfer , time : %dusnr" , 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. * * ****************************************************************************** */ |
|
相关推荐
6个回答
|
|
你说你的思路.
|
|
|
|
我先开辟一片区域,把数据通过普通CPU传输,和DMA中断传输,分别用Systick进行计时,然后通过串口把时间分别打印到助手上,进行对比下,看看传输时间,,我现在Systick好像不计数
if(strncmp((const char *)SRC_Const_Buffer , (const char *)DST_Buffer , BufferSize) == 0) { printf("rn Transmit Success! rn"); } else printf("rn Transmit Fault! rn"); printf("rn CPU transfer , time: %dusnr" , TickCntCPU); printf("rn DMA transfer , time: %dusnr" , TickCntDMA); 这两句话也进不去 我实在不知道怎么回事了 |
|
|
|
|
|
|
|
确实不计数啊,版主帮我看看,怎么样操作固件库让systick计数,
|
|
|
|
我是V3.5的固件库
|
|
|
|
我不用库
|
|
|
|
只有小组成员才能发言,加入小组>>
调试STM32H750的FMC总线读写PSRAM遇到的问题求解?
1632 浏览 1 评论
X-NUCLEO-IHM08M1板文档中输出电流为15Arms,15Arms是怎么得出来的呢?
1559 浏览 1 评论
985 浏览 2 评论
STM32F030F4 HSI时钟温度测试过不去是怎么回事?
688 浏览 2 评论
ST25R3916能否对ISO15693的标签芯片进行分区域写密码?
1605 浏览 2 评论
1869浏览 9评论
STM32仿真器是选择ST-LINK还是选择J-LINK?各有什么优势啊?
652浏览 4评论
STM32F0_TIM2输出pwm2后OLED变暗或者系统重启是怎么回事?
521浏览 3评论
539浏览 3评论
stm32cubemx生成mdk-arm v4项目文件无法打开是什么原因导致的?
508浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-25 06:19 , Processed in 0.890609 second(s), Total 88, Slave 71 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号