Hello,
I can't seem to get a simple DMA transfer to work. Attached is the code I am trying to make work. I am running on a Teensy 4.1.
Thanks for any help I can get.
------
#include <Arduino.h>
#include <imxrt.h>
#include <DMAChannel.h>
DMAChannel dma;
DMAMEM uint32_t src[4] = { 10, 20, 30, 40 };
DMAMEM uint32_t dst[4];
volatile bool dmaDone = false;
void dmaISR() {
dma.clearInterrupt();
dmaDone = true;
Serial.println("
DMA ISR fired!");
}
void setup() {
Serial.begin(115200);
while (!Serial);
dma.begin(true); // Force allocation
Serial.print("DMA channel assigned: ");
Serial.println(dma.channel);
dma.sourceBuffer(src, sizeof(src));
dma.destinationBuffer(dst, sizeof(dst));
dma.disableOnCompletion();
dma.interruptAtCompletion();
attachInterruptVector((IRQ_NUMBER_t)(IRQ_DMA_CH0 + dma.channel), dmaISR);
NVIC_ENABLE_IRQ((IRQ_NUMBER_t)(IRQ_DMA_CH0 + dma.channel));
dma.enable();
Serial.println("Triggering DMA manually...");
dma.triggerManual();
}
void loop() {
if (dmaDone) {
dmaDone = false;
Serial.println("
DMA transfer complete. Verifying data...");
for (int i = 0; i < 4; i++) {
Serial.print("dst[");
Serial.print(i);
Serial.print("] = ");
Serial.println(dst);
}
}
}
I can't seem to get a simple DMA transfer to work. Attached is the code I am trying to make work. I am running on a Teensy 4.1.
Thanks for any help I can get.
------
#include <Arduino.h>
#include <imxrt.h>
#include <DMAChannel.h>
DMAChannel dma;
DMAMEM uint32_t src[4] = { 10, 20, 30, 40 };
DMAMEM uint32_t dst[4];
volatile bool dmaDone = false;
void dmaISR() {
dma.clearInterrupt();
dmaDone = true;
Serial.println("
}
void setup() {
Serial.begin(115200);
while (!Serial);
dma.begin(true); // Force allocation
Serial.print("DMA channel assigned: ");
Serial.println(dma.channel);
dma.sourceBuffer(src, sizeof(src));
dma.destinationBuffer(dst, sizeof(dst));
dma.disableOnCompletion();
dma.interruptAtCompletion();
attachInterruptVector((IRQ_NUMBER_t)(IRQ_DMA_CH0 + dma.channel), dmaISR);
NVIC_ENABLE_IRQ((IRQ_NUMBER_t)(IRQ_DMA_CH0 + dma.channel));
dma.enable();
Serial.println("Triggering DMA manually...");
dma.triggerManual();
}
void loop() {
if (dmaDone) {
dmaDone = false;
Serial.println("
for (int i = 0; i < 4; i++) {
Serial.print("dst[");
Serial.print(i);
Serial.print("] = ");
Serial.println(dst);
}
}
}