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): Add OTP Powerdown feature for MAX32572 #952

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "max32572.h"
#include "mxc_device.h"
#include "gcr_regs.h"
#include "mxc_sys.h"
#include "usbhs_regs.h"
#include "sfcc.h"

extern void (*const __isr_vector[])(void);

Expand Down
7 changes: 7 additions & 0 deletions Libraries/PeriphDrivers/Include/MAX32572/otp.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ typedef enum { MXC_OTP_READ_OP, MXC_OTP_WRITE_OP } mxc_otp_op_t;
*/
int MXC_OTP_Init(mxc_otp_clkdiv_t pclkdiv);

/**
* @brief Power down the OTP Controller.
*
* @return #E_NO_ERROR if everything is successful, \ref MXC_Error_Codes "error" if unsuccessful.
*/
int MXC_OTP_PowerDown(void);

/**
* @brief Checks whether the OTP user block is locked/unlocked.
*
Expand Down
5 changes: 5 additions & 0 deletions Libraries/PeriphDrivers/Source/OTP/otp_me55.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ int MXC_OTP_Init(mxc_otp_clkdiv_t pclkdiv)
return MXC_OTP_RevA_Init((mxc_otp_reva_regs_t *)MXC_OTP, pclkdiv);
}

int MXC_OTP_PowerDown(void)
{
return MXC_OTP_RevA_PowerDown((mxc_otp_reva_regs_t *)MXC_OTP);
}

int MXC_OTP_IsLocked(void)
{
return MXC_OTP_RevA_IsLocked((mxc_otp_reva_regs_t *)MXC_OTP);
Expand Down
18 changes: 18 additions & 0 deletions Libraries/PeriphDrivers/Source/OTP/otp_reva.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

/* **** Includes **** */
#include <stddef.h>
#include "mxc_delay.h"
#include "mxc_device.h"
#include "mxc_assert.h"
#include "mxc_errors.h"
Expand All @@ -37,6 +38,23 @@ int MXC_OTP_RevA_Init(mxc_otp_reva_regs_t *otp, mxc_otp_clkdiv_t pclkdiv)
return E_NO_ERROR;
}

int MXC_OTP_RevA_PowerDown(mxc_otp_reva_regs_t *otp)
{
otp->clkdiv |= MXC_F_OTP_REVA_CLKDIV_PD;

// Must wait 20HCLK cycles after powering down OTP and before
// disabling the OTP clock, so the OTP_STATUS.pwr_rdy
// is properly updated.
MXC_Delay(10);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this delay necessary if we poll the RDY bit before disabling the clock?


MXC_SYS_ClockDisable(MXC_SYS_PERIPH_CLOCK_OTP);

// Poll status bit until OTP is powered off.
while (otp->status & MXC_F_OTP_REVA_STATUS_PWR_RDY) {}

return E_NO_ERROR;
}

int MXC_OTP_RevA_IsLocked(mxc_otp_reva_regs_t *otp)
{
return !(otp->status & MXC_F_OTP_REVA_STATUS_UNLOCK1);
Expand Down
2 changes: 2 additions & 0 deletions Libraries/PeriphDrivers/Source/OTP/otp_reva.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ extern "C" {

int MXC_OTP_RevA_Init(mxc_otp_reva_regs_t *otp, mxc_otp_clkdiv_t pclkdiv);

int MXC_OTP_RevA_PowerDown(mxc_otp_reva_regs_t *otp);

int MXC_OTP_RevA_IsLocked(mxc_otp_reva_regs_t *otp);

void MXC_OTP_RevA_Unlock(mxc_otp_reva_regs_t *otp);
Expand Down
Loading