Struggling the understand the purpose of a bootloader

Howdy,

What I have read online is the purpose of a bootloader:

  • The bootloader code resides at the bottom of the flash memory inside the AtMega328, any pre-configurations will be done here.
  • The reset vector(?) will point to the first address of the bootloader and start the bootloader execution
  • The bootloader will wait to see if there is an external input, such as me uploading a sketch, if not, it will execute code that was previous loaded

Fairly simple, bootloader starts, if there is an external input, bootloader will load it into the application memory portion of the flash, if not, load previous code.

For professionals out there, can you give me an example where you just have to tinker with the bootloader in order to make your project work?

What if I don't need pre-configurations or any setup when I start my MCU? why can't I just want directly into the application memory? Does the bootloader care if the code is from the Arduino framework or from a low level C programme?

Thank you

It seems to me that the word "professional" perhaps should not be used in conjunction with a hobby device. Many people consider Arduinos to be hobby devices.

I have a fair amount of experience with the Arduino, especially the Arduino Uno, and NEVER have had to tinker with the bootloader. Your mileage may vary.

The bootloader lives at the top of flash, not the bottom (at least on the AtMega328, other microprocessors designs may be different).

You are wrong that you think a compiled Arduino sketch is different in any way from a “low level” C++ application. Arduino sketches are C++ programs.

Yes, you can just flash your compiled Arduino application code using the ICSP header and and a separate programmer if you want. But it makes it significantly harder to update your sketch “in the field” if you need to release a new firmware (e.g. to add new features or fix a bug) if there isn’t a bootloader present to allow you to do it via the USB/serial interface.

Just about every single piece of consumer electronics you own, from your mobile phone to your home router, car stereo, tv and set top box will have a bootloader of some sort. The BIOS in a PC is another example of a bootloader.

You might want to modify the bootloader to add extra features. There’s a version that allows wireless connection via a NRF24 board for example. Very useful if your Arduino USB port is not easily accessible but you still want to be able to update it.

wingsuncheung2609:
What if I don't need pre-configurations or any setup when I start my MCU? why can't I just want directly into the application memory? Does the bootloader care if the code is from the Arduino framework or from a low level C programme?

the nicest feature of an Arduino is that it can be reprogrammed simply using a USB serial interface. no special programmer such as an In Circuit Serial Programmer (ICSP) is needed.

yes, the bootloader, like any other program, configures the device, but then resets the device to run the downloaded program.

of course, the code being programmed and executed is machine code representing the assembler code generated by the gcc compiler. neither the bootloader nor processor can tell whether the program was written assembler or any other language. (early processor were programmed in machine code)

why can't I just want directly into the application memory?

How were you proposing to do that? Traditionally, "writing directly to application memory" requires a specialized interface to the microcontroller, using a relatively expensive "programmer" device. This isn't as horrible as it used to be - old chips would require 10+ pins and high voltages, with the programmers costing hundreds of dollars (1990s dollars, at that.)

A bootloader lets you define the "programming protocol" to be whatever you want (UART or USB based, in the case of Arduinos.)

give me an example where you just have to tinker with the bootloader in order to make your project work?

It should NEVER be necessary. (well, it turns out that sometimes only the bootloader (or the programmer interface) can write to flash memory, so if your application needs to write to flash, you may want to have pieces of it replace the Arduino bootloader.)

The Arduino bootloader doesn't do any "pre-configuration", BTW. When your sketch starts, the chip is pretty much in its "freshly reset" state.