Electrical – Atmel SWD. Enabling normal GPIO function on the SWO pin

atmelcortex-m4debugginggpioswd

I'm trying to make a project using the ATSAM4LS2A microcontroller (Cortex M4), and i'm using the AtmelICE debugger. The thing is the pinout for the SWD mode also has, beside the SWCLK and SWDIO pins, also the SWO pin (which should be optional). The problem is that the SWO pin is the same as the SCLK pin that i'm using for the SPI (trying to talk to a CC1101 transceiver).
Even if i don't connect the SWO pin, when i'm debugging and trying to read a byte from SPI i always get 0, even though i'm pretty sure it should be different.
So, my first question is, how would i be able to test that the SCLK pin in working in SCLK mode and not SWO mode?
Second question: How can i disable the SWO pin in case it isn't disabled automatically when it is not connected? (if possible).
Thanks.

Best Answer

I kinda forgot i posted this question here, but in the meantime I found the answer on some other site that I can't find right now.

You can disable the SWO functionality simply through this code:

#include <core_cm4.h>
void disableSWO(void)
{
    CoreDebug_Type *core = CoreDebug_BASE;
    core->DEMCR = (0<<CoreDebug_DEMCR_TRCENA_Pos);
}

Just call disableSWO() and SWO pin is disabled. I could debug while still keeping the SPI working.