http://www.efton.sk/STM32/bt.c

// Timer-triggered memory-to-memory DMA transfer demonstrator for STM32F4xx (probably good enough for STM32F2xx too)
// Note, that we won't use the memory-to-memory mode here, as that would simply run not waiting for the triggers
// To be run in debugger, watching the dst array to being gradually filled, one word each time the trigger reloads
// (and perhaps watching a cycle-counter to see how the timer's ARR setting influences the total time) // (C)2014 by wek at efton dot sk
// Legalese: do whatever you want with this #include "stm32f4xx.h"
#include <stdint.h> #define TIMER 1 #if (TIMER == 1)
#define _DMA_ 2
#define _Stream_ 5
#define _Channel_ 6
#elif (TIMER == 2) // this won't work, as DMA1 can't transfer
#define _DMA_ 1
#define _Stream_ 1
#define _Channel_ 3
#else
#error "no such"
#endif #define GLUE5_(a, b, c, d, e) a ## b ## c ## d ## e
#define GLUE5(a, b, c, d, e) GLUE5_(a, b, c, d, e)
#define GLUE4(a, b, c, d) GLUE5_(a, b, c, d, ) #define DBGMCU_APBxFZ GLUE4(DBGMCU->APB, _DMA_, FZ, )
#define DBGMCU_APB1_FZ_DBG_TIMy_STOP GLUE4(DBGMCU_APB1_FZ_DBG_TIM, TIMER, _STOP, ) #define RCC_AHB1ENR_DMAxEN GLUE4(RCC_AHB1ENR_DMA, _DMA_, EN, ) #define DMAx GLUE4(DMA, _DMA_, , ) #define DMAStream GLUE4(DMA, _DMA_, _Stream, _Stream_) #if (_Stream_ < 4)
#define yISR LISR
#else
#define yISR HISR
#endif #define DMA_yISR_TCIFz GLUE4(DMA_, yISR, _TCIF, _Stream_) #define TIMz GLUE4(TIM, TIMER, , ) #define APBxENR GLUE4(APB, _DMA_, ENR, ) #define RCC_APBxENR_TIMzEN GLUE5(RCC_APB, _DMA_, ENR_TIM, TIMER, EN) #define BUFSIZE 10 volatile uint32_t src[BUFSIZE] = {, , , , , , , , , };
volatile uint32_t dst[BUFSIZE]; int main(void) { // DBGMCU->APB2FZ |= DBGMCU_APB1_FZ_DBG_TIM1_STOP;
DBGMCU_APBxFZ |= DBGMCU_APB1_FZ_DBG_TIMy_STOP; // TIM1_UP -> DMA2 Stream5 Channel6
RCC->AHB1ENR |= RCC_AHB1ENR_DMAxEN;
while (!(RCC->AHB1ENR & RCC_AHB1ENR_DMAxEN)); DMAStream->NDTR = BUFSIZE; // halfwords to transfer
DMAStream->M0AR = (uint32_t)src;
DMAStream->PAR = (uint32_t)dst;
DMAStream->FCR =
| ( * DMA_SxFCR_DMDIS ) // direct mode
| (DMA_SxFCR_FTH__FULL * DMA_SxFCR_FTH_0 ) // [irrelevant - keep it full]
| ( * DMA_SxFCR_FEIE ) // no interrupt
; DMAStream->CR =
| (_Channel_ * DMA_SxCR_CHSEL_0 ) // channel select
| (DMA_SxCR_xBURST_INCR1 * DMA_SxCR_MBURST_0 ) // memory burst (only in FIFO mode)
| (DMA_SxCR_xBURST_INCR1 * DMA_SxCR_PBURST_0 ) // peripheral burst (only in FIFO mode)
| ( * DMA_SxCR_ACK ) // "reserved" (says manual)
| ( * DMA_SxCR_CT ) // current target (only in double-buffer mode)
| ( * DMA_SxCR_DBM ) // double-buffer mode
| (DMA_SxCR_PL_PRIORITY_VERY_HIGH * DMA_SxCR_PL_0 ) // priority level
| ( * DMA_SxCR_PINCOS ) // peripheral increment offset size (only if peripheral address increments, FIFO mode and PBURST is 0)
| (DMA_SxCR_xSIZE_WORD * DMA_SxCR_MSIZE_0 ) // memory data size; in direct mode forced to the same value as PSIZE
| (DMA_SxCR_xSIZE_WORD * DMA_SxCR_PSIZE_0 ) // peripheral data size
| ( * DMA_SxCR_MINC ) // memory address increments
| ( * DMA_SxCR_PINC ) // peripheral address increments
| ( * DMA_SxCR_CIRC ) // circular mode (forced to 1 if double-buffer mode, forced to 0 if flow control is peripheral)
| (DMA_SxCR_DIR_M2P * DMA_SxCR_DIR_0 ) // data transfer direction
| ( * DMA_SxCR_PFCTRL ) // peripheral is the flow controller (i.e. who determines end of transfer) - only for SDIO
| ( * DMA_SxCR_TCIE ) // transfer complete interrupt enable
| ( * DMA_SxCR_HTIE ) // half transfer interrupt enable
| ( * DMA_SxCR_TEIE ) // transfer error interrupt enable
| ( * DMA_SxCR_DMEIE ) // direct mode error interrupt enable
| ( * DMA_SxCR_EN ) // stream enable ;
; RCC->APBxENR |= RCC_APBxENR_TIMzEN; TIMz->PSC = ; // clk is 16MHz, no prescaler
TIMz->ARR = ; // -> the whole 10-beat DMA transfer takes cca 1000 clk
TIMz->DIER = TIM_DIER_UDE; /* Update DMA enable */
TIMz->CR1 = TIM_CR1_CEN; /* Counter enable */ while (!(DMAx->yISR & DMA_yISR_TCIFz)); // wait until DMA transfer finishes __NOP(); // place "finished" breakpoint here while() { } }

Timer-triggered memory-to-memory DMA transfer demonstrator的更多相关文章

  1. Timer triggered DMA transfer - Delay between requesting the DMA transfer

    Hello, I'm working with a STM32F407 controller board.   Right now, I want to trigger a DMA transfer ...

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

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

  3. 直接存储器存取(Direct Memory Access,DMA)详细讲解

    一.理论理解部分. 1.直接存储器存取(DMA)用来提供在外设和存储器之间或者存储器和存储器之间的高速数据传输. 2.无须CPU干预,数据可以通过DMA快速移动,这就节省了CPU的资源来做其他操作. ...

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

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

  5. Data transfer from GPIO port to RAM buffer using DMA upon receiving a trigger signal on the timer capture input channel.

    Data transfer from GPIO port to RAM buffer using DMA upon receiving a trigger signal on the timer ca ...

  6. DMA(Direct Memory Access)简介

    什么是DMA(Direct Memory Access) DMA绕过CPU,在内存和外设之间开辟了一条 "隧道" ,直接控制内存与外设之间的操作,并完全由硬件控制. 这样数据传送不 ...

  7. (转)DMA(Direct Memory Access)

    DMA(Direct Memory Access) DMA(Direct Memory Access)即直接存储器存取,是一种快速传送数据的机制. 工作原理 DMA是指外部设备不通过CPU而直接与系统 ...

  8. DMA : Timer Trigger Memory-to-memory mode,

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

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

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

随机推荐

  1. python导出数据到excel

    1,SMTP发送带excel附件的邮件: def sendMail(filename, addressee): """ :param content: 发送内容 :par ...

  2. HDU 1229 还是A+B(A+B陶冶情操)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1229 解题报告:A+B #include<cstdio> int main() { int ...

  3. Python人工智能之路 - 第一篇 : 你得会点儿Python基础

    Python 号称是最接近人工智能的语言,因为它的动态便捷性和灵活的三方扩展,成就了它在人工智能领域的丰碑 走进Python,靠近人工智能 一.编程语言Python的基础 之 "浅入浅出&q ...

  4. Docker01 CentOS配置Docker

    Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化.容器是完全使用沙箱机制,相互之间不会有任何 ...

  5. IL反编译的实用工具Ildasm.exe

    初识Ildasm.exe——IL反编译的实用工具    https://www.cnblogs.com/yangmingming/archive/2010/02/03/1662307.html   学 ...

  6. CEO、COO、CFO、CTO、CXO

    CEO:Chief Executive Officer 首席执行官——类似总经理.总裁,是企业的法人代表 COO:Chief Operating Officer 首席营运官——类似常务总经理 CFO: ...

  7. win7下iis中配置php.ini文件

    将php.ini-development配置文件重命名为php.ini配置文件即可. 接着做如下配置操作: 1.修改php.ini配置文件 打开php.ini配置文件,找到 12 ; On windo ...

  8. nginx + php + centos 6.3

    2014年2月7日 22:34:52 PHP 5.5.9 http://cn2.php.net/distributions/php-5.5.9.tar.bz2 nginx 1.5.10 http:// ...

  9. Chrome插件 postman的使用方法详解!最全面的教程

    一 简介 Postman 是一款功能超级强大的用于发送 HTTP 请求的 Chrome插件 .做web页面开发和测试的人员应该是无人不晓无人不用!其主要特点 特点: 创建 + 测试:创建和发送任何的H ...

  10. jdk8 lambda表达式总结

    Java8 lambda表达式10个示例   1. 实现Runnable线程案例 使用() -> {} 替代匿名类: //Before Java 8: new Thread(new Runnab ...