Author Topic: Programming a STM32F1 "Blue Pill" using a STM32F4DISCOVERY  (Read 4409 times)

0 Members and 1 Guest are viewing this topic.

Offline Buddy CasinoTopic starter

  • Newbie
  • Posts: 2
  • Country: de
Programming a STM32F1 "Blue Pill" using a STM32F4DISCOVERY
« on: March 21, 2018, 09:40:23 am »
The STM32F4DISCOVERY has a built-in st-link programmer. It can be used to program the F4 or an external device connected to the SWD connector on-board. I want to use it to program a "Blue Pill" STM32F1, because I don't have a dedicated st-link programmer.

The pins VDD_TARGET / SWCLK / GND / SWDIO on the CN2 header are connected to the respective pins of the Blue Pill, no other connections are made. No jumpers on the Blue Pill are set. The CN3 jumpers on the STM32F4DISCOVERY (datasheet: p.25, http://www.st.com/content/ccc/resource/technical/document/user_manual/70/fe/4a/3f/e7/e1/4f/7d/DM00039084.pdf/files/DM00039084.pdf/jcr:content/translations/en.DM00039084.pdf) board are removed, so the programmer points to the external device.

Starting OpenOCD gives:

Code: [Select]
openocd -f interface/stlink-v2-1.cfg -f target/stm32f1x.cfg
Open On-Chip Debugger 0.10.0-dev-ged7b1a9f-dirty (2017-07-12-13:57)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 1000 kHz
adapter_nsrst_delay: 100
none separate
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : clock speed 950 kHz
Info : STLINK v2 JTAG v25 API v2 SWIM v14 VID 0x0483 PID 0x374B
Info : using stlink api v2
Info : Target voltage: 2.923792
Error: init mode failed (unable to connect to the target)
in procedure 'init'
in procedure 'ocd_bouncer'

Any idea?
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14481
  • Country: fr
Re: Programming a STM32F1 "Blue Pill" using a STM32F4DISCOVERY
« Reply #1 on: March 21, 2018, 04:10:16 pm »
Are you properly powering your target board?

The SWD connection is not meant to power the target. VDD_TARGET is an input to level shift the SWCLK/SWDIO signal to the proper levels, not an output to power your target (as far as I know, at least this is how standard SWD adapters work).

Since there is a 3.3V LDO on the "blue pill" and the STLINK only sees a VDD of 2.92V, that may suggest that your target is not powered properly. If it is, then I don't know (maybe check you haven't swapped any of the SWD pins).
 

Online newbrain

  • Super Contributor
  • ***
  • Posts: 1719
  • Country: se
Re: Programming a STM32F1 "Blue Pill" using a STM32F4DISCOVERY
« Reply #2 on: March 21, 2018, 08:42:25 pm »
What SiliconWizard said.
The VDD_TARGET is not only an input, but on the F4 Disco board it's not used at all: the only connection are a 10K resistor to GND and a diode to...nothing (unpopulated 100 \$\Omega\$ resistor).

The voltage reported by OpenOCD is not related to that pin (TBH, I don't know where it comes from... :-//).

You can get 3V (not 3.3V, but they are OK for the BluePill) from jumper JP1 on the Disco (or any pin marked  VDD or 3V if JP1 is not removed).

Another important point: the ST-Link onf the F4 Disco is not V2.1 but V2, the correct interface driver must be used (interface/stlink-v2.cfg)

See the attached pictures for a bad photo of a working setup, and related OpenOCD messages.
It's on Windows, but there's no difference.


Nandemo wa shiranai wa yo, shitteru koto dake.
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14481
  • Country: fr
Re: Programming a STM32F1 "Blue Pill" using a STM32F4DISCOVERY
« Reply #3 on: March 21, 2018, 09:37:45 pm »
What SiliconWizard said.
The VDD_TARGET is not only an input, but on the F4 Disco board it's not used at all: the only connection are a 10K resistor to GND and a diode to...nothing (unpopulated 100 \$\Omega\$ resistor).

Oh yeah. I have only tried a true STlink V2 with OpenOCD (which does level shifting) and not the ones provided with the dev boards (Nucleo or Discovery). As I gathered, the latter don't include any level shifting and will only work at 3.3V (down to probably 3V or 2.7V maybe), so I'm not too surprised they don't even monitor VDD_TARGET.

On a side note, the STLink V2 with OpenOCD gives a flash write speed of approx. half of what you can get with a simple FTDI-based SWD adapter, so if you're not using the ST tools and just OpenOCD, I would suggest switching to one of those. I use this kind of adapter most of the time and that works fairly well: https://www.ebay.com/itm/ARM-JTAG-SWD-USB-2-0-programmer-debugger/263325051170?hash=item3d4f656922:g:He8AAMXQslhRjUOl
Additionally, it can level shift down to 1.4V and be used with many other targets (not just ST micros).

The only thing those adapters don't do is monitoring the SWO output, so if you ever use that (which can be very handy for debugging and testing), you can use an additional simple serial to USB converter, this is what I do and that works a treat at 2Mbit/s.

 

Offline mbless

  • Regular Contributor
  • *
  • Posts: 227
  • Country: 00
Re: Programming a STM32F1 "Blue Pill" using a STM32F4DISCOVERY
« Reply #4 on: March 24, 2018, 03:22:27 am »
I added the following reset code to my board config file since the blue pill doesn’t have the reset pin wired to the pin header.

Code: [Select]
reset_config none
 

Online newbrain

  • Super Contributor
  • ***
  • Posts: 1719
  • Country: se
Re: Programming a STM32F1 "Blue Pill" using a STM32F4DISCOVERY
« Reply #5 on: March 24, 2018, 09:30:47 am »
I added the following reset code to my board config file since the blue pill doesn’t have the reset pin wired to the pin header.

Code: [Select]
reset_config none

Not on the programming header, but it's there on the side header:


That said, I never bother to connect it to the ST-Link, it seems to work as expected.
Specifically, one should also remove the 0R or solder bridge to the on-board target NRST, when using the ST-Link on a Nucleo (SB12) or F4 Disco (SB11).

The OP does not seem to be interested on informing us of their success (or lack thereof) any longer  :-//, but good information is here for others to find.
Nandemo wa shiranai wa yo, shitteru koto dake.
 

Offline stj

  • Super Contributor
  • ***
  • Posts: 2155
  • Country: gb
Re: Programming a STM32F1 "Blue Pill" using a STM32F4DISCOVERY
« Reply #6 on: March 24, 2018, 10:17:49 am »
why not just use the built in bootloader and program it through the serial port??
 

Online newbrain

  • Super Contributor
  • ***
  • Posts: 1719
  • Country: se
Re: Programming a STM32F1 "Blue Pill" using a STM32F4DISCOVERY
« Reply #7 on: March 24, 2018, 10:48:39 am »
why not just use the built in bootloader and program it through the serial port??
Why not? It's for sure a viable option.

Though, it still requires an USB<->3.3V RS232 adapter and fiddling with jumpers, plus some specific piece of SW and cannot be used for debugging.

I find a debugger probe of any kind much more practical and useful.

ST-Link clones are cheap, and and there's one available on every Nucleo (64/144) or Disco Board, it's also possible to flash a Blue Pill with Black Magic Probe firmware, so plenty of choices there.
Nandemo wa shiranai wa yo, shitteru koto dake.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf