Hi
You can get a reference from the open source uTasker project at https://github.com/uTasker/uTasker-Kinetis
FlexTimers are independent of the OS, but the project also supports a FreeRTOS configuration if needed.
This is the code to generate a 50% MSR output on PTC3 (FlexTimer 0, Channel 2) on the K21D50, which is equivalent to your K12.
PWM_INTERRUPT_SETUP pwm_setup;
pwm_setup.int_type = PWM_INTERRUPT;
pwm_setup.pwm_mode = (PWM_SYS_CLK | PWM_PRESCALER_16 | PWM_EDGE_ALIGNED); // clock PWM timer from the system clock with /16 pre-scaler
pwm_setup.int_handler = 0; // no user interrupt call-back on PWM cycle
pwm_setup.pwm_reference = (_TIMER_0 | 2); // timer module 0, channel 2
pwm_setup.pwm_frequency = PWM_FREQUENCY(20000, 16); // generate 20000Hz on PWM output
pwm_setup.pwm_value = _PWM_PERCENT(50, pwm_setup.pwm_frequency); // 50% PWM (high/low)
fnConfigureInterrupt((void *)&pwm_setup); // enter configuration for PWM test
Note that the uTasker FlexTimer interface automatically does all background work like ensuring the used peripherals and ports are clocked and the pin correctly multiplexed to its required peripheral function so that is all that is needed (also supporting interrupt and DMA if needed - here I have set the interrupt handler to 0, which avoids interrupts being generated but a call-back can be entered if a 20kHz interrupt were required).
When using other code you will need to carefully handled these other requirements since they are typically needed to be performed separately.
The uTasker project includes a Kinetis simulator that will emulate all peripherals and make testing and verification simple (without needing HW) and below is a screen shot of it running, with the mouse hovered over PTC3 so that it displays is possible functions and programmed function, as well as showing the signal that the FlexTimer is generating on this particular output - confirming that its frequency is accurate and the 50% MSR was achieved fairly well (with a /16 prescaler).
Regards
Mark
