[BLACK STM32F407VET6:STM32F407] Battery-backed/persistent memory

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
ProudPagan
Posts: 34
Joined: Fri Apr 12, 2019 8:55 am

[BLACK STM32F407VET6:STM32F407] Battery-backed/persistent memory

Post by ProudPagan » Mon Jul 08, 2019 4:37 am

Hi,

I would like to store some invariant data on the BLACK STM32F407VET6 board while
the main power is removed (coin cell remains connected).

The STM32F407 has 4kByte of battery backed SRAM. Is this accessible in MicroPython?

Thanks

PP

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

Re: [BLACK STM32F407VET6:STM32F407] Battery-backed/persistent memory

Post by jimmo » Mon Jul 08, 2019 6:30 am

I don't believe there's a Python-level API for this, however it's fairly straightforward to enable by setting a few bits in registers. See "Access to the backup SRAM" on p119 of RM0090. It's referred to by both "Backup SRAM" and "BKPSRAM" in the docs. Once enabled, you can access it from micropython using machine.mem8/16/32.

Code: Select all

CMSIS/STM32F4xx/Include/stm32f407xx.h
928:#define BKPSRAM_BASE          0x40024000U /*!< Backup SRAM(4 KB) base address in the alias region                         */

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

Re: [BLACK STM32F407VET6:STM32F407] Battery-backed/persistent memory

Post by pythoncoder » Tue Jul 09, 2019 8:34 am

You'll find some code for doing this on the Pyboard here (upower.py). I haven't checked if it works on the '407 but it might be worth a try.
Peter Hinch

ProudPagan
Posts: 34
Joined: Fri Apr 12, 2019 8:55 am

Re: [BLACK STM32F407VET6:STM32F407] Battery-backed/persistent memory

Post by ProudPagan » Tue Jul 09, 2019 3:13 pm

Thanks!

I found there were 4 steps to do:

Code: Select all

	
	//set Backup regulator enable -- do once
	SET_BIT(PWR->CSR, PWR_CSR_BRE);

	//enable power interface clock
        __HAL_RCC_PWR_CLK_ENABLE();
	
	//enable BBRAM interface clock
	SET_BIT(RCC->AHB1ENR, RCC_AHB1ENR_BKPSRAMEN);

	//Enable access to RTC domain by setting the DBP bit
	//DBP = Disable Backup Protection
	HAL_PWR_EnableBkUpAccess();
	
Full code here.

@pythoncoder -- Your implementation is way more complete -- I wouldn't have tried to implement my own had I seen your reply earlier!

Post Reply