How to reset FlexIO Timer on Pin rising edge?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to reset FlexIO Timer on Pin rising edge?

Jump to solution
1,797 Views
mitterha
Senior Contributor I

Hello,

I have two FlexIO timer running on RT1020. FlexIO timer 0 toggles the output every 0.5 seconds and timer 1 is triggered by timer 0. This setup works fine. Now I have to reset timer 0 on a rising edge of an Chip IO. I am using FlexIO PIN 6 (GPIO_AD_B1_09 so it is available at the Arduino Header). I can see the correct level of FlexIO PIN 6 in the FLEXIO1->PIN register but the reset does not work.

My configuration is:

static void flexio_sysbus_timer_init(FLEXIO_Type* base, uint32_t freq_Hz)
{ 
    flexio_timer_config_t fxioTimer0Config, fxioTimer1Config;
    flexio_config_t fxioUserConfig;
    uint32_t timer0Mask;
    uint32_t timer1Mask;
    
    timer0Mask = 1 << 0;
    timer1Mask = 1 << 1;

    /* FlexIO clocks are set by the clocks tool in clock_config.c */
    
    /* Configure FlexIO module */
    FLEXIO_GetDefaultConfig(&fxioUserConfig);
    FLEXIO_Init(base, &fxioUserConfig);
    
    /* Configure FlexIO timer 0 */
    fxioTimer0Config.triggerSelect   = FLEXIO_TIMER_TRIGGER_SEL_PININPUT(6);
    fxioTimer0Config.triggerSource   = kFLEXIO_TimerTriggerSourceInternal;
    fxioTimer0Config.triggerPolarity = kFLEXIO_TimerTriggerPolarityActiveLow;
    fxioTimer0Config.pinConfig       = kFLEXIO_PinConfigOutputDisabled;
    fxioTimer0Config.pinPolarity     = kFLEXIO_PinActiveLow;
    fxioTimer0Config.pinSelect       = 6;
    fxioTimer0Config.timerMode       = kFLEXIO_TimerModeSingle16Bit ;
    fxioTimer0Config.timerOutput     = kFLEXIO_TimerOutputZeroNotAffectedByReset;
    fxioTimer0Config.timerDecrement  = kFLEXIO_TimerDecSrcOnFlexIOClockShiftTimerOutput;
    fxioTimer0Config.timerDisable    = kFLEXIO_TimerDisableNever;
    fxioTimer0Config.timerEnable     = kFLEXIO_TimerEnabledAlways;
    fxioTimer0Config.timerReset      = kFLEXIO_TimerResetOnTimerPinRisingEdge;
    fxioTimer0Config.timerStart      = kFLEXIO_TimerStartBitDisabled;
    fxioTimer0Config.timerStop       = kFLEXIO_TimerStopBitDisabled;
    fxioTimer0Config.timerCompare    = freq_Hz/2; // 0.5 s
    
    /* Configure FlexIO timer 1 */
    fxioTimer1Config.triggerSelect   = FLEXIO_TIMER_TRIGGER_SEL_TIMn(0U);
    fxioTimer1Config.triggerSource   = kFLEXIO_TimerTriggerSourceInternal;
    fxioTimer1Config.triggerPolarity = kFLEXIO_TimerTriggerPolarityActiveLow;
    fxioTimer1Config.pinConfig       = kFLEXIO_PinConfigOutput;
    fxioTimer1Config.pinPolarity     = kFLEXIO_PinActiveHigh;
    fxioTimer1Config.pinSelect       = 5;
    fxioTimer1Config.timerMode       = kFLEXIO_TimerModeSingle16Bit;
    fxioTimer1Config.timerOutput     = kFLEXIO_TimerOutputOneNotAffectedByReset;
    fxioTimer1Config.timerDecrement  = kFLEXIO_TimerDecSrcOnTriggerInputShiftTimerOutput;
    fxioTimer1Config.timerDisable    = kFLEXIO_TimerDisableNever;
    fxioTimer1Config.timerEnable     = kFLEXIO_TimerEnabledAlways;
    fxioTimer1Config.timerReset      = kFLEXIO_TimerResetNever;
    fxioTimer1Config.timerStart      = kFLEXIO_TimerStartBitDisabled;
    fxioTimer1Config.timerStop       = kFLEXIO_TimerStopBitDisabled;
    fxioTimer1Config.timerCompare    = 3;

    // Set configurations
    FLEXIO_SetTimerConfig(base, 0, &fxioTimer0Config);
    FLEXIO_SetTimerConfig(base, 1, &fxioTimer1Config);
    
    // Enable FlexIO Timer 1 interrupt
    FLEXIO_ClearTimerStatusFlags(base, (timer0Mask | timer1Mask));
    FLEXIO_EnableTimerStatusInterrupts(base, timer1Mask);  
}

The pin_mux.c settings for the two timer pins are:

IOMUXC_SetPinMux(
      IOMUXC_GPIO_AD_B1_09_FLEXIO1_FLEXIO06,  /* GPIO_AD_B1_09 is configured as FLEXIO1_FLEXIO06 */
      0U);                                    /* Software Input On Field: Input Path is determined by functionality */
  IOMUXC_SetPinMux(
      IOMUXC_GPIO_AD_B1_10_FLEXIO1_FLEXIO05,  /* GPIO_AD_B1_10 is configured as FLEXIO1_FLEXIO05 */
      0U);                                    /* Software Input On Field: Input Path is determined by functionality */
 
  IOMUXC_SetPinConfig(
      IOMUXC_GPIO_AD_B1_09_FLEXIO1_FLEXIO06,  /* GPIO_AD_B1_09 PAD functional properties : */
      0x70B0U);                               /* Slew Rate Field: Slow Slew Rate
                                                 Drive Strength Field: R0/6
                                                 Speed Field: medium(100MHz)
                                                 Open Drain Enable Field: Open Drain Disabled
                                                 Pull / Keep Enable Field: Pull/Keeper Enabled
                                                 Pull / Keep Select Field: Pull
                                                 Pull Up / Down Config. Field: 47K Ohm Pull Up
                                                 Hyst. Enable Field: Hysteresis Disabled */

I also tried to change the settings to external trigger 0 with XBAR and the same Chip IO Pin but I get the same result. The timer is not reset when I pull FlexIO Pin 06 to GND and release it.

Any suggestions what I am configuring wrong? I attached the project to this post. I'm using the debug configuration.

Kind regards,

Stefan

Labels (1)
Tags (3)
0 Kudos
1 Solution
1,572 Views
mitterha
Senior Contributor I

Hello Felipe,

okay good to know that the documentation is incorrect.

What do you think about the timing problem?

I finally found the problem: the register FLEXIO1->TIMCFG[0] does not get set with the specified value kFLEXIO_TimerResetOnTimerPinRisingEdge instead it just keeps the reset value.

I was able to follow the problem to the FLEXIO driver method FLEXIO_Init in fsl_flexio.c Line number 93. If I place a delay of about 4us after the CLOCK_EnableClock function everything works as expected for the first download and start. If I debug with IAR EWARM and just click the "reset" button while the program is running the 4us are too short. Without the delay (or if the delay is too short) the FLEXIO register is not set correctly.

Here is the working code:

void FLEXIO_Init(FLEXIO_Type *base, const flexio_config_t *userConfig)
{
    uint32_t ctrlReg = 0;

#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
    CLOCK_EnableClock(s_flexioClocks[FLEXIO_GetInstance(base)]);
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
SDK_DelayAtLeastUs(4); // Place this here and the register FLEXIO1->TIMCFG[0] gets set correctly, without the delay the register is in reset state.
    FLEXIO_Reset(base);

    ctrlReg = base->CTRL;
    ctrlReg &= ~(FLEXIO_CTRL_DOZEN_MASK | FLEXIO_CTRL_DBGE_MASK | FLEXIO_CTRL_FASTACC_MASK | FLEXIO_CTRL_FLEXEN_MASK);
    ctrlReg |= (FLEXIO_CTRL_DBGE(userConfig->enableInDebug) | FLEXIO_CTRL_FASTACC(userConfig->enableFastAccess) |
                FLEXIO_CTRL_FLEXEN(userConfig->enableFlexio));
    if (!userConfig->enableInDoze)
    {
        ctrlReg |= FLEXIO_CTRL_DOZEN_MASK;
    }

    base->CTRL = ctrlReg;
}

 

Is there a way to check if the FlexIO clock is enabled correctly or is the delay the only workaround here?

 

I have attached my new test program for the RT1020. If you open a terminal with default SDK settings (115200 baud) it will output the TIMRST value of TIMCFG0 register after initializing the FlexIO peripheral. If everything is correct it should output the value 4. If you comment out line 95 in fsl_flexio.c the value will be 0 which is incorrect.

Kind regards,

Stefan

View solution in original post

0 Kudos
9 Replies
1,572 Views
FelipeGarcia
NXP Employee
NXP Employee

Hi Stefan,

 

Have you tried using different pin? I see you you are configuring same pin for trigger and PINSEL.

 

Best regards,

Felipe

0 Kudos
1,572 Views
mitterha
Senior Contributor I

Hello Felipe,

I changed the Trigger now to Trigger 1 with the same result that the timer does not reset.

Have you tried using different pin? I see you you are configuring same pin for trigger and PINSEL.

I was using the setting

fxioTimer0Config.pinConfig       = kFLEXIO_PinConfigOutputDisabled;
so the PinSelect only tells the FlexIO Module to use Pin 6 as input because the Reference Manual states

"Timer Pin Select
Selects which pin is used by the Timer input or output. PINSEL=i will select the FXIO_Di pin. For pins
configured as an output (PINCFG=11), this field will take effect when the register is written."

is that correct?

Is it possible to use a FlexIO Pin (0-31) as input trigger and still output on a different pin?

Kind regards,

Stefan

0 Kudos
1,572 Views
FelipeGarcia
NXP Employee
NXP Employee

Hi Stefan,

 

I recommend you to check the flexio_uart_interrupt_transfer from the SDK. This example enables reset on timer pin rising edge on the receiver so it could be useful as reference.

 

Best regards,

Felipe

0 Kudos
1,572 Views
mitterha
Senior Contributor I

Hello Felipe,

I finally found the problem: the register FLEXIO1->TIMCFG[0] does not get set with the specified value kFLEXIO_TimerResetOnTimerPinRisingEdge instead it just keeps the reset value.

I was able to follow the problem to the FLEXIO driver method FLEXIO_Init in fsl_flexio.c Line number 93. If I place a delay of about 4us after the CLOCK_EnableClock function everything works as expected for the first download and start. If I debug with IAR EWARM and just click the "reset" button while the program is running the 4us are too short. Without the delay (or if the delay is too short) the FLEXIO register is not set correctly.

Here is the working code:

void FLEXIO_Init(FLEXIO_Type *base, const flexio_config_t *userConfig)
{
    uint32_t ctrlReg = 0;

#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
    CLOCK_EnableClock(s_flexioClocks[FLEXIO_GetInstance(base)]);
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
SDK_DelayAtLeastUs(4); // Place this here and the register FLEXIO1->TIMCFG[0] gets set correctly, without the delay the register is in reset state.
    FLEXIO_Reset(base);

    ctrlReg = base->CTRL;
    ctrlReg &= ~(FLEXIO_CTRL_DOZEN_MASK | FLEXIO_CTRL_DBGE_MASK | FLEXIO_CTRL_FASTACC_MASK | FLEXIO_CTRL_FLEXEN_MASK);
    ctrlReg |= (FLEXIO_CTRL_DBGE(userConfig->enableInDebug) | FLEXIO_CTRL_FASTACC(userConfig->enableFastAccess) |
                FLEXIO_CTRL_FLEXEN(userConfig->enableFlexio));
    if (!userConfig->enableInDoze)
    {
        ctrlReg |= FLEXIO_CTRL_DOZEN_MASK;
    }

    base->CTRL = ctrlReg;
}

Is there a way to check if the FlexIO clock is enabled correctly or is the delay the only workaround here?

I have attached my new test program for the RT1020. If you open a terminal with default SDK settings (115200 baud) it will output the TIMRST value of TIMCFG0 register after initializing the FlexIO peripheral. If everything is correct it should output the value 4. If you comment out line 95 in fsl_flexio.c the value will be 0 which is incorrect.

*************************************************************

After looking at the flexio_uart_interrupt_transfer example I and getting my code running I think there is something wrong with the example or the reference manual. Comparing the RT1020 Reference Manual (FlexIO Timer Control N Register, 44.3.1.20.3)

Trigger Select
• When TRGsrc=0, the valid values for N will depend on TRIGGER field in FLEXIO_PARAM
register.
When TRGsrc=0 the trigger selection is configured as follows:
• N - External trigger N input
When TRGsrc=1 the internal trigger can be configured to select an input pin as follows:
• 2*N - Pin N input

(TRIGGER field in FLEXIO_PARAM register is 0x02. The valid values for N in case of TRGsrc=0 are therefore 0 and 1 correct?)

to the provided example code timer 1 for rx initialization (fsl_flexio_uart.c)

timerConfig.triggerSelect   = FLEXIO_TIMER_TRIGGER_SEL_PININPUT(base->RxPinIndex);
timerConfig.triggerSource   = kFLEXIO_TimerTriggerSourceExternal;

The example code sets triggerSource to 0 but triggerSelect to 2 * PIN-Number which is incorrect if we trust the reference manual. If the reference manual is correct triggerSource has to be set to 1 (kFLEXIO_TimerTriggerSourceInternal) if you use the PIN inputs and not a TRIGGER input.

Is there a mistake in the example code or am I missing something?

Kind regards,

Stefan

0 Kudos
1,572 Views
FelipeGarcia
NXP Employee
NXP Employee

Hello Stefan,

 

This seems to be an error in documentation, SDK example is correct. I was able to run the demo without any issues. Thanks for bringing this to our attention, we will fix that in future revisions.

 

Best regards,

Felipe

0 Kudos
1,573 Views
mitterha
Senior Contributor I

Hello Felipe,

okay good to know that the documentation is incorrect.

What do you think about the timing problem?

I finally found the problem: the register FLEXIO1->TIMCFG[0] does not get set with the specified value kFLEXIO_TimerResetOnTimerPinRisingEdge instead it just keeps the reset value.

I was able to follow the problem to the FLEXIO driver method FLEXIO_Init in fsl_flexio.c Line number 93. If I place a delay of about 4us after the CLOCK_EnableClock function everything works as expected for the first download and start. If I debug with IAR EWARM and just click the "reset" button while the program is running the 4us are too short. Without the delay (or if the delay is too short) the FLEXIO register is not set correctly.

Here is the working code:

void FLEXIO_Init(FLEXIO_Type *base, const flexio_config_t *userConfig)
{
    uint32_t ctrlReg = 0;

#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
    CLOCK_EnableClock(s_flexioClocks[FLEXIO_GetInstance(base)]);
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
SDK_DelayAtLeastUs(4); // Place this here and the register FLEXIO1->TIMCFG[0] gets set correctly, without the delay the register is in reset state.
    FLEXIO_Reset(base);

    ctrlReg = base->CTRL;
    ctrlReg &= ~(FLEXIO_CTRL_DOZEN_MASK | FLEXIO_CTRL_DBGE_MASK | FLEXIO_CTRL_FASTACC_MASK | FLEXIO_CTRL_FLEXEN_MASK);
    ctrlReg |= (FLEXIO_CTRL_DBGE(userConfig->enableInDebug) | FLEXIO_CTRL_FASTACC(userConfig->enableFastAccess) |
                FLEXIO_CTRL_FLEXEN(userConfig->enableFlexio));
    if (!userConfig->enableInDoze)
    {
        ctrlReg |= FLEXIO_CTRL_DOZEN_MASK;
    }

    base->CTRL = ctrlReg;
}

 

Is there a way to check if the FlexIO clock is enabled correctly or is the delay the only workaround here?

 

I have attached my new test program for the RT1020. If you open a terminal with default SDK settings (115200 baud) it will output the TIMRST value of TIMCFG0 register after initializing the FlexIO peripheral. If everything is correct it should output the value 4. If you comment out line 95 in fsl_flexio.c the value will be 0 which is incorrect.

Kind regards,

Stefan

0 Kudos
1,572 Views
FelipeGarcia
NXP Employee
NXP Employee

Hi Stefan,

 

If the peripheral clock needs more time setup then from my perspective your workaround is correct.

 

Best regards,

Felipe

0 Kudos
1,572 Views
mitterha
Senior Contributor I

Hi Felipe,

is there any flag or another way which tells me that everything is done and I can set up my timers?

Will it get included in the next driver version?

Kind regards,

Stefan

0 Kudos
1,572 Views
FelipeGarcia
NXP Employee
NXP Employee

Hello Stefan,

 

No, unfortunately there is no flag that could tell you that the module has been setup correctly and there is no plan so far to include it in the next revision.

 

Sorry for any inconvenience.

 

Best regards,

Felipe

0 Kudos