When the bug lies in your debug print function…

Here’s a riddle:

A for loop with index i and stop condition i < x contains a code which prints i and does some non relevant computations. When x is greater than y the code prints i up to x-1 (as you would expect), but when x is smaller than y the code prints i up to 51. The threshold y is slightly random (it hovers around 1120), but the 51 is not. What is happening ?

Well, first here’s more precise information on what actually happens: if x > y the code actually doesn’t print all the values up to y-1, it only prints the first 51 values and the values between y and x-1 .

Also, my debug prints starts showing only after around 8 seconds (I don’t know why it takes so long), and the 51 first prints are actually all printed at once after the 8 seconds, but the rest of the prints are printed without any latency

So I presume what’s happening is the debug prints sent during the first 8 seconds are stored in a limited buffer. The yth print however takes more than 8 seconds to be sent, so when x > y the 51 buffered prints are shown, but then since the 8 seconds are past there is no buffer problems anymore and the remaining prints are all shown without issues.

Since I didn’t notice the gap between 51 and x-1 when x was greater than y , I took a long time to figure out the problem was in the debug function, and was looking for a problem in the rest of code which was sending SPI frames…

If anyone have any idea why my debug prints (which are using the Real Time Transfer module from Segger) takes so long to start showing, please let me know…

Leave a Reply

Your email address will not be published. Required fields are marked *