9
\$\begingroup\$

I have one of these:
http://www.ebay.com/itm/111297094334?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649

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.

\$\endgroup\$
2
  • \$\begingroup\$ Looks to me like that's programmed through JTAG, not through UART. Unless it comes with a bootloader installed, you'll need JTAG. \$\endgroup\$
    – Majenko
    Jul 4, 2014 at 21:11
  • 1
    \$\begingroup\$ The last time I made a JTAG programmer from scratch, including all the software, it took about 40 hours of solid work. So unless you are already extremely familiar with JTAG programming algorithms for the STM32, or are able to use someone else's work, you won't save much time going this route. \$\endgroup\$
    – user4574
    Oct 3, 2020 at 2:19

4 Answers 4

8
\$\begingroup\$

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).
\$\endgroup\$
3
  • \$\begingroup\$ It should be noted that FTDI sells "TTL" level UART cables containing the FT232 chip. There are various options. 1) 3.3V signal levels (TTL-232RG-VSW3V3-WE). 2) 5.0V signal levels (TTL-232RG-VSW5V-WE). 3) Adjustable signal levels (TTL-232RG-VIP-WE), with the voltage being determined by an external reference. One of these cables would provide a serial port of the correct voltage without any additional modifications. If you are willing to pay you can have them as soon as overnight from Digikey, otherwise 5 days shipping. \$\endgroup\$
    – user4574
    Oct 3, 2020 at 2:13
  • \$\begingroup\$ @user4574 I'm sure that's true, but again, I cannot stress enough the importance of having a proper JTAG programmer for developing firmware (using the bootloader only makes sense if you're programming say a previously developed firmware you downloaded from the internet). Trying to debug code without a JTAG programmer is a handicap akin to competing in a Formula 1 race with a bicycle. \$\endgroup\$
    – swineone
    Oct 3, 2020 at 2:26
  • \$\begingroup\$ I am not disagreeing with you on the copious benefits of a real JTAG programmer. You mentioned modifying "a commercial USB to serial converter". My intent was just to mention that there are cables that could be used without modification (if one were to go that route). \$\endgroup\$
    – user4574
    Oct 3, 2020 at 3:05
4
\$\begingroup\$

Yes, using an Arduino Sketch - see “Poor-man’s boot loader upload” in: https://git.jeelabs.org/jcw/embello/src/branch/master/projects/ask/stm32f1init/stm32f1init.ino

See more on https://jeelabs.org/book/1546c/index.html

\$\endgroup\$
3
  • \$\begingroup\$ Would you mind adding some more information? For example how did you come across this? I tried finding some documentation or README or actually anything about that code, but couldn't find anything. \$\endgroup\$
    – Fabio
    Oct 16, 2020 at 8:57
  • \$\begingroup\$ Found it :) jeelabs.org/book/1546c/index.html \$\endgroup\$
    – Fabio
    Oct 16, 2020 at 9:03
  • \$\begingroup\$ You can also do it with RPi \$\endgroup\$
    – Maple
    Oct 20, 2021 at 20:24
0
\$\begingroup\$

Adding to swineone's answer, I prefer to use the dfu-util command line tool (more info) with a batch script. I simply hold the boot button while plugging in the board, or better yet have a second reset button to quickly power cycle the board.

Then, I double click my batch script and it automatically flashes the board and returns it to normal operation.

set bin=C:\STM32CubeIDE_Workspace\STM32_Project\Debug\STM32_Project.bin
set du=C:\STM32CubeIDE_Workspace\dfu-util-0.9-win64\dfu-util.exe
%du% -a 0 -s 0x08000000:leave -D %bin%
pause
\$\endgroup\$
0
\$\begingroup\$

If you want to use an Arduino (or another board) to program an stm32, the key seems to be the CP2102 or the FTDI chip.

From Fabio's comment, I tried to program my STM32F103C8 fake Chinese clone with an Arduino nano(via Arduino Ide 1.8.5 and Roger Clark's board library) with the stm32duino's Arduino Core Boards support. However, it only worked twice through sheer luck.

The Arduino Decemilia in "Poor-man’s boot loader upload" has an FTDI chip as shown below. If you have a module with an FTDI chip or a CP2102 chip, it should most likely be able to program an STM32.

enter image description here

I tried it with an ESP32 NodeMCU: 38-pin version that I had lying around and it worked perfectly! (with Arduino IDE as well as on PlatformIO).

This is the forum link for using an ESP32 as an FTDI.

My setup:

Between ESP32 and STM32:
3.3V  (ESP32)  -->  3.3V  (STM32)
GND   (ESP32)  -->  GND   (STM32)
TX    (ESP32)  -->  A9    (STM32)
RX    (ESP32)  -->  A10   (STM32)

Internal to the ESP32:
EN (ESP32) --> GND (ESP32)

optional config with Platform IO (platform.ini file):

[env:bluepill_f103c8]
platform = ststm32
board = bluepill_f103c8
framework = arduino
upload_protocol = serial
upload_port = COM3
monitor_speed = 115200

enter image description here

Turns out the ESP32 NodeMCU also has a CP2102 chip. Make sure you get the drivers from here

enter image description here

-Rohit

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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