Adafruit Feather m0 - firmware.bin not running

Hi,

I am currently using the Arduino SDUBoot library allowing me to change sketches on the fly via an SD card on my Adafruit Feather M0 whilst being able to keep the standard boot loader.

All works fine, provided that I export the binary from Arduino IDE. For some reason, the firmware.bin file produced by PlatformIO does not load into the flash and I cannot determine why. The PIO sketches only work if directly built/uploaded, and not via SD card. Only the exported bin files from Arduino IDE work correctly.

Test Case:
SD Card: MS-DOS (FAT32)
Hardware setup - default SPI bus, but the SD CS is on hardware pin 8 (A2)

  1. Upload the SDUBoot project to Feather via USB. Connect SD card to SPI bus and CS to hardware pin 8 (A2)
  2. Format SD card to MS-DOS FAT32
  3. Copy FIRMWARE.bin from Blink_ArduinoIDE and insert SD card
  4. Press reset on board and the LED should flash 250ms on/250ms off
  5. Remove SD card and copy FIRMWARE.bin from Blink_PIO
  6. Press reset on board and see how LED speed doesnā€™t change (LED should flash 1s on/1s off) and how file doesnt get deleted from SD card
  7. Copy FIRMWARE.bin from Fade_ArduinoIDE and insert SD card
  8. Press reset on board and the LED should fade on and off slower than the boot loader fade

All I can assume is that PIO is doing something differently under the hood as the binary files seem a lot smaller than those from Arduino IDE. Then again, Iā€™ve been staring at a screen for a long time, so I hope I am not missing something stupid.

Hoping someone has one of these boards and can help figure out whatā€™s going on, as itā€™s extremely frustrating having to keep messing around with two different IDEā€™s.

Link to example code on Gitlab

Did you solve this?
I found a workaround for my Adafruit M0 custom board

  1. download the ArduinoCore for Samd GitHub - arduino/ArduinoCore-samd: Arduino Core for SAMD21 CPU

  2. modify ArduinoCore-samd-master/libraries/SDU/extras/SDUBoot/SDUBoot.ino to use your settings
    here are mine

     #ifndef SDCARD_SS_PIN
     #define SDCARD_SS_PIN 10
     #endif
    
     #define UPDATE_FILE "UPDATE.BIN" 
    
  3. run the script /ArduinoCore-samd-master/libraries/SDU/extras/SDUBoot/build.sh : it will use the Arduino IDE to compile a special bootloader into the ArduinoCore-samd-master/libraries/SDU/src/boot folder

  4. keep that zero.h file

  5. copy SDU.cpp and SDU.h into your src folder in the Platformio folder

  6. copy the zero.h freshly made into src/boot in your Plaftormio folder

  7. add #include <SDU.h> to your code and upload it once

  8. change something and copy the firmware.bin to the SD card and reset :smile:

I have tried in different projects: you just need to copy these 3 files at the right place in your various Platformio projects

52

sorry but this is not working on a second machine
I need to find why !

Could you try the latest upstream version? Does it work?

To be honest I ended up stopping using PIO completely because of weird quirks like this and the fact it hijacks Atom.

Iā€™ll try again in the coming days.

In fact, itā€™s working again ONLY as I described it previously.
Itā€™s ok for me like that and I donā€™t want to change anything for now
Iā€™ll keep watching all the updates you make here: Releases Ā· platformio/platform-atmelsam Ā· GitHub
to make sure it still works
Anyway it will require the user to make its own boot section prior to using it: maybe having the SDUBoot.ino in the src directory would be the solution to allows compiling the required boot section it before linking to the code
(not sure I am using the correct vocabulary but you get the idea)

Have you tried upstream version mentioned above?

We recommend migrating to PlatformIO IDE for VSCode.

Old thread, but maybe helpful for people finding it on Googleā€¦

That sounds similar to a problem I had with an Arduino MKR GSM 1400.
Here is what I did to fix it for me. Maybe itā€™s helpful to you, too.

For the SAMD boards there is a library called ā€œSDUā€ for OTA update via SD card.

There seems to be a difference in the way how PlatformIO and Arduino IDE compile the code: In Arduino IDE it is working as expected, in PlatformIO itā€™s not.
Here is what I did to fix it:

  1. Usually you #include <SDU.h> in your code. Change it to #include <SDU_fixed.h>.
  2. Make a new file ā€œSDU_fixed.hā€:
#ifndef SDU_fixed_h
#define SDU_fixed_h

#include <Arduino.h>

// copy and paste code from h-file according to your board model from https://github.com/arduino/ArduinoCore-samd/tree/master/libraries/SDU/src/boot
// here: mkrgsm1400.h
__attribute__((section(".sketch_boot"))) unsigned char sduBoot[0x4000] = {
    0x00, 0x80, 0x00, 0x20, 0x95, 0x3b, 0x00, 0x00, 0x7d, 0x3b, 0x00, 0x00,
    0x7d, 0x3b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
...
    0x1d, 0x48, 0x00, 0x00, 0xc1, 0x4a, 0x00, 0x00, 0xb5, 0x20, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00};

#endif // SDU_fixed_h
  1. The difference to the original library is that we copy and paste the board specific code for sduBoot directly instead of including the file (here: mkrgsm1400.h) containing the code. Here you have to copy and paste the code according to your board model. (Then of course your code is only working for that specific model.)

First, you could try this fix with the example here ArduinoCore-samd/libraries/SDU/examples/Usage at master Ā· arduino/ArduinoCore-samd Ā· GitHub
An indicator of whether it worked or not is when the file size of the firmware.bin increases by 16KB.
(ā€œfirmware.binā€ need to be renamed to ā€œUPDATE.binā€ before putting it on the SD card)

Again old thread, but I found this thread while debugging this problem.

I looked into this a bit and I think the problem with SDU in platformio is that
SDU doesnā€™t export any symbols, so if it is linked in as an archive dot-a file,
then the SDU code doesnā€™t get linked in.

The solution proposed above, to put the code directly in the header file, works
because it compiles the code into the current file rather than relying on the linker
to bring it in. But there is a simpler solution that works for me on my
feather adalogger board:

Find the SDU/src library under .platformio/packages. In that directory add
a file called ā€˜library.jsonā€™ with the contents:

{
    "name": "SDU",
    "version": "1.0.0",
    "authors": [
        {
            "name": "Arduino",
            "email": "info@arduino.cc",
            "url": "http://www.arduino.cc/en/Reference/SDU",
            "maintainer": "Arduino <info@arduino.cc>"
        }
    ],
    "description": "Update the sketch on your board from an SD card",
    "platforms": [
        "atmelsam"
    ],
    "build": {
        "libArchive": false
    }
}

The key part of this is the ā€˜libArchive falseā€™. That tells the platformio build process
to link in the SDU code even though there arenā€™t any symbols that we need from
it. And, as described above, if you do this, you should see the executable size
increase by 16KB.

Maybe thereā€™s a better way of controlling the build process as Iā€™m fairly new to
platformio, but for now this works for me.

  • Denis
2 Likes