<div dir="ltr"><div><br></div><div>handler <a href="https://gist.github.com/goog/7bf5ec55139a3ed43e36be5b2eee318b">https://gist.github.com/goog/7bf5ec55139a3ed43e36be5b2eee318b</a></div><div><br></div><div>the main loop code <a href="https://gist.github.com/goog/d83786e0eb2c97ad3126ded1987b5078">https://gist.github.com/goog/d83786e0eb2c97ad3126ded1987b5078</a></div><div><br></div><div>when i pressed key,
printf("loop begin\n"); does not print immediately <br></div><div>so the sleep function does not break<br></div><div><div><br></div><div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jun 20, 2019 at 10:47 PM Christian Mauderer <<a href="mailto:list@c-mauderer.de">list@c-mauderer.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 20/06/2019 16:43, Jython wrote:<br>
> sleep function at the ending of loop, the loop did not begin intermediate<br>
<br>
So just that I understand it correctly: Your have a loop in a task that<br>
sends your processor to sleep at the end of the loop. Then you wake up<br>
the processor via an interrupt and the interrupt handler is executed.<br>
But you don't reach the loop again?<br>
<br>
I think I remember some discussion where you wanted to put a sleep into<br>
your idle loop? Maybe you have a double sleep?<br>
<br>
> <br>
> On Thursday, June 20, 2019, Christian Mauderer <<a href="mailto:list@c-mauderer.de" target="_blank">list@c-mauderer.de</a><br>
> <mailto:<a href="mailto:list@c-mauderer.de" target="_blank">list@c-mauderer.de</a>>> wrote:<br>
> <br>
>Â Â Â On 20/06/2019 13:25, Jython wrote:<br>
>   > do have service routine, handler can printk log, SLEEPONEXIT is 0<br>
> <br>
>Â Â Â So your handler is called? But it seems that the processor wakes up<br>
>Â Â Â then. How does the "won't stop sleep mode" look like?<br>
> <br>
>Â Â Â ><br>
>Â Â Â > On Thu, Jun 20, 2019 at 5:19 PM Christian Mauderer<br>
>Â Â Â <<a href="mailto:list@c-mauderer.de" target="_blank">list@c-mauderer.de</a> <mailto:<a href="mailto:list@c-mauderer.de" target="_blank">list@c-mauderer.de</a>><br>
>Â Â Â > <mailto:<a href="mailto:list@c-mauderer.de" target="_blank">list@c-mauderer.de</a> <mailto:<a href="mailto:list@c-mauderer.de" target="_blank">list@c-mauderer.de</a>>>> wrote:<br>
>Â Â Â ><br>
>Â Â Â >Â Â Â On 20/06/2019 10:57, Jython wrote:<br>
>Â Â Â >Â Â Â > a GPIO EXTI line,<br>
>Â Â Â >Â Â Â > rtems idle phrase called __wfi, does it make stm32 enter<br>
>Â Â Â standby mode?<br>
>Â Â Â >Â Â Â > so key can not wake up it from sleep function<br>
>Â Â Â ><br>
>Â Â Â >Â Â Â Please take a look at the reference manual of your chip. Most<br>
>Â Â Â likely<br>
>Â Â Â >Â Â Â it's "RM0090 Rev 18" but make sure that's the right part number:<br>
>Â Â Â ><br>
>Â Â Â >Â Â Â Â Â <br>
>Â Â Â <a href="https://www.st.com/resource/en/reference_manual/dm00031020.pdf" rel="noreferrer" target="_blank">https://www.st.com/resource/en/reference_manual/dm00031020.pdf</a><br>
>Â Â Â <<a href="https://www.st.com/resource/en/reference_manual/dm00031020.pdf" rel="noreferrer" target="_blank">https://www.st.com/resource/en/reference_manual/dm00031020.pdf</a>><br>
>Â Â Â ><br>
>Â Â Â >Â Â Â On page 127 there is a description of "Entering low-power mode":<br>
>Â Â Â ><br>
>Â Â Â >Â Â Â Â Â "Low-power modes are entered by the MCU by executing the<br>
>Â Â Â WFI (Wait<br>
>Â Â Â >Â Â Â Â Â For Interrupt), or WFE (Wait for Event) instructions, or<br>
>Â Â Â when the<br>
>   >     SLEEPONEXIT bit in the Cortex ®-M4 with FPU System Control<br>
>Â Â Â >Â Â Â Â Â register is set on Return from ISR."<br>
>Â Â Â ><br>
>Â Â Â >Â Â Â There is also a description for "Exiting low-power mode". For<br>
>Â Â Â WFI "any<br>
>Â Â Â >Â Â Â peripheral interrupt acknowledged by the NVIC can wake up the<br>
>Â Â Â device."<br>
>Â Â Â >Â Â Â So your interrupt has to be set up.<br>
>Â Â Â ><br>
>Â Â Â >Â Â Â Your code seems to enable the interrupt. But have you registered a<br>
>Â Â Â >Â Â Â interrupt service routine? Otherwise you might get problems<br>
>Â Â Â with an<br>
>Â Â Â >Â Â Â unhandled interrupt on wakeup.<br>
>Â Â Â ><br>
>Â Â Â >Â Â Â I only skimmed through the power controller chapter. But it<br>
>Â Â Â seems that<br>
>Â Â Â >Â Â Â if you have SLEEPDEEP bit set, you will enter a deeper sleep mode<br>
>Â Â Â >Â Â Â where peripheral clocks can be disabled. In that state it's<br>
>Â Â Â possible<br>
>Â Â Â >Â Â Â that only special pins (like the WKUP) can wake up the processor<br>
>Â Â Â >Â Â Â again. Please have a detailed look at that chapter to find out all<br>
>Â Â Â >Â Â Â traps.<br>
>Â Â Â ><br>
>Â Â Â >Â Â Â Best regards<br>
>Â Â Â ><br>
>Â Â Â >Â Â Â Christian<br>
>Â Â Â ><br>
>Â Â Â >Â Â Â ><br>
>Â Â Â >Â Â Â ><br>
>Â Â Â >Â Â Â >Â Â Â void keys_init()<br>
>Â Â Â >Â Â Â >Â Â Â {<br>
>Â Â Â >Â Â Â >Â Â Â Â Â // config gpio<br>
>Â Â Â >Â Â Â >Â Â Â stm32f4_gpio_set_config(&io_key1);Â // PA12<br>
>Â Â Â >Â Â Â >Â Â Â stm32f4_gpio_set_config(&io_key2);<br>
>Â Â Â >Â Â Â >Â Â Â Â Â stm32f4_gpio_set_config(&io_key3);<br>
>Â Â Â >Â Â Â >Â Â Â stm32f4_gpio_set_config(&io_key4);<br>
>Â Â Â >Â Â Â ><br>
>Â Â Â >Â Â Â >Â Â Â Â <br>
>Â Â Â >Â Â Â >Â Â Â Â Â //Â SYSCFGEN and exit map<br>
>Â Â Â >Â Â Â >Â Â Â (*(uint32_t*)0x40023844) |= 1<<14;<br>
>Â Â Â >Â Â Â >Â Â Â Â <br>
>Â Â Â >Â Â Â >Â Â Â Â Â SYSCFG_EXTICR3 = 0;<br>
>Â Â Â >Â Â Â >Â Â Â Â Â SYSCFG_EXTICR4 = 0;<br>
>Â Â Â >Â Â Â >Â Â Â Â <br>
>Â Â Â >Â Â Â ><br>
>Â Â Â >Â Â Â ><br>
>Â Â Â >Â Â Â >Â Â Â Â Â // EXIT INIT<br>
>Â Â Â >Â Â Â >Â Â Â EXTI_IMR |= (1<<12);<br>
>Â Â Â >Â Â Â >Â Â Â EXTI_RTSR |= (1<<12);<br>
>Â Â Â >Â Â Â ><br>
>Â Â Â >Â Â Â >Â Â Â Â Â EXTI_IMR |= (1<<11);<br>
>Â Â Â >Â Â Â >Â Â Â EXTI_RTSR |= (1<<11);<br>
>Â Â Â >Â Â Â ><br>
>Â Â Â >Â Â Â >Â Â Â Â Â EXTI_IMR |= (1<<10);<br>
>Â Â Â >Â Â Â >Â Â Â EXTI_RTSR |= (1<<10);<br>
>Â Â Â >Â Â Â ><br>
>Â Â Â >Â Â Â >Â Â Â Â Â EXTI_IMR |= (1<<9);<br>
>Â Â Â >Â Â Â >Â Â Â EXTI_RTSR |= (1<<9);<br>
>Â Â Â >Â Â Â ><br>
>Â Â Â >Â Â Â ><br>
>Â Â Â >Â Â Â >Â Â Â Â Â //NVIC_Init<br>
>Â Â Â >Â Â Â >Â Â Â Â Â //NVIC it group2<br>
>Â Â Â >Â Â Â ><br>
>Â Â Â >Â Â Â >Â Â Â SCB_AIRCR = 0x05FA0000 | 0x500;<br>
>Â Â Â >Â Â Â >Â Â Â // ip Interrupt priority register x<br>
>Â Â Â >Â Â Â ><br>
>Â Â Â >Â Â Â >Â Â Â //(*(volatile uint8_t*)0xE000E417) = 0xe0;Â //23<br>
>Â Â Â >Â Â Â >Â Â Â Â Â //(*(volatile uint8_t*)0xE000E428) = 0xe0;Â // 40<br>
>Â Â Â >Â Â Â >Â Â Â Â Â (*(volatile uint8_t*)0xE000E417) = 0x50;Â //23<br>
>Â Â Â >Â Â Â >Â Â Â Â Â (*(volatile uint8_t*)0xE000E428) = 0x50;Â // 40<br>
>Â Â Â >Â Â Â ><br>
>Â Â Â >Â Â Â ><br>
>Â Â Â >Â Â Â ><br>
>Â Â Â >Â Â Â >Â Â Â // 23 40 Interrupt set-enable register x (NVIC_ISERx)<br>
>Â Â Â >Â Â Â >Â Â Â Â Â // nvic enable interrupter number<br>
>Â Â Â >Â Â Â >Â Â Â Â Â // 0xE000E100<br>
>Â Â Â >Â Â Â >Â Â Â Â Â (*(volatile uint32_t*)0xE000E100) |= (1<<23);<br>
>Â Â Â >Â Â Â >Â Â Â Â Â (*(volatile uint32_t *)0xE000E104) |= (1<< (40%32));<br>
>Â Â Â >Â Â Â >Â Â Â }<br>
>Â Â Â >Â Â Â ><br>
>Â Â Â >Â Â Â ><br>
>Â Â Â >Â Â Â > On Thu, Jun 20, 2019 at 4:05 PM Christian Mauderer<br>
>Â Â Â >Â Â Â <<a href="mailto:list@c-mauderer.de" target="_blank">list@c-mauderer.de</a> <mailto:<a href="mailto:list@c-mauderer.de" target="_blank">list@c-mauderer.de</a>><br>
>Â Â Â <mailto:<a href="mailto:list@c-mauderer.de" target="_blank">list@c-mauderer.de</a> <mailto:<a href="mailto:list@c-mauderer.de" target="_blank">list@c-mauderer.de</a>>><br>
>Â Â Â >Â Â Â > <mailto:<a href="mailto:list@c-mauderer.de" target="_blank">list@c-mauderer.de</a> <mailto:<a href="mailto:list@c-mauderer.de" target="_blank">list@c-mauderer.de</a>><br>
>Â Â Â <mailto:<a href="mailto:list@c-mauderer.de" target="_blank">list@c-mauderer.de</a> <mailto:<a href="mailto:list@c-mauderer.de" target="_blank">list@c-mauderer.de</a>>>>> wrote:<br>
>Â Â Â >Â Â Â ><br>
>Â Â Â >Â Â Â >Â Â Â On 20/06/2019 05:28, Jython wrote:<br>
>Â Â Â >Â Â Â >Â Â Â > hi, it seems that exit key interrupt won't stop sleep<br>
>Â Â Â mode, why?<br>
>Â Â Â >Â Â Â >Â Â Â ><br>
>Â Â Â >Â Â Â >Â Â Â > [...]<br>
>Â Â Â >Â Â Â >Â Â Â ><br>
>Â Â Â >Â Â Â ><br>
>Â Â Â >Â Â Â >Â Â Â What do you mean by "exit key interrupt"? I don't know the<br>
>Â Â Â >Â Â Â STM32F4 that<br>
>Â Â Â >Â Â Â >Â Â Â well. So please give some more details.<br>
>Â Â Â >Â Â Â ><br>
>Â Â Â >Â Â Â >Â Â Â I would expect that either only specific interrupt<br>
>Â Â Â sources can<br>
>Â Â Â >Â Â Â wake up<br>
>Â Â Â >Â Â Â >Â Â Â the processor from a deep sleep mode or that you can<br>
>Â Â Â configure<br>
>Â Â Â >Â Â Â which<br>
>Â Â Â >Â Â Â >Â Â Â peripherals are still active. If your "exit key" is a GPIO<br>
>Â Â Â >Â Â Â line with<br>
>Â Â Â >Â Â Â >Â Â Â interrupt capability you should have a look at whether the<br>
>Â Â Â >Â Â Â module is<br>
>Â Â Â >Â Â Â >Â Â Â still active.<br>
>Â Â Â >Â Â Â ><br>
>Â Â Â >Â Â Â >Â Â Â Best regards<br>
>Â Â Â >Â Â Â ><br>
>Â Â Â >Â Â Â >Â Â Â Christian<br>
>Â Â Â >Â Â Â ><br>
>Â Â Â >Â Â Â >Â Â Â _______________________________________________<br>
>Â Â Â >Â Â Â >Â Â Â users mailing list<br>
>Â Â Â >Â Â Â >Â Â Â <a href="mailto:users@rtems.org" target="_blank">users@rtems.org</a> <mailto:<a href="mailto:users@rtems.org" target="_blank">users@rtems.org</a>><br>
>Â Â Â <mailto:<a href="mailto:users@rtems.org" target="_blank">users@rtems.org</a> <mailto:<a href="mailto:users@rtems.org" target="_blank">users@rtems.org</a>>><br>
>Â Â Â >Â Â Â <mailto:<a href="mailto:users@rtems.org" target="_blank">users@rtems.org</a> <mailto:<a href="mailto:users@rtems.org" target="_blank">users@rtems.org</a>><br>
>Â Â Â <mailto:<a href="mailto:users@rtems.org" target="_blank">users@rtems.org</a> <mailto:<a href="mailto:users@rtems.org" target="_blank">users@rtems.org</a>>>><br>
>Â Â Â >Â Â Â >Â Â Â <a href="http://lists.rtems.org/mailman/listinfo/users" rel="noreferrer" target="_blank">http://lists.rtems.org/mailman/listinfo/users</a><br>
>Â Â Â <<a href="http://lists.rtems.org/mailman/listinfo/users" rel="noreferrer" target="_blank">http://lists.rtems.org/mailman/listinfo/users</a>><br>
>Â Â Â >Â Â Â ><br>
>Â Â Â ><br>
> <br>
<br>
</blockquote></div>