# Atmel SWD. Enabling normal GPIO function on the SWO pin

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.

• There should be some kind of "function select" register, defining the function of this pin. Look at the datasheet/prog manual. – Eugene Sh. Jun 2 '16 at 17:41
• When you say while I'm debugging, do you mean you have an active toolchain connection over SWD concurrently? It is possible that the toolchain has done some default configuration to 'help' you. I can tell you for sure, SWO doesn't know if you connected to monitor it, the protocol is all one-way. – Sean Houlihane Jun 2 '16 at 22:31

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.