4

I'm trying to connect to an 'stm32' 'bluepill' using an stlink-v2 to write some code to it

Whenever I run openocd, it fails to connect My openocd.cfg file looks like this

source [find interface/stlink-v2.cfg]
source [find target/stm32f3x.cfg]

when i run openocd, this is the response i recieve:

Open On-Chip Debugger 0.10.0
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
adapter speed: 1000 kHz
adapter_nsrst_delay: 100
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
none separate
srst_only separate srst_nogate srst_open_drain connect_deassert_srst
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 v35 API v2 SWIM v7 VID 0x0483 PID 0x3748
Info : using stlink api v2
Info : Target voltage: 3.166623
Error: jtag status contains invalid mode value - communication failure
Polling target stm32f3x.cpu failed, trying to reexamine
Examination failed, GDB will be halted. Polling again in 100ms
Info : Previous state query failed, trying to reconnect
Error: jtag status contains invalid mode value - communication failure
Polling target stm32f3x.cpu failed, trying to reexamine
Examination failed, GDB will be halted. Polling again in 300ms
Info : Previous state query failed, trying to reconnect
Error: jtag status contains invalid mode value - communication failure
Polling target stm32f3x.cpu failed, trying to reexamine
Examination failed, GDB will be halted. Polling again in 700ms
Info : Previous state query failed, trying to reconnect
Error: jtag status contains invalid mode value - communication failure
Polling target stm32f3x.cpu failed, trying to reexamine
Examination failed, GDB will be halted. Polling again in 1500ms
Info : Previous state query failed, trying to reconnect
Error: jtag status contains invalid mode value - communication failure
Polling target stm32f3x.cpu failed, trying to reexamine
Examination failed, GDB will be halted. Polling again in 3100ms
Info : Previous state query failed, trying to reconnect
Error: jtag status contains invalid mode value - communication failure
Polling target stm32f3x.cpu failed, trying to reexamine
Examination failed, GDB will be halted. Polling again in 6300ms
^C

I had previoulsy written some code to the stm32f103 on the bluepill and when i connect to my PC,the code runs(it causes the led on pc13 to blink)

I haven't altered the openocd.cfg file sice the last time it worked well

Clifford
  • 88,407
  • 13
  • 85
  • 165
Martin
  • 41
  • 1
  • 3
  • Did you perhaps set RDP (read-out protection) when you programmed it previously? Can you connect to and read-out the device using https://www.st.com/en/development-tools/stsw-link004.html? If not use the same tool to reset the option bytes disable RDP (will bulk-erase the chip). – Clifford Mar 08 '21 at 16:55
  • Caution - PC13 only sources ~3mA and is probably unsuited to driving an LED. Check the data sheet: _" PC13, PC14 and PC15 [...] these IOs must not be used as a current source (e.g. to drive an LED)."_ . – Clifford Mar 08 '21 at 17:00
  • ... except I see that PC13 is connected to the on-board LED - well I guess someone did not read the data sheet. The 510R resistor is specified to keep the current below 3mA, but it remains a poor design choice IMO. – Clifford Mar 08 '21 at 17:10
  • 1
    This problem can be related to incorrect wiring (recheck all wires and their continuity), reset or reconfiguration of the SWDIO and SWDCLK pins. Is NRST connected and if so to which pin? Also try to press the reset button while OpenOCD connects (in case the SWDIO and SWDCLK pins have been reconfigured). – Codo Mar 08 '21 at 20:55
  • @Clifford , the stlink utility doesnt read my stlink connector despite changing the settings – Martin Mar 09 '21 at 07:16
  • @Codo, the wiring is fine, I've just rechecked it ,and holding down the reset button only halts program execution on the bluepill,once I let go execution continues(LED keeps blinking) .It doesn't help with openocd though – Martin Mar 09 '21 at 07:19
  • I've just spotted *stm32f3x.cfg*. That's the wrong config file for a BluePill board. Use *stm32f1x.cfg* instead. – Codo Mar 09 '21 at 07:46
  • @Codo Good spot, but does not explain why the ST-Link utility also does not work. That should detect the device automatically by its chip ID. – Clifford Mar 09 '21 at 09:11
  • @Martin I cannot think what "read my connector" could possibly mean. Changing what settings? I would suggest the if the ST utility cannot connect, you are wasting your time with OpenOCD. Get the simple case working before worrying about the complex case - something fundamental is not working, avoid unnecessary layers whilst trying to diagnose it. – Clifford Mar 09 '21 at 09:15

1 Answers1

5

Press and hold the reset button while OpenOCD is trying to connect.

I was getting the exact same error on my STM32F3DISCOVERY board.
Doing this allowed me to connect again.

RubberDuck
  • 11,933
  • 4
  • 50
  • 95