简体   繁体   English

DMA 存储器到存储器模式在 STM32F103C8 中不起作用

[英]DMA Memory to Memory mode is not working in STM32F103C8

I am trying to copy array using DMA MEM2MEM mode in STM32F103C8我正在尝试在 STM32F103C8 中使用 DMA MEM2MEM 模式复制数组

But when i run this below code, the dest array still remains empty, no interrupt event fired但是当我在下面的代码中运行这个时,dest 数组仍然是空的,没有触发中断事件

Please give me solutions or notice me if i missed any config, thanks very much如果我错过了任何配置,请给我解决方案或通知我,非常感谢

My code:我的代码:

uint32_t source[MEMSIZE];
uint32_t dest[MEMSIZE];

for (i = 0; i < MEMSIZE; i++) {
    source[i] = i;
}

//Reset CCR and CNDTR register 
DMA1_Channel1->CCR &= ~0x7FFF;
DMA1_Channel1->CNDTR &= ~0xFFFF;
/*
* DMA configure:
* MEM 2 MEM: Enabled
* Priority: Medium
* Memory size: 32 bit
* Peripheral size: 32bit
* Memory increment: ON
* Peripheral Increment: ON
* Circular: OFF
* Direction: Copy from peripheral
* Transfer error IR: OFF
* Haft Transferred IR: OFF
* Transfer complete IR: ON
* Channel Enable: OFF
*/
DMA1_Channel1->CCR |= 0x00005AC2;
// Setting number of data
DMA1_Channel1->CNDTR |= MEMSIZE;
// Setting Peripheral address
DMA1_Channel1->CPAR = (uint32_t)source;
// Setting memory address
DMA1_Channel1->CMAR = (uint32_t)dest;
// NVIC setup
NVIC_SetPriority(DMA1_Channel1_IRQn, 0);
NVIC_EnableIRQ(DMA1_Channel1_IRQn);
// Enable DMA channel
DMA1_Channel1->CCR |= 0x00000001;

Update: I tried using GPIO ODR instead of array address for memory, and thats works perfectly更新:我尝试使用 GPIO ODR 而不是内存的数组地址,效果很好

I'm unable to detect the problem in your code, but I created a minimal example on Blue Pill board.我无法检测到您代码中的问题,但我在Blue Pill板上创建了一个最小示例。 I checked the values in dest array in a debug session.我在调试会话中检查了dest数组中的值。 The code seems to work as expected.该代码似乎按预期工作。

#include "stm32f1xx.h"

#define MEMSIZE 32

uint32_t source[MEMSIZE];
uint32_t dest[MEMSIZE];

int main(void) {

    RCC->AHBENR |= RCC_AHBENR_DMA1EN; // Enable DMA clock

    // Initialize the test data
    for (int i = 0; i < MEMSIZE; ++i) {
        source[i] = i;
    }

    DMA1_Channel1->CCR |= DMA_CCR_MEM2MEM // Memory to memory mode
            | (0b01 << DMA_CCR_PL_Pos) // Medium priority
            | (0b10 << DMA_CCR_MSIZE_Pos) // Memory size: 32-bits
            | (0b10 << DMA_CCR_PSIZE_Pos) // Peripheral size: 32-bits
            | DMA_CCR_MINC // Memory increment is enabled
            | DMA_CCR_PINC; // Peripheral increment is enabled
    DMA1_Channel1->CPAR = (uint32_t) source;
    DMA1_Channel1->CMAR = (uint32_t) dest;
    DMA1_Channel1->CNDTR = MEMSIZE;

    DMA1_Channel1->CCR |= DMA_CCR_EN; // Start DMA transfer

    while (1) {

    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM