Author Topic: STM32 code debugging  (Read 3630 times)

0 Members and 1 Guest are viewing this topic.

Offline VanitarNordicTopic starter

  • Frequent Contributor
  • **
  • Posts: 277
  • Country: 00
STM32 code debugging
« on: July 28, 2018, 02:08:51 pm »
I use TrueStudio to code STM32. Besides, I use STLink SWD and serial wire viewer (SWV) for debugging.

I declared two variables and used them like below:

Code: [Select]
uint16_t i = 0, temp = 0;

......
......

int main(void){

.....
.....
while (1){

for (i = 0; i<1000; i++)
  temp = i;

}

....
....

}


but when I want to trace i or temp as variables inside the SWV setting, it says that the temp variable (either i) is not declared! :o :o

Anybody knows why? I have declared them isn't it?



« Last Edit: July 28, 2018, 02:54:21 pm by VanitarNordic »
 

Online langwadt

  • Super Contributor
  • ***
  • Posts: 4427
  • Country: dk
Re: STM32 code debugging
« Reply #1 on: July 28, 2018, 02:32:38 pm »
if you have any optimization turned on the compiler is smart enough to remove variables or keep them in registers if it can tell they aren't used anywhere else
 
The following users thanked this post: gnif, VanitarNordic

Offline gnif

  • Administrator
  • *****
  • Posts: 1676
  • Country: au
Re: STM32 code debugging
« Reply #2 on: July 28, 2018, 02:33:00 pm »
if you have any optimization turned on the compiler is smart enough to remove variables or keep them in registers if it can tell they aren't used anywhere else

Beat me to it.
 

Offline VanitarNordicTopic starter

  • Frequent Contributor
  • **
  • Posts: 277
  • Country: 00
Re: STM32 code debugging
« Reply #3 on: July 28, 2018, 02:47:58 pm »
if you have any optimization turned on the compiler is smart enough to remove variables or keep them in registers if it can tell they aren't used anywhere else

Yes, I have optimized for speed. I will test your suggestion.
 

Offline Skashkash

  • Regular Contributor
  • *
  • Posts: 118
  • Country: us
Re: STM32 code debugging
« Reply #4 on: July 28, 2018, 03:12:24 pm »
See if your compiler offers an "optimize for debug".

 For GCC it's the -Og option.

 It's a good compromise that enables optimizations that won't interfere (hopefully) with the debugging experience.

relevant page:
https://gcc.gnu.org/onlinedocs/gcc-4.8.3/gcc/Optimize-Options.html
 
The following users thanked this post: VanitarNordic

Offline VanitarNordicTopic starter

  • Frequent Contributor
  • **
  • Posts: 277
  • Country: 00
Re: STM32 code debugging
« Reply #5 on: July 28, 2018, 03:19:31 pm »
The problem was fixed. Thank you.

I have another issue with the SWV tracing.

As picture says I have imported the "temp" variable to trace all values sequentially, but SWV jumps between values. I mean it misses many values between 0 and 999, sometimes it print 30, once 430 ... , Except than I put a break-point there and debug it traditionally which I don't want to do so.

This is just a simple example to fix another problem I have, which I want to grab all ADC values in the buffer, in realtime and see how well it samples an input signal inside the "SWV Data Trace Timeline Graph".

« Last Edit: July 28, 2018, 03:23:06 pm by VanitarNordic »
 

Offline tsman

  • Frequent Contributor
  • **
  • Posts: 599
  • Country: gb
Re: STM32 code debugging
« Reply #6 on: July 28, 2018, 04:07:57 pm »
As picture says I have imported the "temp" variable to trace all values sequentially, but SWV jumps between values. I mean it misses many values between 0 and 999, sometimes it print 30, once 430 ... , Except than I put a break-point there and debug it traditionally which I don't want to do so
You're trying to send too much data too fast. Your core clock is 120MHz but the SWO pin is only 2MHz and that has overhead as well.
 
The following users thanked this post: VanitarNordic

Offline VanitarNordicTopic starter

  • Frequent Contributor
  • **
  • Posts: 277
  • Country: 00
Re: STM32 code debugging
« Reply #7 on: July 28, 2018, 06:38:09 pm »
Quote
You're trying to send too much data too fast. Your core clock is 120MHz but the SWO pin is only 2MHz and that has overhead as well.

What can I do in such cases? I have to check the data stream by any mean. I had read SWV does not miss any data and it passes them one by one. This is the clock diagram:

« Last Edit: July 28, 2018, 07:36:59 pm by VanitarNordic »
 

Offline Brutte

  • Frequent Contributor
  • **
  • Posts: 614
Re: STM32 code debugging
« Reply #8 on: July 28, 2018, 08:25:40 pm »
On ARMv7 you cannot trace working registers.
Only the traffic on busses can be traced, if you know address of a variable.
So it woud be hard to trace auto variables or values that are optimized out.
Now, SWV can be configured in many ways. It is just a TX UART. But I bet that even when you configured it to run at 120Mbps - it won't be able to printf your while(1) fast enough. Maybe add a delay in that loop.
 
The following users thanked this post: VanitarNordic

Offline VanitarNordicTopic starter

  • Frequent Contributor
  • **
  • Posts: 277
  • Country: 00
Re: STM32 code debugging
« Reply #9 on: July 28, 2018, 10:38:36 pm »
On ARMv7 you cannot trace working registers.
Only the traffic on busses can be traced, if you know address of a variable.
So it woud be hard to trace auto variables or values that are optimized out.
Now, SWV can be configured in many ways. It is just a TX UART. But I bet that even when you configured it to run at 120Mbps - it won't be able to printf your while(1) fast enough. Maybe add a delay in that loop.

Putting a delay did not work. Actually SWV was introduced as a realtime debugging tool, which naturally should not introduce timing limitations. it must be a way to do this.
 

Online langwadt

  • Super Contributor
  • ***
  • Posts: 4427
  • Country: dk
Re: STM32 code debugging
« Reply #10 on: July 28, 2018, 11:23:32 pm »
On ARMv7 you cannot trace working registers.
Only the traffic on busses can be traced, if you know address of a variable.
So it woud be hard to trace auto variables or values that are optimized out.
Now, SWV can be configured in many ways. It is just a TX UART. But I bet that even when you configured it to run at 120Mbps - it won't be able to printf your while(1) fast enough. Maybe add a delay in that loop.

Putting a delay did not work. Actually SWV was introduced as a realtime debugging tool, which naturally should not introduce timing limitations. it must be a way to do this.

real-time as in it doesn't stop the cpu you can read variables in a running system,  there is only so much bandwidth to send data it can't  do magic

 

Offline VanitarNordicTopic starter

  • Frequent Contributor
  • **
  • Posts: 277
  • Country: 00
Re: STM32 code debugging
« Reply #11 on: July 29, 2018, 10:40:04 am »
This problem could be solved somehow by using a break-point, and debug the code traditionally. but I constantly get the following error and the debug gets interrupted:
Code: [Select]
Remote failure reply: E31

I do not power the board by the programmer and I use an external supply. I don't know why this happens.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf