Arduino Support for 64-pin SAMD21 package

Hi All,

I am trying to setup a workspace and work on a project using one of the 64-pin SAMD21 ICs.

I have been able to identify various 48-pin packages and SAM21 Arduino Boards supported by the software. However, I am unable to see as much support for the 64-pin package.

Does the latest Arduino IDE (v1.18.9) support the configuration of the 64-pin SAMD21J package? Is there any documentation provided by Arduino discussing the steps involved and software packages to be installed?

If not, is it a work in progress or is there any other solution for using the 64-pin SAMD21 packages with Arduino?

Looking forward to your response. Thank you.

Best Regards,
Bhindhiya Raja

It looks like the excellent "MattairTech SAM D|L|C core for Arduino" boards platform has support for the ATSAMD21J:

https://github.com/mattairtech/ArduinoCore-samd#features-summary-for-d21l21c21d11

You can install it via Boards Manager by following these instructions:

https://github.com/mattairtech/ArduinoCore-samd#mattairtech-dlc-core-installation

Hi @bhindhiya

Yes, it's possible to use the 64-pin SAMD21.

Provided you use the same 256k flash, 32k RAM version, in other words the SAMD21J18A, as well as an external 32.768kHz crystal, then the chip can be programmed with the standard Arduino Zero bootloader and even run Arduino sketches that use that same (port) pins as the 48-pin, SAMD21G18A.

However, to benefit from the device's additional pins (without having to accessing them directly using the microcontroller's registers), you'll need either follow @in0 advice and use an existing supported board, which is by far the easiest option, or alternatively modify the Arduino SAMD21 core file called "variant.cpp" and append them as new entries to the pin list.

Here's the additional lines that I added to the pin description array in the "variant.cpp" file for my custom SAMD21J18A board:

// SAMD21J18A Pins...
	
  // 44..47 - Analog pins
  { PORTB,  4, PIO_ANALOG, 0, ADC_Channel12, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_4 }, // ADC/AIN[12]
  { PORTB,  5, PIO_ANALOG, 0, ADC_Channel13, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_5 }, // ADC/AIN[13]
  { PORTB,  6, PIO_ANALOG, 0, ADC_Channel14, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_6 }, // ADC/AIN[14]
  { PORTB,  7, PIO_ANALOG, 0, ADC_Channel15, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_7 }, // ADC/AIN[15]
	
  // 48..51 - Digital pins
  { PORTB,  12, PIO_DIGITAL, (PIN_ATTR_DIGITAL), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_12 }, 
  { PORTB,  13, PIO_DIGITAL, (PIN_ATTR_DIGITAL), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_13 }, 
  { PORTB,  14, PIO_DIGITAL, (PIN_ATTR_DIGITAL), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_14 }, 
  { PORTB,  15, PIO_DIGITAL, (PIN_ATTR_DIGITAL), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_15 }, 
	
  // 52..53 - SERCOM/UART (Serial1)
  { PORTB, 16, PIO_SERCOM, (PIN_ATTR_DIGITAL), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_0 }, // TX: SERCOM5/PAD[0]
  { PORTB, 17, PIO_SERCOM, (PIN_ATTR_DIGITAL), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_1 }, // RX: SERCOM5/PAD[1]
	
  // 54..55 - Digital pins
  { PORTB,  30, PIO_DIGITAL, (PIN_ATTR_DIGITAL), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_14 }, 
  { PORTB,  31, PIO_DIGITAL, (PIN_ATTR_DIGITAL), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_15 }, 
	
  // 56..57 - Analog pins
  { PORTB,  0, PIO_ANALOG, 0, ADC_Channel8, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_0 }, // ADC/AIN[8]
  { PORTB,  1, PIO_ANALOG, 0, ADC_Channel9, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_1 }, // ADC/AIN[9]
	
  // 58..59 - SERCOM/UART (Serial2)
  { PORTA, 12, PIO_SERCOM, (PIN_ATTR_DIGITAL), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_12 }, // TX: SERCOM2/PAD[0]
  { PORTA, 13, PIO_SERCOM, (PIN_ATTR_DIGITAL), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_13 }, // RX: SERCOM2/PAD[1]

@MartinL I recommend you to read my Arduino SE answer linked in my previous comment here. It is a more elegant and clean way to customize board definitions, then modifying a variant in an installed core.

2 Likes

Hi @Juraj

Thank you. Your solution is a much simpler and more elegant way.

I'll have to bear it in mind for the future.

for example I have a M0 with Zero bootloader but M0 pin mapping

@Juraj Thanks for the link, it makes a useful template for other boards.

Hi all,

Firstly, thank you for your responses. I have been taking some time to look into the options mentioned above to identify the best method to proceed with.

@Juraj, in the link shared by you, the method is described to be the best for someone who aims to add a custom board using an existing core. I understand an "existing core" to mean a board that is a recognized Arduino SAMD21 variant such as Arduino Zero, M0, MKR Zero, etc. Please correct me if I am wrong.

If I intend to use the SAMD21 J18A processor, which board can I use as the variant board that is closest to it? Is there any specific requirement that determines this decision?

Additionally, according to the link I am required to modify the boards.txt file according to my custom board. How can I identify the variables (upload_port.0.vid, pid, extra_flags, ldscript, etc.) that need to be set in boards.txt for my custom board?

@MartinL what are the other changes that are required to be made in other files after I add the additional pin configurations in the variant.cpp file if I used the method you have mentioned? Again, which variant can I use to add the additional pin configs to? Any specific requirement that determines this decision?

Thank you so much for your kind support. Looking forward to your response. Thank you.

Best Reagrds,
Bhindhiya Raja

the Arduino SAMD core is made on top of the Atmel/Microchip toolchain for SAMD21 boards. that is for all SAMD21 boards.
variant.h/.cpp is about the board not about the MCU (they have all the same MCU). so you start with a board definition most similar to your board.
you have to evaluate the board.txt settings one by one and determine the value for your MCU. The properties are explained in the documentation.

all boards in Arduino SAMD core use ATSAMD21G18 so from MCU perspective it doesn't matter which one you choose as template.

The ATSAMD21J18 has just more pins, more ADC, more memory, more timers than ATSAMD21G18

Hi @bhindhiya

Personally, I'd recommend following @Juraj 's suggestion regarding adding a custom board.

It's possible to create a new board entry in the Arduino IDE, but this is quite involved. I've described it in the following Arduino forum link, but it was written awhile ago back in 2016 and some of the details might be out of date: https://forum.arduino.cc/t/adding-custom-zero-based-boards-to-the-arduino-ide/394499.

The bottom line is that the closer your custom board is to the Arduino design, the easier the integration. If you use a SAMD21J18A together with an external 32.768kHz crystal and the same memory footprint (as the SAMD21G18A), it will require minimal changes.

If you use a SAMD21 with a different memory size, (SAMD21x15, 16 or 17), this will require modification to the bootloader and Arduino's SAMD21 core code. If you use one of the newer non-default SAMD21 variants then it will additionally require a compatible version of "bossac.exe", the program used to upload your sketches over the SAMD21's native USB port.

the boards from sketchbook's hardware folder are in Tools menu grouped by architectures

@Juraj My apologies, probably a poor choice of words on my part, since I appreciate your suggested method achieves that same goal much more easily.

In hindsight, it would've perhaps been better if I hadn't muddied the waters with the link to the old method.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.