Hi,
I'd like to let the MCF52259 enter stop mode and then wake-up upon alarm interrupt from RTC. Reading in the reference manual, it is suggested to enter stop mode in a controlled manner. So, I was looking for an application note or some code examples, but I couldn't find nothing helpful. Does anyone have any example?
I'd not like to make something wrong in the procedure, for example: can I launch the stop mode during the execution of an interrupt service routine? I don't think it's the best way, so I'd like to find a good procedure.
Finally, which is the "stop command" to enter stop mode? Is it the "STOP" assembly command?
Regards,
Marco.
Unfortunately I'm still encountering problems with the stop mode. I remind you that I'm testing it on MCF52259DEMOKIT.
I set the LPICR register with ENBSTOP bit enabled and priority level = 0.
I set the LPCR register with LPMD = 11 (stop mode chosen) and STPMD = 11 (all disabled).
The way I should exit the stop mode is through an alarm interrupt from RTC.
I launch my application and the CPU enters stop mode, but the alarm can't wake it up. When I press the reset button on the board, the red reset led remains on; I have to unplug and plug USB cable to be able to restart the board.
Reading in the clock module section of the reference manual, I thought that could be a PLL problem and there could be loss of clock or loss of lock when disabling PLL.
To verify this thought I changed the STPMD field in the LPCR register according to table 10-10 of the reference manual; I tried the other three options. The board is always stuck in stop mode, but, now, when I press reset it restarts normally.
Finally I tried another low-power mode, wait mode, and it works fine; the alarm I set can wake the CPU up from the wait mode.
Where is the problem?
Thanks,
Marco.
Hi Marco,
What is the input clock for your RTC module? Is it an external 32.768kHz crystal?
Regards,
Steve
The DEMOKIT comes with a 32.768kHz crystal. Do you think it is important?
Regards,
Marco
Do you feed your RTC module with this external crystal or with internal system clock?
Your question let me understand the problem, thank you I was feeding the RTC with the internal clock; by stopping it, RTC stopped, too. So I changed the value in the register RTCGOCNT to 0x2000 (value for 32.768Khz crystal) and now it works!
Thank you,
Marco
Hi Mark,
thanks for your fast reply. According to my purpose, I can shut down all peripherals so I can use the STOP mode. You referred to WAIT mode, while I was looking for the procedure to enter STOP mode. Maybe did you mean it is the same? Well, the reference manual states about the stop mode:
"Stop mode must be entered in a controlled manner to ensure that any current operation is properly terminated...."
What does it mean exactly? For WAIT and DOSE modes it is not said the same. This caution is only taken for STOP mode, so I think there some more care to take. Am I wrong?
Regards,
Marco
Hi Marco
All modes (Wait, doze and stop) use the STOP instruction.
The difference is in the 'additional' clocks which are disabled, whereby the wait mode is the basic form since only the CPU clock is disabled and all peripherals can wake the CPU via interrupt.
When using 'deeper' modes one has to take more care that the wakeup source (or sources) is not disabled otherwise the CPU may get stuck in that mode.
I think that the extra care required is to do with shutting down peripherals (that will not be required in the stop mode) before they have completed any job that they started. Eg. DMA based UART transmission may be in progress and so one would first wait for the DMA engine to completely send the full buffer that it had started before disabling its clock - in the simpler wait state the CPU can stop but the DMA controller will continue doing what it was in the process of doing...
Regards
Mark
Ok, I see!
Thank you!
Hi Marco
The way to enter the wait mode is to execute the stop instruction; this leaves all peripheral clocks running but stops CPU operation. As soon as any interrupt takes place the CPU will run again.
First ensure that no SW is needed to operate, generally with interrupt masked (this depends on the SW and OS used - eg. avoid entereing the mode when a task should process something) and then execute the STOP instruction:
Codewarrior can use:
asm { stop #0x2000 }
This clears the interrupt mask (the value 0x2000 is set to the status register when it enters the stop mode) and enters stop mode.
Note that the uTasker project includes a "low power" task which automatically uses the wait mode whenever it is possible in order to generally reduce current consumption without any performance reduction. To save more power, additional peripheral clocks can be disabled, but this will also stop these peripherals from operating when in the wait/stop state.
Regards
Mark
www.uTasker.com
- OS, TCP/IP stack, USB, device drivers and simulator for M521X, M521XX, M5221X, M5222X, M5223X, M5225X. One package does them all - "Embedding it better..."