PlatformIO Community

SDU Library Arduino MKR

I am trying to same the same process that I use in Arduino IDE on Platformio for VS Code. I use MKR NB 1500 with Arduino memory board for the SD (CS on pin 4)

  1. Include <SDU.h> in a blink example
  2. Upload sketch with 1s delay
  3. Modify delay to 200ms and compile
  4. In the Arduino IDE I use Export compiled binary, In VS Code I Use firmware.bin in .pio folder
  5. Rename the .bin file to UPDATE.bin and copy to uSD (It is extrange because the size of .bin file from VS Code it is smaller that exported from Arduino IDE)
  6. Reset the board and the second stage bootloader update the sketch (Only in Arduino IDE)

This process works with Arduino IDE but not in Platformio.
Someone use SDU with Platformio?
Where is my error?

Best regards

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
// 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
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)

1 Like

Tanks you very very much @roener!

I’ve been dealing with this for days!

Do you have any idea about the cause of this issue/behavior?

I continue with the issue with SDU, it works fine with Arduino IDE but not with platformio under VSCode.

I copy the content from .h file to a new SDU_fixed.h as [roener] but continue with the issue.

If I comment and uncomment #include “SDU_fixed.h” binary file output size is the same