Hi
I have attached the LPTMR module from the uTasker project as reference. Project configuration is LPTMR_CLOCK_EXTERNAL_32kHz, which is what you are going for I think. This is the part that will interest you:
POWER_UP(5, SIM_SCGC5_LPTIMER); // ensure that the timer can be accessed
LPTMR0_CSR = 0; // reset the timer and ensure no pending interrupts
LPTMR0_PSR = (LPTMR_PSR_PCS_ERCLK32K | LPTMR_PSR_PBYP); // clock from external 32kHz timer
That is all that should be needed.
It may be that you are confused by the option to clock from the OSCERCLK, which would be the option LPTMR_CLOCK_OSCERCLK.
This would then look like this:
POWER_UP(5, SIM_SCGC5_LPTIMER); // ensure that the timer can be accessed
LPTMR0_CSR = 0; // reset the timer and ensure no pending interrupts
OSC0_CR |= (OSC_CR_ERCLKEN | OSC_CR_EREFSTEN); // enable the external reference clock and keep it enabled in stop mode
LPTMR0_PSR = (LPTMR_PSR_PCS_OSC0ERCLK | (LPTMR_PRESCALE_VALUE << LPTMR_PSR_PRESCALE_SHIFT)); // program pre-scaler
To generate a periodic rate you then need to set LPTMR0_CMR with the period value
and enable with LPTMR0_CSR |= LPTMR_CSR_TEN;
I am not absolutely sure, but I have the feeling that you also want to run the processor directly from the 32kHz crystal. I have attached the MCG-Lite module too as reference. The code of interest is:
MCG_C2 = (MCG_C2_EREFS | MCG_C2_IRCS); // select oscillator as external clock source
OSC0_CR = (OSC_CR_ERCLKEN | OSC_CR_EREFSTEN); // enable the oscillator and allow it to continue oscillating in stop mode
SIM_CLKDIV1 = (((SYSTEM_CLOCK_DIVIDE - 1) << 28) | ((BUS_CLOCK_DIVIDE - 1) << 16)); // prepare bus clock divides
while ((MCG_S & MCG_S_OSCINIT0) == 0) {} // wait for the oscillator to start
MCG_C1 = MCG_C1_CLKS_EXTERN_CLK; // select external clock source
while ((MCG_S & MCG_S_CLKST_MASK) != MCG_S_CLKST_EXT) {} // wait until the source is selected
This is the default configuration if other clock sources are not specified. Note that debuggers tend to have difficulty working with such a slow clock rate; either run without the debugger or else try to set the debugger's clock speed as low as possible.
I understand that you are not interested in the uTasker project but it may still be worthwhile using it as reference since it allows you to set up things like this with one or two defines and test in its KL03 simulator so that you can then anaylse its operation and transfer the code to correct your configuration or the difficulties with your environment. You can probably save a huge amount of time in the long run.
To show you how simple and powerful it is in comparison to to your present solution I also attached a short video (1:25) showing how I can build a KL03 project according to your requirements and verify it in its KL03 simulator. All code can be analysed in the emulator, including interrupts and peripheral behavior in order to avoid lengthy trial and error on the HW.
Regards
Mark