Open dppddd opened 4 years ago
From the reference manual:
After reset, access to the Backup registers and RTC is disabled and the Backup domain (BKP) is protected against possible parasitic write access. To enable access to the Backup registers and the RTC, proceed as follows: • enable the power and backup interface clocks by setting the PWREN and BKPEN bits in the RCC_APB1ENR register • set the DBP bit the Power Control Register (PWR_CR) to enable access to the Backup registers and RTC.
For the first requirement I found these macros: __HAL_RCC_PWR_CLK_ENABLE()
and __HAL_RCC_BKP_CLK_ENABLE()
For the second point I found this function: LL_PWR_EnableBkUpAccess()
This library was a quick-and-dirty implementation for use in our Arduino port for Polaris development boards, based on STM32L4 series, and in our variant initialization code we already take care of enabling the correct flags.
It is far from being complete or fully supporting all STM32 families, but contributions are definitely welcome. I don't know if a similar library might be in the works by stm32duino community now (it was not when I started this).
Could it be because the STM32F103 registers are 16 bts long instead of 32 bits long and you are reading more than you should? (I'm trying to figure how to use those registers so I can avoid using the flash memory for just a few bytes of data)
I am trying to use backup registers library with stm32f103c8 board under Arduino 1.8.10 with STM Cores 1.6.1 installed. I put the code in the setup() and the result definitely shows that value in setRegister does not match the value in getRegister. Is the STM32Backup library currently working and supporting the stm32f103c8 board? Here is my code:
include "STM32LowPower.h"
include "STM32Backup.h"
STM32RTC& rtc = STM32RTC::getInstance(); STM32Backup bc;
void setup() { pinMode(Button0Pin, INPUT);
pinMode(Led1Pin, OUTPUT); pinMode(Led2Pin, OUTPUT); pinMode(Led3Pin, OUTPUT); pinMode(Led4Pin, OUTPUT);
digitalWrite(Led1Pin, LOW); digitalWrite(Led2Pin, LOW); digitalWrite(Led3Pin, LOW); digitalWrite(Led4Pin, LOW); LowPower.begin(); LowPower.attachInterruptWakeup(Button0Pin, PO, FALLING);
bc.setRegister(1,B111); if(bc.getRegister(1)==B111) { digitalWrite(Led1Pin, HIGH); digitalWrite(Led2Pin, HIGH); digitalWrite(Led3Pin, HIGH); digitalWrite(Led4Pin, HIGH);
delay(2000);
} else
{ digitalWrite(Led1Pin, HIGH); digitalWrite(Led2Pin, LOW); digitalWrite(Led3Pin, LOW); digitalWrite(Led4Pin, LOW);
delay(2000);
digitalWrite(Led1Pin, LOW); digitalWrite(Led2Pin, LOW); digitalWrite(Led3Pin, HIGH); digitalWrite(Led4Pin, LOW);
delay(2000);
} }