Neil
The LPO 1kHz has nothing to do with the input clock - it can be used as RTC clock source by selecting it with
SIM_SOPT1 = ((SIM_SOPT1 & ~SIM_SOPT1_OSC32KSEL_MASK) | SIM_SOPT1_OSC32KSEL_LPO_1kHz);
The RTC actually runs 1/32.6 times slower than normal but this can be compensated for.
You should look at the TWR-KL25Z48M as reference since it uses a low power 32kHz oscillator.
http://www.utasker.com/kinetis/TWR-KL25Z48M.html
For low power see also : http://www.utasker.com/kinetis/LLWU.html
To do what you want in the uTasker framework you just need to select your board and the defines:
#define SUPPORT_RTC // enables RTC and time keeping (see http://www.utasker.com/docs/uTasker/uTasker_Time.pdf)
#define RTC_USES_RTC_CLKIN // to use the RTC_IN pin
#define SUPPORT_LOW_POWER // enable low power support
#define SUPPORT_LLWU // enable LLWU
In code, enable a wakeup on the RTC alarm using (see LLWU link above) with:
INTERRUPT_SETUP interrupt_setup; // interrupt configuration parameters
interrupt_setup.int_port = PORT_MODULE; // define a wakeup interrupt on a module (rather than LLWU port input)
interrupt_setup.int_port_bits = (MODULE_RTC_ALARM); // wakeup on RTC alarm interrupts
fnConfigureInterrupt((void *)&interrupt_setup); // configure wakeup interrupt
To move to LLS with wakeup in 300s:
fnSetShowTime(SET_RTC_ALARM_TIME, "+300"); // program an alarm to fire in +300s and wake the processor [this can also be an absolute time or date/time]
fnSetLowPowerMode(LLS_MODE); // move to LLS mode as soon as no more local communication activity
This is a non-blocking function and will allow any communication that is presently in progress to complete before making the switch. The processor will reduce power consumption to about 1.7uA.
After 300s the processor will wake and interrupt routine interrupt_setup() will be called (which doesn't need to do anything if it doesn't want to signal anything specific), and the processor will continue at full speed again until the shut down sequence is called again.
When not sleeping you can run everything at full power to keep the processing as short as possible so no need to do anything special with clocks.
As you can see this functionality is completely developed and can be built with KDS2.0 for any KE,KL,KV or K parts.
I2C and SPI Flash is included too - just enable the defines
#define IIC_INTERFACE // enable I2C driver (use explained in http://www.utasker.com/docs/uTasker/uTaskerIIC.PDF)
#define SPI_FILE_SYSTEM // enable SPI Flash driver (see http://www.utasker.com/docs/uTasker/uTaskerFileSystemSPI_FLASH_003.PDF)
- the SPI chips supported are
- AT45DBxxxB/C (optionally power-of-twos mode)
- STM25Pxxx (data and program types)
- SST25xxx
- Winbond W25Qxx
You can also run the project in the uTasker Kinetis simulator (simulates also I2C and SPI Flash as well as all Kinetis peripherals in (approx.) real-time).
The only down side would be that you possibly wouldn't be able to experiment with the various components that you are piecing together at the moment because with the defines above you will probably have most of the work completed ;-)
Regards
Mark
P.S. If you have a FRDM-KL26Z board and load the mbed debugger (rather than the P&E one) it generates a 32kHz input for the RTC_CLKIN (see SDA_PTD6 and R22). this is useful for preparing SW for designs that later have an external clock generator.
Kinetis: µTasker Kinetis support
KL26: µTasker Kinetis FRDM-KL26Z support / µTasker Kinetis Teensy LC support
For the complete "out-of-the-box" Kinetis experience and faster time to market