Programming a STM32F1 "Blue Pill" using a STM32F4DISCOVERY - Page 1
Forum section: electronics / general

author: Buddy Casino
author_rank: Newbie
timestamp: March 21, 2018, 09:40:23 am
content: 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:openocd -f interface/stlink-v2-1.cfg -f target/stm32f1x.cfgOpen On-Chip Debugger 0.10.0-dev-ged7b1a9f-dirty (2017-07-12-13:57)Licensed under GNU GPL v2For bug reports, readhttp://openocd.org/doc/doxygen/bugs.htmlInfo : 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/SWDadapter speed: 1000 kHzadapter_nsrst_delay: 100none separateInfo : Unable to match requested speed 1000 kHz, using 950 kHzInfo : Unable to match requested speed 1000 kHz, using 950 kHzInfo : clock speed 950 kHzInfo : STLINK v2 JTAG v25 API v2 SWIM v14 VID 0x0483 PID 0x374BInfo : using stlink api v2Info : Target voltage: 2.923792Error: init mode failed (unable to connect to the target)in procedure 'init'in procedure 'ocd_bouncer'Any idea?

author: SiliconWizard
author_rank: Super Contributor
timestamp: March 21, 2018, 04:10:16 pm
content: 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).

author: newbrain
author_rank: Super Contributor
timestamp: March 21, 2018, 08:42:25 pm
content: 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 100resistor).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.

author: SiliconWizard
author_rank: Super Contributor
timestamp: March 21, 2018, 09:37:45 pm
content: Quote from: newbrain on March 21, 2018, 08:42:25 pmOh 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:He8AAMXQslhRjUOlAdditionally, 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.

author: mbless
author_rank: Regular Contributor
timestamp: March 24, 2018, 03:22:27 am
content: 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:reset_config none

author: newbrain
author_rank: Super Contributor
timestamp: March 24, 2018, 09:30:47 am
content: Quote from: mbless on March 24, 2018, 03:22:27 amNot 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.

author: stj
author_rank: Super Contributor
timestamp: March 24, 2018, 10:17:49 am
content: why not just use the built in bootloader and program it through the serial port??

author: newbrain
author_rank: Super Contributor
timestamp: March 24, 2018, 10:48:39 am
content: Quote from: stj on March 24, 2018, 10:17:49 amWhy 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.