Go Down

Topic: Optimization. How to use bootloader UART code from the main program? (Read 687 times) previous topic - next topic

selevo

How to use bootloader UART code from the main program?
In order not to take up space for this in the program.

That is, I mean, when I execute serial .print \ serial.setup in my program, then code is added to my program, code is added that actually already exists in the bootloader and I just repeat it again.
Therefore, it would be nice to use ready-made code so that it benefits more than just for updating the firmware.

Budvar10

No, there is not the .print. Yes, there are similarities. Even some empty space in the boot region there can be, which is normally useless. However, the boot region is locked and it is fixed size (can be set in some fixed amount of memory). It is prevention for changes from outside like chip erase function, which otherwise will erase also the bootloader.
So simple answer is: Nowise.
Arduino clone with ATmega1284P   http://forum.arduino.cc/index.php?topic=277260.0

selevo

But this sketch
(Teme on this  forum)

Used call function located in bootloader  memory page and  it work, write   dates  in flash memory   from  main programm.
(it' s use  optiboot  mod  with enabled this option - fixed adres entrypoint )

Budvar10

The topic is about programming FLASH memory from the running sketch. You've started with little different issue.
I am not telling it is impossible. See the datatasheet how the boot regions, bootloader and self programming work. I'm recommending read about R/W protection of boot region.
You can see the source code of the bootloader and study what is feasible for you but there is no Serial.print etc. It is very simple program with very specific purpose with focus on to be as small as possible.
In addition, in the Arduino SW there is a lot of ballast, no to mention libraries, but the goal is to simplify programming.

Do not forget that sometimes it's much more efficient just make another copy of some piece of code than call it from some fixed location. Depending on circumstances.
Arduino clone with ATmega1284P   http://forum.arduino.cc/index.php?topic=277260.0

selevo


westfw

The bootloader serial code does not have any buffering, nor is it interrupt driven.  You'd have the simple versions of Serial.read() and Serial.write() (and would still need whatever "print" code you were using (which the bootloader doesn't have any of.)
If you were to duplicate that code in your sketch - just copy in putch() and getch(), it would be about 30 bytes (probably plus a bit extra to connect it to C++), compared to about 700 bytes for HardwareSerial.  The copy would PROBABLY be shorter than trying to connect C++ to the bootloader functions...

Do you need to save 650 bytes?

david_2018

You can always program your code with an ISP programmer and remove the bootloader entirely, then there will be no duplication of code.

selevo

Do you need to save 650 bytes?

Thank's
Save will not hurt, but I think more about how to get the most out of what is, if possible. :)

Go Up