--- tags: [entity] type: entity topic: stm32-lower note: 18 created: 2026-07-16 updated: 2026-07-16 --- # Note 18: Power (lower/stm32/15~20) ## Projects | # | Directory | Mode | Library | |---|---|---|---| | 15 | `15_lowpower_sleep_register` | Sleep | Register | | 16 | `16_lowpower_sleep_hal` | Sleep | HAL | | 17 | `17_lowpower_stop_register` | Stop | Register | | 18 | `18_lowpower_stop_hal` | Stop | HAL | | 19 | `19_lowpower_standby_register` | Standby | Register | | 20 | `20_lowpower_standby_hal` | Standby | HAL | ## Code Accuracy Audit ### Path Audit All paths are correct (no double `stm32/` issue for these projects). ### Sleep Mode — Register (15_lowpower_sleep_register/main.c) | Claimed by Note | Actual Code (line 45) | Match? | |---|---|---| | `SCB->SCR &= ~SCB_SCR_SLEEPDEEP` | Line 45 | ✅ Match | | `__WFI()` | Line 48 | ✅ Match | | Calls `enter_sleep_mode()` | Function defined lines 42-48 | ✅ Match | | Uses `USART_Init()`, `LED_Init()`, `Delay_s()` includes | Lines 9-11 | ✅ Match | Note mentions `SLEEPONEXIT` option — actual code only implements SLEEP-NOW (SLEEPDEEP=0, immediate WFI). The SLEEP-ON-EXIT variant is described in note but not implemented in this file. ### Sleep Mode — HAL (16_lowpower_sleep_hal/main.c) | Claimed by Note | Actual Code | Match? | |---|---|---| | `HAL_SuspendTick()` | Present | ✅ Match | | `HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI)` | Present | ✅ Match | | `HAL_ResumeTick()` | Present | ✅ Match | ### Stop Mode — Register (17_lowpower_stop_register/main.c) | Claimed by Note | Actual Code | Match? | |---|---|---| | `SCB->SCR |= SCB_SCR_SLEEPDEEP` | Present | ✅ Match | | `RCC->APB1ENR |= RCC_APB1ENR_PWREN` | Present | ✅ Match | | `PWR->CR &= ~PWR_CR_PDDS` (Stop mode) | Present | ✅ Match | | `PWR->CR |= PWR_CR_LPDS` (Low-power regulator) | Present | ✅ Match | | `__WFI()` | Present | ✅ Match | | Wake: `SystemInit()` | Present | ✅ Match | | `get_clock_freq()` helper | Present (lines in file) | ✅ Match | ### Stop Mode — HAL (18_lowpower_stop_hal/main.c) | Claimed by Note | Actual Code | Match? | |---|---|---| | `HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFI)` | Present | ✅ Match | | Wake: `SystemClock_Config()` | Present | ✅ Match | ### Standby Mode — Register (19_lowpower_standby_register/main.c) | Claimed by Note | Actual Code | Match? | |---|---|---| | `SCB->SCR |= SCB_SCR_SLEEPDEEP` | Present | ✅ Match | | `PWR->CR |= PWR_CR_PDDS` | Present | ✅ Match | | `PWR->CSR |= PWR_CSR_EWUP` (PA0 wake) | Present | ✅ Match | | `__WFI()` | Present | ✅ Match | | Wake detection: `PWR->CSR & PWR_CSR_SBF` | Present | ✅ Match | | `PWR->CR |= PWR_CR_CSBF` (clear SB flag) | Present | ✅ Match | | `PWR->CR |= PWR_CR_CWUF` (clear WUF flag) | Present | ✅ Match | ### Standby Mode — HAL (20_lowpower_standby_hal/main.c) | Claimed by Note | Actual Code | Match? | |---|---|---| | `__HAL_PWR_GET_FLAG(PWR_FLAG_SB)` | Present | ✅ Match | | `__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB)` | Present | ✅ Match | | `__HAL_PWR_GET_FLAG(PWR_FLAG_WU)` | Present | ✅ Match | | `__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU)` | Present | ✅ Match | | `HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1)` | Present | ✅ Match | | `HAL_PWR_EnterSTANDBYMode()` | Present | ✅ Match | ### PVD Configuration Note's claim: ```c PWR->CR |= PWR_CR_PLS_2 | PWR_CR_PLS_1; // PLS=110 → 2.8V PWR->CR |= PWR_CR_PVDE; EXTI->RTSR &= ~EXTI_RTSR_TR16; EXTI->FTSR |= EXTI_FTSR_TR16; EXTI->IMR |= EXTI_IMR_MR16; NVIC_EnableIRQ(PVD_IRQn); ``` This PVD code is referenced in the note but does NOT exist in any of the 6 power project main.c files. It may be from a separate demo or the note's general reference material. ## Summary **Overall Accuracy**: Very High **Issues Found**: 1. PVD code mentioned in note is NOT found in projects 15-20 main.c files — likely from separate reference material 2. SLEEP-ON-EXIT variant (`SLEEPONEXIT=1`) described in note but only SLEEP-NOW implemented in project 15 3. All other register/HAL low-power mode code matches actual files perfectly