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

Merged
merged 7 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions Libraries/CMSIS/Device/Maxim/MAX32657/Include/gcr_regs.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

/******************************************************************************
*
* Copyright (C) 2024 Analog Devices, Inc.
* Copyright (C) 2024-2025 Analog Devices, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -312,7 +312,7 @@ typedef struct {
#define MXC_F_GCR_PM_RTC_WE_POS 5 /**< PM_RTC_WE Position */
#define MXC_F_GCR_PM_RTC_WE ((uint32_t)(0x1UL << MXC_F_GCR_PM_RTC_WE_POS)) /**< PM_RTC_WE Mask */

#define MXC_F_GCR_PM_WUT_WE_POS 7 /**< PM_WUT_WE Position */
#define MXC_F_GCR_PM_WUT_WE_POS 6 /**< PM_WUT_WE Position */
#define MXC_F_GCR_PM_WUT_WE ((uint32_t)(0x1UL << MXC_F_GCR_PM_WUT_WE_POS)) /**< PM_WUT_WE Mask */

#define MXC_F_GCR_PM_ERFO_BP_POS 20 /**< PM_ERFO_BP Position */
Expand Down
2 changes: 1 addition & 1 deletion Libraries/CMSIS/Device/Maxim/MAX32657/Include/max32657.svd
Original file line number Diff line number Diff line change
Expand Up @@ -2334,7 +2334,7 @@
<field derivedFrom="GPIO_WE">
<name>WUT_WE</name>
<description>Enable Wakeup Timer as wakeup source.</description>
<bitOffset>7</bitOffset>
<bitOffset>6</bitOffset>
<bitWidth>1</bitWidth>
</field>
<field>
Expand Down
88 changes: 38 additions & 50 deletions Libraries/PeriphDrivers/Include/MAX32657/lp.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

/******************************************************************************
*
* Copyright (C) 2024 Analog Devices, Inc.
* Copyright (C) 2024-2025 Analog Devices, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down 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_EnableRetentionReg(void);

/**
* @brief Disable retention regulator
*/
void MXC_LP_DisableRetentionReg(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
35 changes: 19 additions & 16 deletions Libraries/PeriphDrivers/Include/MAX32657/mxc_sys.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
*
* Copyright (C) 2024 Analog Devices, Inc.
* Copyright (C) 2024-2025 Analog Devices, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -27,6 +27,7 @@
#include "mxc_device.h"
#include "gcr_regs.h"
#include "fcr_regs.h"
#include "mcr_regs.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -88,7 +89,6 @@ typedef enum {
} mxc_sys_periph_clock_t;

/** @brief Enumeration to select System Clock source */
// TODO(ME30): CLKCTRL sysclk_sel values seem incorrect.
typedef enum {
MXC_SYS_CLOCK_IPO =
MXC_V_GCR_CLKCTRL_SYSCLK_SEL_IPO, /**< Select the Internal Primary Oscillator (IPO) */
Expand Down Expand Up @@ -116,6 +116,17 @@ typedef enum {
MXC_SYS_CLOCK_DIV_128 = MXC_S_GCR_CLKCTRL_SYSCLK_DIV_DIV128
} mxc_sys_system_clock_div_t;

/** @brief Enumeration to select 32KHz Clock source used by the RTC, the timers, the wakeup timers,
* and the system clock */
typedef enum {
MXC_SYS_32K_CLOCK_ERTCO =
MXC_V_MCR_CTRL_CLKSEL_ERTCO, /**< Select the External Real-Time Clock Oscillator (ERTCO) */
MXC_SYS_32K_CLOCK_INRO =
MXC_V_MCR_CTRL_CLKSEL_INRO_DIV4, /**< Select the Internal Baud Rate Oscillator (INRO) */
MXC_SYS_32K_CLOCK_RTC_IN =
MXC_V_MCR_CTRL_CLKSEL_RTC_IN_DIV8, /**< Select the External clock input (RTC_CLK_IN) */
} mxc_sys_32k_clock_t;

/** @brief Compare clock enumeration. Used in MXC_SYS_ClockMeasure function. */
typedef enum {
MXC_SYS_COMPARE_CLOCK_RTC = MXC_S_FCR_FRQCNTCTRL_CMP_CLKSEL_RTC,
Expand Down Expand Up @@ -270,22 +281,14 @@ void MXC_SYS_RTCClockEnable(void);
int MXC_SYS_RTCClockDisable(void);

/**
* @brief Enables the 32kHz oscillator to be powered down when not in use.
* Only available for ME17 Rev. B and older chips. This has no effect on ME17
* Rev. A chips.
*
* @returns E_NO_ERROR if everything is successful
*/
void MXC_SYS_RTCClockPowerDownEn(void);

/**
* @brief Disables the 32kHz oscillator from being powered down when not in use.
* Only available for ME17 Rev. B and older chips. This has no effect on ME17
* Rev. A chips.
* @brief Selects the 32KHz clock source used by the RTC, the timers, the wakeup timers,
* and the system clock.
*
* @returns E_NO_ERROR if everything is successful
* @param clock Clock source to use. See @ref mxc_sys_32k_clock_t for options.
* @return E_NO_ERROR if everything is successful
* E_BAD_PARAM if the clock is not valid
*/
void MXC_SYS_RTCClockPowerDownDis(void);
int MXC_SYS_Select32KClockSource(mxc_sys_32k_clock_t clock);

/**
* @brief Enable System Clock Source without switching to it
Expand Down
18 changes: 1 addition & 17 deletions Libraries/PeriphDrivers/Include/MAX32657/rtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

/******************************************************************************
*
* Copyright (C) 2024 Analog Devices, Inc.
* Copyright (C) 2024-2025 Analog Devices, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -75,15 +75,6 @@ typedef enum {
MXC_RTC_INT_FL_READY = MXC_F_RTC_CTRL_RDY, /**< Timer ready interrupt flag */
} mxc_rtc_int_fl_t;

/**
* @brief Clock settings
*/
typedef enum {
MXC_RTC_ERTCO_CLK = 0,
MXC_RTC_INRO_CLK = 1,
MXC_RTC_EXT_CLK = 2,
} mxc_rtc_clock_t;

/**
* @brief Set Time-of-Day alarm value and enable Interrupt
* @param ras 20-bit value 0-0xFFFFF
Expand All @@ -99,13 +90,6 @@ int MXC_RTC_SetTimeofdayAlarm(uint32_t ras);
*/
int MXC_RTC_SetSubsecondAlarm(uint32_t rssa);

/**
* @brief Set the RTC clock source
* @param clk_src Clock source to use
* @retval returns Success or Fail, see \ref MXC_ERROR_CODES
*/
int MXC_RTC_SetClockSource(mxc_rtc_clock_t clk_src);

/**
* @brief Start the Real Time Clock (Blocking function)
* @retval returns Success or Fail, see \ref MXC_ERROR_CODES
Expand Down
62 changes: 38 additions & 24 deletions Libraries/PeriphDrivers/Source/LP/lp_me30.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
*
* Copyright (C) 2024 Analog Devices, Inc.
* Copyright (C) 2024-2025 Analog Devices, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -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_EnableRetentionReg(void)
{
MXC_PWRSEQ->lpctrl |= MXC_F_PWRSEQ_LPCTRL_RETLDO_EN;
}

void MXC_LP_DisableRetentionReg(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;
}
Loading
Loading