Skip to content

Commit

Permalink
Implement standby mode and RAM retention for MAX32657
Browse files Browse the repository at this point in the history
Added standby mode and SRAM retention. Unavailable features are removed.

Signed-off-by: Tahsin Mutlugun <[email protected]>
  • Loading branch information
ttmut committed Jan 3, 2025
1 parent 1d20720 commit e906dca
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 72 deletions.
86 changes: 37 additions & 49 deletions Libraries/PeriphDrivers/Include/MAX32657/lp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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.
*/
Expand All @@ -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
Expand Down
60 changes: 37 additions & 23 deletions Libraries/PeriphDrivers/Source/LP/lp_me30.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

0 comments on commit e906dca

Please sign in to comment.