Customizing the board def and bootloader for SAMD21G17A

Hey all,

I have a custom board using a SAMD21G17A. I've created a custom board definition and I've also re-built the bootloader to work with the smaller memory specs of the G17A compared to the G18A. Unfortunately, I am having some issues, so I figured I would see if y'all can provide any wisdom.

The main issue is with regard to the USB virtual serial port being available. Here is the behavior I am seeing:

  1. I first use Atmel Studio to burn my bootloader to the board. After doing so, the USB virtual serial port does not immediately appear. If I unplug the USB cable, and plug it back into a different USB port, it then appears (as COM3 for the bootloader).
  2. At this point, I open the Arduino IDE, and I upload a very simple blink sketch. The upload is successful, but the USB virtual serial port disappears. I must unplug the USB cable, and plug it back in. It now appears as COM37 for the uploaded sketch.
  3. Now, let's assume I want to upload the sketch again, or even upload a different sketch. I try uploading the sketch, but the upload fails. It attempts to use the 1200 bps method to force a reset and enter the bootloader, but this fails. Meanwhile, COM37 disappears.
  4. If I once again disconnect the USB cable and reconnect it, now we are back in the bootloader, and COM3 appears.

So basically, if I want to upload, and if I am in the bootloader, I can successfully upload - but then I need to disconnect/reconnect the USB in order for the sketch to work.

Otherwise, if I want to upload, but if I am not in the bootloader, I must attempt to upload (which then fails), then disconnect/reconnect the USB, and then I will be in the bootloader again.

Now, you're probably wondering what changes I have made to bootloader and such, so I'll describe my changes below.

I am using the Arduino Zero bootloader, but I have made the following changes.

First, to the board_definitions_arduino_zero.h file in the bootloader: I have changed the BOOT_DOUBLE_TAP_ADDRESS to be the correct address for the SAMD21G17A. The correct address is calculated as:

Double Tap Status Address: 0x20000000 + 0x4000 - 4 = 0x20003FFC

Code changes:

#define BOOT_DOUBLE_TAP_ADDRESS           (0x20003FFCul)
#define BOOT_DOUBLE_TAP_DATA              (*((volatile uint32_t *) BOOT_DOUBLE_TAP_ADDRESS))

Next, I changed the bootloader linker file to account for the fact that the SAMD21G17A only has 16 KB of RAM (0x4000), rather than 32 KB (0x8000) like the SAMD21G18A:

MEMORY
{
  FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x2000 /* First 8KB used by bootloader */
  RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00004000-0x0400 /* last 4 bytes used by bootloader to keep data between resets, but reserves 1024 bytes for sketches to have same possibility */
}

Those are all the changes for the bootloader.

In my board definition, I have changed the linker definition to also account for the memory differences between the G17A and the G18A:

MEMORY
{
  FLASH (rx) : ORIGIN = 0x00000000+0x2000, LENGTH = 0x00020000-0x2000 /* First 8KB used by bootloader */
  RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00004000
}

In the boards.txt file, I have changed the maximum upload size and specified we are using G17A:

my_custom_board.upload.maximum_size=122880
my_custom_board.build.extra_flags=-D__SAMD21G17A__ {build.usb_flags}

And here is my OpenOCD script:

source [find interface/cmsis-dap.cfg]

# chip name
set CHIPNAME at91samd21g17
set ENDIAN little

# choose a port here
set telnet_port 0

source [find target/at91samdXX.cfg]

Many of these changes are exactly what has been described as necessary in an older forum thread: 128k vs 256k ATSAMD21 - #2 by MartinL

If anyone has any insights as to what could be going on, I would greatly appreciate it! Thank you!

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