Electronic – arduino – Is it possible to program an STM32 with an Arduino


I have one of these:

I know an USB-TLL dongle is usually used to program it, but I don't have one and I really don't want to wait 2 weeks until it arrives.

Is it possible to program it with an Arduino ? I have a Arduino Mega and Uno laying around. Thanks.

Best Answer

Through JTAG, it's practically impossible. Your best bet is using the embedded bootloader that ships factory installed in every STM32 chip. This bootloader uses the USART1 peripheral of the STM32 to interface with a computer or other device. However, the most useful tool to interface to this bootloader is a USB to serial converter, using e.g. an FT232 chip, which you can connect to your computer. You could then install the ST Flash Loader Demonstrator app to upload code to your board using the bootloader.

A few important points to make:

  • to use the bootloader, you need to pull BOOT1 low (connect to GND) and BOOT0 high (connect to VDD) before powering up the board. Then, when running the code you just looaded, pull BOOT0 low back. See section 3.4 of the STM32F10x reference manual.
  • a commercial USB to serial converter would include a voltage level translator, since RS-232 voltage levels are much higher than the 3.3 V used in the STM32 (usually \$\pm\$12V). You'd need to hack such a converter to get TX and RX signals straight from the FT232, otherwise you're going to let out the magic smoke from the STM32. If you don't have one, you might just find it in your local computer store for sale. Another option would be to search for some Arduino code that emulates a USB to serial converter (it'd be far too much work to write one yourself). Note that even if your converter uses 5.0 V signaling, that's OK to use with the STM32 since the USART1 pins needed for the bootloader are 5V-tolerant.
  • finally, you must be aware that this is no substitute for a real JTAG programmer. Using the bootloader, you can only load and run the program. It's impossible to debug it (i.e. insert breakpoints, read and modify register and memory values, step through the code, etc.) Using the bootloader is fine if you just want to see a few LEDs flash on your shiny new board, but for serious work, a real debugger makes you orders of magnitude more productive. Do order a JTAG now, if you haven't already. The ST-Link/V2 is a nice one and not too expensive ($29.75 from Digi-Key as of this writing).