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

User avatar
Luc_Exe
Posts: 37
Joined: Fri May 01, 2015 6:08 pm
Location: Viña del Mar, Chile

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

Post by 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.

User avatar
Rick Kimball
Posts: 862
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

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

Post by Rick Kimball » Tue May 05, 2015 8:46 pm

When you use an stlink programmer you get all those benefits.
-rick

madias
Posts: 813
Joined: Mon Apr 27, 2015 11:26 am
Location: Vienna, Austria

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

Post by 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.

User avatar
Luc_Exe
Posts: 37
Joined: Fri May 01, 2015 6:08 pm
Location: Viña del Mar, Chile

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

Post by Luc_Exe » Tue May 05, 2015 10:47 pm

Rick Kimball wrote:When you use an stlink programmer you get all those benefits.
@Rick
Is that only with an original STLink or applicable to the chinese STLink V2 clones?

I was going to order one today, just wanted to make time to first read carefully this thread. I did read it just a little in the morning and I saw momething about the need to unplug-replug the stlink after the upload. Considering the low price I think I will order it anyway :lol:

@madias
Those are the naked PCB (without a chasis) versions? because i was going to buy ther version with chasis, but only found it at arround $4 ~ $4.5 on aliexpress.

@Rick, @madias

Maybe number 3 is still a good reason.

There are a few scenarios that can fit, like hobbyst making their first steps in STM32 after playing with the typical AVR arduinos, or one that just forgot or dindt know that they need an external programmer for this (for most countries is another month if they dont realize that until the board arrive). Or maybe they are just not as exited as us with the STM32 development and don't want to spend $3 in a device that will only be used as an "accesory" for the board they bought, while an arduino can be used for this and for many other things.

User avatar
Rick Kimball
Posts: 862
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

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

Post by 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?
Yes same for the chinese clones.
Luc_Exe wrote:Maybe number 3 is still a good reason.
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

User avatar
ahull
Posts: 1514
Joined: Mon Apr 27, 2015 11:04 pm
Location: Sunny Scotland
Contact:

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

Post by 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.
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.
- Andy Hull -

User avatar
Rick Kimball
Posts: 862
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

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

Post by 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.
Could be true for the clone. I was actually talking about the TARGET VCC pin you often find on the 6 pin SWD connectors. If your stlink device can supply enough power than sure you could power it from it but you don't have to. Also, a lot of people are fooled into thinking that the VCC pin on the SWD connector supplies power, but it doesn't, it is an input.
-rick

User avatar
RogerClark
Posts: 5939
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

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

Post by 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
Posts: 10
Joined: Wed Dec 02, 2015 4:37 pm

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

Post by 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)

User avatar
RogerClark
Posts: 5939
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

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

Post by 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.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests