Thanks for your sharing.
I've ported the InspectReq() to a helio_world demo from the code your shared and you can find MY codes below.
However I didn't encounter the issue you mentioned, the FRDM-KE02Z board can be programmed again by PE Micro U-MULTILINK after the PTA4 and PTC4 work as the GPIO.
Hope it helps.
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2011-2012 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
*******************************************************************************
*
* @file SWD_Issue.c
*
* @author a13984
*
* @version 0.0.1
*
* @date Jul-15-2011
*
* @brief providing framework of test cases for MCU.
*
*******************************************************************************/
#include "common.h"
#include "rtc.h"
/******************************************************************************
* Global variables
******************************************************************************/
/******************************************************************************
* Constants and macros
******************************************************************************/
/******************************************************************************
* Local types
******************************************************************************/
/******************************************************************************
* Local function prototypes
******************************************************************************/
/******************************************************************************
* Local variables
******************************************************************************/
/******************************************************************************
* Local functions
******************************************************************************/
int main (void);
void RTC_Task(void);
void InspectReq(void);
/******************************************************************************
* Global functions
******************************************************************************/
#define inINSP() ((GPIOA_PDIR & GPIO_PDIR_PDI(1 << 20)) >> 20) ///< PTC4 read
#define inOutINSP() ((GPIOA_PDOR & GPIO_PDOR_PDO(1 << 4)) >> 4) ///< PTA4 read
/********************************************************************/
int main (void)
{
char ch;
printf("\nRunning the SWD_Issue project.\n");
LED0_Init();
LED2_Init();
RTC_SetupTimerCallback(RTC_Task);
RTC_Init(RTC_CLKSRC_1KHZ,3, RTC_CLK_PRESCALER_100);
InspectReq();
while(1)
{
ch = in_char();
out_char(ch);
}
}
/*****************************************************************************//*!
+FUNCTION----------------------------------------------------------------
* @function name: RTC_Task
*
* @brief callback routine of RTC driver which does what you want to do at
* every RTC period.
*
* @param none
*
* @return none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/
void RTC_Task(void)
{
/* toggle LED1 */
LED0_Toggle();
}
/********************************************************************/
void InspectReq(void) {
// Forza le porte SWD e CLK a diventare porta di GPIO (I/O generico)
/* SIM_SOPT: SWDE=0 */
SIM_SOPT = (uint32_t)((SIM_SOPT & (uint32_t)~(uint32_t)(
SIM_SOPT_SWDE_MASK
)));
// Imposta le porte PTA4 e PTC4 nel modo corretto
// PTA4 = Output, Pull up disabled, PTC4 = Input Pull up disabled
/* PORT_PUEL: PTCPE4=0,PTAPE4=0 */
PORT_PUEL = (uint32_t)((PORT_PUEL & (uint32_t)~(uint32_t)(
PORT_PUEL_PTCPE4_MASK |
PORT_PUEL_PTAPE4_MASK
)));
/* GPIOA_PSOR: PTSO&=~0x00000010 */
GPIOA_PSOR &= (uint32_t)~(uint32_t)(0x00000010);
/* GPIOA_PCOR: PTCO|=0x00000010 */
GPIOA_PCOR |= (uint32_t)(0x00000010);
/* GPIOA_PDDR: PDD&=~0x00100000,PDD|=0x00000010 */
GPIOA_PDDR = (uint32_t)((GPIOA_PDDR & (uint32_t)~(uint32_t)(
GPIO_PDDR_PDD(0x00100000)
)) | (uint32_t)(
GPIO_PDDR_PDD(0x00000010)
));
/* GPIOA_PIDR: PID&=~0x00100010 */
GPIOA_PIDR = (uint32_t)((GPIOA_PIDR & (uint32_t)~(uint32_t)(
GPIO_PIDR_PID(0x00100010)
)));
LED1_Toggle();
// // Restore programming pin (SWD e CLK)
// /* SIM_SOPT: SWDE=1 */
// SIM_SOPT = (uint32_t)((SIM_SOPT | (uint32_t)(
// SIM_SOPT_SWDE_MASK
// )));
}