XBAR setup on T4

Status
Not open for further replies.
Hi all. I'm really excited about using the T4 in a big upcoming project, but am getting off to a rocky start. The XBAR can route PWM and/or GPIO into DMA triggers, which is exactly what I need. Unfortunately, I haven't been able to make a DMA transfer happen based on PWM output. The reason that I want PWM triggering (instead of PIT), is because I'm going to sample GPIO, and I want this sampling time to be very tightly linked to an external falling or rising edge. In the future, I may want to sample based on an incoming edge.


Does anyone see anything wrong with this code? If you uncomment the DMA manual trigger, testdest will be loaded with the state of gpio4 each time the loop runs. With it commented, testdest is 0 because the dma channel never triggers. XBARA1_CTRL0 indicates that an edge was never detected. Perhaps this is because the PWM module only outputs short pulses that are too short for edge detection to work if both modules are running at 150MHz. I've also tried to setup XBAR with a physical GPIO as input via IOMUX, but had the same problem (no edge detected). Any help is much appreciated -- the internet has almost no example XBAR code anywhere I can find. I plan to make my whole project open source as soon as I get the first bits working. It's a raster scan generator and realtime image capture unit for my electron microscope.


Code:
#include "DMAChannel.h"

DMAChannel testDMA;
uint32_t testdest;

void setup() {
analogWriteResolution(16);

analogWriteFrequency(3,20);  //Pin 3 =  FlexPWM4_2_B    // EMC_05  Slow 20Hz, about 50% duty
analogWrite(3,30000);

FLEXPWM4_SM2TCTRL |= (1<<15) | (1<<14)  | (1<<5) | (1<<4) | (1<<3) | (1<<2) | (1<<1) | (1<<0);  // Set PWM4 to output triggers on both A and B, and all six VAL registers
FLEXPWM4_MCTRL |= FLEXPWM_MCTRL_LDOK((uint16_t)1<<2);  //Reload PWM after register changes (doesn't seem to affect)

CCM_CCGR2 |= CCM_CCGR2_XBAR1(CCM_CCGR_ON);  // Turn on clock source for XBARA1.  150MHz?
XBARA1_SEL0 =  54;  //54 = FLEXPWM4_PWM2_OUT_TRIG0 and TRIG1
XBARA1_CTRL0 =  (1<<3) | (1<<2) | 1;  //Rising and falling edge detection, no interrupt, with DMA trigger

testDMA.source((volatile const uint32_t &) GPIO4_PSR);
testDMA.destination(testdest);
testDMA.triggerAtHardwareEvent(30);  //30 = XBARA1
testDMA.transferSize(4);
testDMA.transferCount(1);
testDMA.enable();

}

void loop() {
//testDMA.triggerManual();
Serial.print("gpio: ");
Serial.print(GPIO4_PSR);
Serial.print(" testdest: ");
Serial.println(testdest);

Serial.println(XBARA1_CTRL0);
delay(100);
}
 
Last edited:
Status
Not open for further replies.
Back
Top