Use SWD as input

I'm using SWD as input.

It works, there is a pullup enabled.
x = ( REG_PORT_IN0 & PORT_PA31 ) // SWDIO - PA31
x = ( REG_PORT_IN0 & PORT_PA30 ) // SWDCLK - PA30

I am afraid that SWD activates

If I disable SWD, the input no longer works.

PORT->Group[PORTA].PINCFG[30].bit.PMUXEN = 0; // Remove other function from In11
PORT->Group[PORTA].PINCFG[31].bit.PMUXEN = 0; // Remove other function from In12

But if I could activate it, would I lose the possibility to program it via SWD ?
Or I lose only the debugging, but tanks reset programming work the same ?

help help help

If i don't disable SWD, at startup I read SWDIO-PA31 High
Only wen I rise and fall D8-PA6, after SWDIO-PA31 work well.

This code not work, I read always High Input

#define In11 !( REG_PORT_IN0 & PORT_PA31 )  // SWDIO  - PA31
#define In12 !( REG_PORT_IN0 & PORT_PA30 )  // SWDCLK - PA30

Setup{
  PORT->Group[PORTA].PINCFG[30].bit.PMUXEN = 0;   // Remove other function from In11
  PORT->Group[PORTA].PINCFG[31].bit.PMUXEN = 0;   // Remove other function from In12
  PORT->Group[PORTA].DIRCLR.reg = PORT_PA30;  // input
  PORT->Group[PORTA].DIRCLR.reg = PORT_PA31;
  PORT->Group[PORTA].OUTSET.reg = PORT_PA30;  // Pullup
  PORT->Group[PORTA].OUTSET.reg = PORT_PA31;
//  PORT->Group[PORTA].PINCFG[30].bit.DIRCLR = 1;   // Input
//  PORT->Group[PORTA].PINCFG[31].bit.DIRCLR = 1;
//  PORT->Group[PORTA].PINCFG[30].bit.OUTSET = 1;   // Pullup
//  PORT->Group[PORTA].PINCFG[31].bit.OUTSET

And I do not understand the difference between these two statements.
Way the firs work and the second give compilation error, DIRCLR does not exist?

  PORT->Group[PORTA].PINCFG[30].bit.PMUXEN = 0;   // Remove other function from In11
  PORT->Group[PORTA].PINCFG[30].bit.DIRCLR = 1;   // Inp

ut

Help

Hi x-giorgio-x,

I tested using the PA30 (SWCLK) pin as a GPIO input. It appears as though this input cannot be held low while the SAMD21 is booting, as it interferes with SWD port operation.

It's probably necessary for the outputs of any devices connected to these pins to be in a tri-state (high impedance) condition during either a power-up or reset.

How come you're using these pins for GPIO?

I need all the IO, included this.
I already have 100 cards made this way.

All work propely now.
But I'm afraid that by moving the inputs, SWD will activate if I have not disabled it.

#define In11 !( REG_PORT_IN0 & PORT_PA31 )  // SWDIO  - PA31
#define In12 !( REG_PORT_IN0 & PORT_PA30 )  // SWDCLK - PA30

void gevino_io_setup( void ){
//  PORT->Group[PORTA].PINCFG[30].bit.PMUXEN = 0;   // Remove other function from In11
//  PORT->Group[PORTA].PINCFG[31].bit.PMUXEN = 0;   // Remove other function from In12
  PORT->Group[PORTA].DIRCLR.reg = PORT_PA30;  // input
  PORT->Group[PORTA].DIRCLR.reg = PORT_PA31;
  PORT->Group[PORTA].OUTSET.reg = PORT_PA30;  // Pullup
  PORT->Group[PORTA].OUTSET.reg = PORT_PA31;
}

Hi x-giorgio-x,

Provided the SWCLK input is held high during power up, it should be possible to use it as standard GPIO pin during operation.

Here's some test code, pulling the SWCLK (PA30) input low switches off the Arduino Zero's LED on digital pin D13:

void setup() 
{
  PORT->Group[PORTA].PINCFG[30].bit.PULLEN = 1;     // Enable pull up resistor on SWCLK (PA30)
  PORT->Group[PORTA].DIRSET.reg = PORT_PA17;        // Set the Arduino Zero's D13 as an output
}

void loop() 
{
  if (PORT->Group[PORTA].IN.reg & PORT_PA30)        // Check if the SWCLK (PA30) pin is HIGH
  {
    PORT->Group[PORTA].OUTSET.reg = PORT_PA17;      // Set the Arduino Zero's LED on D13
  }
  else
  {
    PORT->Group[PORTA].OUTCLR.reg = PORT_PA17;      // Clear the Arduino Zero's LED on D13
  }
}

If I do not change PMUXE, i can read SWDIO and SWDCLK, only after a firt state change of SWCLK
After reset, i read SWDIO low, even if it is high.

If i put:
PORT->Group[PORTA].PINCFG[30].bit.PMUXEN = 0;
PORT->Group[PORTA].PINCFG[31].bit.PMUXEN = 0;
Nothing Work.

If i put:
PORT->Group[PORTA].PINCFG[30].bit.PMUXEN = 1;
PORT->Group[PORTA].PINCFG[31].bit.PMUXEN = 1;
IO work well.

But I do not understand what the manual says.
A .. H what bits are they ?

Putting to 1 what did I do?

Multiplexed Signals
Each pin is by default controlled by the PORT as a general purpose I/O and alternatively it can be
assigned to one of the peripheral functions A, B, C, D, E, F, G or H. To enable a peripheral function on a
pin, the Peripheral Multiplexer Enable bit in the Pin Configuration register corresponding to that pin
(PINCFGn.PMUXEN, n = 0-31) in the PORT must be written to one. The selection of peripheral function A
to H is done by writing to the Peripheral Multiplexing Odd and Even bits in the Peripheral Multiplexing
register (PMUXn.PMUXE/O) in the PORT.
This table describes the peripheral signals multiplexed to the PORT I/O pins.