what if we make a custom programmer for STM32 using an AVR arduino?

Luc_Exe
Tue May 05, 2015 8:41 pm
I’m sure many of you thought it before, but I didnt see it posted (yet i have to read the community board thread, it may have been posted there as suggestion).

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:

  1. dont have to mess with Boot jumpers
  2. dont have to mess with the reset button
  3. use hardware you might already have
  4. dont have to detach/attach the programmer after each upload

Disvantages:

  1. need voltage level adaptation
  2. capable of only basic debug using the same serial
  3. 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.


Rick Kimball
Tue May 05, 2015 8:46 pm
When you use an stlink programmer you get all those benefits.

madias
Tue May 05, 2015 9:31 pm
Ok, Rick was faster, this was also my first thought: ST-Link clones are about 3 USD, so there is no need for soldering something.

Luc_Exe
Tue May 05, 2015 10:47 pm
Rick Kimball wrote:When you use an stlink programmer you get all those benefits.

Rick Kimball
Tue May 05, 2015 10:56 pm
Luc_Exe wrote:Is that only with an original STLink or applicable to the chinese STLink V2 clones?

ahull
Tue May 05, 2015 11:06 pm
Rick Kimball wrote:
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.

Rick Kimball
Tue May 05, 2015 11:20 pm
ahull wrote:I’m not sure you are correct, on my ST-Link V2 clone, I can power my STM32F103CXXX board from the 3v3 line. I actually disconnect the 3v3 line when I have the board connected to the USB port just in case. There may be different versions of the programmer with different pinouts, so check on the particular version you have to see if the 3v3 and 5v pins are putting out those voltages or not.

RogerClark
Thu May 07, 2015 1:13 am
Guys,

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


armleo
Mon Dec 21, 2015 5:26 pm
U don’t need voltage shifter because of 5V – tolerant pins of JTAg SWD And Serial (more FT at documentation of ur STM32)

RogerClark
Mon Dec 21, 2015 8:59 pm
Good point about those pins being 5V tollerent.

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.


stevech
Tue Dec 22, 2015 7:38 am
RogerClark wrote:

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

RogerClark
Tue Dec 22, 2015 8:45 pm
@stevech

This thread is about using an AVR Arduino as a programmer.

Its not about using an STLink


stevech
Wed Dec 23, 2015 12:46 am
Since there exists a $20 ST-Link, what’s the benefit of a DIY AVR microprocessor-as-programmer?
Must be something I can learn from such a goal!

mrburnette
Wed Dec 23, 2015 1:01 am
stevech wrote:Since there exists a $20 ST-Link, what’s the benefit of a DIY AVR microprocessor-as-programmer?
Must be something I can learn from such a goal!

RogerClark
Wed Dec 23, 2015 5:02 am
I guess its for people who have a STM32 board but forgot to get a USB to serial and can’t easily / quickly get hold of one.

Leave a Reply

Your email address will not be published. Required fields are marked *