Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: XBAR setup on T4

  1. #1
    Junior Member
    Join Date
    Jan 2019

    XBAR setup on T4

    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.

    #include "DMAChannel.h"
    DMAChannel testDMA;
    uint32_t testdest;
    void setup() {
    analogWriteFrequency(3,20);  //Pin 3 =  FlexPWM4_2_B    // EMC_05  Slow 20Hz, about 50% duty
    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.triggerAtHardwareEvent(30);  //30 = XBARA1
    void loop() {
    Serial.print("gpio: ");
    Serial.print(" testdest: ");

  2. #2
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    I can't answer your question, but NXP SDK had various XBAR examples. I have a T4 XBAR example with PIT, see
    you might also do a "Search thread" for XBAR on the huge T4 beta testing thread, mjs513 had a sketch using XBAR with quadrature encoder

    i never could get XBAR to work with PIT+ADC_ETC+DMA
    Last edited by manitou; 08-22-2019 at 11:18 PM.

  3. #3
    Senior Member
    Join Date
    Mar 2015
    Just been doing some work myself last night with XBARA1. I also ran into trouble, but did manage eventually to get an analog comparator functioning very well. Might give you some ideas? You have to read that manual VERY carefully to fully understand the terminology.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts