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. [机器学习笔记]主成分分析PCA简介及其python实现

    主成分分析(principal component analysis)是一种常见的数据降维方法,其目的是在“信息”损失较小的前提下,将高维的数据转换到低维,从而减小计算量. PCA的本质就是找一些投影 ...

  2. RaspberryPi.1.开机与远程桌面

    raspberry  3b+ ------------------------------------------------------------------------------- 写系统 有 ...

  3. python3光学字符识别模块tesserocr与pytesseract

    OCR,即Optical Character Recognition,光学字符识别,是指通过扫描字符,然后通过其形状将其翻译成电子文本的过程,对应图形验证码来说,它们都是一些不规则的字符,这些字符是由 ...

  4. rtop:一个通过 SSH 监控远程主机的交互式工具【转】

    编译自: http://www.tecmint.com/rtop-monitor-remote-linux-server-over-ssh/ rtop[1] 是一个基于 SSH 的直接的交互式远程系统 ...

  5. C#使用WSDL服务总结

    站在巨人肩上才能看的更远! 1.C# 利用VS自带的WSDL工具生成WebService服务类 2.C#使用WSDL服务

  6. C# XML 文档注释

    原文链接:http://www.shinater.com/DocsBuilder/help.html <summary>description</summary> 描述类型或类 ...

  7. _findfirst和_findnext

    1.首先是_finddata结构体,用于存储文件信息的结构体. 2._findfirst函数:long _findfirst(const char *, struct _finddata_t *); ...

  8. Cover Points

    CF#511 div2 B 现场掉分赛(翻车)...qwq 题目大意: 给定n个点的左边,你需要求出一个腰长最短的等腰直角三角形(顶点为坐标轴原点),是的所有点都在这个等腰直角三角形的内部或者边上. ...

  9. Hive知识汇总

    两种Hive表 hive存储:数据+元数据 托管表(内部表) 创建表: hive> create table test2(id int,name String,tel String) > ...

  10. 【Java】 大话数据结构(18) 排序算法(5) (直接插入排序)

    本文根据<大话数据结构>一书,实现了Java版的直接插入排序. 更多:数据结构与算法合集 基本概念 直接插入排序思路:类似扑克牌的排序过程,从左到右依次遍历,如果遇到一个数小于前一个数,则 ...