Well, Arduinos can be used to program other arduinos when you load the right firmware, you can even find firmwares to program other devices (in example, the “JTag whisperer” project uses an arduino as XSVF player to program some xilinx devices).
With the same idea in mind, but (I think) less complicated than emulating a jtag, we could program a generic STM32 board without messing with the boot jumpers or the reset button (that could be managed by the firmware in the AVR arduino) and making use of hardware you might have already.
If I get it correctly, when you compile the sketch and load it to an AVR arduino with onboard USB to TTL chip (a simple com port for the SO), a control signal is triggered on that chip, allowing to reset the MCU and OR put it in program mode (not sure if only reset and the bootloader works with timing or other signal is involved). So, there should be an usable flag in the upload script to diferentiate between normal serial comunication and programming.
If the firmware on the AVR arduino can detect and use that flag to tie Boot0 to high and then send a short pulse to reset to make the STM32 enter in the program mode using the embedded serial bootloader, upload the program using simple serial communication, ans when the upload finish turn back Boot0 to low and send another short pulse to reset to put the STM32 back in normal operation mode.
That way we would not mess with changing jumpers, reseting the MCU, or attaching/detaching the programmer. Is really annoying to have to do that things when we only correct little pieces of code and want to try fast the result.
The main advantages might be:
- dont have to mess with Boot jumpers
- dont have to mess with the reset button
- use hardware you might already have
- dont have to detach/attach the programmer after each upload
Disvantages:
- need voltage level adaptation
- capable of only basic debug using the same serial
- may need other power source for the MCU at least for operation mode
For me it looks well even with the disvantages. Maybe someone with the stlink v2 (clone or not) can help me to make a comparison table between the 3 options, as for now I only have accesss to try the USB to serial TLL.
You don’t actually power the device with the stlink device. The vcc pin on the programmer is an input to the stlink device so it knows what voltage you are providing to your board. I just leave the usb cable plugged into my stm32f103c8t6 to power it.
I’m not sure about SWD, but I took a quick look at just writing a sketch using Software Serial to pass through the data to the board
unfortunately it doesn’t seem to work.
But I still think Serial is best option
I have seen code for SWD, but things then get a whole load more complicated, as the host PC needs some form of protocol that communicates with the AVR Arduino
Interestingly UART 1 is 5V tollerent but UART 2 is not.
But as this uses UART 1, it should be fine using a Uno which has been held in reset.
I must try it some time.
I have seen code for SWD, but things then get a whole load more complicated, as the host PC needs some form of protocol that communicates with the AVR Arduino
This thread is about using an AVR Arduino as a programmer.
Its not about using an STLink
Must be something I can learn from such a goal!
Must be something I can learn from such a goal!