Timer-triggered memory-to-memory DMA transfer demonstrator
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的更多相关文章
- 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 ...
- Java (JVM) Memory Model – Memory Management in Java
原文地址:http://www.journaldev.com/2856/java-jvm-memory-model-memory-management-in-java Understanding JV ...
- 直接存储器存取(Direct Memory Access,DMA)详细讲解
一.理论理解部分. 1.直接存储器存取(DMA)用来提供在外设和存储器之间或者存储器和存储器之间的高速数据传输. 2.无须CPU干预,数据可以通过DMA快速移动,这就节省了CPU的资源来做其他操作. ...
- System memory,AGP memory和video memory【转】
system memory就是电脑的内存条上的,一般都很大.显卡不能访问 . video memory就是显示卡上的显存,一般是32,64,128M这样,速度最快,显卡可直接访问 .用来描述电脑上一 ...
- 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 ...
- DMA(Direct Memory Access)简介
什么是DMA(Direct Memory Access) DMA绕过CPU,在内存和外设之间开辟了一条 "隧道" ,直接控制内存与外设之间的操作,并完全由硬件控制. 这样数据传送不 ...
- (转)DMA(Direct Memory Access)
DMA(Direct Memory Access) DMA(Direct Memory Access)即直接存储器存取,是一种快速传送数据的机制. 工作原理 DMA是指外部设备不通过CPU而直接与系统 ...
- 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 ...
- PatentTips - Method to manage memory in a platform with virtual machines
BACKGROUND INFORMATION Various mechanisms exist for managing memory in a virtual machine environment ...
随机推荐
- iOS常用小功能
CHENYILONG Blog 常用小功能 技术博客http://www.cnblogs.com/ChenYilong/ 新浪微博http://weibo.com/luohanchenyilong ...
- composer "Failed to decode zlib stream"
dockerFile 中安装composer.... RUN curl -s -f -L -o /tmp/installer.php https://raw.githubusercontent.com ...
- 第5月第15天 php email
1. <?php require_once "Mail.php"; $from = "luckyeggs<fuping304@163.com>" ...
- 第6月第19天 lua动态链接库(luaopen_*函数的使用) skynet
1. 给这个测试库取名为dylib,它包含一个函数add.lua中这样使用: local dylib = require "dylib.test" local c = dyl ...
- pip2和pip3冲突问题解决方法
python使用pip安装模块时报错:unable to create process using ' '的解决方法: 参考:http://qoogle.cn/?id=39 1.删除C:\Python ...
- Coins in a Line I & II
Coins in a Line I There are n coins in a line. Two players take turns to take one or two coins from ...
- 促使团队紧密协作[高效能程序员的修炼-N1]
在Jeff看来,团队里最重要的事情,是人与人之间地协作和沟通!所有的问题,其实都是人的问题.“不管什么问题,那总是人的问题”-温伯格.即,让你和团队陷入困境的最快的方法,就是认为技术是决定性的因素,而 ...
- centos6.5环境通过shell脚本备份php的web及mysql数据库并做远程备份容灾
centos6.5环境通过shell脚本备份php的web及mysql数据库并做远程备份容灾 系统:centos6.5 1.创建脚本目录 mkdir -p /usr/local/sh/ 创建备份web ...
- docker 构建带健康检查的redis镜像
=============================================== 2018/11/5_第1次修改 ccb_warlock == ...
- Python_oldboy_自动化运维之路_socket编程(十)
链接:http://www.cnblogs.com/linhaifeng/articles/6129246.html 1.osi七层 引子: 须知一个完整的计算机系统是由硬件.操作系统.应用软件三者组 ...