PlatformIO Community

Problem uploading to SAMD21G18A from VS Code using Atmel ICE

Hi.

I am not able to flash a SAMD21 using Atmel-ICE from PlatformIO in Visual Studio Code. When I use AtmelStudio 7 it works great. Just getting my feets wet with PlatformIO, so I really don’t know what I’m doing here. Any help would be greatly appreciated. Here is my platformio.ini file:

[env:zeroUSB]
platform = atmelsam
board = zeroUSB
framework = arduino
debug_tool = atmel-ice
upload_protocol = atmel-ice
build_type=debug

And this is what I get when I try to PlatformIO:Upload

Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: docs platformio org/page/boards/atmelsam/zeroUSB.html
PLATFORM: Atmel SAM 3.9.0 > Arduino Zero (USB Native Port)
HARDWARE: SAMD21G18A 48MHz, 32KB RAM, 256KB Flash
DEBUG: Current (atmel-ice) External (atmel-ice, blackmagic, jlink)
PACKAGES: toolchain-gccarmnoneeabi 1.70201.0 (7.2.1), framework-arduinosam 4.4.191002, tool-openocd 2.1000.190707 (10.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 20 compatible libraries
Scanning dependencies…
No dependencies
Building in debug mode
Checking size .pio\build\zeroUSB\firmware.elf
Advanced Memory Usage is available via “PlatformIO Home > Project Inspect”
DATA: [= ] 9.0% (used 2940 bytes from 32768 bytes)
PROGRAM: [= ] 5.5% (used 14304 bytes from 262144 bytes)
Configuring upload protocol…
AVAILABLE: atmel-ice, blackmagic, jlink, sam-ba
CURRENT: upload_protocol = atmel-ice
Uploading .pio\build\zeroUSB\firmware.bin
xPack OpenOCD, 64-bit Open On-Chip Debugger 0.10.0+dev (2019-07-17-11:28)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
debug_level: 1

at91samd21g18
target halted due to debug-request, current mode: Thread
xPSR: 0x41000000 pc: 0x00000158 msp: 0x20008000
** Programming Started **
** Programming Finished **
** Verify Started **
** Verified OK **
** Resetting Target **
target halted due to breakpoint, current mode: Handler HardFault
xPSR: 0x41000003 pc: 0x00000140 msp: 0x20007fc0
shutdown command invoked

This shows a successful upload procedure. What’s the code that’s being run? What’s the expected and actual result? Manual reset does not help?

Just a simple blink. Code below. The LED stays on high infinite. It does not help to manually reset.

#include <Arduino.h>

void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(700);
digitalWrite(LED_BUILTIN, LOW);
delay(700);
}

I have also disconnected the ICE programmer and toggled power on the chip. Still the LED_BUILTIN just sits there HIGH.

Can you show the Arduino IDE settings with which it works succesfully?

I got it working now! It turns out that I had uploaded code from ATMEL Studio, and that did something strange with the controller. I flashed the bootloader and did a fresh upload from VS Code and it works as it should. So if someone ever gets the same message, just re-burn the bootloader and everything is A-OK. :slight_smile:

Thank you so much for the follow up.