SWDIO and SWCLK pads on XIAO SAMD21

Is it possible to use the SWDIO and SWCLK pads on the back of the XIAO SAMD21 as general purpose GPIO pins ?

According to the circuit diagram,
SWCLK = PA30 and SWDIO = PA31.
Please try it.

2 Likes

Thanks for the reply.

I did try to setup as input and output on pin 30,31 but it does not work, locks up the SAMD21, even if you start setup() with a short delay.

pins_Arduino.h apparently has them defined as;

#define D29 (30u)
#define D30 (31u)

(BTW I am fully aware that the same physical pads on the ESP32S3 XIAO can be used as GPIOs, bit its not relevant to the SAMD21 or nRF52840 variants)

This post on the Microchip forum;

https://forum.microchip.com/s/topic/a5C3l000000UhMYEA0/t179797

Suggests you can use the CLK and DIO as GPIO pins ………………

1 Like

You might need to set the port muxes first.
I delay by a few seconds before doing this to have time to erase or flash via SWD if necessary.

  // Allow time for SWD access...
  delay(5000);

  // Disable peripheral multiplexing to ensure full GPIO control
  PORT->Group[PORTA].PINCFG[30].bit.PMUXEN = 0;  // PA30 (SWCLK)
  PORT->Group[PORTA].PINCFG[31].bit.PMUXEN = 0;  // PA31 (SWDIO)

  // Set pins as outputs
  PORT->Group[PORTA].DIRSET.reg = (1 << 30) | (1 << 31);  // Set PA30 and PA31 as outputs


//*** In loop ***
  // Toggle pins
  PORT->Group[PORTA].OUTTGL.reg = (1 << 30);
  PORT->Group[PORTA].OUTTGL.reg = (1 << 31);

See Datasheet page 29.

1 Like

Excellant, that works !.

After setting up the IO Multiplexing, as per your post, I was able to blink an LED on the SW pins like so;

PORT->Group[PORTA].OUTSET.reg = 1 << 30 ; //set pin 30 high
delay(100);
PORT->Group[PORTA].OUTCLR.reg = 1 << 30 ; //set pin 30 low
delay(899);

And presumably its also possible to set the pins as inputs etc.

Whilst that does allow direct drive of the SW pins would there be a way of passing the pins as a reference for a control pin to an Arduino library, say if you wanted to use one of the SW pins as the select pin on a TFT display or SD card ?

You would probably need to modify the library to support those pins. I could check in the morning, 10pm here now. :zzz: