The DMA channels can also work without being triggered by a request from a peripheral.

This mode is called Memory to Memory mode.

If the MEM2MEM bit in the DMA_CCRx register is set, then the channel initiates transfers

as soon as it is enabled by software by setting the Enable bit (EN) in the DMA_CCRx register."

// STM32 TIM2 DMA Mem-to-Mem pacing VLDiscovery - sourcer32@gmail.com

#include "STM32vldiscovery.h"

#define OUTLENGTH 5

volatile u16 InBuffer[OUTLENGTH], OutBuffer[OUTLENGTH];

/**************************************************************************************/

void RCC_Configuration(void)
{
// clock for DMA
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); // clock for TIM2
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
} /**************************************************************************************/ void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure; NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = ;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = ;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
} /******************************************************************************/ void DMA1_Channel2_IRQHandler(void) // Called at 10 Hz
{
if (DMA_GetITStatus(DMA1_IT_TC2))
{
DMA_ClearITPendingBit(DMA1_IT_TC2); STM32vldiscovery_LEDToggle(LED3); // Toggle 5 Hz
STM32vldiscovery_LEDToggle(LED4); // Do something
}
} /**************************************************************************************/ void DMA_Configuration(void)
{
DMA_InitTypeDef DMA_InitStructure; DMA_DeInit(DMA1_Channel2); DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)&InBuffer[]; // Source
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&OutBuffer[]; // Destination
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = OUTLENGTH;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Enable;
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; // Repetitive, for my convenience
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; // So we can pace via trigger
DMA_Init(DMA1_Channel2, &DMA_InitStructure); /* Enable DMA1 Channel2 Transfer Complete interrupt */
DMA_ITConfig(DMA1_Channel2, DMA_IT_TC, ENABLE); // turning DMA on (DMA1 Channel2 -> TIM2_UP)
DMA_Cmd(DMA1_Channel2, ENABLE);
} /**************************************************************************************/ void TIM2_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_TimeBaseStructure.TIM_Prescaler = (SystemCoreClock / ) - ; // 1 MHz
TIM_TimeBaseStructure.TIM_Period = -; // 1MHz/20000 = 50 Hz
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_RepetitionCounter = ;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); // "connecting" DMA and TIM2
TIM_DMACmd(TIM2, TIM_DMA_Update, ENABLE); // turning on TIM2
TIM_Cmd(TIM2, ENABLE);
} /**************************************************************************************/ int main(void)
{
/* Initialise LEDs LD3 & LD4 */
STM32vldiscovery_LEDInit(LED3);
STM32vldiscovery_LEDInit(LED4); STM32vldiscovery_LEDOn(LED3);
STM32vldiscovery_LEDOff(LED4); RCC_Configuration(); NVIC_Configuration(); DMA_Configuration(); TIM2_Configuration(); while();
}

DMA : Timer Trigger Memory-to-memory mode,的更多相关文章

  1. Java (JVM) Memory Model – Memory Management in Java

    原文地址:http://www.journaldev.com/2856/java-jvm-memory-model-memory-management-in-java Understanding JV ...

  2. System memory,AGP memory和video memory【转】

    system  memory就是电脑的内存条上的,一般都很大.显卡不能访问 . video memory就是显示卡上的显存,一般是32,64,128M这样,速度最快,显卡可直接访问 .用来描述电脑上一 ...

  3. stm32 DMA+timer+DAC

    是有延迟的:

  4. Operating System Memory Management、Page Fault Exception、Cache Replacement Strategy Learning、LRU Algorithm

    目录 . 引言 . 页表 . 结构化内存管理 . 物理内存的管理 . SLAB分配器 . 处理器高速缓存和TLB控制 . 内存管理的概念 . 内存覆盖与内存交换 . 内存连续分配管理方式 . 内存非连 ...

  5. STM32F4 Timer Internal Trigger Connection

    The Timers can be cascaded to make more complex timing relationships, or longer periods. Internally ...

  6. PatentTips - Method to manage memory in a platform with virtual machines

    BACKGROUND INFORMATION Various mechanisms exist for managing memory in a virtual machine environment ...

  7. Understanding Virtual Memory

    Understanding Virtual Memory by Norm Murray and Neil Horman Introduction Definitions The Life of a P ...

  8. OpenCL memory object 之 Global memory (2)

    转载自:http://www.cnblogs.com/mikewolf2002/archive/2011/12/18/2291584.html 当我们用clCreateBuffer, clCreate ...

  9. DTrace to Troubleshoot Java Native Memory Problems

    How to Use DTrace to Troubleshoot Java Native Memory Problems on Oracle Solaris 11 Hands-On Labs of ...

随机推荐

  1. IE 11 使用 flexbox 垂直居中 bug

    不要使用 min-height 改为 height 即可 caniuse: https://caniuse.com/#search=flexbox

  2. 如何使用jpegtran 压缩JPG图片

    说到jpegtran相信很多人都比较陌生,网上相关的资料也很少. jpegtran可以让图片更加的简化,缩小图片的容量,从而增加网络的传输速度.说在多你也不信,下面就让事实证明. 首先下载  jpeg ...

  3. tensorboard遇到的坑

    <ul><li>No graph definition files were found.</li></ul> <p>启动命令 tensor ...

  4. 谁在call我-backtrace的实现原理【转】

    转自:http://www.xuebuyuan.com/1504689.html 显示函数调用关系(backtrace/callstack)是调试器必备的功能之一,比如在gdb里,用bt命令就可以查看 ...

  5. 解决JavaFTP上传文件假死问题

    之前使用ftp上传文件,代码很稳定,用了快三年,因为数据迁移,从搭建了ftp服务器,配置好ip和账号密码后,再使用之前代码发现: 在下载过程中,程序出现假死的现象,就是,既不报错,也不抛异常,还不终止 ...

  6. 使用react中遇到的问题

    引入antdesign中Carousel走马灯时遇到问题? Uncaught Error: Element ref was specified as a string (slick) but no o ...

  7. SqlServer中 SET DATEFIRST更改

    在 SQL Server 中默认情况下,每周的开始都是从周日开始算起的,如果默认星期一呢? 这里有三种方式可以解决这个问题: 一:直接通过 SET DATEFIRST VALUE 来更改重新生成新的 ...

  8. 原 nc在centos7上的安装和简单使用

    https://blog.csdn.net/qq_16414307/article/details/50291341 https://www.cnblogs.com/rocky-AGE-24/p/69 ...

  9. CentOS7.x使用overlay文件系统

    https://www.cnblogs.com/yufeng218/p/8370670.html http://www.cnblogs.com/lehuoxiong/p/9908118.html ht ...

  10. maven windows 环境变量

    MAVEN_HOME,内容是解压的maven文件路径 Path中添加 %MAVEN_HOME%\bin 为了测试安装成功,打开命令提示符,输入 mvn -version