Devin Wolfe

Debugger explodes on GPIO write

Discussion created by Devin Wolfe on May 15, 2018
Latest reply on May 22, 2018 by Jorge Antonio Alcala Vazquez

I'm trying to debug a program I wrote for an MKL26Z MCU.  The MCU is on a custom PCB, in the CAL4 WLSCP package.  Debugging is happening using SWD, with SWDIO, SWCLK and reset connected.  SWDIO is pulled up with a 10K, clock is pulled down with a 10K, and the reset pin is pulled up with a 10K and a cap to ground, as recommended.  I am using a Segger Base debugger, and KDS 3.2.


During the startup process, I set some GPIO to enable or disable various supplies/clocks/peripherals etc.  On the first call of the GPIO_DRV_WritePinOutput() function (KSDK 1.3), the debugger freaks out and halts execution.  I attached screenshots showing the behavior, before and after I step the line that causes the problem (before/after.png).  Stepping into the function, the most granular instruction I can find related to the error is GPIO_WR_PSOR, which is just a macro to write the PSOR register for a GPIO pin.


In my main, the processor expert init function is being called before the GPIO write, and I have configured GPIO for auto-initialization in PE.  There are no interrupts on the pin.  Interestingly, the problem does not appear to be specific to that particular function call.  If I comment out the first GPIO write function call, the debugger fails on the next call.  However, the problem is definitely related to that code - if I comment out the function in which the GPIO write is being called, I can debug and the program executes as expected.


Interestingly, if I close the debugger session after the device has been flashed, my program executes correctly.  It has a UART command line interface, and I can send commands, receive responses, and observe correct peripheral behavior.  The problem seems to be isolated to debugging the unit.


Anyone have an idea about what is happening here?