Hey community
I can't get FlexIO to work. I'm on imxrt1011 (eval board) and wanted to periodically read the FLEXIO pin 1. I use the code pasted below:
void init ()
{
static constexpr uint32_t PIN_NO = 1;
static constexpr uint32_t SHIFTER_NO = 0;
static constexpr uint32_t TIMER_NO = 0;
CLOCK_EnableClock (kCLOCK_Flexio1);
flexio_config_t fxioUserConfig{};
FLEXIO_GetDefaultConfig (&fxioUserConfig);
FLEXIO_Init (FLEXIO1, &fxioUserConfig);
flexio_shifter_config_t shifterConfig{};
shifterConfig.timerSelect = TIMER_NO; // Which timer controls the shifter.
shifterConfig.timerPolarity = kFLEXIO_ShifterTimerPolarityOnPositive;
shifterConfig.pinConfig = kFLEXIO_PinConfigOutputDisabled; // I guess this mean "input" in kinda indirect way.
shifterConfig.pinSelect = PIN_NO; // Pin to read.
shifterConfig.pinPolarity = kFLEXIO_PinActiveHigh; //
shifterConfig.shifterMode = kFLEXIO_ShifterModeReceive; // One of these 6 modes.
shifterConfig.parallelWidth = 0;
shifterConfig.inputSource = kFLEXIO_ShifterInputFromPin;
shifterConfig.shifterStop = kFLEXIO_ShifterStopBitDisable;
shifterConfig.shifterStart = kFLEXIO_ShifterStartBitDisabledLoadDataOnEnable;
FLEXIO_SetShifterConfig (FLEXIO1, SHIFTER_NO, &shifterConfig);
flexio_timer_config_t fxioTimerConfig{};
fxioTimerConfig.triggerSelect = FLEXIO_TIMER_TRIGGER_SEL_SHIFTnSTAT (1U);
fxioTimerConfig.triggerPolarity = kFLEXIO_TimerTriggerPolarityActiveHigh;
fxioTimerConfig.triggerSource = kFLEXIO_TimerTriggerSourceInternal;
fxioTimerConfig.pinConfig = kFLEXIO_PinConfigOutputDisabled;
fxioTimerConfig.pinSelect = 0; // ?
fxioTimerConfig.pinPolarity = kFLEXIO_PinActiveHigh;
fxioTimerConfig.timerMode = kFLEXIO_TimerModeSingle16Bit;
fxioTimerConfig.timerOutput = kFLEXIO_TimerOutputOneNotAffectedByReset;
fxioTimerConfig.timerDecrement = kFLEXIO_TimerDecSrcOnFlexIOClockShiftTimerOutput;
fxioTimerConfig.timerReset = kFLEXIO_TimerResetNever;
fxioTimerConfig.timerDisable = kFLEXIO_TimerDisableNever;
fxioTimerConfig.timerEnable = kFLEXIO_TimerEnabledAlways; // This probably makes trigger config irrelevant. Does it?
fxioTimerConfig.timerStop = kFLEXIO_TimerStopBitDisabled;
fxioTimerConfig.timerStart = kFLEXIO_TimerStartBitDisabled;
fxioTimerConfig.timerCompare = 0xff;
FLEXIO_SetTimerConfig (FLEXIO1, TIMER_NO, &fxioTimerConfig);
FLEXIO_ClearShifterErrorFlags (FLEXIO1, 0xff);
FLEXIO_ClearTimerStatusFlags (FLEXIO1, 0xff);
FLEXIO_Enable (FLEXIO1, true);
auto waitForShifterStatus = [] {
while (!(FLEXIO_GetShifterStatusFlags (FLEXIO1) & (1 << SHIFTER_NO))) {
};
};
waitForShifterStatus ();
auto prev = FLEXIO1->SHIFTBUF[SHIFTER_NO];
// uint32_t pinPrev = FLEXIO_ReadPinInput (FLEXIO1);
while (true) {
/*
* In 16-bit counter mode, the timer status flag is set when the
* 16-bit counter equals zero and decrements. Timer number is 0.
*/
while ((FLEXIO_GetTimerStatusFlags (FLEXIO1) & (1 << SHIFTER_NO)) == 0) {
}
/*
* For SMOD=Receive, the status flag is set when SHIFTBUF has been loaded with data from Shifter
* (SHIFTBUF is full), and the status flag is cleared when SHIFTBUF register is read.
*
* fxioTimerConfig.timerCompare has impact on how frequently this condition is asserted. So
* the timer seems to work.
*/
waitForShifterStatus ();
if (auto err = FLEXIO_GetShifterErrorFlags (FLEXIO1); (err & (1 << SHIFTER_NO)) != 0) {
asm ("bkpt");
}
auto curr = FLEXIO1->SHIFTBUF[SHIFTER_NO];
// GPIO_PortToggle (GPIO1, 1u << 19);
if (prev != curr) {
prev = curr;
GPIO_PortToggle (GPIO1, 1u << 19);
}
// uint32_t pinCurr = FLEXIO_ReadPinInput (FLEXIO1);
// if (pinPrev != pinCurr) {
// pinPrev = pinCurr;
// GPIO_PortToggle (GPIO1, 1u << 19);
// }
}
}
In mcuxpresso config tool I configured FlexIO clock to 3.75MHz my PIN config is like this:

I use the config tool, but the program file structure is custom (config tool files are compiled in however).
I feed square wave into FLEXIO pin 1 (pin D0 on the eval board) and also I've got an oscilloscope hooked up to GPIO19 (D10 on the evk). I expect to see a square signal (with frequency dependent on the input signal frequency and timer compare config) but it's not there.
I think that the timer works, because when I uncomment the FLEXIO_ReadPinInput part (at the bottom) I can see on GPIO19 that pinPrev != pinCurr is asserted periodically. Under debugger I verified that this is indeed bit no 1 that is begin toggled, so looks like the pin works.
However no matter what I do FLEXIO1->SHIFTBUF reads 0x80000000 when read for the first time, and then it reads only 0. What do I do wrong?