From e906dcaf16d43c7ae89e272f3caca6c09a3214b4 Mon Sep 17 00:00:00 2001 From: Tahsin Mutlugun Date: Wed, 18 Dec 2024 13:30:02 +0300 Subject: [PATCH] Implement standby mode and RAM retention for MAX32657 Added standby mode and SRAM retention. Unavailable features are removed. Signed-off-by: Tahsin Mutlugun --- Libraries/PeriphDrivers/Include/MAX32657/lp.h | 86 ++++++++----------- Libraries/PeriphDrivers/Source/LP/lp_me30.c | 60 ++++++++----- 2 files changed, 74 insertions(+), 72 deletions(-) diff --git a/Libraries/PeriphDrivers/Include/MAX32657/lp.h b/Libraries/PeriphDrivers/Include/MAX32657/lp.h index 0e4ea3bb688..02caae843ed 100644 --- a/Libraries/PeriphDrivers/Include/MAX32657/lp.h +++ b/Libraries/PeriphDrivers/Include/MAX32657/lp.h @@ -88,6 +88,39 @@ void MXC_LP_EnterPowerDownMode(void); */ void MXC_LP_SetOVR(mxc_lp_ovr_t ovr); +/** + * @brief Enable retention regulator + */ +void MXC_LP_RetentionRegEnable(void); + +/** + * @brief Disable retention regulator + */ +void MXC_LP_RetentionRegDisable(void); + +/** + * @brief Is the retention regulator enabled + * + * @return 1 = enabled 0 = disabled + */ +int MXC_LP_RetentionRegIsEnabled(void); + +/** + * @brief Enables data retention to RAM blocks 0-4 in BACKUP mode. + * + * @param[in] mask The mask of the RAM blocks to enable data retention. Bit 0 enables + * block 0, bit 1 enables block 1, etc. + */ +void MXC_LP_EnableSramRetention(uint32_t mask); + +/** + * @brief Disables data retention to RAM blocks 0-4 in BACKUP mode. + * + * @param[in] mask The mask of the RAM blocks to disable data retention. Bit 0 disables + * block 0, bit 1 disables block 1, etc. + */ +void MXC_LP_DisableSramRetention(uint32_t mask); + /** * @brief Turn bandgap on */ @@ -152,16 +185,6 @@ void MXC_LP_EnableTimerWakeup(mxc_tmr_regs_t *tmr); */ void MXC_LP_DisableTimerWakeup(mxc_tmr_regs_t *tmr); -/** - * @brief Enables the USB to wake up the device from any low power mode. - */ -void MXC_LP_EnableUSBWakeup(void); - -/** - * @brief Disables the USB from waking up the device. - */ -void MXC_LP_DisableUSBWakeup(void); - /** * @brief Enables the WUT alarm to wake up the device from any low power mode. */ @@ -172,54 +195,19 @@ void MXC_LP_EnableWUTAlarmWakeup(void); */ void MXC_LP_DisableWUTAlarmWakeup(void); -/** - * @brief Enables the HA0 to wake up the device from any low power mode. - */ -void MXC_LP_EnableHA0Wakeup(void); - -/** - * @brief Disables the HA)0 from waking up the device. - */ -void MXC_LP_DisableHA0Wakeup(void); -/** - * @brief Enables the HA1 to wake up the device from any low power mode. - */ -void MXC_LP_EnableHA1Wakeup(void); - -/** - * @brief Disables the HA1 from waking up the device. - */ -void MXC_LP_DisableHA1Wakeup(void); - /** * @brief Configure which clocks are powered down at deep sleep and which are not affected. * - * @note Need to configure all clocks at once any clock not passed in the mask will be unaffected by Deepsleep. This will - * always overwrite the previous settings of ALL clocks. + * @note Need to configure all clocks at once any clock not passed in the mask will be + * unaffected by Deepsleep. * - * @param[in] mask The mask of the clocks to power down when part goes into deepsleep + * @param[in] mask The mask of the clocks to power down when part goes into deepsleep. + * Only ERTCO can be switched off. * * @return #E_NO_ERROR or error based on /ref MXC_Error_Codes */ int MXC_LP_ConfigDeepSleepClocks(uint32_t mask); -/** - * @brief Enable NFC Oscilator Bypass - */ -void MXC_LP_NFCOscBypassEnable(void); - -/** - * @brief Disable NFC Oscilator Bypass - */ -void MXC_LP_NFCOscBypassDisable(void); - -/** - * @brief Is NFC Oscilator Bypass Enabled - * - * @return 1 = enabled, 0 = disabled - */ -int MXC_LP_NFCOscBypassIsEnabled(void); - /**@} end of group pwrseq */ #ifdef __cplusplus diff --git a/Libraries/PeriphDrivers/Source/LP/lp_me30.c b/Libraries/PeriphDrivers/Source/LP/lp_me30.c index e900eba30e0..e971b6af7f1 100644 --- a/Libraries/PeriphDrivers/Source/LP/lp_me30.c +++ b/Libraries/PeriphDrivers/Source/LP/lp_me30.c @@ -26,8 +26,6 @@ #define SET_SLEEPDEEP(X) (SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk) #define CLR_SLEEPDEEP(X) (SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk) -// TODO(SW): Update this. - void MXC_LP_EnterSleepMode(void) { MXC_LP_ClearWakeStatus(); @@ -39,19 +37,15 @@ void MXC_LP_EnterSleepMode(void) __WFI(); } -void MXC_LP_EnterLowPowerMode(void) +void MXC_LP_EnterStandbyMode(void) { - return; -} + MXC_LP_ClearWakeStatus(); -void MXC_LP_EnterMicroPowerMode(void) -{ - return; -} + /* Clear SLEEPDEEP bit */ + SET_SLEEPDEEP(); -void MXC_LP_EnterStandbyMode(void) -{ - return; + /* Go into Standby mode and wait for an interrupt to wake the processor */ + __WFI(); } void MXC_LP_EnterBackupMode(void) @@ -79,6 +73,31 @@ void MXC_LP_SetOVR(mxc_lp_ovr_t ovr) //not supported yet } +void MXC_LP_RetentionRegEnable(void) +{ + MXC_PWRSEQ->lpctrl |= MXC_F_PWRSEQ_LPCTRL_RETLDO_EN; +} + +void MXC_LP_RetentionRegDisable(void) +{ + MXC_PWRSEQ->lpctrl &= ~MXC_F_PWRSEQ_LPCTRL_RETLDO_EN; +} + +int MXC_LP_RetentionRegIsEnabled(void) +{ + return (MXC_PWRSEQ->lpctrl & MXC_F_PWRSEQ_LPCTRL_RETLDO_EN); +} + +void MXC_LP_EnableSramRetention(uint32_t mask) +{ + MXC_PWRSEQ->lpctrl |= (mask & 0x1F) << MXC_F_PWRSEQ_LPCTRL_SRAMRET_EN_POS; +} + +void MXC_LP_DisableSramRetention(uint32_t mask) +{ + MXC_PWRSEQ->lpctrl &= ~((mask & 0x1F) << MXC_F_PWRSEQ_LPCTRL_SRAMRET_EN_POS); +} + void MXC_LP_BandgapOn(void) { MXC_PWRSEQ->lpctrl &= ~MXC_F_PWRSEQ_LPCTRL_BG_DIS; @@ -135,16 +154,6 @@ void MXC_LP_DisableRTCAlarmWakeup(void) MXC_GCR->pm &= ~MXC_F_GCR_PM_RTC_WE; } -void MXC_LP_EnableTimerWakeup(mxc_tmr_regs_t *tmr) -{ - return; -} - -void MXC_LP_DisableTimerWakeup(mxc_tmr_regs_t *tmr) -{ - return; -} - void MXC_LP_EnableWUTAlarmWakeup(void) { MXC_GCR->pm |= MXC_F_GCR_PM_WUT_WE; @@ -157,6 +166,11 @@ void MXC_LP_DisableWUTAlarmWakeup(void) int MXC_LP_ConfigDeepSleepClocks(uint32_t mask) { - MXC_GCR->pm |= mask; + if (!(mask & MXC_F_MCR_CTRL_ERTCO_EN)) { + return E_BAD_PARAM; + } + + MXC_MCR->ctrl &= ~mask; + return E_NO_ERROR; }