MKR Vidor 4000 with VidorPeripherals : upload fails

With a simple sketch using the WiFiWebServer library (which requires WiFiNINA_Generic, which itself requires VidorPeripherals), the upload fails with “file operation exceeds flash size”.

Project Inspection shows the flash size being 482.8 KB (well over the 256 KB limit for the SAMD21), the most part being the FPGA bitstream (415.8 KB).

Everything works fine with the Arduino IDE.

As far as I understand, the Arduino IDE has to use a “modified bossac” to properly handle the double Flash memory (SAMD21 + FPGA).

Is it possible to use that bossac in PIO ?

Full platformio.ini and code for reproduction?

Full error message log when uploading?

Hello,

Here are the files.

platformio.ini:

[env:mkrvidor4000]
board = mkrvidor4000
monitor_port = /dev/cu.usbmodem14101
platform = atmelsam
framework = arduino
lib_deps =
  khoih-prog/WiFiWebServer @ ^1.1.1
  khoih-prog/Functional-Vlpp@^1.0.1
  vidor-libraries/VidorPeripherals @ ^1.1.0

main.cpp (simplified to absolute minimum):

#include <WiFiWebServer.h>
#include <Arduino.h>
void setup()
{
} 
void loop()
{
}

Error:

Thanks

Thanks. Could you please do two more things:

  1. In PlatformIO, use the “Advanced → Verbose Upload” task and post the output in text starting at CURRENT: upload_protocol = sam-ba
  2. In the Arduino IDE, where you say the upload works, please go to File → Settings → Enable Verbose Upload and then upload the same sketch code as you did above. Then again copy the output starting from where bossac is invoked.

A problem I’m seeing is that PlatformIO just tries to upload the whole .bin file

bossac --info --debug --port “COM14” --write --verify --reset --erase -U true .pio\build\mkrvidor4000\firmware.bin

I’m not sure how bossac is supposed to know then that somewhere at the end (?) the FPGA bitstream lies that needs to be flashed separately. Thus it would be intersting to see what the Arduino IDE does now :slight_smile:

PlatformIO:

CURRENT: upload_protocol = sam-ba
BeforeUpload(["upload"], [".pio/build/mkrvidor4000/firmware.bin"])
Auto-detected: /dev/cu.usbmodem14101
Forcing reset using 1200bps open/close on port /dev/cu.usbmodem14101
Waiting for the new upload port...
bossac --info --debug --port "cu.usbmodem14101" --write --verify --reset --erase -U true .pio/build/mkrvidor4000/firmware.bin

Set binary mode
readWord(addr=0)=0x20007ffc
readWord(addr=0xe000ed00)=0x410cc601
file operation exceeds flash size
readWord(addr=0x41002018)=0x10010305
version()=v2.0 [Arduino:XYZ] Aug  9 2018 11:17:30
chipId=0x10010005
Connected at 921600 baud
readWord(addr=0)=0x20007ffc
readWord(addr=0xe000ed00)=0x410cc601
readWord(addr=0x41002018)=0x10010305
Atmel SMART device 0x10010005 found
write(addr=0x20004000,size=0x34)
writeWord(addr=0x20004030,value=0x10)
*** [upload] Error 1
writeWord(addr=0x20004020,value=0x20008000)
Device       : ATSAMD21G18A
readWord(addr=0)=0x20007ffc
readWord(addr=0xe000ed00)=0x410cc601
readWord(addr=0x41002018)=0x10010305
Chip ID      : 10010005
version()=v2.0 [Arduino:XYZ] Aug  9 2018 11:17:30
Version      : v2.0 [Arduino:XYZ] Aug  9 2018 11:17:30
Address      : 8192
Pages        : 3968
Page Size    : 64 bytes
Total Size   : 248KB
Planes       : 1
Lock Regions : 16
Locked       : readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
none
readWord(addr=0x41004018)=0
Security     : false
Boot Flash   : true
readWord(addr=0x40000834)=0x7000a
BOD          : true
readWord(addr=0x40000834)=0x7000a
BOR          : true
Arduino      : FAST_CHIP_ERASE
Arduino      : FAST_MULTI_PAGE_WRITE
Arduino      : CAN_CHECKSUM_MEMORY_BUFFER
Erase flash
chipErase(addr=0x2000)
done in 0.852 seconds

Arduino IDE:

Uploading using selected port: /dev/cu.usbmodem14101
/Users/philippe/Library/Arduino15/packages/arduino/tools/bossac/1.7.0-arduino3/bossac -i -d --port=cu.usbmodem14101 -I -U true -i -e -w /var/folders/sx/g5n3hgks0z356wtyn16__m6r0000gp/T/arduino_build_507571/FlashErrorA.ino.bin -R 
Set binary mode
readWord(addr=0)=0x20007ffc
readWord(addr=0xe000ed00)=0x410cc601
readWord(addr=0x41002018)=0x10010305
version()=v2.0 [Arduino:XYZ] Aug  9 2018 11:17:30
chipId=0x10010005
Connected at 921600 baud
readWord(addr=0)=0x20007ffc
readWord(addr=0xe000ed00)=0x410cc601
readWord(addr=0x41002018)=0x10010305
Atmel SMART device 0x10010005 found
write(addr=0x20004000,size=0x34)
writeWord(addr=0x20004030,value=0x10)
writeWord(addr=0x20004020,value=0x20008000)
Device       : ATSAMD21G18A
readWord(addr=0)=0x20007ffc
readWord(addr=0xe000ed00)=0x410cc601
readWord(addr=0x41002018)=0x10010305
Chip ID      : 10010005
version()=v2.0 [Arduino:XYZ] Aug  9 2018 11:17:30
Version      : v2.0 [Arduino:XYZ] Aug  9 2018 11:17:30
Address      : 8192
Pages        : -129
Page Size    : 64 bytes
Total Size   : 4194295KB
Planes       : 1
Lock Regions : 16
Locked       : readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
none
readWord(addr=0x41004018)=0
Security     : false
Boot Flash   : true
readWord(addr=0x40000834)=0x7000a
BOD          : true
readWord(addr=0x40000834)=0x7000a
BOR          : true
Arduino      : FAST_CHIP_ERASE
Arduino      : FAST_MULTI_PAGE_WRITE
Arduino      : CAN_CHECKSUM_MEMORY_BUFFER
Erase flash
chipErase(addr=0x2000)
done in 0.851 seconds

Write 683844 bytes to flash (10686 pages)
write(addr=0x20005000,size=0x1000)
writeBuffer(scr_addr=0x20005000, dst_addr=0x2000, size=0x1000)
[                              ] 0% (64/10686 pages)write(addr=0x20005000,size=0x1000)
writeBuffer(scr_addr=0x20005000, dst_addr=0x3000, size=0x1000)
[                              ] 1% (128/10686 pages)write(addr=0x20005000,size=0x1000)

(many rows removed)

writeBuffer(scr_addr=0x20005000, dst_addr=0xa7000, size=0x1000)
[============================= ] 99% (10624/10686 pages)write(addr=0x20005000,size=0xf80)
writeBuffer(scr_addr=0x20005000, dst_addr=0xa8000, size=0xf80)
[==============================] 100% (10686/10686 pages)
done in 3.291 seconds
CPU reset.
readWord(addr=0)=0x20007ffc
readWord(addr=0xe000ed00)=0x410cc601
readWord(addr=0x41002018)=0x10010305
writeWord(addr=0xe000ed0c,value=0x5fa0004)

The Arduino IDE version of the bossac tool thinks the total size of the device is…

over 4096 Megabytes? o_o.

While PIO’s version thinks

Somehow saner values. But maybe it makes sense after all, huh.

Can you please try the following:

  • Find where the bossac version that Arduino uses locally. For me that’s C:\Users\<user>\AppData\Local\Arduino15\packages\arduino\tools\bossac\1.7.0-arduino3\bossac.exe but since you seem to be using Mac, that will be different. EDIT: Just looked into the logs again and it says it right there: /Users/philippe/Library/Arduino15/packages/arduino/tools/bossac/1.7.0-arduino3/bossac
  • Open the folder /Users/<user>/.platformio/packages/tool-bossac/
  • rename the original bossac file to bossac_backup
  • copy the bossac file from the Arduino-IDE version to the opened folder
  • Retry normal uploading
  • If uploading fails, post “Verbose Upload” logs again

Nothing seems to have changed:

CURRENT: upload_protocol = sam-ba
BeforeUpload(["upload"], [".pio/build/mkrvidor4000/firmware.bin"])
Auto-detected: /dev/cu.usbmodem14101
Forcing reset using 1200bps open/close on port /dev/cu.usbmodem14101
Waiting for the new upload port...
bossac --info --debug --port "cu.usbmodem14101" --write --verify --reset --erase -U true .pio/build/mkrvidor4000/firmware.bin

Set binary mode
readWord(addr=0)=0x20007ffc
readWord(addr=0xe000ed00)=0x410cc601
readWord(addr=0x41002018)=0x10010305
version()=v2.0 [Arduino:XYZ] Aug  9 2018 11:17:30
chipId=0x10010005
Connected at 921600 baud
readWord(addr=0)=0x20007ffc
file operation exceeds flash size
readWord(addr=0xe000ed00)=0x410cc601
*** [upload] Error 1
readWord(addr=0x41002018)=0x10010305
Atmel SMART device 0x10010005 found
write(addr=0x20004000,size=0x34)
writeWord(addr=0x20004030,value=0x10)
writeWord(addr=0x20004020,value=0x20008000)
Device       : ATSAMD21G18A
readWord(addr=0)=0x20007ffc
readWord(addr=0xe000ed00)=0x410cc601
readWord(addr=0x41002018)=0x10010305
Chip ID      : 10010005
version()=v2.0 [Arduino:XYZ] Aug  9 2018 11:17:30
Version      : v2.0 [Arduino:XYZ] Aug  9 2018 11:17:30
Address      : 8192
Pages        : 3968
Page Size    : 64 bytes
Total Size   : 248KB
Planes       : 1
Lock Regions : 16
Locked       : readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
none
readWord(addr=0x41004018)=0
Security     : false
Boot Flash   : true
readWord(addr=0x40000834)=0x7000a
BOD          : true
readWord(addr=0x40000834)=0x7000a
BOR          : true
Arduino      : FAST_CHIP_ERASE
Arduino      : FAST_MULTI_PAGE_WRITE
Arduino      : CAN_CHECKSUM_MEMORY_BUFFER
Erase flash
chipErase(addr=0x2000)
done in 0.852 seconds

Could it be the options -I or -R ?

bossac help:

  -I, --ignoreOverflow  ignore if binary is bigger than internal flash
                        may be used to program external flash with contiguous address space)

Can you add

upload_flags = -I

to the platformio.ini and retry?

1 Like

It works :smiley:

After the upload, things seem frozen, but it ends after ~ 35 seconds:

[============================= ] 98% (10560/10686 pages)
[============================= ] 99% (10624/10686 pages)
[==============================] 100% (10686/10686 pages)
done in 3.302 seconds

Verify 683844 bytes of flash with checksum.
Verify successful
done in 34.395 seconds
CPU reset.
============================================================================================ [SUCCESS] Took 52.03 seconds ============================================================================================

Environment    Status    Duration
-------------  --------  ------------
mkrvidor4000   SUCCESS   00:00:52.029
============================================================================================= 1 succeeded in 00:00:52.029 =============================================================================================

Many thanks for your help… :grinning:

Does it also work as in the Arduino-IDE? Would be bad if just uploading is fixed but the .bin file is still built in some wrong way and doesn’t actually end up in the FPGA bitstream. (Also, I’m opening a bug issue for this).

EDIT: Bug opened at Flashing binary with FPGA bitstream fails in upload: "file operation exceeds flash size" · Issue #142 · platformio/platform-atmelsam · GitHub.

Workaround with upload_flags = -I exists until resolvement.

Further will be discuessed in the bugreport issue.

Yes, I did the upload_flags to my original sketch, and the WebServer works.

As the communication between the SAMD21 and the NINA module goes through the FPGA, I guess everything is fine.

1 Like

Also, I don’t know if this qualifies as a bug, but the SVD file for the ATSAMD21G18A (used in all Arduino MKR boards) is an old one, with some errors. I got a newer one from the Atmel.SAMD21_DFP.1.3.395.atpack.

In both versions, some parts of the file are not interpreted correctly by PIO. In file ~/.platformio/platforms/atmelsam/misc/svd/ATSAMD21E18A.svd, line 7716 (<register derivedFrom="PINCFG0_%s">) should give a copy of the whole PINCFG0_%s part, but it doesn’t work (just formatted as a list of hex words).
Same thing with line 7838 (<register derivedFrom="PMUX0_%s">).

I did just copy the previous section in the file to fix the issue.

Can you directly create a PR into the repo for that regarding the files in platform-atmelsam/misc/svd at develop · platformio/platform-atmelsam · GitHub?

Sure.

But I don’t really know how to do it… :neutral_face:

No worries, then I’ve created the PR Update SVD files by maxgerhardt · Pull Request #143 · platformio/platform-atmelsam · GitHub. At Github you basically have to fork the repo into your own account, then clone it, change the files, commit and push it into your fork, and then in the PR tab of the original repo you can create the pull request from your fork into the main repo.

Oh my bad the PR I did was just to update the files to the latest ones by Atmel, not a SVD parsing bug. Can you file that separately in Issues · platformio/platformio-vscode-ide · GitHub with all info you have?

Sorry I couldn’t answer earlier, my reply quota was exceeded…

Thanks for the PR.

I have created the issue PIO SVD doesn't handle "derivedFrom=" applied to a <register>, <cluster> or <field> line · Issue #2336 · platformio/platformio-vscode-ide · GitHub.