1

I am about to ask a kind of complex question due to the number of system parts involved and the system architecture I am planning to use.

First of all I have a tiny bit of experience with the Arduino Nano and a professional experience with C microcontroller programming.

What I would like is to create a custom ATMega328p board that does something and be able to update whatever firmware is running on it using the UART port.

1) Firmware updating

Since I am not so familiar with bootloaders, I would skip for now writing my own, so I would like to use the newest Arduino Bootloader for ATMega328p to support the firmware updates.

2) Custom program compilation

What I definitely do NOT want is use Arduino Sketch IDE to compile whatever application code. I am using Atmel Studio up to now for whatever bootloaderless applications I was doing and I would like to keep using that with my own project and code structure. The question here is, do I need to make any linker modifications or modifications in the code in Atmel Studio projects in order to be able to "transform" my code into application code so that can coexist with the bootloader?

3) Updated firmware programming

After the board is on the field running with the Optiboot bootloader and an outdated firmware, I would like to use a thirdparty software to communicate with the bootloader and update the application code. Since the optiboot bootloader used by Arduino uses the STK500 communication protocol and functionality, could I use AVRdude to communicate with the bootloader and flash the applications code only through UART?

Do you think this concept could work?

Thank you in advance. polylogic

closed as too broad by Juraj, sempaiscuba, MichaelT, VE7JRO, MatsK Mar 13 at 15:39

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    your question boils down to asking if it is possible to build an Arduino UNO – jsotola Mar 13 at 1:34
  • ask and discus AVR questions on avrfreaks.net/forum – Juraj Mar 14 at 6:13
0

Since I am not so familiar with bootloaders, I would skip for now writing my own, so I would like to use the newest Arduino Bootloader for ATMega328p to support the firmware updates.

Even people who do know about bootloaders rarely bother writing their own when there is a perfectly good one with good support and good cross-platform tools available. Why would you?

The question here is, do I need to make any linker modifications or modifications in the code in Atmel Studio projects in order to be able to "transform" my code into application code so that can coexist with the bootloader?

No. The bootloader resides at a high memory address, and your code at address 0x0000 just like normal. A fuse is set to say "Boot at the bootloader address", and another lets you set the size of the bootloader area (and thus the bootloader address).

Since the optiboot bootloader used by Arduino uses the STK500 communication protocol and functionality, could I use AVRdude to communicate with the bootloader and flash the applications code only through UART?

Yes. This is what the Arduino IDE does. It just runs avrdude to communicate with the bootloader. If you turn on verbose mode in the preferences you should be able to see what the exact command is that it runs so you can replicate it in your own program or script.

  • I would add that the only purpose of the bootloader is flashing over UART. – Juraj Mar 12 at 16:42
  • @Juraj Sure, if you want to state the obvious. – Majenko Mar 12 at 16:43
  • Majenko! Thank you so much for the answer!It seems that this is pretty standard since I managed to compile a custom program in Atmel Studio and load it to the uC via cmd avrdude. Im not sure if I need to post a different question but I was wondering the following; in order to increase security: I could modify the optiboot code to first receive a predetermined set of chars via UART before it goes into STK500 mode.Would that be doable?Apart from cold-reset, I would like to be able to call the bootloader from the app code. How could I call it and should I reset some registers before I call it? – grpolylogic Mar 13 at 10:58
  • That would constitute a new question. I'm not going to be able to answer those in comments. – Majenko Mar 13 at 11:07

Not the answer you're looking for? Browse other questions tagged or ask your own question.