Hi,
I'm trying to access the builtin LED(pin13) on Teensy4.1 through DMA by writing to the GPIO2_DR_TOGGLE register but it doesn't work. Code is included below, is there anything missing from the DMA setup?
#include <Arduino.h>
#include <imxrt.h>
const int gpio = LED_BUILTIN;
static volatile uint32_t mode = (0b1<<3);
static volatile uint32_t toggle = (0b1<<3);
void setup() {
while (!Serial) {
;// wait for Arduino Serial Monitor to be ready
}
CCM_CCGR0 |= CCM_CCGR0_GPIO2(CCM_CCGR_ON);//turn on gpio2 clock
IOMUXC_SW_MUX_CTL_PAD_GPIO_B0_03 = 0b101; //IOMuxing for pin 10 0b101 for alt5 GPIO, 0b011 for alt3 PCS[0]
CCM_CCGR5 |= CCM_CCGR5_DMA(CCM_CCGR_ON); // enables DMA clock if not already enabled
__enable_irq();
DMAMUX_CHCFG0 = ((0b1<<31)|(0b1<<30));
IMXRT_DMA_TCD[0].CITER = 1;
IMXRT_DMA_TCD[0].BITER = 1;
IMXRT_DMA_TCD[0].NBYTES = 4;
IMXRT_DMA_TCD[0].SADDR = &mode;
IMXRT_DMA_TCD[0].SOFF = 0; // Adjustment to the source address made after every minor loop iteration
IMXRT_DMA_TCD[0].SLAST = 0; // Source address adjustment after major loop completion
IMXRT_DMA_TCD[0].DADDR = &GPIO2_GDIR;
IMXRT_DMA_TCD[0].DOFF = 0;
IMXRT_DMA_TCD[0].DLASTSGA = 0;
IMXRT_DMA_TCD[0].ATTR = DMA_TCD_ATTR_DSIZE(2)|DMA_TCD_ATTR_SSIZE(2);//source data transfer size 32bit, d data transfer size 32bit
IMXRT_DMA_TCD[0].CSR =0;//set major channel linking to ch4
DMA_SERQ = 0;
DMA_SSRT = 1;
DMAMUX_CHCFG1 = ((0b1<<31)|(0b1<<30));
IMXRT_DMA_TCD[1].CITER = 1;
IMXRT_DMA_TCD[1].BITER = 1;
IMXRT_DMA_TCD[1].NBYTES = 4;
IMXRT_DMA_TCD[1].SADDR = &toggle;
IMXRT_DMA_TCD[1].SOFF = 0; // Adjustment to the source address made after every minor loop iteration
IMXRT_DMA_TCD[1].SLAST = 0; // Source address adjustment after major loop completion
IMXRT_DMA_TCD[1].DADDR = &GPIO2_DR_TOGGLE;
IMXRT_DMA_TCD[1].DOFF = 0;
IMXRT_DMA_TCD[1].DLASTSGA = 0;
IMXRT_DMA_TCD[1].ATTR = DMA_TCD_ATTR_DSIZE(2)|DMA_TCD_ATTR_SSIZE(2);//source data transfer size 32bit, d data transfer size 32bit
IMXRT_DMA_TCD[1].CSR =0;//set major channel linking to ch4
DMA_SERQ = 1;
Serial.println(GPIO2_GDIR,BIN);
}
void loop() {
delay(1000);
DMA_SSRT = 1;
Serial.print("Reading");
Serial.println(GPIO2_DR,BIN);
//GPIO7_DR_TOGGLE = (0b1<<3);// non dma access to pin13
}
I'm trying to access the builtin LED(pin13) on Teensy4.1 through DMA by writing to the GPIO2_DR_TOGGLE register but it doesn't work. Code is included below, is there anything missing from the DMA setup?
#include <Arduino.h>
#include <imxrt.h>
const int gpio = LED_BUILTIN;
static volatile uint32_t mode = (0b1<<3);
static volatile uint32_t toggle = (0b1<<3);
void setup() {
while (!Serial) {
;// wait for Arduino Serial Monitor to be ready
}
CCM_CCGR0 |= CCM_CCGR0_GPIO2(CCM_CCGR_ON);//turn on gpio2 clock
IOMUXC_SW_MUX_CTL_PAD_GPIO_B0_03 = 0b101; //IOMuxing for pin 10 0b101 for alt5 GPIO, 0b011 for alt3 PCS[0]
CCM_CCGR5 |= CCM_CCGR5_DMA(CCM_CCGR_ON); // enables DMA clock if not already enabled
__enable_irq();
DMAMUX_CHCFG0 = ((0b1<<31)|(0b1<<30));
IMXRT_DMA_TCD[0].CITER = 1;
IMXRT_DMA_TCD[0].BITER = 1;
IMXRT_DMA_TCD[0].NBYTES = 4;
IMXRT_DMA_TCD[0].SADDR = &mode;
IMXRT_DMA_TCD[0].SOFF = 0; // Adjustment to the source address made after every minor loop iteration
IMXRT_DMA_TCD[0].SLAST = 0; // Source address adjustment after major loop completion
IMXRT_DMA_TCD[0].DADDR = &GPIO2_GDIR;
IMXRT_DMA_TCD[0].DOFF = 0;
IMXRT_DMA_TCD[0].DLASTSGA = 0;
IMXRT_DMA_TCD[0].ATTR = DMA_TCD_ATTR_DSIZE(2)|DMA_TCD_ATTR_SSIZE(2);//source data transfer size 32bit, d data transfer size 32bit
IMXRT_DMA_TCD[0].CSR =0;//set major channel linking to ch4
DMA_SERQ = 0;
DMA_SSRT = 1;
DMAMUX_CHCFG1 = ((0b1<<31)|(0b1<<30));
IMXRT_DMA_TCD[1].CITER = 1;
IMXRT_DMA_TCD[1].BITER = 1;
IMXRT_DMA_TCD[1].NBYTES = 4;
IMXRT_DMA_TCD[1].SADDR = &toggle;
IMXRT_DMA_TCD[1].SOFF = 0; // Adjustment to the source address made after every minor loop iteration
IMXRT_DMA_TCD[1].SLAST = 0; // Source address adjustment after major loop completion
IMXRT_DMA_TCD[1].DADDR = &GPIO2_DR_TOGGLE;
IMXRT_DMA_TCD[1].DOFF = 0;
IMXRT_DMA_TCD[1].DLASTSGA = 0;
IMXRT_DMA_TCD[1].ATTR = DMA_TCD_ATTR_DSIZE(2)|DMA_TCD_ATTR_SSIZE(2);//source data transfer size 32bit, d data transfer size 32bit
IMXRT_DMA_TCD[1].CSR =0;//set major channel linking to ch4
DMA_SERQ = 1;
Serial.println(GPIO2_GDIR,BIN);
}
void loop() {
delay(1000);
DMA_SSRT = 1;
Serial.print("Reading");
Serial.println(GPIO2_DR,BIN);
//GPIO7_DR_TOGGLE = (0b1<<3);// non dma access to pin13
}