Skip to content

Commit

Permalink
mcu/stm32: Fix hal_nvreg_write for STM32F1
Browse files Browse the repository at this point in the history
Writing to backup registers requires enabling BPK_CLK.
For read it does not seem to be needed.

Signed-off-by: Jerzy Kasenberg <[email protected]>
  • Loading branch information
kasjer committed Jun 8, 2024
1 parent 3ea5f71 commit 23196d5
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions hw/mcu/stm/stm32_common/src/hal_nvreg.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,15 @@ hal_nvreg_write(unsigned int reg, uint32_t val)
#if PWR_ENABLED
RTC_HandleTypeDef hrtc = { .Instance = RTC };
if (reg < HAL_NVREG_MAX) {
#if defined(__HAL_RCC_BKP_CLK_ENABLE)
__HAL_RCC_BKP_CLK_ENABLE();
#endif
HAL_PWR_EnableBkUpAccess();
HAL_RTCEx_BKUPWrite(&hrtc, reg, val);
HAL_PWR_DisableBkUpAccess();
#if defined(__HAL_RCC_BKP_CLK_DISABLE)
__HAL_RCC_BKP_CLK_DISABLE();
#endif
}
#endif
}
Expand Down

0 comments on commit 23196d5

Please sign in to comment.