Hello dear Freescale community,
I have previously used VLPS modes to wake-up my KL03 from GPIO and it has worked fine. However, I am having issues trying to go into sleep mode using the TPM.
I want to bring the KL03 into deep sleep, then wake-up roughly every 6ms and perform some computation. I want to use the TPM as my wake-up source. However, the WFI instruction doesn't seem to be sending the microcontroller into deep sleep mode. I have read before that WFI might act as a NOP if some conditions are valid, but AFAIK there is no condition to nullify the WFI call.
Here it is what I have tried:
- Using debugger and setting breakpoints on i++ and on the TPM0_IRQHandler. I see multiple sequences of i++ followed by a TPM0_IRQHandler (when I should see a 1-to-1 interleaving).
- Disconnected debugger, and probe the FRDMKL03z J10's connection. I see a roughly constant voltage drop between 8-10mV over the 10ohm resistor in J10 (I had removed R27). If my code was working, I would expect a lower power consumption for most of the time.
Attached is my code. Any suggestions would be greatly appreciated. I use KDS and the default startup code.
Thank you!
<code>
int main(void)
{
configure_clocks(); //Sets the MCGIR clock to 2M/8/8 = 31kHz
memset(&tpm_driver_config, 0, sizeof(tpm_driver_config) );
tpm_driver_config.isDBGMode=true;
assert( TPM_DRV_Init(TPM_INSTANCE, &tpm_driver_config) == kStatusTpmSuccess);
TPM_DRV_SetClock(TPM_INSTANCE, kClockTpmSrcMcgIrClk, kTpmDividedBy8); //Do not divide by 8 at the end and you'll count 6.3ms
//Configure sleep mode
SMC_PMPROT = SMC_PMPROT_AVLP_MASK; //Key to allow entering VLP sleep modes
SMC_PMCTRL &= ~SMC_PMCTRL_STOPM_MASK; //Clean all other stop modes
i = SMC_PMCTRL; //ensures the control register is written
for (;;) {
TPM_DRV_OutputCompareEnable( TPM_INSTANCE, 0, kTpmOutputNone,10000u, 5000u, true); //5k cycles for Ocompare at 31Khz/8 = 1.28s
i++; //Dummy computation
SMC_PMCTRL |= SMC_PMCTRL_STOPM(0x2); //Allow going into VLPS
i = SMC_PMCTRL; //ensures the control register is written
__asm("WFI");
}
/* Never leave main */
return 0;
}
void TPM0_IRQHandler( ) {
TPM_DRV_IRQHandler(TPM_INSTANCE); //Clears appropriate flags
}
</code>
Solved! Go to Solution.
Hello,
Thanks for the suggestion. I removed R32 and measure the current until I got the VLPS working. Here are 3 things that I had wrong in my code:
1) Errata 8068 fix - disable RTC
2) Enable deepsleep control in the SCB->SCR register
-- Where are does registers documented???? There is only a vague reference in AN4503 and no reference on the KL03P24M48SF0RM manual
-- Looked at ARM website, but it'd be nice if Freescale provides some documentation to them
3) The worst thing: TPM is disabled during VLPS as per AN4503, so, obviously my program will never work as is
Hi Carlos,
After a brief look through your question, I'd like to suggest that you'd better to remove the R32 too, then use the multimeter to measure the current through the J10.
To confirm whether the MCU enters the VLPS mode successful or not, you need to disable the TPM at first , then measure the current through the J10 by multimeter after execute the WFI instruction. Next, contrast the current value with the specifications in the datasheet, now it will be obviously to confirm whether the MCU enters the VLPS mode successful or not.
Hope it helps.
Have a great day,
Ping
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hello,
Thanks for the suggestion. I removed R32 and measure the current until I got the VLPS working. Here are 3 things that I had wrong in my code:
1) Errata 8068 fix - disable RTC
2) Enable deepsleep control in the SCB->SCR register
-- Where are does registers documented???? There is only a vague reference in AN4503 and no reference on the KL03P24M48SF0RM manual
-- Looked at ARM website, but it'd be nice if Freescale provides some documentation to them
3) The worst thing: TPM is disabled during VLPS as per AN4503, so, obviously my program will never work as is
Hi Carlos,
Firstly, I'm glad to hear that you had already fixed your issue.
And thanks for your suggestions.
If you have any further questions about it, please feel free to contact with me.
Have a great day,
Ping
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------