Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(PeriphDrivers): Implement low power modes for MAX32657 #1317

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put action verb at the beginning of the function name for tone to be consistent in the rest of the file.

/**
 * @brief      Enable retention regulator
 */
void MXC_LP_EnableRetentionReg(void);

/**
 * @brief      Disable retention regulator
 */
void MXC_LP_DisableRetentionReg(void);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MXC_LP_RetentionRegIsEnabled is fine. Didn't mean to include that function in the review window.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood. Thanks.


/**
* @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;
}
8 changes: 8 additions & 0 deletions Libraries/zephyr/MAX/Include/wrap_max32_lp.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,20 @@ static inline void Wrap_MXC_LP_EnterPowerDownMode(void)

static inline void Wrap_MXC_LP_EnterLowPowerMode(void)
{
#if defined(CONFIG_SOC_MAX32657)
MXC_LP_EnterSleepMode();
#else
MXC_LP_EnterLowPowerMode();
#endif
}

static inline void Wrap_MXC_LP_EnterMicroPowerMode(void)
{
#if defined(CONFIG_SOC_MAX32657)
MXC_LP_EnterSleepMode();
#else
MXC_LP_EnterMicroPowerMode();
#endif
}

static inline void Wrap_MXC_LP_EnterStandbyMode(void)
Expand Down
Loading