advice on pybd deepsleep wake up on X1

The official PYBD running MicroPython, and its accessories.
Target audience: Users with a PYBD
Post Reply
irsla
Posts: 11
Joined: Mon Sep 21, 2020 2:04 pm

advice on pybd deepsleep wake up on X1

Post by irsla » Tue Sep 22, 2020 8:37 am

Hi Everybody,

I've been trying for days now to have my SF6W wake up on X1 after a deepsleep.

First of all let me explain my configuration.

the board (firmware v1.13) is "externally" powered via it's VUSB Pin, and controls a MMA5284Q (accelerometer) via I2C.
The MMA5284Q is configured to raise a interrupt on a tap, this will lower the INT pin (from 3v3 to 0v).

I read that the X1 wakeup can only work if you raise the pin, therefore I've added a PNP transistor that will reverse the process.

checking with multimeter shows that it works.

if I try to go to lightsleep everything works fine. the board goes to sleep, and is successfully woke up on the tap.

if I try to go to deepsleep the board never wakes up, although I can see the interruption (multimeter) being raised from the MMA5284Q.

I guess I'm doing something wrong, but I can't figure what ;) I would be grateful if anyone can point me to the right solution

If you need more information, please ask.

here the test code:

Code: Select all

import time
from pyb import Pin, ExtInt, LED, Switch
import machine
import MMA8452Q

STOP=False

ledR = LED(1)
ledG = LED(2)

# turn of red led as it was turned on in boot.py
ledR.off()
sw = Switch()

def stop():
    global STOP
    global sw

    print("in stop")
    STOP = True

sw.callback(stop)

def wokeUP(line):
    print("pin change", line)

def loop(i2c):
    global STOP

    Accel = MMA8452Q.MMA8452Q(i2c)

    # configure the accel to raise interrupt on Z tap
    Accel.setupTap(0x80, 0x80, 0x08, True)

    ledG.on()
    while STOP is False:
        print("sleeping in 3")
        time.sleep(3)
        #machine.lightsleep()
        machine.deepsleep()
        #need to readTap to reset the interrupt
        print("tapState: " + str(Accel.readTap()))
        time.sleep(1)

    ledG.off()

#ext = ExtInt(Pin('X1'), ExtInt.IRQ_RISING, Pin.PULL_UP, wokeUP)
pinX1 = Pin("X1", Pin.IN, Pin.PULL_DOWN)
pinX1.irq(trigger=Pin.IRQ_RISING, handler=wokeUP)

i2c = machine.I2C('X')
s = i2c.scan()

if len(s) > 0:
    loop(i2c)

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

Re: advice on pybd deepsleep wake up on X1

Post by irsla » Tue Sep 22, 2020 2:19 pm

Continuing testing and understanding all this.

The timeout value works fine.

Code: Select all

while STOP is False:
        print("sleeping in 3")
        time.sleep(3)
        #machine.lightsleep()
        machine.deepsleep(10000)
        #need to readTap to reset the interrupt
        print("tapState: " + str(Accel.readTap()))
        time.sleep(1)
So my problem seams to be with the X1 signal.

Which by the way works in lightsleep

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

Re: advice on pybd deepsleep wake up on X1

Post by jimmo » Tue Sep 22, 2020 2:37 pm

I don't have a pybd in front of me right now to test, but I think the answer lies somewhere in one of these links:

https://github.com/micropython/micropython/issues/3834

viewtopic.php?f=20&t=8518&p=48337 --> https://github.com/peterhinch/micropython-micropower

In short - it looks like you have to manually enable X1 (PA0) as a wakeup source. I'm not entirely sure why machine.deepsleep() doesn't do this for you.

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

Re: advice on pybd deepsleep wake up on X1

Post by irsla » Tue Sep 22, 2020 3:02 pm

Hi Jimmo,

Thanks for pointing the links, unfortunately it doesn't work

this line:

Code: Select all

stm.mem32[stm.PWR + stm.PWR_CSR] |= 1 << 8 # enable WKUP pin on PA0
indeed should enable the wake up pin PA0 / X1 (PWR_CSR2_EWUP1 although it's on PWR_CSR2 and not PWR_CSR) but when entering in the deepsleep the firmware will clear this pin

Code: Select all

    #if defined(STM32F7)
    // disable wake-up flags
    PWR->CSR2 &= ~(PWR_CSR2_EWUP6 | PWR_CSR2_EWUP5 | PWR_CSR2_EWUP4 | PWR_CSR2_EWUP3 | PWR_CSR2_EWUP2 | PWR_CSR2_EWUP1);
    // clear global wake-up flag
    PWR->CR2 |= PWR_CR2_CWUPF6 | PWR_CR2_CWUPF5 | PWR_CR2_CWUPF4 | PWR_CR2_CWUPF3 | PWR_CR2_CWUPF2 | PWR_CR2_CWUPF1;
    #elif defined(STM32H7)
I found this when you posted your message.

I've rebuild the firmware with the modified code, and my first test seems good.
It seems I'm able to wakeup on X1 raising

BTW we could configure it to wake on X1 falling.

Will post more once I've confirmed all this.

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

Re: advice on pybd deepsleep wake up on X1

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

Hi Everybody,

News of the day: I got it working by adding a few parameter to the deepsleep function.

I would like to share this patch with the community by having added to the main source code. I will move this discussion to the appropriate channel.

Regards,

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

Re: advice on pybd deepsleep wake up on X1

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

I am currently working to fix the problems with the micropower repo and the Pyboard D. I did some work on this in June to get X18 working, but it needs completing.
Peter Hinch

webbhm
Posts: 5
Joined: Sun Nov 08, 2020 10:08 pm

Status of deepsleep wake up on X1?

Post by webbhm » Thu Dec 31, 2020 3:36 pm

I was wondering if there were any updates on pin interrupt for deepsleep wake up.
I am wrapping up the testing of a Pyboard-D (SF2W) for a water quality sensor, and I would like the option of putting a reed switch between the RST pin and GND (or some other wiring) to wake the system. Ideally I could then trap this via:
if machine.reset_cause() == machine.WDT_RESET on start-up.

I have tried jumpering between RST and GND, and it seems to wake up when unplugging the jumper, but the reset_cause always comes back as machine.DEEPSLEEP_RESET, which is the same as the RTC alarm. The pin may be working, but I cannot identify it via the software. I may be missing something on how this is intended to work.

This in not necessary functionality for my project, but it would be easier to offload the data via wifi, rather than having to disassemble the package and pull out the SD card which contains the data.

I really like the Pyboard-D and micropython. It is a nice system to work with and the power sipping is great. I have emulated over a year of sampling (26,000 events) running off of 3 AA batteries, and believe it could go on much longer.

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

A solution to wake up on X1

Post by pythoncoder » Fri Jan 01, 2021 1:18 pm

I have fixed this but for reasons that elude me my PR languishes with no reason given. It seems odd to lose a feature long available on the Pyboard 1.x. You can access the PR but you will need to build firmware. See this doc for details.
Peter Hinch

Post Reply