Monday, January 22nd 2018, 5:25pm UTC+1

You are not logged in.

  • Login
  • Register

Dear visitor, welcome to SEGGER Forum. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

zappel

Beginner

Date of registration: Jul 4th 2015

Posts: 17

1

Sunday, December 6th 2015, 2:02am

[SOLVED] RTT printf implementation bug

Using V5.10c Software for OS X with my J-Link first of all I'm missing the RTT files in the Samples folder (at least here it is stated it should be there).
I'm not sure where I got my RTT files from, but they are V210.

But the real problem is the bad quality of the printf-implementation. Running the printf-test I get the following output:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
SEGGER Real-Time-Terminal Sample

###### Testing SEGGER_printf() ######
printf Test: %c,         'S' : S.
printf Test: %5c,        'E' : E.
printf Test: %-5c,       'G' : G.
printf Test: %5.3c,      'G' : G.
printf Test: %.3c,       'E' : E.
printf Test: %c,         'R' : R.
printf Test: %s,      "RTT" : RTT.
printf Test: %s, "RTT\r\nRocks." : RTT
Rocks..


And that's it. All other format specifier's are never printed. So looking into the code I am not sure whats a fix for the bug, because the source code is very chaotic at least in my opinion. But the following line is definitly a bug (for example in _PrintUnsigned l.179):

C/C++ Source code

1
2
3
4
while (((v / Digit) >= Base) || (NumDigits > 1u)) {
      NumDigits--;
      Digit *= Base;
    }


NumDigits is unsigned and could be zero. So during the first iteration NumDigits = 4294967295...

Probably lines 148-153 are also problematic because Width is never ever used after these lines....

I don't want to waste more time debugging the printf-functions, because these are a advertised features so they should work.

Thanks in Advance

BTW, it would be nice to have these files hosted on a public git server, so you could add a submodule to your git-controlled own project and get upstream updates very easily. Really pleasant, that ARM did the same to CMSIS this year (https://github.com/ARM-software/CMSIS).

SEGGER - Johannes

Super Moderator

Date of registration: Aug 31st 2012

Posts: 376

2

Wednesday, December 9th 2015, 9:57am

Hi,

Currently the RTT files are only part of the Windows version.
We will make sure the RTT files will be in the samples folder of the OS X version, too, and that SEGGER_RTT_Printf is working.

We will think about making them available in a repository,
but currently the J-Link Software Package is the only source for the RTT files.

Best regards
Johannes

zappel

Beginner

Date of registration: Jul 4th 2015

Posts: 17

3

Friday, December 11th 2015, 3:45pm


Currently the RTT files are only part of the Windows version.
We will make sure the RTT files will be in the samples folder of the OS X version, too, and that SEGGER_RTT_Printf is working.


Thanks, I will report back if it is working for me if it is available (presumably in beta first?).

zappel

Beginner

Date of registration: Jul 4th 2015

Posts: 17

4

Friday, January 22nd 2016, 9:55pm

We will make sure the RTT files will be in the samples folder of the OS X version, too, and that SEGGER_RTT_Printf is working.


I have downloaded the new V511b package and the printf-implementation is working much better now. The output I get now is:

C/C++ Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
SEGGER Real-Time-Terminal Sample

###### Testing SEGGER_printf() ######
printf Test: %c,         'S' : S.
printf Test: %5c,        'E' : E.
printf Test: %-5c,       'G' : G.
printf Test: %5.3c,      'G' : G.
printf Test: %.3c,       'E' : E.
printf Test: %c,         'R' : R.
printf Test: %s,      "RTT" : RTT.
printf Test: %s, "RTT\r\nRocks." : RTT
Rocks..
printf Test: %u,       12345 : 12345.
printf Test: %+u,      12345 : 12345.
printf Test: %.3u,     12345 : 12345.
printf Test: %.6u,     12345 : 012345.
printf Test: %6.3u,    12345 :  12345.
printf Test: %8.6u,    12345 :   012345.
printf Test: %08u,     12345 : 00012345.
printf Test: %08.6u,   12345 :   012345.
printf Test: %0u,      12345 : 12345.
printf Test: %-.6u,    12345 : 012345.
printf Test: %-6.3u,   12345 : 12345 .
printf Test: %-8.6u,   12345 : 012345  .
printf Test: %-08u,    12345 : 12345   .
printf Test: %-08.6u,  12345 : 012345  .
printf Test: %-0u,     12345 : 12345.
printf Test: %u,      -12345 : 4294954951.
printf Test: %+u,     -12345 : 4294954951.
printf Test: %.3u,    -12345 : 4294954951.
printf Test: %.6u,    -12345 : 4294954951.
printf Test: %6.3u,   -12345 : 4294954951.
printf Test: %8.6u,   -12345 : 4294954951.
printf Test: %08u,    -12345 : 4294954951.
printf Test: %08.6u,  -12345 : 4294954951.
printf Test: %0u,     -12345 : 4294954951.
printf Test: %-.6u,   -12345 : 4294954951.
printf Test: %-6.3u,  -12345 : 4294954951.
printf Test: %-8.6u,  -12345 : 4294954951.
printf Test: %-08u,   -12345 : 4294954951.
printf Test: %-08.6u, -12345 : 4294954951.
printf Test: %-0u,    -12345 : 4294954951.
printf Test: %d,      -12345 : -12345.
printf Test: %+d,     -12345 : -12345.
printf Test: %.3d,    -12345 : -12345.
printf Test: %.6d,    -12345 : -012345.
printf Test: %6.3d,   -12345 : -12345.
printf Test: %8.6d,   -12345 :  -012345.
printf Test: %08d,    -12345 : -0012345.
printf Test: %08.6d,  -12345 :  -012345.
printf Test: %0d,     -12345 : -12345.
printf Test: %-.6d,   -12345 : -012345.
printf Test: %-6.3d,  -12345 : -12345.
printf Test: %-8.6d,  -12345 : -012345 .
printf Test: %-08d,   -12345 : -12345  .
printf Test: %-08.6d, -12345 : -012345 .
printf Test: %-0d,    -12345 : -12345.
printf Test: %x,      0x1234ABC : 1234ABC.
printf Test: %+x,     0x1234ABC : 1234ABC.
printf Test: %.3x,    0x1234ABC : 1234ABC.
printf Test: %.6x,    0x1234ABC : 1234ABC.
printf Test: %6.3x,   0x1234ABC : 1234ABC.
printf Test: %8.6x,   0x1234ABC :  1234ABC.
printf Test: %08x,    0x1234ABC : 01234ABC.
printf Test: %08.6x,  0x1234ABC :  1234ABC.
printf Test: %0x,     0x1234ABC : 1234ABC.
printf Test: %-.6x,   0x1234ABC : 1234ABC.
printf Test: %-6.3x,  0x1234ABC : 1234ABC.
printf Test: %-8.6x,  0x1234ABC : 1234ABC .
printf Test: %-08x,   0x1234ABC : 1234ABC .
printf Test: %-08.6x, 0x1234ABC : 1234ABC .
printf Test: %-0x,    0x1234ABC : 1234ABC.
printf Test: %p,      &_Cnt      : 20000D1C.
###### SEGGER_printf() Tests done. ######


But obviously this output is not really perfect. Maybe further bugfixing should be done.

Besides, the RTT-files are not included in the OS X package. I have to get the Windows one to test the new implementation.

SEGGER - Johannes

Super Moderator

Date of registration: Aug 31st 2012

Posts: 376

5

Tuesday, January 26th 2016, 6:57pm

Hi,

In general SEGGER_RTT_Printf is working.
The only difference is, that field width and precision are ignored for the %c specifier.
We might improve this, too, to match the output you would expect from printf().

Regards
Johannes