Skip to content

Commit

Permalink
feat(PeriphDrivers): Add API to lock Debug Access Port (#845)
Browse files Browse the repository at this point in the history
Co-authored-by: Jake Carter <[email protected]>
  • Loading branch information
Jacob-Scheiffler and Jake-Carter authored Feb 12, 2024
1 parent d4a64f0 commit 1498581
Show file tree
Hide file tree
Showing 29 changed files with 697 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Libraries/CMSIS/Device/Maxim/MAX32650/Include/max32650.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ typedef enum {
#define MXC_FLASH_PAGE_SIZE 0x00004000UL
#define MXC_FLASH_MEM_SIZE 0x00300000UL
#define MXC_INFO_MEM_BASE 0x10800000UL
#define MXC_INFO_MEM_SIZE 0x00008000UL
#define MXC_INFO_MEM_SIZE 0x00004000UL
#define MXC_SRAM_MEM_BASE 0x20000000UL
#define MXC_SRAM_MEM_SIZE 0x00100000UL
#define MXC_HBMC_MEM_BASE 0x60000000UL
Expand Down
8 changes: 8 additions & 0 deletions Libraries/PeriphDrivers/Include/MAX32520/mxc_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,14 @@ uint8_t MXC_SYS_GetRev(void);
*/
int MXC_SYS_GetUSN(uint8_t *serialNumber, int len);

/**
* @brief This function PERMANENTLY locks the Debug Access Port.
*
* @warning After executing this function you will never be able
* to reprogram the target micro.
*/
int MXC_SYS_LockDAP_Permanent(void);

#ifdef __cplusplus
}
#endif
Expand Down
8 changes: 8 additions & 0 deletions Libraries/PeriphDrivers/Include/MAX32570/mxc_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,14 @@ uint8_t MXC_SYS_GetRev(void);
*/
int MXC_SYS_GetUSN(uint8_t *serialNumber, int len);

/**
* @brief This function PERMANENTLY locks the Debug Access Port.
*
* @warning After executing this function you will never be able
* to reprogram the target micro.
*/
int MXC_SYS_LockDAP_Permanent(void);

#ifdef __cplusplus
}
#endif
Expand Down
8 changes: 8 additions & 0 deletions Libraries/PeriphDrivers/Include/MAX32650/mxc_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,14 @@ uint32_t MXC_SYS_SysTick_GetFreq(void);
*/
int MXC_SYS_SysTick_DelayUs(uint32_t us);

/**
* @brief This function PERMANENTLY locks the Debug Access Port.
*
* @warning After executing this function you will never be able
* to reprogram the target micro.
*/
int MXC_SYS_LockDAP_Permanent(void);

/**@} end of group mxc_sys */

#ifdef __cplusplus
Expand Down
8 changes: 8 additions & 0 deletions Libraries/PeriphDrivers/Include/MAX32655/mxc_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,14 @@ void MXC_SYS_RISCVShutdown(void);
*/
uint32_t MXC_SYS_RiscVClockRate(void);

/**
* @brief This function PERMANENTLY locks the Debug Access Port.
*
* @warning After executing this function you will never be able
* to reprogram the target micro.
*/
int MXC_SYS_LockDAP_Permanent(void);

#ifdef __cplusplus
}
#endif
Expand Down
9 changes: 9 additions & 0 deletions Libraries/PeriphDrivers/Include/MAX32660/mxc_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,21 @@ mxc_sys_system_clock_div_t MXC_SYS_GetClockDiv(void);
* @return E_NO_ERROR if ready, E_TIME_OUT if timeout
*/
int MXC_SYS_Clock_Timeout(uint32_t ready);

/**
* @brief Reset the peripherals and/or CPU in the rstr0 or rstr1 register.
* @param Enumeration for what to reset. Can reset multiple items at once.
*/
void MXC_SYS_Reset_Periph(mxc_sys_reset_t reset);

/**
* @brief This function PERMANENTLY locks the Debug Access Port.
*
* @warning After executing this function you will never be able
* to reprogram the target micro.
*/
int MXC_SYS_LockDAP_Permanent(void);

#ifdef __cplusplus
}
#endif
Expand Down
9 changes: 9 additions & 0 deletions Libraries/PeriphDrivers/Include/MAX32662/mxc_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,12 +328,21 @@ mxc_sys_system_clock_div_t MXC_SYS_GetClockDiv(void);
* @return E_NO_ERROR if ready, E_TIME_OUT if timeout
*/
int MXC_SYS_Clock_Timeout(uint32_t ready);

/**
* @brief Reset the peripherals and/or CPU in the rstr0 or rstr1 register.
* @param Enumeration for what to reset. Can reset multiple items at once.
*/
void MXC_SYS_Reset_Periph(mxc_sys_reset_t reset);

/**
* @brief This function PERMANENTLY locks the Debug Access Port.
*
* @warning After executing this function you will never be able
* to reprogram the target micro.
*/
int MXC_SYS_LockDAP_Permanent(void);

#ifdef __cplusplus
}
#endif
Expand Down
8 changes: 8 additions & 0 deletions Libraries/PeriphDrivers/Include/MAX32665/mxc_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,14 @@ void MXC_SYS_Reset_Periph(mxc_sys_reset_t reset);
*/
uint8_t MXC_SYS_GetRev(void);

/**
* @brief This function PERMANENTLY locks the Debug Access Port.
*
* @warning After executing this function you will never be able
* to reprogram the target micro.
*/
int MXC_SYS_LockDAP_Permanent(void);

#ifdef __cplusplus
}
#endif
Expand Down
9 changes: 9 additions & 0 deletions Libraries/PeriphDrivers/Include/MAX32670/mxc_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,21 @@ mxc_sys_system_clock_div_t MXC_SYS_GetClockDiv(void);
* @return E_NO_ERROR if ready, E_TIME_OUT if timeout
*/
int MXC_SYS_Clock_Timeout(uint32_t ready);

/**
* @brief Reset the peripherals and/or CPU in the rstr0 or rstr1 register.
* @param reset The peripheral to reset
*/
void MXC_SYS_Reset_Periph(mxc_sys_reset_t reset);

/**
* @brief This function PERMANENTLY locks the Debug Access Port.
*
* @warning After executing this function you will never be able
* to reprogram the target micro.
*/
int MXC_SYS_LockDAP_Permanent(void);

#ifdef __cplusplus
}
#endif
Expand Down
9 changes: 9 additions & 0 deletions Libraries/PeriphDrivers/Include/MAX32672/mxc_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,21 @@ mxc_sys_system_clock_div_t MXC_SYS_GetClockDiv(void);
* @return E_NO_ERROR if ready, E_TIME_OUT if timeout
*/
int MXC_SYS_Clock_Timeout(uint32_t ready);

/**
* @brief Reset the peripherals and/or CPU in the rstr0 or rstr1 register.
* @param Enumeration for what to reset. Can reset multiple items at once.
*/
void MXC_SYS_Reset_Periph(mxc_sys_reset_t reset);

/**
* @brief This function PERMANENTLY locks the Debug Access Port.
*
* @warning After executing this function you will never be able
* to reprogram the target micro.
*/
int MXC_SYS_LockDAP_Permanent(void);

#ifdef __cplusplus
}
#endif
Expand Down
9 changes: 9 additions & 0 deletions Libraries/PeriphDrivers/Include/MAX32675/mxc_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,21 @@ mxc_sys_system_clock_div_t MXC_SYS_GetClockDiv(void);
* @return E_NO_ERROR if ready, E_TIME_OUT if timeout
*/
int MXC_SYS_Clock_Timeout(uint32_t ready);

/**
* @brief Reset the peripherals and/or CPU in the rstr0 or rstr1 register.
* @param Enumeration for what to reset. Can reset multiple items at once.
*/
void MXC_SYS_Reset_Periph(mxc_sys_reset_t reset);

/**
* @brief This function PERMANENTLY locks the Debug Access Port.
*
* @warning After executing this function you will never be able
* to reprogram the target micro.
*/
int MXC_SYS_LockDAP_Permanent(void);

#ifdef __cplusplus
}
#endif
Expand Down
8 changes: 8 additions & 0 deletions Libraries/PeriphDrivers/Include/MAX32680/mxc_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,14 @@ void MXC_SYS_RISCVShutdown(void);
*/
uint32_t MXC_SYS_RiscVClockRate(void);

/**
* @brief This function PERMANENTLY locks the Debug Access Port.
*
* @warning After executing this function you will never be able
* to reprogram the target micro.
*/
int MXC_SYS_LockDAP_Permanent(void);

#ifdef __cplusplus
}
#endif
Expand Down
8 changes: 8 additions & 0 deletions Libraries/PeriphDrivers/Include/MAX32690/mxc_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,14 @@ void MXC_SYS_RISCVShutdown(void);
*/
uint32_t MXC_SYS_RiscVClockRate(void);

/**
* @brief This function PERMANENTLY locks the Debug Access Port.
*
* @warning After executing this function you will never be able
* to reprogram the target micro.
*/
int MXC_SYS_LockDAP_Permanent(void);

#ifdef __cplusplus
}
#endif
Expand Down
8 changes: 8 additions & 0 deletions Libraries/PeriphDrivers/Include/MAX78000/mxc_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,14 @@ void MXC_SYS_RISCVShutdown(void);
*/
uint32_t MXC_SYS_RiscVClockRate(void);

/**
* @brief This function PERMANENTLY locks the Debug Access Port.
*
* @warning After executing this function you will never be able
* to reprogram the target micro.
*/
int MXC_SYS_LockDAP_Permanent(void);

#ifdef __cplusplus
}
#endif
Expand Down
8 changes: 8 additions & 0 deletions Libraries/PeriphDrivers/Include/MAX78002/mxc_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,14 @@ void MXC_SYS_RISCVShutdown(void);
*/
uint32_t MXC_SYS_RiscVClockRate(void);

/**
* @brief This function PERMANENTLY locks the Debug Access Port.
*
* @warning After executing this function you will never be able
* to reprogram the target micro.
*/
int MXC_SYS_LockDAP_Permanent(void);

#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions Libraries/PeriphDrivers/Source/FLC/flc_me10.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ int MXC_FLC_ME10_GetByAddress(mxc_flc_regs_t **flc, uint32_t addr)
int MXC_FLC_ME10_GetPhysicalAddress(uint32_t addr, uint32_t *result)
{
if ((addr >= MXC_FLASH_MEM_BASE) && (addr < (MXC_FLASH_MEM_BASE + MXC_FLASH_MEM_SIZE))) {
*result = addr - MXC_FLASH_MEM_BASE;
*result = (addr & (MXC_FLASH_MEM_SIZE - 1));
} else if ((addr >= MXC_INFO_MEM_BASE) && (addr < (MXC_INFO_MEM_BASE + MXC_INFO_MEM_SIZE))) {
*result = (addr & (MXC_INFO_MEM_SIZE - 1)) + MXC_FLASH_MEM_SIZE;
*result = (addr & (MXC_INFO_MEM_SIZE - 1)) + (MXC_INFO_MEM_BASE - MXC_FLASH_MEM_BASE);
} else {
return E_BAD_PARAM;
}
Expand Down
44 changes: 44 additions & 0 deletions Libraries/PeriphDrivers/Source/SYS/sys_ai85.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
/* **** Definitions **** */
#define MXC_SYS_CLOCK_TIMEOUT MSEC(1)

// DAP Lock macros
#define INFOBLOCK_DAP_LOCK_OFFSET 0x30
#define DAP_LOCK_SEQUENCE_01 0x5A5AA5A5
#define DAP_LOCK_SEQUENCE_23 0xFFFFFFFF

/* **** Globals **** */

/* Symbol defined by the build system when loading RISCV image */
Expand Down Expand Up @@ -554,4 +559,43 @@ uint32_t MXC_SYS_RiscVClockRate(void)
}
}

/* ************************************************************************** */
int MXC_SYS_LockDAP_Permanent(void)
{
#ifdef DEBUG
// Locking the DAP is not supported while in DEBUG.
// To use this function, build for release ("make release")
// or set DEBUG = 0
// (see https://analog-devices-msdk.github.io/msdk/USERGUIDE/#build-tables)
return E_NOT_SUPPORTED;
#else
int err;
uint32_t info_blk_addr;
uint32_t lock_sequence[4];

// Infoblock address to write lock sequence to
info_blk_addr = MXC_INFO_MEM_BASE + INFOBLOCK_DAP_LOCK_OFFSET;

// Set lock sequence
lock_sequence[0] = DAP_LOCK_SEQUENCE_01;
lock_sequence[1] = DAP_LOCK_SEQUENCE_01;
lock_sequence[2] = DAP_LOCK_SEQUENCE_23;
lock_sequence[3] = DAP_LOCK_SEQUENCE_23;

// Initialize FLC
MXC_FLC_Init();

// Unlock infoblock
MXC_FLC_UnlockInfoBlock(info_blk_addr);

// Write DAP lock sequence to infoblock
err = MXC_FLC_Write128(info_blk_addr, lock_sequence);

// Re-lock infoblock
MXC_FLC_LockInfoBlock(info_blk_addr);

return err;
#endif
}

/**@} end of mxc_sys */
44 changes: 44 additions & 0 deletions Libraries/PeriphDrivers/Source/SYS/sys_ai87.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
/* **** Definitions **** */
#define MXC_SYS_CLOCK_TIMEOUT MSEC(5)

// DAP Lock macros
#define INFOBLOCK_DAP_LOCK_OFFSET 0x30
#define DAP_LOCK_SEQUENCE_01 0x5A5AA5A5
#define DAP_LOCK_SEQUENCE_23 0xFFFFFFFF

/* **** Globals **** */

/* Symbol defined by the build system when loading RISCV image */
Expand Down Expand Up @@ -554,4 +559,43 @@ uint32_t MXC_SYS_RiscVClockRate(void)
}
}

/* ************************************************************************** */
int MXC_SYS_LockDAP_Permanent(void)
{
#ifdef DEBUG
// Locking the DAP is not supported while in DEBUG.
// To use this function, build for release ("make release")
// or set DEBUG = 0
// (see https://analog-devices-msdk.github.io/msdk/USERGUIDE/#build-tables)
return E_NOT_SUPPORTED;
#else
int err;
uint32_t info_blk_addr;
uint32_t lock_sequence[4];

// Infoblock address to write lock sequence to
info_blk_addr = MXC_INFO_MEM_BASE + INFOBLOCK_DAP_LOCK_OFFSET;

// Set lock sequence
lock_sequence[0] = DAP_LOCK_SEQUENCE_01;
lock_sequence[1] = DAP_LOCK_SEQUENCE_01;
lock_sequence[2] = DAP_LOCK_SEQUENCE_23;
lock_sequence[3] = DAP_LOCK_SEQUENCE_23;

// Initialize FLC
MXC_FLC_Init();

// Unlock infoblock
MXC_FLC_UnlockInfoBlock(info_blk_addr);

// Write DAP lock sequence to infoblock
err = MXC_FLC_Write128(info_blk_addr, lock_sequence);

// Re-lock infoblock
MXC_FLC_LockInfoBlock(info_blk_addr);

return err;
#endif
}

/**@} end of mxc_sys */
Loading

0 comments on commit 1498581

Please sign in to comment.