STM32 code debugging - Page 1
Forum section: electronics / general

author: VanitarNordic
author_rank: Frequent Contributor
timestamp: July 28, 2018, 02:08:51 pm
content: 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: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!Anybody knows why? I have declared them isn't it?

author: langwadt
author_rank: Super Contributor
timestamp: July 28, 2018, 02:32:38 pm
content: 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

author: gnif
author_rank: Unknown
timestamp: July 28, 2018, 02:33:00 pm
content: Quote from: langwadt on July 28, 2018, 02:32:38 pmBeat me to it.

author: VanitarNordic
author_rank: Frequent Contributor
timestamp: July 28, 2018, 02:47:58 pm
content: Quote from: langwadt on July 28, 2018, 02:32:38 pmYes, I have optimized for speed. I will test your suggestion.

author: Skashkash
author_rank: Regular Contributor
timestamp: July 28, 2018, 03:12:24 pm
content: 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

author: VanitarNordic
author_rank: Frequent Contributor
timestamp: July 28, 2018, 03:19:31 pm
content: 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".

author: tsman
author_rank: Frequent Contributor
timestamp: July 28, 2018, 04:07:57 pm
content: Quote from: VanitarNordic on July 28, 2018, 03:19:31 pmYou'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.

author: VanitarNordic
author_rank: Frequent Contributor
timestamp: July 28, 2018, 06:38:09 pm
content: QuoteWhat 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:

author: Brutte
author_rank: Frequent Contributor
timestamp: July 28, 2018, 08:25:40 pm
content: 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.

author: VanitarNordic
author_rank: Frequent Contributor
timestamp: July 28, 2018, 10:38:36 pm
content: Quote from: Brutte on July 28, 2018, 08:25:40 pmPutting 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.

author: langwadt
author_rank: Super Contributor
timestamp: July 28, 2018, 11:23:32 pm
content: Quote from: VanitarNordic on July 28, 2018, 10:38:36 pmreal-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

author: VanitarNordic
author_rank: Frequent Contributor
timestamp: July 29, 2018, 10:40:04 am
content: 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:Remote failure reply: E31I do not power the board by the programmer and I use an external supply. I don't know why this happens.