STM32 RTC Write Protection

OP #4385204
Lesenswert?

Hallo,
ich versuche gerade die RTC meines STM32F103C8 zum Laufen zu bringen.
Sie läuft auch so weit nur ich kann die Register nicht modifizieren.
Um Fehler von mir aus zu schließen, habe ich die STM Std. Lib 
verwendet(ohne Erfolg) und dann direkt zugegriffen, selbst "manuell" mit 
dem Debugger keine Chance. Irgendetwas blockiert die Register. Die 
Sekunden laufen aber.


Von STM:
wird am Anfang aufgerufen
1
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
2

3
  /* Allow access to BKP Domain */
4
  PWR_BackupAccessCmd(ENABLE);
5

6
  /* Reset Backup Domain */
7
  BKP_DeInit();
8

9
  /* Enable LSE */
10
  RCC_LSEConfig(RCC_LSE_ON);
11
  /* Wait till LSE is ready */
12
  while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
13
  {}
14

15
  /* Select LSE as RTC Clock Source */
16
  RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
17

18
  /* Enable RTC Clock */
19
  RCC_RTCCLKCmd(ENABLE);
20

21
  /* Wait for RTC registers synchronization */
22
  RTC_WaitForSynchro();
23

24
  /* Wait until last write operation on RTC registers has finished */
25
  RTC_WaitForLastTask();
26

27
  /* Enable the RTC Second */
28
  RTC_ITConfig(RTC_IT_SEC, ENABLE);
29

30
  /* Wait until last write operation on RTC registers has finished */
31
  RTC_WaitForLastTask();
32

33
  /* Set RTC prescaler: set RTC period to 1sec */
34
  RTC_SetPrescaler(32767); /* RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1) */
35

36
  /* Wait until last write operation on RTC registers has finished */
37
  RTC_WaitForLastTask();

Funktion zum modifizieren des Alarms
1
void rtc_set_alarm(uint32_t data)
2
{
3
  
4
  
5
while((RTC->CRL & RTC_FLAG_RSF) == 0);   // wait for sync
6
 
7
RTC->CRL |= RTC_CRL_CNF; //enter configuration mode
8
 
9
RTC->ALRH = data>>16;
10
RTC->ALRL = data&0xFFFF; 
11

12
 
13
RTC->CRL &= ~RTC_CRL_CNF; //exit configuration mode
14
 
15
while((RTC->CRL & RTC_FLAG_RTOFF) == 0)   // wait for last task
16
{}
17
}
Gast #4386296
Lesenswert?

Im Reference Manual vom F205(!) heißt es im Kapitel
"RTC initialization and configuration":
1
After system reset, the RTC registers are protected against
2
parasitic write access with the DBP bit of the PWR power control
3
register (PWR_CR). The DBP bit must be set to enable RTC
4
registers write access.
5

6
After backup domain reset, all the RTC registers are
7
write-protected. Writing to the RTC registers is enabled by
8
writing a key into the Write Protection register, RTC_WPR.
9

10
The following steps are required to unlock the write protection
11
on all the RTC registers except for RTC_ISR[13:8], RTC_TAFCR,
12
and RTC_BKPxR.
13
1.   Write `0xCA' into the RTC_WPR register.
14
2.   Write `0x53' into the RTC_WPR register.
15
Writing a wrong key reactivates the write protection.
16

17
The protection mechanism is not affected by system reset.

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren