Adding Wake up Pins configuration to deepsleep for STM32 / pyboard-d

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
irsla
Posts: 11
Joined: Mon Sep 21, 2020 2:04 pm

Adding Wake up Pins configuration to deepsleep for STM32 / pyboard-d

Post by irsla » Wed Sep 23, 2020 9:47 am

Hi Everyone,

Following my question here viewtopic.php?f=20&t=9056

I dig into the firmware code and found the missing bits.

I now have a patch that allows a user to call deepsleep with the PINS parameters and successuflly tested it on a SF6W board for the X1 pins.

All these work the way they should

machine.deepsleep([time_ms | 0 for infinity], [WKUP_PINS_X1/X18], [WKUP_PINS_X1/X18_RISING/FALLING])

# will sleep forever
machine.deepsleep()
# will wakeup in 20 seconds
machine.deepsleep(20000)
# will wakeup in 10 second unless there is a rising on X1
machine.deepsleep(10000, machine.WKUP_X1, machine.WKUP_X1_RISING)
# will sleep forerver unless there is a rising on X1
machine.deepsleep(0, machine.WKUP_X1, machine.WKUP_X1_RISING)
# will sleep forerver unless there is a falling on X1
machine.deepsleep(0, machine.WKUP_X1, machine.WKUP_X1_FALLING)



Now I know that machine is for all boards and that it means that it can't be added to the core code without rework for the other platform.
I also now it will require more test for the X18 pin. but for the moment I don't know how to reach it ;)

I'm posting here because I don't know the next steps and I would love to discuss all this.

BTW: thanks for the amazing job you've been doing so far ;)

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Adding Wake up Pins configuration to deepsleep for STM32 / pyboard-d

Post by jimmo » Thu Sep 24, 2020 12:22 am

irsla wrote:
Wed Sep 23, 2020 9:47 am
I'm posting here because I don't know the next steps and I would love to discuss all this.
Hi, great work! Thanks for adding this feature.

The next step would be to raise a PR on https://github.com/micropython/micropython

Let me know if you have any questions on the process to do that.
irsla wrote:
Wed Sep 23, 2020 9:47 am
Now I know that machine is for all boards and that it means that it can't be added to the core code without rework for the other platform.
Yeah, this is a bit tricky. (And maybe this is the reason it hasn't been done so far!). Either way I'd still suggest raising a PR for what you've got so far and we can discuss there.

Note that the machine module doesn't have to support all features on all ports, as long as the subset that does work on all ports is clear. (This isn't always the case though right now).

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Support for low power modes (Pyboard 1.x and D)

Post by pythoncoder » Thu Sep 24, 2020 7:00 am

I have this repo which provides low power support for the Pyboard 1.x. It has been partially adapted for the Pyboard D and I'm currently working on completing this.

Pin X18 is CPU pin C13. It is available on the wbus and also on the WBUS_DIP68 adaptor (pin W26).

Firmware support for low power modes was never been added for the Pyboard 1.x. It is reasonably straightforward to implement in Python using the STM module as per my repo.

In my opinion if official support were to be provided it should comprise a Python module rather than bloat the firmware. After all, speed is not an issue here. Further, the code, however implemented, is entirely STM specific. If it were to be written in C, the pyb module would make more sense than machine.
Peter Hinch
Index to my micropython libraries.

irsla
Posts: 11
Joined: Mon Sep 21, 2020 2:04 pm

Re: Adding Wake up Pins configuration to deepsleep for STM32 / pyboard-d

Post by irsla » Thu Sep 24, 2020 10:51 am

jimmo wrote:
Thu Sep 24, 2020 12:22 am
irsla wrote:
Wed Sep 23, 2020 9:47 am
I'm posting here because I don't know the next steps and I would love to discuss all this.
Hi, great work! Thanks for adding this feature.

The next step would be to raise a PR on https://github.com/micropython/micropython

Let me know if you have any questions on the process to do that.
You're welcome ! I hope it will be useful.

I will look how to do this in the next 2 hours (it's about lunch time for me now ;)) and will come back with questions or "done state"
jimmo wrote:
Thu Sep 24, 2020 12:22 am
irsla wrote:
Wed Sep 23, 2020 9:47 am
Now I know that machine is for all boards and that it means that it can't be added to the core code without rework for the other platform.
Yeah, this is a bit tricky. (And maybe this is the reason it hasn't been done so far!). Either way I'd still suggest raising a PR for what you've got so far and we can discuss there.

Note that the machine module doesn't have to support all features on all ports, as long as the subset that does work on all ports is clear. (This isn't always the case though right now).
OK, looking forward to discussing this on my code proposal.

irsla
Posts: 11
Joined: Mon Sep 21, 2020 2:04 pm

Re: Support for low power modes (Pyboard 1.x and D)

Post by irsla » Thu Sep 24, 2020 10:56 am

pythoncoder wrote:
Thu Sep 24, 2020 7:00 am
I have this repo which provides low power support for the Pyboard 1.x. It has been partially adapted for the Pyboard D and I'm currently working on completing this.

Pin X18 is CPU pin C13. It is available on the wbus and also on the WBUS_DIP68 adaptor (pin W26).

Firmware support for low power modes was never been added for the Pyboard 1.x. It is reasonably straightforward to implement in Python using the STM module as per my repo.

In my opinion if official support were to be provided it should comprise a Python module rather than bloat the firmware. After all, speed is not an issue here. Further, the code, however implemented, is entirely STM specific. If it were to be written in C, the pyb module would make more sense than machine.
Hi Peter,

Yes I found your repo when I started working on all this. Thank you for it, it was of great help

Thanks for the information for C13 it will be of good use !

About upower.py, I tried it of course, but I don't see how it can work on the V1.13 firmware (I haven't looked at previous version) as the standby function clears out any wakeup bit before entering in standby. I pretty sure of what I read, but I would love you to prove me wrong. we can either talk about it here or on the PR once it's opened.

irsla
Posts: 11
Joined: Mon Sep 21, 2020 2:04 pm

Re: Adding Wake up Pins configuration to deepsleep for STM32 / pyboard-d

Post by irsla » Thu Sep 24, 2020 12:53 pm

Hi Everyone,

Although I had a github (I'm using gitlab ;)) account since Dec 2012, I've never used it. Nevertheless I think I was able to make a PR ;)

https://github.com/micropython/micropython/pull/6482

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Support for low power modes (Pyboard 1.x and D)

Post by pythoncoder » Thu Sep 24, 2020 5:36 pm

irsla wrote:
Thu Sep 24, 2020 10:56 am
...
About upower.py, I tried it of course, but I don't see how it can work on the V1.13 firmware (I haven't looked at previous version) as the standby function clears out any wakeup bit before entering in standby...
The port to the Pyboard D is incomplete. The code on GitHub needs adapting in a number of ways: some registers are different and the RTC works in a different way. Many features will fail on the D at present.

I'm not aware of a firmware issue. I have run the alarm.py test program successfully on a Pyboard D with current firmware and my work-in-progress upower.py, but I've yet to prove the other wakeup mechanisms.

I hope to push an update soon. I'll then look into possible enhancements specific to the Pyboard D.
Peter Hinch
Index to my micropython libraries.

Post Reply