Arduino Forum

Using Arduino => Avrdude, stk500, Bootloader issues => Topic started by: pjrebordao on Sep 16, 2020, 06:50 pm

Title: Running a sketch without bootloader
Post by: pjrebordao on Sep 16, 2020, 06:50 pm
I have a finished sketch that I would like to load and run "naked" on a Nano 33 BLE without bootlader.
The purpose is to make it start faster without the delay that the bootloader always imposes while listening for a connection.

For that I bought a cheap CMSIS-DAP programmer from Alex Taradov and made the 5-pin connector for the SWD pins on the underside of the Nano.

I made sure that the whole thing worked together by burning sucessfully the bootloader using the SWD pins.

Now I want to upload my compiled sketch into the Nano, overwriting the existing bootloader. How to do it ?

Title: Re: Running a sketch without bootloader
Post by: Juraj on Sep 16, 2020, 07:12 pm
did you try "Upload with programmer" in menu?

if it works it will not delete the bootloader. for that you have to create a custom variant with a different linker script putting the binary together to address 0.
 
https://arduino.stackexchange.com/questions/54484/adding-a-custom-board-to-the-arduino-ide/60660#60660

in my_boards I have a M0 variant without bootloader
Title: Re: Running a sketch without bootloader
Post by: pjrebordao on Sep 16, 2020, 08:45 pm
Oops... I didn't see that option
I tried it and it worked but of course the bootloader is still there.

To set up my own variant can I grab the board definition from somewhere within the arduino installation?
Title: Re: Running a sketch without bootloader
Post by: Juraj on Sep 16, 2020, 09:18 pm
Oops... I didn't see that option
I tried it and it worked but of course the bootloader is still there.

To set up my own variant can I grab the board definition from somewhere within the arduino installation?

it is
.arduino15/packages/arduino/hardware/mbed/1.1.6/variants/ARDUINO_NANO33BLE/
and
.arduino15/packages/arduino/hardware/mbed/1.1.6/boards.txt

location of the arduino15 folder is the location of the preferences file you can see in Preferences dialog in IDE.

simple option is to copy the folder to other name and copy the boards settings in boars.txt for modified boards settings

but this will be lost at package update so better is to create your variant in your hardware folder in the 'my_boards' way
Title: Re: Running a sketch without bootloader
Post by: pjrebordao on Sep 17, 2020, 10:00 am
Me again...

Ok, I created the variant structure inside my sketch:
C:\Users\pjr\Google Drive\wf_meter\wf_meter_v2\hardware\my_boards\nrf52\variants\ARDUINO_NANO33BLE

Now, I suppose I have to change the location where the sketch will be loaded ?

Is it -DMBED_APP_START inside ldflags.txt ?
Title: Re: Running a sketch without bootloader
Post by: Juraj on Sep 17, 2020, 11:39 am
Me again...

Ok, I created the variant structure inside my sketch:
C:\Users\pjr\Google Drive\wf_meter\wf_meter_v2\hardware\my_boards\nrf52\variants\ARDUINO_NANO33BLE

Now, I suppose I have to change the location where the sketch will be loaded ?

Is it -DMBED_APP_START inside ldflags.txt ?
the location should be the hardware folder in the sketchbook folder. the sketchbook folder is configured in Preferences.

for M0 I changed in .ld
FLASH (rx) : ORIGIN = 0x00000000+0x4000, LENGTH = 0x00040000-0x4000
to
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00040000

so I guess you should change something in linker_script.ld

Title: Re: Running a sketch without bootloader
Post by: pjrebordao on Sep 17, 2020, 12:19 pm
Ok and should I do something to force the usage of the hardware folder inside the sketch ?
Title: Re: Running a sketch without bootloader
Post by: Juraj on Sep 17, 2020, 01:02 pm
Ok and should I do something to force the usage of the hardware folder inside the sketch ?

it is not possible
Title: Re: Running a sketch without bootloader
Post by: pjrebordao on Sep 17, 2020, 01:07 pm
So it will be used by default the next time I do an upload ?
Title: Re: Running a sketch without bootloader
Post by: Juraj on Sep 17, 2020, 02:00 pm
So it will be used by default the next time I do an upload ?

to apply changes in boards definitions the IDE must be restarted
Title: Re: Running a sketch without bootloader
Post by: pjrebordao on Sep 17, 2020, 03:00 pm
Done everything. The sketch was indeed uploaded through CMSIS-DAP, but the bootloader is still there.

The board is still recognized by the IDE when I plug the USB port and the sketch still takes the same time to start.

What could be wrong ?
Title: Re: Running a sketch without bootloader
Post by: Juraj on Sep 17, 2020, 05:06 pm
Done everything. The sketch was indeed uploaded through CMSIS-DAP, but the bootloader is still there.

The board is still recognized by the IDE when I plug the USB port and the sketch still takes the same time to start.

What could be wrong ?

is it possible to upload over serial? the USB is there because the sketch has it
Title: Re: Running a sketch without bootloader
Post by: pjrebordao on Sep 17, 2020, 06:14 pm
Indeed, while the port appears visible, I'm unable to upload the sketch over USB anymore.
However, the sketch still takes the same time as before to start running.
Title: Re: Running a sketch without bootloader
Post by: Juraj on Sep 17, 2020, 06:53 pm
Indeed, while the port appears visible, I'm unable to upload the sketch over USB anymore.
However, the sketch still takes the same time as before to start running.

mbed RTOS boot?
Title: Re: Running a sketch without bootloader
Post by: pjrebordao on Sep 17, 2020, 07:28 pm
Maybe, how can I find out?
Title: Re: Running a sketch without bootloader
Post by: Juraj on Sep 17, 2020, 07:56 pm
Maybe, how can I find out?
I have the board but I didn't do much with it.

maybe try
https://github.com/adafruit/Adafruit_nRF52_Arduino
Title: Re: Running a sketch without bootloader
Post by: westfw on Sep 18, 2020, 04:20 am
The non-AVR boards have bootloaders that work significantly differently, and the erasure of the AVR bootloader when you "upload using programmer" is more of an unavoidable side-effect than a feature.

You probably have to explicitly erase or replace the bootloader code to get rid of it.

Title: Re: Running a sketch without bootloader
Post by: pjrebordao on Sep 18, 2020, 10:57 am
You probably have to explicitly erase or replace the bootloader code to get rid of it.
Do you have any idea of how to do it in this context (Nano 33 BLE) ?
Title: Re: Running a sketch without bootloader
Post by: westfw on Sep 19, 2020, 03:49 am
What sort of startup time do you need to achieve?
For example, there's a ~0.5s pause while the bootloader checks for "double tap reset", and (I guess) a longer pause waiting for traffic.  One elegant solution would be to change the startup to ONLY enter the bootloader on the double-tap...
Title: Re: Running a sketch without bootloader
Post by: Juraj on Sep 19, 2020, 07:42 am
What sort of startup time do you need to achieve?
For example, there's a ~0.5s pause while the bootloader checks for "double tap reset", and (I guess) a longer pause waiting for traffic.  One elegant solution would be to change the startup to ONLY enter the bootloader on the double-tap...

btw the bootloader is already removed
Title: Re: Running a sketch without bootloader
Post by: pjrebordao on Sep 19, 2020, 10:31 am
What sort of startup time do you need to achieve?
For example, there's a ~0.5s pause while the bootloader checks for "double tap reset", and (I guess) a longer pause waiting for traffic.  One elegant solution would be to change the startup to ONLY enter the bootloader on the double-tap...

I don't need a 0sec delay, but I would like to cut the delay by half.

Entering the bootloader on a double-tap would be an elegant solution, but where resides that startup code ?
Title: Re: Running a sketch without bootloader
Post by: westfw on Sep 19, 2020, 10:35 am
Quote
you have to create a custom variant with a different linker script putting the binary together to address 0.
Yes, that's one of the ways to do it.  Somehow I missed that part of the conversation :-(
I was thinking of replacing the bootloader with one that does nothing but start the app, which would theoretically be an easy modification (keeping any initialization that it might do) or even to write from scratch (doing essentially nothing.)  But I can't find the makefile used to build the nRF bootloader, so ... grumble.
Title: Re: Running a sketch without bootloader
Post by: pjrebordao on Sep 19, 2020, 10:56 am
I already changed the linker script to load the app at 0, but the results were:

- I can no longer update a sketch using USB
- The app still takes the same time to start

Title: Re: Running a sketch without bootloader
Post by: westfw on Sep 19, 2020, 11:36 am
I'll go back to "how long are you talking about?" (And - under exactly what circumstances?)
I dug out my nano33ble, and it starts up blink in about a second after power on or reset (with the bootloader present.)
Maybe it's your app - what does it do at startup?