[SOLVED] RTT printf implementation bug

  • [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. SEGGER Real-Time-Terminal Sample
    2. ###### Testing SEGGER_printf() ######
    3. printf Test: %c, 'S' : S.
    4. printf Test: %5c, 'E' : E.
    5. printf Test: %-5c, 'G' : G.
    6. printf Test: %5.3c, 'G' : G.
    7. printf Test: %.3c, 'E' : E.
    8. printf Test: %c, 'R' : R.
    9. printf Test: %s, "RTT" : RTT.
    10. printf Test: %s, "RTT\r\nRocks." : RTT
    11. Rocks..
    Display All


    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 Source Code

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


    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 (github.com/ARM-software/CMSIS).
  • 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
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • SEGGER - Johannes wrote:

    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 Source Code

    1. SEGGER Real-Time-Terminal Sample
    2. ###### Testing SEGGER_printf() ######
    3. printf Test: %c, 'S' : S.
    4. printf Test: %5c, 'E' : E.
    5. printf Test: %-5c, 'G' : G.
    6. printf Test: %5.3c, 'G' : G.
    7. printf Test: %.3c, 'E' : E.
    8. printf Test: %c, 'R' : R.
    9. printf Test: %s, "RTT" : RTT.
    10. printf Test: %s, "RTT\r\nRocks." : RTT
    11. Rocks..
    12. printf Test: %u, 12345 : 12345.
    13. printf Test: %+u, 12345 : 12345.
    14. printf Test: %.3u, 12345 : 12345.
    15. printf Test: %.6u, 12345 : 012345.
    16. printf Test: %6.3u, 12345 : 12345.
    17. printf Test: %8.6u, 12345 : 012345.
    18. printf Test: %08u, 12345 : 00012345.
    19. printf Test: %08.6u, 12345 : 012345.
    20. printf Test: %0u, 12345 : 12345.
    21. printf Test: %-.6u, 12345 : 012345.
    22. printf Test: %-6.3u, 12345 : 12345 .
    23. printf Test: %-8.6u, 12345 : 012345 .
    24. printf Test: %-08u, 12345 : 12345 .
    25. printf Test: %-08.6u, 12345 : 012345 .
    26. printf Test: %-0u, 12345 : 12345.
    27. printf Test: %u, -12345 : 4294954951.
    28. printf Test: %+u, -12345 : 4294954951.
    29. printf Test: %.3u, -12345 : 4294954951.
    30. printf Test: %.6u, -12345 : 4294954951.
    31. printf Test: %6.3u, -12345 : 4294954951.
    32. printf Test: %8.6u, -12345 : 4294954951.
    33. printf Test: %08u, -12345 : 4294954951.
    34. printf Test: %08.6u, -12345 : 4294954951.
    35. printf Test: %0u, -12345 : 4294954951.
    36. printf Test: %-.6u, -12345 : 4294954951.
    37. printf Test: %-6.3u, -12345 : 4294954951.
    38. printf Test: %-8.6u, -12345 : 4294954951.
    39. printf Test: %-08u, -12345 : 4294954951.
    40. printf Test: %-08.6u, -12345 : 4294954951.
    41. printf Test: %-0u, -12345 : 4294954951.
    42. printf Test: %d, -12345 : -12345.
    43. printf Test: %+d, -12345 : -12345.
    44. printf Test: %.3d, -12345 : -12345.
    45. printf Test: %.6d, -12345 : -012345.
    46. printf Test: %6.3d, -12345 : -12345.
    47. printf Test: %8.6d, -12345 : -012345.
    48. printf Test: %08d, -12345 : -0012345.
    49. printf Test: %08.6d, -12345 : -012345.
    50. printf Test: %0d, -12345 : -12345.
    51. printf Test: %-.6d, -12345 : -012345.
    52. printf Test: %-6.3d, -12345 : -12345.
    53. printf Test: %-8.6d, -12345 : -012345 .
    54. printf Test: %-08d, -12345 : -12345 .
    55. printf Test: %-08.6d, -12345 : -012345 .
    56. printf Test: %-0d, -12345 : -12345.
    57. printf Test: %x, 0x1234ABC : 1234ABC.
    58. printf Test: %+x, 0x1234ABC : 1234ABC.
    59. printf Test: %.3x, 0x1234ABC : 1234ABC.
    60. printf Test: %.6x, 0x1234ABC : 1234ABC.
    61. printf Test: %6.3x, 0x1234ABC : 1234ABC.
    62. printf Test: %8.6x, 0x1234ABC : 1234ABC.
    63. printf Test: %08x, 0x1234ABC : 01234ABC.
    64. printf Test: %08.6x, 0x1234ABC : 1234ABC.
    65. printf Test: %0x, 0x1234ABC : 1234ABC.
    66. printf Test: %-.6x, 0x1234ABC : 1234ABC.
    67. printf Test: %-6.3x, 0x1234ABC : 1234ABC.
    68. printf Test: %-8.6x, 0x1234ABC : 1234ABC .
    69. printf Test: %-08x, 0x1234ABC : 1234ABC .
    70. printf Test: %-08.6x, 0x1234ABC : 1234ABC .
    71. printf Test: %-0x, 0x1234ABC : 1234ABC.
    72. printf Test: %p, &_Cnt : 20000D1C.
    73. ###### SEGGER_printf() Tests done. ######
    Display All


    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.
  • 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
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.