STM3F0 debug probe connection on-the-fly - Page 1
Forum section: electronics / general

author: Warhawk
author_rank: Frequent Contributor
timestamp: January 17, 2018, 07:11:53 am
content: Hello everyone,I use STM32 my first time and have been wondering if there is a chance to connect to the MCU with a debug probe on-the-fly without stopping code execution or resetting the chip.I have a module with the MCU connected to a host system, which gives the module a special startup sequence (and also power) in order to start the code.I would need to wait until everything "boots" and then connect the debug probe to the MCU to read (and modify) a couple of variables.I use Keil uVision v5, Discovery kit and my own PCB with the MCU. I use all SWD wires and can't connect with different settings other than "connect under reset".If that does not work, I'll do UART.Thanks for any hint.PS: Great IC, but documentation, libraries and information consistency is

author: ataradov
author_rank: Super Contributor
timestamp: January 17, 2018, 07:47:02 am
content: Technically it is possible, whether Keil supports it, I don't know, but it may be worth keeping trying.

author: mikerj
author_rank: Super Contributor
timestamp: January 17, 2018, 08:33:46 am
content: It's been a while since I've used an STM32 but I had to do exactly this on an ADuCM320 recently, using Keil. I tried every single option, and the only way that worked for me was selecting hardware reset but leaving the hardware reset pin of the debugger disconnected. It would then reliably connect without resetting the target. YMMV of course.

author: andyturk
author_rank: Frequent Contributor
timestamp: January 17, 2018, 06:38:25 pm
content: Making a physical connection on the fly seems risky. Whenever I try that (on STM32 boards) the board almost always seems to reset.Once you've got the electrical connection, it's certainly possible to allow the mcu to run and then break in whenever you want.

author: ataradov
author_rank: Super Contributor
timestamp: January 17, 2018, 06:41:32 pm
content: Quote from: andyturk on January 17, 2018, 06:38:25 pmThat is something wrong with the hardware design. Attaching to a running target is one of the advertised features of the Cortex-Mx family.I have not tried this with ST chips, but it works very reliably with Atmel/Microchip chips. I do that very often, it is a very helpful thing when debugging wireless network software, which typically runs on many devices to form a network.

author: Warhawk
author_rank: Frequent Contributor
timestamp: January 17, 2018, 07:01:29 pm
content: Quote from: ataradov on January 17, 2018, 06:41:32 pmI second that. My colleagues and I used this feature on SAM3U (CM3) successfully.

author: janoc
author_rank: Super Contributor
timestamp: January 17, 2018, 08:56:57 pm
content: No idea about Keil, don't use it, but OpenOCD has no issues with connecting to an already running STM32. Just once it connects you get a warning message that the target is running already, so debugging could be iffy due to the uncertain state of the CPU.I have done this (minus the probe hotplugging - it is safer to connect the probe with the power off) to debug various hangs. MCU not responding, I fired up OpenOCD/gdb, sent a break command and checked where is the firmware stuck from the backtrace.

author: lucazader
author_rank: Regular Contributor
timestamp: January 18, 2018, 05:37:22 am
content: Definitely can be done.I dont tend to try this with the likes of keil or other IDE's.One of the best tools that i have found for the stm32 chips of run time debugging is STMstudio (made by st).This program AFAIK can only connect to a chip on the fly.Basically it can gives you a live text or graph read out of any variable in ram.You cant use it to set break points and step through code, but for projects such as motor control it has been invaluable for tuning the PID loops.Much easier and less overhead than uart debugging. Requires no additional code, just compile for debug and you can open up the elf file and import variables to watch.

author: andyturk
author_rank: Frequent Contributor
timestamp: January 18, 2018, 05:49:31 pm
content: Quote from: ataradov on January 17, 2018, 06:41:32 pmIt might have something to do with my daily caffeine intake.Shaky hands.

author: Warhawk
author_rank: Frequent Contributor
timestamp: January 22, 2018, 07:41:13 pm
content: Thanks for the tip with STMstudio, I am just downloading it.

author: Jeroen3
author_rank: Super Contributor
timestamp: January 23, 2018, 10:23:59 am
content: Yes you can. But I couldn't get it to work with an ST-Link, have done it countless times with ULink an JLink.http://www.keil.com/support/docs/3697.htm

author: janoc
author_rank: Super Contributor
timestamp: January 24, 2018, 08:33:51 pm
content: Quote from: Jeroen3 on January 23, 2018, 10:23:59 amFor me it worked fine with a cheap ST-Link clone too, using OpenOCD. It is not a ST-Link problem.

author: Warhawk
author_rank: Frequent Contributor
timestamp: January 28, 2018, 01:11:01 pm
content: Just a quick follow-up.I could not achieve the desired functionality using Keil and STlink on the discovery board. No matter what I do it always halts the CPU, at least. That's practically that they say here:http://www.keil.com/support/docs/3697.htmI use STM32 studio and it does what I want. Thanks for the tip!