Hi all,
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)(
SIM_SOPT_SWDE_MASK
)));
// 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)(
PORT_PUEL_PTCPE4_MASK |
PORT_PUEL_PTAPE4_MASK
)));
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)(
GPIO_PDDR_PDD(0x00100000)
)) | (uint32_t)(
GPIO_PDDR_PDD(0x00000010)
));
// Enable port input of PTA4 and PTC4
GPIOA_PIDR = (uint32_t)((GPIOA_PIDR & (uint32_t)~(uint32_t)(
GPIO_PIDR_PID(0x00100010)
)));
..................... // do some stuff
// Reset ports to the start-up default settings
PORT_Init();
GPIOA_Init();
// Restore SWD debug functionality
/* SIM_SOPT: SWDE=1 */
SIM_SOPT = (uint32_t)((SIM_SOPT | (uint32_t)(
SIM_SOPT_SWDE_MASK
)));
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,
Sandro
Solved! Go to Solution.
Hi Sandro,
I've had a brief look through the SCH of the debug interface you shared, it seems ok.
Actually, I'm not 100% sure of the PE Micro U-MULTILINK support to reset the device when at the beginning of the programming, and it works at my board.
So I'd like to suggest that you can follow the procedure below to debug the board now and you can also create a thread in PE community for confirm this with
PE support engineers, they're expert of the PE Micro U-MULTILINK tool.
Procedure:
1. First, Press and hold the reset button;
2. Next click the debug option in the IDE;
3. Then Release the reset button, the IDE will enter debug mode automatically.
PE community:
Have a great day,
Ping
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Help, any feedback please?
gaston
Hi Sandro,
Please follows the steps to enter the debug mode again when SWD_DIO and SWD_CLK work as GPIO function previous.
1. First, Press and hold the reset button;
2. Next click the debug option in the IDE;
3. Then Release the reset button, the IDE will enter debug mode automatically.
Have a great day,
Ping
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Dear Ping,
thank u for the answer, but I dont see any reset button on the debugger...did u mean reset button on the board?
We dont have any reset button, I'm sorry but I didnt specifiy that the board isnt a freescale demo board, it's an our-production board, without a reset button on the RESET/PTA5 port of the controller.
Anyway, we had the same idea, and we tried to put a "flying" button between RESET pin and ground, and make the same steps u described, but without success.
The only way to unlock the situation, is using another programmer, for example PE Cyclone Max.
My principal question is so: why Multilink cant enter in debug/programming mode? And first of all, using ports as GPIO can really broke the debugger? Is this possible?
I hope u can help us,
Thanks again,
Sandro
Hi Sandro,
Please share me your whole code, then I can reproduce the issue on my FRDM-KE02 board.
I'm looking forward to your reply.
Have a great day,
Ping
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Thanks Ping,
I cannot provide all my code (confidential), but I attached the project, without the not-necessary code.
The project is made with CW 10.6, using Processor Expert for generating controller configurations. I think u can import it in a fresh workspace without problem
So u have all the code from PE, and the code from myself regarding the issue.
Take a look to the InspectReq() function, there the problem raise.
In few words, we generate a square wave from PTA4 (SWD), and we read it in PTC4 (CLK). If on PTC4 we read the same as PTA4, we go to the Inspect() function (shortcircuit-like).
But what it interesting to u it's all in the InspectReq().
Only one thing I couldnt provide: in InspectReq() there is a missing Wait function between the PTA4 toggles and the PTC4 reads, put one yourself (for cycle for example).
Let me know if u find something wrong.
Thanks,
Sandro
Careful Ping! Our ports configurations are totally different from the demo board! :-)
Hi Sandro,
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.
Have a great day,
Ping
-----------------------------------------------------------------------------------------------------------------------
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
// )));
}
Dear Ping,
thank u for the precise answer, I see one difference in your code: why did u commented the last line of code, where we restore the SIM_SOPT register?
We have this dubt: the freedom board has the SWD pin connected to the Open SDA interface: is somewhere in this connection a pull-up?
Because our board hasnt any pull-up system connected to SWD pin, externally of the controller there isnt connected anything. Can be this a problem? We read somewhere that external pull-up is NOT necessary, but someone suggest it...
We made the programming circuit according to the FRDM-KE02Z schematics, taking out the OpenSDA section, so no pull-up.
Also because we read that there should just be a pull-up connected to SWD inside the controller (as described in datasheet, chapter "Debug"), is this right?
I ask u this because we tried to connect a 10K pull-up between SWD and VDD, and it seemed that the controller came "alive" again. But also, this MAYBE broken the Multilink...
How many times did u try to program the board with this project? I mean, with board still powered up. Cause not always gets locked, but after a while.
We now have only one Multilink, so we cant right now do riskious tests... :smileyhappy:
I wait your considerations, thanks a lot for the helps!
Regards
Sandro
Hi Sandro,
I've tried several times continuously, it didn't jump out any messages that notify programming errors.
I canceled the last line of code then can make the SWD_DIO and SWD_CLK work as GPIO function originally when I want to program it again.
So I think it doesn't matter and I also tried without canceling the last line of code, the PE Micro U-MULTILINK still worked.
I'd highly recommend that refer to attachment for designing the debug interface, then give a shot again.
Have a great day,
Ping
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi Ping,
sorry for my late response, I missed your one until now :smileysad:
Anyway, we tried to pull-up the SWD_DIO pin, but the problem remains.
More precisely, the problem that remains is when we DONT come back to original pin funciontality, but only when we stay in GPIO mode.
It seems that PE Multilink isnt able to reset the device, when ports PTA4 and PTC4 are configured as GPIOs: in fact, just I said before, we added a reset button between RESET and GND; if we do a reset with the button, and then we start to program with Multilink, it works!
I attach a schematic of connections in our board, and some of the errors that occurs when we program with CW 10.6.
Thanks a lot for helping.
Have a nice day too!
Sandro
Hi Sandro,
I've had a brief look through the SCH of the debug interface you shared, it seems ok.
Actually, I'm not 100% sure of the PE Micro U-MULTILINK support to reset the device when at the beginning of the programming, and it works at my board.
So I'd like to suggest that you can follow the procedure below to debug the board now and you can also create a thread in PE community for confirm this with
PE support engineers, they're expert of the PE Micro U-MULTILINK tool.
Procedure:
1. First, Press and hold the reset button;
2. Next click the debug option in the IDE;
3. Then Release the reset button, the IDE will enter debug mode automatically.
PE community:
Have a great day,
Ping
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi Ping,
I'm facing the same issue but using USBDM 4.11.1.60 (KL25Z FRDM based) instead of the P&E Micro debugger. Definitely I'm not able to program/debug the MKE02Z64 after configuring SWD as GPIO output.
As Sandro has suggested I've added a 10k pull-up on SWD_DIO pin and a HW reset on my board. Then I've followed the steps you've enumerated. Nothing. The board is still locked. Here's the GDB server error message
Any hints?
regards,
gaston
Hi Ping,
thanks for the answer, we didnt know that Multilink maybe couldnt reset the device, I think this is the point.
So, we will add a reset button when we need :smileyhappy:
Thanks for evenrything!
Have a great day,
Sandro