backup memory during low power mode

Discussion related to "under the hood" OpenMV topics.
User avatar
chrisPyres66
Posts: 138
Joined: Mon Jul 16, 2018 9:22 am
Location: France

backup memory during low power mode

Postby chrisPyres66 » Tue Aug 27, 2019 11:34 am

Dear all,

I know on STM32F7 and STM32H7, there is a backup sram to use for keeping the configuration during low power mode like deepsleep.
But i dont know how to use it in python code, is it possible ?

Thanks,
User avatar
iabdalkader
Posts: 1088
Joined: Sun May 24, 2015 3:53 pm

Re: backup memory during low power mode

Postby iabdalkader » Tue Aug 27, 2019 12:47 pm

No we don't have an API to access that memory, not sure MicroPython has one either.
User avatar
kwagyeman
Posts: 3727
Joined: Sun May 24, 2015 2:10 pm

Re: backup memory during low power mode

Postby kwagyeman » Tue Aug 27, 2019 2:11 pm

Use the stm module and manually do register accesses.

e.g.

stm.mem32[address] = value
Nyamekye,
User avatar
kwagyeman
Posts: 3727
Joined: Sun May 24, 2015 2:10 pm

Re: backup memory during low power mode

Postby kwagyeman » Tue Aug 27, 2019 2:11 pm

Read the chip reference manual. Linked to on the product page for what you need to do.
Nyamekye,
User avatar
chrisPyres66
Posts: 138
Joined: Mon Jul 16, 2018 9:22 am
Location: France

Re: backup memory during low power mode

Postby chrisPyres66 » Wed Aug 28, 2019 10:38 am

Dear both,

Thanks for your precious help.

I could not test it with STM32H7 because deep_sleep.py example does work with it : https://github.com/openmv/openmv/issues/573

But with STM32F7, here is the code which seems to works :

Code: Select all

import pyb, time, machine, stm
rtc = pyb.RTC()
rtc.datetime((2019, 4, 29, 0, 0, 0, 0, 0))
def writelog(texte):
   with open('test.txt', 'a') as logfile:
	  logfile.write(texte + '\n')
   return
class BkpRAMF7(object):
	BKPSRAM = 0x40024000
	def __init__(self):
	  stm.mem32[stm.RCC + stm.RCC_APB1ENR] |= 0x10000000
	  stm.mem32[stm.PWR + stm.PWR_CR1] |= 0x100
	  stm.mem32[stm.RCC +stm.RCC_AHB1ENR]|= 0x40000
	  stm.mem32[stm.PWR + stm.PWR_CSR1] |= 0x200
	  stm.mem32[stm.PWR + stm.PWR_CSR1] |= 0x100
	def __getitem__(self, idx):
		assert idx >= 0 and idx <= 0x3ff, "Index must be between 0 and 1023"
		return stm.mem32[self.BKPSRAM + idx * 4]
	def __setitem__(self, idx, val):
		assert idx >= 0 and idx <= 0x3ff, "Index must be between 0 and 1023"
		stm.mem32[self.BKPSRAM + idx * 4] = val
b = BkpRAMF7()
if b[0] != 0 :
   b[0] = 0
   b[1] = 0
b[1] += 1
writelog("F7 : %d" % b[1] )
rtc.wakeup(5000)
if b[1] < 5 :
   machine.deepsleep()
while True :
   pyb.LED(2).toggle()
   time.sleep(500)
Thanks,
User avatar
kwagyeman
Posts: 3727
Joined: Sun May 24, 2015 2:10 pm

Re: backup memory during low power mode

Postby kwagyeman » Wed Aug 28, 2019 1:45 pm

Cool! Glad to see it worked. Ibrahim just fixed deep sleep on the H7. It will be fixed in the next firmware release.
Nyamekye,

Return to “Technical Discussion”

Who is online

Users browsing this forum: MSN [Bot] and 7 guests