How to wake on TAMP1 (PC13)..?

The official PYBD running MicroPython, and its accessories.
Target audience: Users with a PYBD
Post Reply
incognico
Posts: 19
Joined: Tue Jun 05, 2018 4:51 am

How to wake on TAMP1 (PC13)..?

Post by incognico » Thu Jun 11, 2020 8:28 am

Hi all,

Anyone with working code to wake a PYBD from Standby using PC13? I have been hacking at this on and off for a while, but I'm clearly missing something in the 1954-page datasheet :?

Appreciate any insight!

Cheers,

--Nick

incognico
Posts: 19
Joined: Tue Jun 05, 2018 4:51 am

Re: How to wake on TAMP1 (PC13)..?

Post by incognico » Fri Jun 12, 2020 6:29 am

Well, a bucket of coffee this morning and a fresh look and it was just me being stupid. Couple of registers have changed names that I managed to miss several times through... I was looking for something far more complicated and missed the simple stuff :lol:

For example, to make Peter's upower library Tamper() work on the PYDB, just rename the registers...

PWR_CR -> PWR_CSR2
RTC_TAFCR -> RTC_TAMPCR

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

Re: How to wake on TAMP1 (PC13)..?

Post by pythoncoder » Sat Jun 13, 2020 5:42 am

Adapting that library to support Pyboard D is on my (very long) TODO list. I wonder how many other names need to be changed.

I have amended upower.py to detect a Pyboard D and make those changes if you'd like to try it.
Peter Hinch
Index to my micropython libraries.

incognico
Posts: 19
Joined: Tue Jun 05, 2018 4:51 am

Re: How to wake on TAMP1 (PC13)..?

Post by incognico » Mon Jun 15, 2020 3:17 am

Just a couple of small things by the looks of it -

An oldie but a goodie :)

Code: Select all

>>> import upower
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "upower.py", line 20, in <module>
AttributeError: type object 'board' has no attribute 'USB_VBUS'
Looks like X18 is removed from the board definitions (I'm just using cpu.C13).

Code: Select all

>>> tamper=upower.Tamper()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "upower.py", line 34, in getinstance
  File "upower.py", line 113, in __init__
AttributeError: type object 'board' has no attribute 'X18'
My application has the line going high to trigger the interrupt (level=1). I changed the pin setup to PULL_DOWN, and in addition to your code I needed to disable the tamper pullup/precharge (set RTC_TAMPCR bit 15). Pg 1167:
Bit 15 TAMPPUDIS: RTC_TAMPx pull-up disable
This bit determines if each of the RTC_TAMPx pins are precharged before each sample.
0: Precharge RTC_TAMPx pins before sampling (enable internal pull-up)
1: Disable precharge of RTC_TAMPx pins.
Also specific to my application, I'm using the Tamper line as a general wake-up interrupt, not a security "tamper" mechanism, so I did not want the backup registers to be deleted. I needed to set RTC_TAMPCR bit 17 to achieve this. Pg 1167:
Bit 17 TAMP1NOERASE: Tamper 1 no erase
0: Tamper 1 event erases the backup registers.
1: Tamper 1 event does not erase the backup registers.
Hope this is useful.

--Nick

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

Re: How to wake on TAMP1 (PC13)..?

Post by pythoncoder » Mon Jun 15, 2020 7:11 am

Very useful indeed, Nick. Thank you. Clearly the behaviour for level 1 was incorrect for Pyboard 1.x too. I've pushed an upgrade to address the points you've made.

It seems that the erasure of backup registers is specific to the Pyboard D: chip data for the V1.x assigns a different meaning to bit 17 so I've made that Pyboard D specific.

I wonder what else has been broken on the Pyboard D: which other features of upower.py have you used? Have you measured the current draw when in low power mode?
Peter Hinch
Index to my micropython libraries.

incognico
Posts: 19
Joined: Tue Jun 05, 2018 4:51 am

Re: How to wake on TAMP1 (PC13)..?

Post by incognico » Tue Jun 23, 2020 3:02 am

Hi Peter,

Sorry I thought I replied to this at the time but clearly I imagined it.

I haven't tried the other features/modes of the upower library sorry. I hope to get the opportunity to give it a thorough run through at some stage but there always seems to be something urgent requiring attention first. I will see if I can find a moment to throw a fresh PYBD on the bench and test current draw (my dev unit has had a hard life and now appears to baseline at ~35mA no matter what is shut down...!)

--Nick

bradstew
Posts: 41
Joined: Thu Nov 29, 2018 9:29 pm

Re: How to wake on TAMP1 (PC13)..?

Post by bradstew » Mon Mar 29, 2021 10:08 pm

I am using a PYB with V1.14.
I am able to wake up using PA0 if I add the code,

stm.mem32[stm.PWR + stm.PWR_CSR] |= 1 << 8 # enable WKUP pin on PA0 (X1)

However, I'm not having much luck using PC13 to wake up on a rising edge. I have looked at Peter's upower.py program and tried setting the tamper 1 enable, and disable pullups and precharge.

stm.mem32[stm.PWR + stm.RTC_TAFCR] |= 3 | (1<< 15) # Tamper 1 disable pullups and precharge

Does upower support PC13 on the PYB V11? Or is it only for the PYBD?

Thanks,
Brad

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

Re: How to wake on TAMP1 (PC13)..?

Post by pythoncoder » Tue Mar 30, 2021 8:32 am

I have recently updated the upower library to support Pyboard D.

The Pyboard 1.1 supports wakeup on X1 and X18/C13, the latter being facilitated by the Tamper class. The pin has special properties in Tamper mode as described in the docs.

The Pyboard D also supports those pins.

Via the new version of upower the Pyboard D also supports these pins but you will need a daily firmware build to achieve this.
Peter Hinch
Index to my micropython libraries.

bradstew
Posts: 41
Joined: Thu Nov 29, 2018 9:29 pm

Re: How to wake on TAMP1 (PC13)..?

Post by bradstew » Tue Mar 30, 2021 7:15 pm

Thank you!
Brad

Post Reply