We are in the midst of designing a custom board with a blank Atmega328, the Rx and Tx also the SPI lines are connected to another MCU's Rx, Tx and GPIO lines. Ideally we want our product to be able to interface with the Arduino IDE.
Can we use the MCU that is hooked up to the empty Atmega328 to burn the bootloader with SPI? Does anyone have any ideas on how to easily burn the bootloader into the Atmega328 during mass production? Ideally we do not want to use another Arduino UNO or another external programmer.
We have also contemplated on not using the bootloader. If we don't use the bootloader, it seems you can also program the Atmega328 directly through SPI. Will this work with a blank Atmega328 chip? I have seen some examples with the Raspberry PI but how difficult is it to program it with any MCU say like the nrF52 or MSP430? My understanding is that if we program directly with SPI without the bootloader, we cannot use the Arduino IDE to program the Atmega328 (but instead Atmel studio) is this correct?
Thanks in advance for any help. I really appreciate it.
If you want users to easily be able to upload their own code to your board via the Arduino IDE, having a bootloader is a good idea.
There are some "standalone programmers" that allow you to upload .hex files from an SD card, without needing a computer. Here's a tutorial for a DIY one:
Here's a similar commercial product sold by a member of the Arduino community:
Since you mentioned the Raspberry Pi, maybe you've already seen this article on how Sparkfun programs their boards:
They were specifically interested in achieving high speed for production.
My understanding is that if we program directly with SPI without the bootloader, we cannot use the Arduino IDE to program the Atmega328 (but instead Atmel studio) is this correct?
No, that's not correct. The Arduino IDE allows you to do this via Sketch > Upload Using Programmer. However, for production work you would want to just directly use the AVRDUDE tool that the Arduino IDE uses for this purpose to upload the compiled .hex file. If you turn on File > Preferences > Show verbose output during: Upload in the Arduino IDE, do an "Upload Using Programmer", and then examine the contents of the black console window at the bottom of the Arduino IDE after the process finishes (scroll up to see all the output), you will find the avrdude command that the Arduino IDE generated. You can run the same command from the command line or a script (quote any paths that have a space in them first).
Note that the compiled .hex file generated by the Arduino IDE is stored in a temporary build folder that will be deleted when you exit the Arduino IDE. If you want to save the file, you would need to copy it somewhere safe before exiting the Arduino IDE. The IDE also allows you to easily save the .hex file to the sketch folder via Sketch > Export Compiled Binary.