PlatformIO Community

Arduino Zero (SAMD21G18) seems to program but won't run

Like others here I’m trying to replace the Arduino IDE with Platform.io for better development of libraries and particularly so I can debug. I’m working with an Arduino Zero (this one) with the built-in EDBG debug chip.

In case it’s relevant, I also spent some time (unsuccessfully) trying to get Atmel Studio 7 to program this Arduino. In the process I seemed to blow away the bootloader. I used the Arduino IDE to re-burn the bootloader.

I’m testing with the ubiquitous blink program.

#include "Arduino.h"

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

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

From the Arduino IDE, I can successfully upload and run the sketch as expected (after removing the first #include line)

However, when I switch over to platform.io, I get the following when I build and run.

[Mon Aug  7 13:03:02 2017] Processing zero (platform: atmelsam; board: zero; framework: arduino)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
Collected 7 compatible libraries
Looking for dependencies...
Project does not have dependencies
Linking .pioenvs/zero/firmware.elf

Checking program size
text       data     bss     dec     hex filename
9448        256    1780   11484    2cdc .pioenvs/zero/firmware.elf
Uploading .pioenvs/zero/firmware.bin
GNU MCU Eclipse 64-bits Open On-Chip Debugger 0.10.0+dev-00135-g80299198 (2017-06-22-18:37)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
none separate
adapter speed: 400 kHz
cortex_m reset_config sysresetreq
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : CMSIS-DAP: FW Version = 03.22.01B3
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 400 kHz
Info : SWD DPIDR 0x0bc11477
Info : at91samd21g18.cpu: hardware has 4 breakpoints, 2 watchpoints
target halted due to debug-request, current mode: Thread
xPSR: 0x81000000 pc: 0x00000614 msp: 0x20007ffc
** Programming Started **
auto erase enabled
Info : SAMD MCU: SAMD21G18A (256KB Flash, 32KB RAM)
Warn : Adding extra erase range, 00000000 to 0x00001fff
wrote 24576 bytes from file .pioenvs/zero/firmware.bin in 2.411482s (9.952 KiB/s)
** Programming Finished **
** Verify Started **
verified 9704 bytes in 0.820003s (11.557 KiB/s)
** Verified OK **
** Resetting Target **
**Error: at91samd21g18.cpu -- clearing lockup after double fault**
target halted due to debug-request, current mode: Handler HardFault
xPSR: 0x61000003 pc: 0xfffffffe msp: 0xffffffd8
shutdown command invoked
========================= [SUCCESS] Took 5.14 seconds =========================
  • Despite the “Success” message, the sketch does not run (as expected with the Error line showing the lockup after double fault.

Also not sure why there is the line “Info : at91samd21g18.cpu: hardware has 4 breakpoints, 2 watchpoints”. Could these have been added by Atmel Studio and not removed? I’ve unsuccessfully tried to run the platform.io debugger but didn’t get anywhere near adding breakpoints.

Furthermore, if I go back to the Arduino IDE and try to Upload the sketch it reports the same lockup/double fault error, and I cannot proceed until I re-burn the bootloader.

Happy to provide any further log dumps as needed to diagnose.

Thanks for any help.

Just worked out that the line

Info : at91samd21g18.cpu: hardware has 4 breakpoints, 2 watchpoints
just means that that processor’s M0 core hardware is capable of 4 breakpoints, 2 watchpoints.

However, I’m still wondering what I’ve done wrong to stop my program from starting. Do I have debugging enabled incorrectly somewhere in Platform.io?

Please file an issue here https://github.com/platformio/platform-atmelsam/issues

@robroyaus Did you ever find out what was wrong? Having the same problem.