EEVblog® Electronics Community Forum

Electronics => Microcontrollers => Topic started by: VanitarNordic on July 28, 2018, 02:08:51 pm

Title: STM32 code debugging
Post by: VanitarNordic 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?

(http://uupload.ir/files/b8hr_2018-07-28_18-31-32.jpg)

(http://uupload.ir/files/l0u_2018-07-28_18-34-59.jpg)
Title: Re: STM32 code debugging
Post by: langwadt 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
Title: Re: STM32 code debugging
Post by: gnif 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.
Title: Re: STM32 code debugging
Post by: VanitarNordic 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.
Title: Re: STM32 code debugging
Post by: Skashkash 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
Title: Re: STM32 code debugging
Post by: VanitarNordic 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".

Title: Re: STM32 code debugging
Post by: tsman 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.
Title: Re: STM32 code debugging
Post by: VanitarNordic 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:

(http://uupload.ir/files/tyub_2018-07-28_23-06-30.jpg)
Title: Re: STM32 code debugging
Post by: Brutte 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.
Title: Re: STM32 code debugging
Post by: VanitarNordic 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.
Title: Re: STM32 code debugging
Post by: langwadt 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

Title: Re: STM32 code debugging
Post by: VanitarNordic 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.