Skip to content

Commit 516d0ef

Browse files
ME15: Added LP OVR Feature Support. (#441)
* ME15: Added LP OVR Feature Support. * Updating lp_me15.c for clang-formatting error. * Clang-formatted lp_me15.c locally. * ME16 LP: Updated OVR enum values. * ME16 LP: Fixed function prototype. * LP OVR: Added note in doxygen header for peripheral reset. * LP OVR: Removed @note from doxygen. * LP ME15: Ensure appropriate control bit is set for OVR. * Fixed syntax error.
1 parent 1fa83df commit 516d0ef

File tree

3 files changed

+109
-10
lines changed

3 files changed

+109
-10
lines changed

Libraries/PeriphDrivers/Include/MAX32670/lp.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,12 @@ extern "C" {
6060

6161
/**
6262
* @brief Enumeration type for voltage selection
63-
*
6463
*/
65-
typedef enum { MXC_LP_V0_9 = 0, MXC_LP_V1_0, MXC_LP_V1_1 } mxc_lp_ovr_t;
64+
typedef enum {
65+
MXC_LP_OVR_0_9 = MXC_S_PWRSEQ_LPCN_OVR_0_9V, /**< OVR 0.9V */
66+
MXC_LP_OVR_1_0 = MXC_S_PWRSEQ_LPCN_OVR_1_0V, /**< OVR 1.0V */
67+
MXC_LP_OVR_1_1 = MXC_S_PWRSEQ_LPCN_OVR_1_1V, /**< OVR 1.1V */
68+
} mxc_lp_ovr_t;
6669

6770
/**
6871
* @brief Enumeration type for PM Mode
@@ -103,11 +106,14 @@ void MXC_LP_EnterStorageMode(void);
103106
void MXC_LP_EnterShutDownMode(void);
104107

105108
/**
106-
* @brief Set ovr bits to set the voltage the micro will run at.
109+
* @brief Sets the operating voltage for the device. The caller must perform the peripheral reset after
110+
* calling this function.
107111
*
108112
* @param[in] ovr The ovr options are only 0.9V, 1.0V, and 1.1V use enum mxc_lp_ovr_t
113+
*
114+
* @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes.
109115
*/
110-
void MXC_LP_SetOVR(mxc_lp_ovr_t ovr);
116+
int MXC_LP_SetOVR(mxc_lp_ovr_t ovr);
111117

112118
/**
113119
* @brief Enable retention regulator

Libraries/PeriphDrivers/Include/MAX32675/lp.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,12 @@ extern "C" {
6060

6161
/**
6262
* @brief Enumeration type for voltage selection
63-
*
6463
*/
65-
typedef enum { MXC_LP_V0_9 = 0, MXC_LP_V1_0, MXC_LP_V1_1 } mxc_lp_ovr_t;
64+
typedef enum {
65+
MXC_LP_OVR_0_9 = MXC_S_PWRSEQ_LPCN_OVR_0_9V, /**< OVR 0.9V */
66+
MXC_LP_OVR_1_0 = MXC_S_PWRSEQ_LPCN_OVR_1_0V, /**< OVR 1.0V */
67+
MXC_LP_OVR_1_1 = MXC_S_PWRSEQ_LPCN_OVR_1_1V, /**< OVR 1.1V */
68+
} mxc_lp_ovr_t;
6669

6770
/**
6871
* @brief Enumeration type for PM Mode
@@ -103,11 +106,14 @@ void MXC_LP_EnterStorageMode(void);
103106
void MXC_LP_EnterShutDownMode(void);
104107

105108
/**
106-
* @brief Set ovr bits to set the voltage the micro will run at.
109+
* @brief Sets the operating voltage for the device. The caller must perform the peripheral reset after
110+
* calling this function.
107111
*
108112
* @param[in] ovr The ovr options are only 0.9V, 1.0V, and 1.1V use enum mxc_lp_ovr_t
113+
*
114+
* @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes.
109115
*/
110-
void MXC_LP_SetOVR(mxc_lp_ovr_t ovr);
116+
int MXC_LP_SetOVR(mxc_lp_ovr_t ovr);
111117

112118
/**
113119
* @brief Enable retention regulator

Libraries/PeriphDrivers/Source/LP/lp_me15.c

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@
3333

3434
#include "mxc_device.h"
3535
#include "mxc_assert.h"
36+
#include "mxc_errors.h"
3637
#include "mxc_sys.h"
3738
#include "gcr_regs.h"
39+
#include "flc_regs.h"
3840
#include "lp.h"
3941

4042
void MXC_LP_EnterSleepMode(void)
@@ -102,9 +104,94 @@ void MXC_LP_EnterShutDownMode(void)
102104
// Should never reach this line - device will reset on exit from shutdown mode.
103105
}
104106

105-
void MXC_LP_SetOVR(mxc_lp_ovr_t ovr)
107+
int MXC_LP_SetOVR(mxc_lp_ovr_t ovr)
106108
{
107-
//not supported yet
109+
uint32_t current_clock, div;
110+
int error;
111+
112+
// Ensure part is operating from internal LDO for core power
113+
if (MXC_PWRSEQ->lpcn & MXC_F_PWRSEQ_LPCN_LDO_DIS) {
114+
return E_BAD_STATE;
115+
}
116+
117+
// Select the 8KHz nanoring (no guarantee 32KHz is attached) as system clock source
118+
current_clock = MXC_GCR->clkctrl & MXC_F_GCR_CLKCTRL_SYSCLK_SEL;
119+
if (current_clock == MXC_SYS_CLOCK_IPO) {
120+
error = MXC_SYS_Clock_Select(MXC_SYS_CLOCK_INRO);
121+
if (error != E_NO_ERROR) {
122+
return error;
123+
}
124+
}
125+
126+
// Set flash wait state for any clock so its not to low after clock changes.
127+
MXC_GCR->memctrl = (MXC_GCR->memctrl & ~(MXC_F_GCR_MEMCTRL_FWS)) |
128+
(0x5UL << MXC_F_GCR_MEMCTRL_FWS_POS);
129+
130+
// Set the OVR bits
131+
// The OVR enums in mxc_lp_ovr_t equals to their appropriate register setting.
132+
MXC_SETFIELD(MXC_PWRSEQ->lpcn, MXC_F_PWRSEQ_LPCN_OVR, ovr);
133+
134+
// Set LVE bit
135+
if (ovr == MXC_LP_OVR_0_9) {
136+
MXC_FLC0->ctrl |= MXC_F_FLC_CTRL_LVE;
137+
138+
} else {
139+
MXC_FLC0->ctrl &= ~(MXC_F_FLC_CTRL_LVE);
140+
}
141+
142+
// Revert the clock to original state if it was IPO
143+
if (current_clock == MXC_SYS_CLOCK_IPO) {
144+
error = MXC_SYS_Clock_Select(MXC_SYS_CLOCK_IPO);
145+
if (error != E_NO_ERROR) {
146+
return error;
147+
}
148+
}
149+
150+
// Update SystemCoreClock variable
151+
SystemCoreClockUpdate();
152+
153+
// Get the clock divider
154+
div = (MXC_GCR->clkctrl & MXC_F_GCR_CLKCTRL_SYSCLK_DIV) >> MXC_F_GCR_CLKCTRL_SYSCLK_DIV_POS;
155+
156+
// Set Flash Wait States
157+
if (ovr == MXC_LP_OVR_0_9) {
158+
if (div == 0) {
159+
MXC_GCR->memctrl = (MXC_GCR->memctrl & ~(MXC_F_GCR_MEMCTRL_FWS)) |
160+
(0x2UL << MXC_F_GCR_MEMCTRL_FWS_POS);
161+
162+
} else {
163+
MXC_GCR->memctrl = (MXC_GCR->memctrl & ~(MXC_F_GCR_MEMCTRL_FWS)) |
164+
(0x1UL << MXC_F_GCR_MEMCTRL_FWS_POS);
165+
}
166+
167+
} else if (ovr == MXC_LP_OVR_1_0) {
168+
if (div == 0) {
169+
MXC_GCR->memctrl = (MXC_GCR->memctrl & ~(MXC_F_GCR_MEMCTRL_FWS)) |
170+
(0x2UL << MXC_F_GCR_MEMCTRL_FWS_POS);
171+
172+
} else {
173+
MXC_GCR->memctrl = (MXC_GCR->memctrl & ~(MXC_F_GCR_MEMCTRL_FWS)) |
174+
(0x1UL << MXC_F_GCR_MEMCTRL_FWS_POS);
175+
}
176+
177+
} else {
178+
if (div == 0) {
179+
MXC_GCR->memctrl = (MXC_GCR->memctrl & ~(MXC_F_GCR_MEMCTRL_FWS)) |
180+
(0x4UL << MXC_F_GCR_MEMCTRL_FWS_POS);
181+
182+
} else if (div == 1) {
183+
MXC_GCR->memctrl = (MXC_GCR->memctrl & ~(MXC_F_GCR_MEMCTRL_FWS)) |
184+
(0x2UL << MXC_F_GCR_MEMCTRL_FWS_POS);
185+
186+
} else {
187+
MXC_GCR->memctrl = (MXC_GCR->memctrl & ~(MXC_F_GCR_MEMCTRL_FWS)) |
188+
(0x1UL << MXC_F_GCR_MEMCTRL_FWS_POS);
189+
}
190+
}
191+
192+
// Caller must perform peripheral reset
193+
194+
return E_NO_ERROR;
108195
}
109196

110197
void MXC_LP_RetentionRegEnable(void)

0 commit comments

Comments
 (0)