Skip to content
This repository was archived by the owner on Apr 16, 2021. It is now read-only.
This repository was archived by the owner on Apr 16, 2021. It is now read-only.

Is it possible to put the Arduino 33 BLE into bootloader mode from code? #64

Closed
@morettigiorgio

Description

@morettigiorgio

I would like to be sure that my Arduino is in upload mode before pressing the upload button from IDE. This is because my Arduino is not easy to reach and I often have to press the reset button to load the sketch.
I could put Arduino in upload mode, from bluetooth, with a code if this were possible.
Thanks

Activity

facchinm

facchinm commented on Apr 7, 2020

@facchinm
Member

Hi Giorgio, sure you can 🙂
The function we invoke to reboot into bootloader is _ontouch1200bps_() (from here) .
You can add a BLE characteristic that will call that function when written.
I'm a bit more interested in why you often need to double press the reset button... Are you on Linux? In that case there might be modemmanager interfering with the upload procedure (as reported multiple times, for example here arduino/Arduino#7690)

morettigiorgio

morettigiorgio commented on Apr 8, 2020

@morettigiorgio
Author

Hi Martino.
It is perfect. It is properly that I looked for. Thanks
I hope I'm not off topic too:
The problem is only when I use the WDT routine.
At the end of compile, my IDE looks for COMs and Arduino changes from COM12 in COM13, the upload starting but after a few seconds, Arduino disconnects from USB (LED_BUILTIN flash 2 fast and 2 slow).
Only reset with bootload mode resolves it
It seems that WDT interrupts the uploading

facchinm

facchinm commented on Apr 8, 2020

@facchinm
Member

Ah, it's what surely happens... How often is your watchdog configured to fire? From what I read on Nordic forum, there's no way to deactivate it using a soft reset, only the reset button works, so the code I gave you is unlikely to fix the problem.
A workaround could be to configure the watchdog period to a long one just before calling NVIC_SystemReset inside _ontouch1200bps_() (https://devzone.nordicsemi.com/f/nordic-q-a/53904/nrf52840-watchdog-for-arduino-nano-33-ble-sense/217952#217952) and then, when the sketch boots, reconfigure it to the desired period

morettigiorgio

morettigiorgio commented on Apr 8, 2020

@morettigiorgio
Author

In fact, your code works only with WDT disable and my uploading problem is the same of your link indicates. I use that WDT code (5 sec) and once it started there is not way to stop it. I also tried to modify the WDT time with NRF_WDT->CRV = 3932159; (120s) before ontouch1200bps(); but, unfortunately, it seams irrelevat

leomonan

leomonan commented on Apr 17, 2020

@leomonan

I use this code and it works (reset to bootloader):

NRF_POWER->GPREGRET = 0xB0UL;
NVIC_SystemReset();
manchoz

manchoz commented on Apr 17, 2020

@manchoz
Contributor

@morettigiorgio in order to actually change the timeout value you also need to feed the WDT. Please, refer to Reload Criteria for more information.

The complete sequence should be:

constexpr uint32_t WDT_MAX_VALUE = 0x07CFFFFF;
NRF_WDT->CRV = WDT_MAX_VALUE;
for (auto rr = 0; r < 8; r++)
  NRF_WDT->RR[rr] = NRF_WDT_RR_VALUE;

This feature is also available via the NRF5 SDK that you can use directly from the Arduino sketch.

constexpr uint32_t WDT_MAX_VALUE = 0x07CFFFFF;
nrf_wdt_reload_value_set(WDT_MAX_VALUE);
nrfx_wdt_feed();

FYI, NRF52840's watchdog is fully supported via the MbedOS Watchdog API even on Arduino Nano 33. Still, the MbedOS Watchdog API is pretty simple/naive and Nordic's Watchdog can't be stopped.

morettigiorgio

morettigiorgio commented on Apr 17, 2020

@morettigiorgio
Author

Thanks @leomonan and @manchoz, I will test them soon.

facchinm

facchinm commented on Apr 22, 2020

@facchinm
Member

Closing as answered 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @manchoz@morettigiorgio@facchinm@leomonan

        Issue actions

          Is it possible to put the Arduino 33 BLE into bootloader mode from code? · Issue #64 · arduino/ArduinoCore-nRF528x-mbedos