Author Topic: 32F4: Can a target crash or affect Cube IDE?  (Read 2039 times)

0 Members and 1 Guest are viewing this topic.

Online peter-hTopic starter

  • Super Contributor
  • ***
  • Posts: 4152
  • Country: gb
  • Doing electronics since the 1960s...
32F4: Can a target crash or affect Cube IDE?
« on: July 12, 2023, 05:10:23 pm »
Here is a funny Q on Cube, running a STLINK debugger:

Is there any way for a "dodgy" target to hang or crash Cube, or cause Cube to lose contact with the debugger, or mess up a part of Cube's debug functionality e.g. the SWV ITM debug output feature?

I would think that the answer must be NO unless you are running in Debug mode. But who knows? There is still a USB connection PC to debugger, and I can see there is probably continuous data on that cable.

In Debug mode, there is definitely constant USB data.

Reason I ask is that over the 2-3 years I've been writing and debugging code (mostly with STLINK V2 ISOL or STLINK V3 ISOL) I have found that sometimes the Debug mode runs for no more than an hour (or even much less) and sometimes it seems to run for weeks, before it drops Debug mode. Right now, on the current and nearly final generation of my code, Cube does run for weeks in Debug.

And this is at two different sites (home and office).

Sometimes Cube loses breakpoints until you exit it and restart it. Weird stuff like that.

Is that possible?
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 28102
  • Country: nl
    • NCT Developments
Re: 32F4: Can a target crash or affect Cube IDE?
« Reply #1 on: July 12, 2023, 05:17:49 pm »
Very probable. Keep in mind that JTAG / SWD is a synchronous protocol and 1 false clock on the clock line can screw things up badly.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline ajb

  • Super Contributor
  • ***
  • Posts: 2735
  • Country: us
Re: 32F4: Can a target crash or affect Cube IDE?
« Reply #2 on: July 12, 2023, 05:59:01 pm »
I've definitely seen issues with multiple debug environments along these lines.  Not necessarily a target crash, but something goes wrong somewhere in the debug chain, and debugging won't work again until you restart the IDE and/or unplug/replug the debug tool.  There's a lot that goes on between click "Debug" and actually getting the debug session up and running, and a lot of software involved: UI stuff in the debug environment, the debug backend, USB drivers, OS-level USB support, firmware on the probe, etc, plus electrical aspects of the SWD/JTAG interface.  So lots of opportunities for errors to occur, and lots of code that needs to be able to handle those errors appropriately. 

FWIW, I mostly saw these sorts of issues when using an ST-Link V2.  IME, J-Link probes are much more reliable, and also generally faster.  I've still had to restart an IDE once in a while when using a J-Link, but overall FAR fewer issues than with an ST-Link.  No experience with the newer ST-Links.

 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6277
  • Country: es
Re: 32F4: Can a target crash or affect Cube IDE?
« Reply #3 on: July 12, 2023, 06:24:28 pm »
I've had issues with the IDE getting slower and slower when debugging with SWO enabled, until eventually crashing, mostly when using SWD Data Trace plot.
It's been a long time since last time, back then the IDE was a lot slower and greedy for RAM, opening large source files made it extremely sluggish, requiring all the smart code functions to be disabled.
I've never had that issue again since 1.09 or so, so the SWD slowdown might be also fixed by now.
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8901
  • Country: fi
Re: 32F4: Can a target crash or affect Cube IDE?
« Reply #4 on: July 12, 2023, 06:30:33 pm »
Buggy software usually fails to validate/sanitize input data, plus abstractions between modules are leaky spaghetti mess, so yes, anything is possible.
 

Online peter-hTopic starter

  • Super Contributor
  • ***
  • Posts: 4152
  • Country: gb
  • Doing electronics since the 1960s...
Re: 32F4: Can a target crash or affect Cube IDE?
« Reply #5 on: July 12, 2023, 08:14:26 pm »
Quote
I've had issues with the IDE getting slower and slower when debugging with SWO enabled, until eventually crashing

Yes; stuff like that.

It's got better but not properly fixed. Cube has to be restarted.

But the strange thing is that the target software affects how [un]reliable it is. It almost looks like something subtle is affecting Cube. I have two targets which have suddenly become much more reliable after I put in the CPU ID checks for making use of the extra 64k of the 437. But only one of the two targets actually has a 437 :) The other is a 417. So it looks like calling the CPU ID check func changes something.
https://www.eevblog.com/forum/microcontrollers/32f417-32f437-auto-detect-of-extra-64k-ram/

A bit more detail in case anybody thinks of something:

Cube gets the CPU ID (and rev code etc) for the debugger init, obviously (it shows the detail, too).
My boot block gets the CPU ID, but it runs fully in 417 mode and the only thing it does differently if it is a 437 is that it fills the 437 stack (8k, top of RAM) with "S", whereas with a 417 it fills the 417 stack (also 8k, top of RAM) with "s".
Then it jumps to main() which also gets the CPU ID and uses it for various things, especially the Vbat measurement R ratio.
« Last Edit: July 12, 2023, 08:37:27 pm by peter-h »
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6277
  • Country: es
Re: 32F4: Can a target crash or affect Cube IDE?
« Reply #6 on: July 12, 2023, 08:24:41 pm »
Have you ever tried emBitz? Last time I used it was astonishing fast.
Then I stopped for a while and I simply forgot.
I want to try running the HK32/PY32 there!
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Online peter-hTopic starter

  • Super Contributor
  • ***
  • Posts: 4152
  • Country: gb
  • Doing electronics since the 1960s...
Re: 32F4: Can a target crash or affect Cube IDE?
« Reply #7 on: July 12, 2023, 08:26:17 pm »
No; I am stuck with Cube IDE, for many reasons.
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Offline newbrain

  • Super Contributor
  • ***
  • Posts: 1773
  • Country: se
Re: 32F4: Can a target crash or affect Cube IDE?
« Reply #8 on: July 12, 2023, 08:34:35 pm »
I have managed to repeatably crash gdb while developing my debug monitor with an out of sequence message.
No SWD involved, just serial (over USB, admittedly).
Nandemo wa shiranai wa yo, shitteru koto dake.
 

Online peter-hTopic starter

  • Super Contributor
  • ***
  • Posts: 4152
  • Country: gb
  • Doing electronics since the 1960s...
Re: 32F4: Can a target crash or affect Cube IDE?
« Reply #9 on: July 12, 2023, 09:09:49 pm »
Should there be any SWD activity if no breakpoints are set in Cube?

I have no dual-use SWD or BOOT pins, and everything is pulled up/down.

AIUI, SWD or JTAG is a huge PISO+SIPO shift register which goes all around the CPU and you can read, or even write, various things. But if not writing (which is possible only while stopped anyway) the CPU should not be affected and it should not affect anything via SWD/JTAG.
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Offline abyrvalg

  • Frequent Contributor
  • **
  • Posts: 837
  • Country: es
Re: 32F4: Can a target crash or affect Cube IDE?
« Reply #10 on: July 13, 2023, 06:20:24 am »
The never stopping USB activity doesn’t necessarily mean SWD activity:
- ST-Link V3 has a virtual serial port, the OS should poll it even if you close the IDE
- There can be something like continuous target voltage sensing by the IDE
 

Online peter-hTopic starter

  • Super Contributor
  • ***
  • Posts: 4152
  • Country: gb
  • Doing electronics since the 1960s...
Re: 32F4: Can a target crash or affect Cube IDE?
« Reply #11 on: July 13, 2023, 06:32:26 am »
Right, but something is terminating the Debug mode. This happened after an unusually long time - a few days. Most people report hours or less...



In the absence of breakpoints set, what could terminate the Debug mode?

Tried all the usual things over the years e.g. running SWD at some low frequency, etc.

It might be related to getting the CPU ID - as I posted above.

But why would Cube even be aware that the target is running, if there are no breakpoints? Does SWD have a CRC on it, so if Cube is running a continuous clock+data around the chip and gets a bad CRC...? I guess Cube does not assume it knows about breakpoints (especially the five "hardware" ones) so it is continuously polling the loop.
« Last Edit: July 13, 2023, 06:48:01 am by peter-h »
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 
The following users thanked this post: jamesglanville

Offline Perkele

  • Regular Contributor
  • *
  • Posts: 59
  • Country: ie
Re: 32F4: Can a target crash or affect Cube IDE?
« Reply #12 on: July 13, 2023, 07:59:27 pm »
STLinkv3, MCU connected over SWD, ITM used as debug print output.
STM32CubeIDE crashes if I leave it for more than one hoour with debugger running.

I wasn't bothered with finding the cause, because I don't use Cube regularly.
Connected a logic analyser and used GPIOs and UART instead of breakpoints.
Found the cause of issues in firmware and successfully continued to ignore the existence of STM32CubeIDE.
 

Offline abyrvalg

  • Frequent Contributor
  • **
  • Posts: 837
  • Country: es
Re: 32F4: Can a target crash or affect Cube IDE?
« Reply #13 on: July 14, 2023, 12:40:48 am »
But why would Cube even be aware that the target is running, if there are no breakpoints?

In theory there are ways to initiate debug halt from the firmware side w/o setting any breakpoints from the IDE:
- executing a BKPT instruction
- setting a breakpoint by programming the FPB unit
- halting directly by a write to CoreDebug->DHCSR

While 2nd and 3rd ways looks quite exotic to be supported by the IDE, the BKPT instruction was seen in some panic()- and exit()-like functions. So they could've decided to poll the halt state regardless of BPs being set.
« Last Edit: July 14, 2023, 12:43:23 am by abyrvalg »
 

Online peter-hTopic starter

  • Super Contributor
  • ***
  • Posts: 4152
  • Country: gb
  • Doing electronics since the 1960s...
Re: 32F4: Can a target crash or affect Cube IDE?
« Reply #14 on: July 14, 2023, 01:29:39 pm »
I can understand you, but why would Cube be doing this on a target running under Debug, or how could the target cause Cube to drop the Debug mode (and say "target is not responding")?

Taking that error message as correct (probably unwise) what kind of "response" would Cube be looking for? Is the target sending some data unilaterally? AIUI, SWD/JTAG is a synch protocol, with the PC supplying the clock.
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6277
  • Country: es
Re: 32F4: Can a target crash or affect Cube IDE?
« Reply #15 on: July 14, 2023, 01:53:22 pm »
Don't try to find reasonable explanations for buggy software  ;)
Seriously, give a try to emBitz, shouldnt be hard and it will peacefully coexist with the CubeIDE project files.
I'm not telling to use it for developing, just for long debugging sessions.
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Online peter-hTopic starter

  • Super Contributor
  • ***
  • Posts: 4152
  • Country: gb
  • Doing electronics since the 1960s...
Re: 32F4: Can a target crash or affect Cube IDE?
« Reply #16 on: July 15, 2023, 07:08:34 am »
What I found to be much more "reliable" is that the use of the SWV ITM debug feature bombs Cube much faster, but that was only during the target actually outputting.

The problem was not related to the clock speed used for SWV ITM.
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6277
  • Country: es
Re: 32F4: Can a target crash or affect Cube IDE?
« Reply #17 on: July 15, 2023, 08:08:11 am »
For only the de ITM console you can use STLink utility.
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 
The following users thanked this post: peter-h

Online peter-hTopic starter

  • Super Contributor
  • ***
  • Posts: 4152
  • Country: gb
  • Doing electronics since the 1960s...
Re: 32F4: Can a target crash or affect Cube IDE?
« Reply #18 on: July 15, 2023, 09:22:53 am »
I had a play with that and it looks like it has great potential, but it is difficult to get it to work. Maybe some subtle config issue.

I have a printf redirected to SWV ITM and this works with Cube IDE. This comes out shortly after startup and outputs "Hello" and PCLK1/2 etc.

I managed to get the line of output to come out but only a bit at a time, say 5 chars, by pressing start/stop on the SWV console, but that was my entire success. Then that stopped... I am using the System Reset button to restart the target so I can get the output, and the reset works ok.

For SWV to work one has to config the CPU clock, which I have at 168000000. The 2000kHz SWV clock is not evidently configurable anywhere. For the SWD clock, currently 8000kHz, I have tried all speeds.

Cube IDE not running, is correct, I presume. It can run but not with any debug functionality since the USB debugger port cannot be shared.

EDIT: I got it running eventually, by disconnecting the STLINK USB cable a few times :) Let's see how long it lasts for... The output is rendered much faster than in Cube. Probably the STLINK utility isn't running 10k lines of Java for each byte :)

Spotted something curious: the debug console expands \r to \r\n. I checked this with a breakpoint on the actual ST low level function. IOW, a pure "CR" (a line overwriting itself) cannot be implemented e.g.
printf("In app.c %010lu\r",loopcnt++);

« Last Edit: July 15, 2023, 10:55:17 am by peter-h »
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Online peter-hTopic starter

  • Super Contributor
  • ***
  • Posts: 4152
  • Country: gb
  • Doing electronics since the 1960s...
Re: 32F4: Can a target crash or affect Cube IDE?
« Reply #19 on: July 15, 2023, 04:39:56 pm »
How does the ST-LINK Utility implement a continuously updated live view on RAM, on a running target?

It must be halting the target and reading out the RAM, surely?

This is the stack area, continuously changing as the interrupts etc are running. Quite impressive.
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Offline abyrvalg

  • Frequent Contributor
  • **
  • Posts: 837
  • Country: es
Re: 32F4: Can a target crash or affect Cube IDE?
« Reply #20 on: July 15, 2023, 05:29:46 pm »
Cortex debug port has direct system bus access, no need to halt the core to read/write memories. Debugger just writes addresses/access types and transfers the data. That’s great, compared to i.e. older ARM7, where you needed to inject a load/store instruction and observe/overwrite right bus cycle.
 
The following users thanked this post: peter-h

Offline ajb

  • Super Contributor
  • ***
  • Posts: 2735
  • Country: us
Re: 32F4: Can a target crash or affect Cube IDE?
« Reply #21 on: July 15, 2023, 05:55:56 pm »
The Debug support section of the datasheet should have a diagram showing how the debug components interface with the system.  Between that and the bus matrix diagram you should see that the debug support components have access to memory (and everything else on the bus) independent of the core.  Since the bus matrix supports multiple masters anyway (it has to for DMA to work, and to support multi-core architectures) the debug interface can operate as just another bus master and initiate accesses independently of the core.  It may incur a performance penalty, though, since even with a comprehensive bus matrix there may still be some contention for access to the same resources.
 
The following users thanked this post: peter-h

Online peter-hTopic starter

  • Super Contributor
  • ***
  • Posts: 4152
  • Country: gb
  • Doing electronics since the 1960s...
Re: 32F4: Can a target crash or affect Cube IDE?
« Reply #22 on: July 15, 2023, 08:49:08 pm »
This is an impressive tool.

I guess most use it to also set things like level 2 security, even though your code can do the same.
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6277
  • Country: es
Re: 32F4: Can a target crash or affect Cube IDE?
« Reply #23 on: July 25, 2023, 07:36:27 pm »
Anyways, you can leave the target running and connect later on when it crashes.
Check the STM32CubeIDE manual, "Attach to running target", and better read it whole!
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 
The following users thanked this post: peter-h


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf