we are facing problem as in subject, about Sharing SWD debug ports with GPIO features.
Is it possible to use the programming / debugging ports SWD_DIO and SWD_CLK as general purpose I/O on MKE02Z64VLH4 controller?
Following datasheet, I set up SIM_SOPT register, putting SWDE = 0.
After this I set GPIO register for using SWD_DIO/PTA4 as output port, and SWD_CLK/PTC4 as input port. Both ports have pull-up disabled. Here is portion of code (some of it is "copied" from Processor Expert generation):
/* SIM_SOPT: SWDE=0 */
SIM_SOPT = (uint32_t)((SIM_SOPT & (uint32_t)~(uint32_t)(
// setting SWD as GPIO ports configuration
// 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)(
GPIOA_PSOR &= (uint32_t)~(uint32_t)(0x00000010);
// PTA4 = 0
GPIOA_PCOR |= (uint32_t)(0x00000010);
// PTC4 input. PTA4 output
GPIOA_PDDR = (uint32_t)((GPIOA_PDDR & (uint32_t)~(uint32_t)(
)) | (uint32_t)(
// Enable port input of PTA4 and PTC4
GPIOA_PIDR = (uint32_t)((GPIOA_PIDR & (uint32_t)~(uint32_t)(
..................... // do some stuff
// Reset ports to the start-up default settings
// Restore SWD debug functionality
/* SIM_SOPT: SWDE=1 */
SIM_SOPT = (uint32_t)((SIM_SOPT | (uint32_t)(
The result is that after some programmings, using PE Micro U-MULTILINK with SWD connection, che controller become non-programmable anymore.
Programming procedure's log reports the error "Memory secured" (or "Memory protected", I'm sorry but I cant remeber precisly...).
So, I have a dubt: before start programming, shouldn't the MULTILINK do a controller reset and, consequently, gets control on programming lines?
Moreover and seriously bad, after some attempts, the debbuger got broken...!
I have read this post, it seems he has similar issue: Controller gets locked if SWDE pins are configured as GPIO
But I see no solving answer...
What can be problem, is there some mistakes in the code? Can u help me?
Thanks in advance,