Programming ATSAMD21 via Atmel-ICE ?

I want to restore bootloader on my feather m0 proto that includes ATSAMD21G18A
I have Atmel-ICE Basic and Atmel Studio 7 on X64 Windows7 Machine.

Atmel SAM port has 100mil 10pin connector.

2-1
4-3
6-5
8-7
10-9

For programming we need;

1 > Vcc 3.3V > Feather proto's 3V3 pin ( second in pin line )
2> SWDIO > SWDIO on Feather's bottom side
4> SWDCLK > SWDCLK on Feather's bottom side
3,5 > GND > Feather proto's GND pin (4th in pin line)
10 > RST > Feather proto's RST pin (1st in pin line)

I powered Feather with Lipo ( tried with USB too)
Atmel-ICE basic has three lights. Green and red are on.

On Atmel Studio > Tools > Device Programming >
Tool > Atmel-ICE
Device > ATSAMD21G18A
Interface > SWD
and clicked Apply.

When I tried to read device signature, it returned an error ("Unable to enter programming mode.") Code 4109

Target Voltage 2.6V ( From pins directly I measured its 3.2V )

(I connected SWD's pin 5 to GND it will give correct voltage 3.2-3.4 volts)

I changed SWD Clock from 2Mhz to 32Khz, but nothing changed.

Are there any suggestions to try?

Sounds like your voltage is dropping to low. Maybe try to add an condensator between the Pin that drops low and Ground?

I burned firmware from Adafruits M0 with Jlink to custom M0 board with these settings.

NVMCTRL_NVM_LOCK = 0x00
NVMCTRL_PSZ = 0x03
NVMCTRL_NVMP = 0x1000
ADC_LINEARITY_0 = 0x08
ADC_LINEARITY_1 = 0x04
ADC_BIASCAL = 0x03
OSC32K_CAL = 0x3A
USB_TRANSN = 0x05
USB_TRANSP = 0x1D
USB_TRIM = 0x03
DFLL48M_COARSE_CAL = 0x1D
DFLL48M_FINE_CAL = 0x200
ROOM_TEMP_VAL_INT = 0x1D
ROOM_TEMP_VAL_DEC = 0x06
HOT_TEMP_VAL_INT = 0x54
HOT_TEMP_VAL_DEC = 0x09
ROOM_INT1V_VAL = 0x00
HOT_INT1V_VAL = 0xFE
ROOM_ADC_VAL = 0xB1A
HOT_ADC_VAL = 0xD10
NVMCTRL_BOOTPROT = 0x07
NVMCTRL_EEPROM_SIZE = 0x07
BOD33USERLEVEL = 0x07
BOD33_EN = [X]
BOD33_ACTION = 0x01
WDT_ENABLE = [ ]
WDT_ALWAYSON = [ ]
WDT_PER = 0x0B
WDT_WINDOW_0 = [X]
WDT_WINDOW_1 = 0x05
WDT_EWOFFSET = 0x0B
WDT_WEN = [ ]
BOD33_HYST = [ ]
NVMCTRL_REGION_LOCKS = 0xFFFF

OTP1_WORD_0 = 0x10000300 (unknown)
OTP4_WORD_0 = 0x40004007 (unknown)
OTP4_WORD_1 = 0x75F4AE9C (unknown)
OTP4_WORD_2 = 0xFFFFFE00 (unknown)
TEMP_LOG_WORD_0 = 0x95461D (unknown)
TEMP_LOG_WORD_1 = 0xD10B1AFE (unknown)
USER_WORD_0 = 0xD8E0C7FF (valid)
USER_WORD_1 = 0xFFFFFC5D (valid)

Device cannot be known. M0 drivers already loaded. When powered it look like bootloader mode or blink, i cannot decide with one ?

Any ideas ? Could anyone confirm the fuses right.

After restoring bootloader ( https://learn.adafruit.com/system/assets/assets/000/031/337/original/featherm0bootloader_160305.zip?1458155274 )

Is bootloader has default blink program ? or it's for the bootloader mode ?

Windows Device Manager shows device as Unknown.

I installed these drivers, but nothing changed.


Schematic that I used for MC and USB connections are.



I have ten units. I tried another one to burn firmware. It's successfully flashed and verify the firmware, but it's still stuck in bootloader mode.

I use two clicks the button but doesn't work.

I also tried to do the same thing you are doing here, but instead I cam up with a different error:

"Failed to write segment at 0x0 to target for memorytype

Severity: ERROR
ComponentId: 20100
StatusCode: 131103
ModuleName: TCF command: Modules:writeToMemory failed.

Failed to write segment at 0x0 to target for memorytype"

Not sure if anyone has any thoughts. I followed similar instructions as to what was shown in the Adafruit tutorial.

After much experimentation, I think a lot of the errors I found that uploading the bootloader and getting Windows to reliably detect the device requires proper placement of decoupling capacitors. I followed the decoupling capacitor guidelines carefully in the SAMD21 datasheet, and this solved my problem.

I also once encountered the "Unable to enter programming mode" problem when I accidently swapped the SWDIO and SWCLK pin connections with the Atmel ICE programmer.

Hey @AwakingDragon,
Could you please provide more information on how you got it to work? I am getting the same error when I try to program "Failed to write segment at 0x0 to target for memorytype base" and I am getting this error when I try to verify "Verifying Flash...Failed! address=0x0000 expected=0x50 actual=0xff". Could you please direct me to the page in SAMD21 datasheet where it gives information on where to place the decoupling capacitors? I have been going through the datasheet but have not been able to find anything. Sorry, i am beginner at this. Thank you.

The datasheet (http://www.atmel.com/Images/Atmel-42181-SAM-D21_Datasheet.pdf), provides some rudimentary schematic for the capacitors in Figure 8.1.

Unfortunately, the datasheet is a bit vague about the actual value of the capacitors, but suggestions are provided on Table 37-17. You can also emulate the setup which was used in the design of the Adafruit Feather M0, schematic found here: Adafruit Learning System

Hope this helps.