It’s possible to burn the bootloader onto an AVR using the SPI pins with another Arduino acting as the programmer and the Arduino IDE. Once the AVR has the bootloader, it can be programmed using external USB cables or onboard chips like the CH430/FTDI or still through the SPI pins.
(Since you keep repeating the error over and over: it's CH
340, not CH
430.)
I think you missed my point: if you program via the SPI pins, you
do not need a bootloader. The bootloader's job is to add serial programming. If you use SPI programming, you skip the bootloader altogether. In fact, if you use SPI programming, you will overwrite (=delete) the bootloader if you had flashed it before.
Consider:
-Using AVR with bootloader:
Step 1. Connect SPI programmer.
Step 2. Flash bootloader.
Step 3. Disconnect SPI programmer.
Step 4. Connect serial adapter (if no USB bridge built in) or USB cable (if USB bridge built in)
Step 5. Upload sketch via serial.
Step 6. Disconnect serial adapter or USB cable.
-Using AVR without bootloader:
Step 1. Connect SPI programmer.
Step 2. Flash the sketch.
Step 3. Disconnect SPI programmer.
The sole advantage of using the bootloader is if you want your users to be able to upload new firmware without needing an SPI programmer. Other than that there are no advantages at all.
But what will happen if other devices are on board and connected also to these SPI pins. Will they be damaged during programming??
Depends on your circuit design. Ideally, you'll either leave them free, or share them with things where it does not matter. Otherwise, you can program the MCUs
before installing them in the board, and/or use some 0 ohm jumpers to make it possible to isolate the rest of the circuit if need be.
If you use SPI programming, you can completely free up the IO0 and IO1 pins, which are normally used up for serial programming -- as long as you don't need that serial for communication with the running MCU, of course!
The reason I'm pursuing this is that, although I prefer using the Arduino IDE (I'm still fairly new to programming), I can't rely on Arduino boards being around long-term, as they are frequently updated or become obsolete.
LOL
what?!?! Arduino keeps most board models around forever! The Arduino Uno has been around since 2010 and is still sold today. (The Uno R3 revision with 328p chip, the most popular Arduino board, has been sold since at least 2013, and is still sold today.) They keep adding new models, but haven't retired all that many. And even when they do, it's no big deal. One of the biggest strengths of the Arduino platform is portability between not just boards, but entire architectures. I can write the same code and run it nearly or entirely unchanged on an Arduino Uno, an ESP32, a Teensy, a Rpi Pico, or STM32 Nucleo board. (All you really need to change is the pin numbers.) The only
major MCU architecture that is categorically unsupported on Arduino is PIC -- and there has been some work towards this, but never quite to completion.
In fact, I often do this when first developing algorithms for a sketch: write and debug on an Uno, then use it on an ESP32. (Compiling for ESP32 takes way longer than compiling for AVR, so it's faster to develop on AVR.) If possible, I do SPI programming since it uploads even faster.
Where things get hairier is if you start using hardware features specific to the MCU in question. You can sometimes use libraries that abstract this away in a way that is hardware-agnostic (or that actually uses each MCU's hardware features to do it). For example, the TaskmanagerIO library lets you schedule things, and under the hood it will use the timers of the MCU you're using, or of the underlying FreeRTOS on the ESP32 or Rpi Pico. With the Uno being fairly basic, moving up to a bigger MCU is rarely a problem.
In the end, chances are
you will
want to migrate away from AVR sooner than any other factor would force you to.
The AVR chips, on the other hand, are likely to outlast them, so I'm considering directly integrating the AVRs into my designs.
Arduino is open source, so as long as Microchip keeps making the chips, clone makers will keep making Arduino boards if there's demand for them, regardless of what Arduino itself decides to do. You can also do it yourself quite easily. But there is absolutely no reason to assume Arduino itself will stop, and as I said, even if they did, it doesn't matter.
I assume we are talking about hobby projects here. I would not integrate Arduino boards into a commercial product. You'd integrate a modern MCU directly.
I agree that performance-wise, these devices aren't the best. That's why I'm also researching RP2040 devices and, eventually, the RP2350. I still need to figure out their bootloading and programming processes as bare chips, but that might be a topic for another discussion.
It's fundamentally the same as a Rpi Pico. The bootloader is factory-programmed in ROM. See e.g.
https://raspberrypi.stackexchange.com/questions/145812/how-to-program-a-rp2040-chip-i-dont-have-a-pico-board-just-the-chip-im-buiYou must provide the Flash memory chip, then the factory bootloader lets you program it.