-
Notifications
You must be signed in to change notification settings - Fork 3k
Full sleep() documentation? #10192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Internal Jira reference: https://jira.arm.com/browse/MBOCUSTRIA-1042 |
Can you share some references - is it doxygen docs, our docs. Looking at the API level, sleep and power mng headers have docs, would like to know which ones there lack details. What do you want to enable or disable it? This should be captured in the documentation: mbed classic - explicit call to sleep https://github.com/ARMmbed/mbed-os-5-docs/blob/e0703742672f72e746c1f08da7828750091200b1/docs/api/platform/PowerManagement.md |
I agree there's something documentation issue here. But Also note that calling Really Also, we do need a system suspend call which really would shut off until a limited specific wakeup, not any arbitrary interrupt or timer - #10104 is a step towards that. |
Looking at the docs, I guess what's missing is the concrete description of what My quick summary:
Also, the example on the power management page looks fine to me, at least for an RTOS build -
So I don't see why |
I should note that I have been running into this issue in attempting to migrate a number of power-sensitive applications from mbed 2 to mbed 5, since 2 is effectively no longer supported, and thus I'm hoping to find documentation that eases that process. I understand that sleep() is not really supposed to be called in the context of an RTOS operation; I believe could achieve the same task with an event queue/thread and Thread::wait(osWaitForever). But it does seem like overkill for an application to implement an event queue when it only has a single 2-10 minute polling operation that it should only perform once, when an interrupt occurs, and sleep for the remaining 24 hours of the day. This is a common theme for almost all my mbed classic projects, and I think environmental sensors in general. For instance, here is the mbed classic code that I've found recommended for this task:
If this code is no longer expected to work (due to consistent os-level interrupts that don't occur in classic for instance), I would appreciate being able find out why via the documentation, and the recommended way to achieve the same structure without implementing a minimum of unnecessary queue overhead. I think this is a common enough task among IoT sensors that this would be worth explaining. I suppose that "is it appropriate to use mbed-os for simple applications without any of the RTOS tools because it has the only public collection of device libraries and basic filesystem APIs besides Arduino" is a different question, but that's not one I've yet been able to get out of your corporate guys :) |
also, @kjbracey-arm, is the |
That code is assuming that there's only 1 interrupt in the entire system, and it's your button. And it's also assuming On the one hand, yes, we obviously don't want there to be lots of other wake-up sources in the system stopping you getting to sleep, but your application needs to be tolerant in case that happens, in any environment. You can't assume that your button has been pressed just because If wanting to support current bare-metal in 5.12, or mbed OS 2, I would recommend
That will be tolerant to any other interrupts happening, or any other spurious wakeups. It's obviously clunky, but I think that's the best you can currently do. (General rule of thumb for low-level sleep primitives like If the RTOS is there mbed OS 5, you just use:
#10104 is intending to make APIs like Your You have to actually get the OS involved and let it decide to stop the ticker - you do that by actually sleeping your thread with an OS sleeping call. In this case, I'm currently looking at a The bare metal profile is new to mbed OS 5.12, which isn't quite finalised yet, so not sure if the documentation is up. PR was #9800. |
Thank you for the detailed reply, lots of good information. Brute force suspend would be very useful for simple applications and I hope it makes it in. Do you think your rtos example would be worth adding to the power management section, so that there's a reference example for interrupt driven wake from sleep code, as opposed to polling only? I slipped up with my issue with wait() - the issue was actually It seems this issue may also be very sensitive to board subfamily changes - sleep power savings, tickless or not, do not appear to activate at all on a STM32103C8T6 using the 103RB as a target. Probably no reason to document this since obviously boards like the bluepill aren't officially supported but it's the first time I have ever run into an incompatibility. I'm still confirming this against the 103RB which I won't have on hand until monday. I'm extremely interested in the bare metal profile and would love to write an article on it when it's done. Is that intended as an up to date replacement of sorts for mbed 2? It'll take the flash and complexity back down to ultra-cheap Arduino levels which is very exciting from a rapid-prototyping perspective. |
Also, I only found the Doxygen pages by literally stumbling on it in Google, might be nice to add a link there in the readme. |
On I see the 103RB lacks The bare-metal profile is intended to let you make Mbed 2-like images with Mbed OS 5, yes. I'm not directly involved in the tools/documentation work, but I'd expect to see more information + publicity on it soon. |
Note that we're reworking the sleep docs, and I've incorporated the info from this thread there. Should be up in the coming weeks. |
@kjbracey-arm, does the potentially upcoming suspend() api include any support for shutting down peripherals like PWM, as referenced here? |
Current assumption is that suspend() will ignore the deep sleep lock - if you're explicitly asking for suspend you accept that peripherals will be suspended in general. So a |
How will that actually affect the peripherals in practice? PWMOut does not have an "off switch" so to speak other than just setting the pulsewidth to 0 - in Mbed 2, once you set the period, that's it, no more sleeping unless you free the instance since it'll constantly wake the processor. It isn't clear from the HAL or datasheet what happens when you just force suspend. Would we expect the PWM to just shut down? Or would it risk constantly re-waking the way it does in Mbed 2? |
Suspend would be intended to be a system suspend, so the intent would be that you are basically off. The PWM output would be expected to stop. Is this a software PWM in the system you're talking about? If it's software, then it would naturally stop. We'd have masked off whatever timer interrupt was timing it. If it is hardware, it would probably stop because we'd stopped whichever clock by entering deep sleep. There may be certain systems where it would keep going unless we took extra action. (Basic suspend functionality is to mask all interrupts except designated wakeup sources.) |
Per Jan's comment, doc will be updated. Please reopen if you still have issues. |
Description
Where is the sleep() function fully documented? The power management section of the API only mentions it in passing, instead focusing on how to disable it/re-enable it, and how it is called when all threads are idle. I find that calling the sleep() function has no effect whatsoever on my ST boards (F103, F411, F401), though in most mbed classic examples it is referenced as though it will immediately halt the processor.
I find it also worth noting that the current example on the power management page does not work out of the box, only Thread::wait() sends the processor into sleep mode.Issue was actually MBED_TICKLESSIssue request type
The text was updated successfully, but these errors were encountered: