7
\$\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\$
  • \$\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 '14 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 at 2:19
6
\$\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).
| improve this answer | |
\$\endgroup\$
  • \$\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 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 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 at 3:05
2
\$\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

| improve this answer | |
\$\endgroup\$
  • \$\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 at 8:57
  • \$\begingroup\$ Found it :) jeelabs.org/book/1546c/index.html \$\endgroup\$ – Fabio Oct 16 at 9:03
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
| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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