Note 19 BKP RTC.md 4.2 KB


tags: [entity] type: entity topic: stm32-lower note: 19 created: 2026-07-16

updated: 2026-07-16

Note 19: BKP/RTC (lower/stm32/21~26)

Projects

# Directory Topic Library
21 21_bkp_test_register BKP backup registers Register
22 22_bkp_test_hal BKP backup registers HAL
23 23_rtc_alarm_standby_register RTC alarm + standby wake Register
24 24_rtc_alarm_standby_hal RTC alarm + standby wake HAL
25 25_rtc_calendar_register RTC calendar Register
26 26_rtc_calendar_hal RTC calendar HAL

Code Accuracy Audit

Path Audit

Claimed Path Actual Path Status
stm32/21_bkp_test_register/Hardware/BKP/bkp.c 21_bkp_test_register/Hardware/BKP/bkp.c ✅ Correct
stm32/25_rtc_calendar_register/Hardware/RTC/rtc.c 25_rtc_calendar_register/Hardware/RTC/rtc.c ✅ Correct
stm32/25_rtc_calendar_register/Hardware/RTC/rtc.h 25_rtc_calendar_register/Hardware/RTC/rtc.h ✅ Correct
stm32/25_rtc_calendar_register/User/main.c 25_rtc_calendar_register/User/main.c ✅ Correct
stm32/23_rtc_alarm_standby_register/User/main.c 23_rtc_alarm_standby_register/User/main.c ✅ Correct

BKP Code (bkp.c)

Claimed by Note Actual Code Match?
`RCC->APB1ENR = RCC_APB1ENR_PWREN` Present
`PWR->CR = PWR_CR_DBP` Present
`RCC->APB1ENR = RCC_APB1ENR_BKPEN` Present
bkp.h has #include "stm32f10x.h", BKP_Init(void) Present ✅ Match

RTC Init (25_rtc_calendar_register/Hardware/RTC/rtc.c)

Claimed by Note Actual Code (lines) Match?
`RCC->APB1ENR = RCC_APB1ENR_PWREN` Line 15
`PWR->CR = PWR_CR_DBP` Line 18
`RCC->BDCR = RCC_BDCR_RTCEN` Line 28
`RCC->BDCR = RCC_BDCR_LSEON` Line 31
while (!(RCC->BDCR & RCC_BDCR_LSERDY)) Lines 32-34 ✅ Match
`RCC->BDCR &= ~RCC_BDCR_RTCSEL; RCC->BDCR = RCC_BDCR_RTCSEL_0` Lines 37-38
Wait RTC_CRL_RTOFF Lines 42-44 ✅ Match
`RTC->CRL = RTC_CRL_CNF` Line 47
RTC->PRLH = 0; RTC->PRLL = 0x7fff Lines 50-51 ✅ Match
RTC->CRL &= ~RTC_CRL_CNF Line 54 ✅ Match

RTC_SetAlarm

Claimed by Note Actual Code Match?
RTC->CRL &= ~RTC_CRL_ALRF Line 66 ✅ Match
Wait RTOFF Line 69 ✅ Match
`RTC->CRL = RTC_CRL_CNF` Line 74
RTC->CNTH = 0; RTC->CNTL = 0 Lines 78-79 ✅ Match
s -= 1; RTC->ALRH = (s >> 16) & 0xffff; RTC->ALRL = (s >> 0) & 0xffff Lines 82-84 ✅ Match
RTC->CRL &= ~RTC_CRL_CNF Line 87 ✅ Match

RTC_SetTimestamp

Claimed by Note Actual Code Match?
Wait RTOFF, CNF=1, set CNTH/CNTL, CNF=0, wait RTOFF Lines 99-116 ✅ Match

RTC_GetDateTime

Claimed by Note Actual Code Match?
while (!(RTC->CRL & RTC_CRL_RSF)) Line 123 ✅ Match
`uint32_t second = RTC->CNTH << 16 RTC->CNTL` Line 127
struct tm* ptm = localtime(&second) Line 130 ✅ Match
dateTime->year = ptm->tm_year + 1900 etc. Lines 133-138 ✅ Match

DateTime struct (rtc.h)

Claimed by Note Actual Code Match?
typedef struct { uint16_t year; uint8_t month; ... } DateTime; Present ✅ Match
Function prototypes: RTC_Init, RTC_SetAlarm, RTC_SetTimestamp, RTC_GetDateTime Present ✅ Match

RTC Alarm + Standby (23_rtc_alarm_standby_register)

Note claims loop: RTC_SetAlarm(5); enter_standby_mode(); with PA0 wakeup → matches actual code.

HAL RTC Calendar

Note's HAL code (RTC_TimeTypeDef, RTC_DateTypeDef, HAL_RTC_SetTime, HAL_RTC_GetTime) matches project 26.

BKP Store Date (HAL)

Note's read_stored_date / write_stored_date functions using HAL_RTCEx_BKUPRead/Write — these exist in project 22's code.

Summary

Overall Accuracy: Excellent (99%+)

Issues Found: None significant. RTC register operations, HAL API usage, BKP operations all match actual source files exactly. This is the most technically accurate section.