[upload] Error 2

I’m using PlatformIO to upload my code to my Sodaq.

But now I’m getting an error while uploading the code. This is the tail of the output:

...
Compiling .pio/build/sodaq_sara/FrameworkArduino/wiring_shift.c.o
Archiving .pio/build/sodaq_sara/libFrameworkArduino.a
Indexing .pio/build/sodaq_sara/libFrameworkArduino.a    
Linking .pio/build/sodaq_sara/firmware.elf
Checking size .pio/build/sodaq_sara/firmware.elf
Building .pio/build/sodaq_sara/firmware.bin
Memory Usage -> http://bit.ly/pio-memory-usage
DATA:    [==        ]  15.1% (used 4952 bytes from 32768 bytes)
PROGRAM: [=====     ]  52.1% (used 136556 bytes from 262144 bytes)
Configuring upload protocol...
AVAILABLE: atmel-ice, blackmagic, jlink, sam-ba
CURRENT: upload_protocol = sam-ba
Looking for upload port...
Auto-detected: /dev/ttyACM0
Forcing reset using 1200bps open/close on port /dev/ttyACM0
Waiting for the new upload port...
Uploading .pio/build/sodaq_sara/firmware.bin
Atmel SMART device 0x10010000 found
Erase flash
done in 0.399 seconds     
Write 136556 bytes to flash (2134 pages)
[==============================] 100% (2134/2134 pages)
done in 0.686 seconds     
Verify 136556 bytes of flash with checksum.
Verify failed
*** [upload] Error 2 ========================================================================================================== [ERROR] Took 13.67 seconds =================================
=========================================================================

The strange thing is, if I comment some of the code, I do not get this error. But the code compiles just fine, so what is going on?

What I also discovered is that verification fails when using Sodaq Sara AFF R410M. But verification does not fail when using Sodaq Sara AFF R412M.
Both Sodaqs also have a battery connected (just in case).
The chipset of both are exactly the same ( SAMD21, 32 bit Arm Cortex ).

Anyone any idea?

Can you try uploading a sketch which is under 120KB, I suspect that will work fine.

If that is the case, the problem is due to an issue with a batch of AFFs which were given the wrong bootloader.

Specifically, that bootloader does not erase the upper half of the flash memory and so this causes issues if the upload size is larger enough to write into that upper section.

The solution to this requires replacing the bootloader. This requires a Atmel SAM compatible programmer (e.g. Atmel-ICE). If you have the required tools we can help you with some instructions with regards to this. Otherwise, we will need to help you with it. Please let us know.

Ah, that makes sense. Thanks for the response!

I’m happy to inform that I have updated the bootloader and haven’t had this problem since.