backup memory during low power mode

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,

No we don’t have an API to access that memory, not sure MicroPython has one either.

Use the stm module and manually do register accesses.

e.g.

stm.mem32[address] = value

Read the chip reference manual. Linked to on the product page for what you need to do.

Dear both,

Thanks for your precious help.

I could not test it with STM32H7 because deep_sleep.py example does work with it : deep_sleep.py example does not work with STM32H7 cam · Issue #573 · openmv/openmv · GitHub

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

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,

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