Disable sketch uploads temporarily

I'm currently working on a sketch that will occasionally do complex operations that if interrupted by a USB sketch upload will leave the data, and potentially the Giga itself, in a bad state (a near bricking). Is there a way to temporarily disable the Giga from receiving sketch uploads, purely from within the sketch itself without any hardware modifications, over USB so that it protects it's data integrity?

I don't understand your problem. To start an upload you have to explicitly do something - they are not random. Don't do an upload when you don't want it.

Of course you don't understand my problem, I didn't expect you to anyway. Why do I have to justify my question to you? Do you even deserve an explanation why with your attitude?

No. But you'll not be able to brick the giga by what you describe, anyway.

Actually, it's managed to corrupt the internal flash to the point I had to reload the entire bootloader when I did a sketch update as it was automatically writing to a datalog file and the internal flash (for storing settings/data in non-volatile memory) at an un-predicted time, effectively a bricking if you're working on it from a remote machine since you have to be there to push the BOOT0 button to get it to accept a new bootloader.

Declaring and beginning your own USBSerial object might do it, but if you are using kvstore to save data to the mcu's internal flash I'd seriously consider switching to using TDBStore on a new partition on the external QSPI flash.

Most likely using internal (progmem) flash for storing data is a bad idea in the first place.

You have my attention. What would that look like and how can I do a repartition from within the sketch it will ultimately run on? What does the API look like as well?

Have a read thru this No more EEPROM with Giga R1, how to use flash - #5 by JoeHuber - I'll be happy to answer any follow-ups

In addition to steve9's perfect suggestion to solve the data integrity issue you might also consider implementing updates on request by the GIGA rather than manually pushing them at potentially inopportune times.

Hi @alphathinktink. I think the other forum helpers are taking the correct approach by looking into the root problem.

However, in case you are still interested in disabling uploads, I will share some information. Unfortunately I don't know of an way to do this purely from the sketch. However, I do know how to do it by modifying the configuration of the "Arduino GIGA R1 WiFi" board definition in the "Arduino Mbed OS Giga Boards" platform files on your computer.

At the start of the upload process, Arduino IDE sends a special signal (referred to as the "1200 bps touch" to the GIGA R1 WiFi:

https://arduino.github.io/arduino-cli/latest/platform-specification/#1200-bps-bootloader-reset

When the GIGA R1 WiFi receives this signal, it goes into a special "boot" mode where it can accept a sketch upload.

The sending of the "1200 bps touch" signal is enabled via the platform configuration files. So if you change the configuration so that the signal is not sent, then the upload will fail. You would do this by changing the following line in the board definition:

to:

giga.upload.use_1200bps_touch=true

This could be accomplished by editing the boards.txt file on your computer, but that risks the chance of accidentally making other unintended changes to the file while editing (keep in mind you would need to make this edit after each time you update to a new version of Arduino Mbed OS Giga Boards). A better solution is to instead put your modifications into a dedicated file named boards.local.txt, placed in the same folder as the platform's boards.txt file. The properties you define in that folder override the properties in boards.txt, so the change can be accomplished by simply putting this line in the file:

giga.upload.use_1200bps_touch=true

Note that you must restart Arduino IDE before any changes you make to the platform configuration files will take effect.

After making that change, you will find that uploads to the board fail:

Failed uploading: uploading error: exit status 74

But obviously you also need a way to perform intentional uploads. Fortunately there is an alternative method for putting the board into the "boot" mode where it can receive an upload. You do this by pressing the "RST" button on the board twice quickly. After doing that, you will see the built-in LED on the board start to pulse. If you then trigger an upload in Arduino IDE while the board is in that mode, it will succeed.


If you are interested in this potential solution and would like more detailed instructions for implementing it, just let us know and we'll provide further assistance with that.