Reputation: 15
I am trying to copy array using DMA MEM2MEM mode in STM32F103C8
But when i run this below code, the dest array still remains empty, no interrupt event fired
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
Upvotes: 0
Views: 1359
Reputation: 2602
I'm unable to detect the problem in your code, but I created a minimal example on Blue Pill board. I checked the values in dest
array in a debug session. 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) {
}
}
Upvotes: 1