Arduino mkrzero, upload via atmel-ice programmer failed

Hello everyone,
I work with an Arduino mkrzero board. I use the Atmel-ice programmer. The upload via Microchip Studio via swd works with it.
When I do an upload via PlatformIO and the same HW, it does not work!
I have defined the programmer and the protocol in the PIO.ini:
debug_tool = atmel-ice
upload_protocol = atmel-ice

The terminal output is:

Building in release mode
Checking size .pio\build\mkrzero\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]   7.5% (used 2444 bytes from 32768 bytes)
Flash: [          ]   4.7% (used 12336 bytes from 262144 bytes)
Configuring upload protocol...
AVAILABLE: atmel-ice, blackmagic, jlink, sam-ba
CURRENT: upload_protocol = atmel-ice
Uploading .pio\build\mkrzero\firmware.bin
xPack Open On-Chip Debugger 0.12.0-01004-g9ea7f3d64-dirty (2023-01-30-15:04)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
debug_level: 1

at91samd21g18
Warn : could not read product string for device 0x058f:0x9540: Entity not found
Error: [at91samd21g18.cpu] clearing lockup after double fault
Polling target at91samd21g18.cpu failed, trying to reexamine
[at91samd21g18.cpu] halted due to debug-request, current mode: Thread 
xPSR: 0x61000000 pc: 0xfffffffe msp: 0xfffffffc
** Programming Started **
** Programming Finished **
** Verify Started **
** Verified OK **
** Resetting Target **
Error: [at91samd21g18.cpu] clearing lockup after double fault
[at91samd21g18.cpu] halted due to debug-request, current mode: Handler HardFault
xPSR: 0x61000003 pc: 0xfffffffe msp: 0xffffffd8
shutdown command invoked

Does anyone have an idea what the problem could be?
Many thanks in advance!
VG

Hardfault means the firmware immediately crashed upon upload.

The causes could be many, hard to tell without the exact PlatformIO project. From wrong linker script, startup file, upload address, to crashing C/C++ code, each one is possible…

Hello,
the reason was the missing bootloader “samd21_sam_ba_arduino_mkrzero.bin”. After flashing the bootloader, it was possible to flash via SWD. The bootloader is then retained without having to protect it via the fuses! This is probably achieved via certain offsets during flashing.
Greetings