[SOLVED] RTT compile error with GCC

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • [SOLVED] RTT compile error with GCC

    I'm a maintainer of TinyUSB project, to ensure the code quality we have some strict GCC flags enabled.

    Wcast-align and Wcast-qual cause SEGGER_RTT.c failed to compile with following error:

    Source Code

    1. e:\mcu\tinyusb\lib\segger_rtt\rtt\segger_rtt.c: In function '_DoInit':
    2. e:\mcu\tinyusb\lib\segger_rtt\rtt\segger_rtt.c:323:10: error: cast discards 'volatile' qualifier from pointer target type [-Werror=cast-qual]
    3. 323 | memset((SEGGER_RTT_CB*)p, 0, sizeof(_SEGGER_RTT)); // Make sure that the RTT CB is always zero initialized.
    4. | ^
    5. compilation terminated due to -Wfatal-errors.
    6. cc1.exe: all warnings being treated as errors
    7. make: *** [Makefile.mk:1269: build/release-BIN1/tinyusb__lib__SEGGER_RTT__RTT__SEGGER_RTT.o] Error 1
    8. e:\mcu\tinyusb\lib\segger_rtt\rtt\segger_rtt.c: In function 'SEGGER_RTT_WriteSkipNoLock':
    9. e:\mcu\tinyusb\lib\segger_rtt\rtt\segger_rtt.c:954:11: error: cast increases required alignment of target type [-Werror=cast-align]
    10. 954 | pRing = (SEGGER_RTT_BUFFER_UP*)((char*)&_SEGGER_RTT.aUp[BufferIndex] + SEGGER_RTT_UNCACHED_OFF); // Access uncached to make sure we see changes made by the J-Link side and all of our changes go into HW directly
    Display All

    Please either fix them or suppress the error by adding:

    Source Code

    1. #ifdef __GNUC__
    2. #pragma GCC diagnostic ignored "-Wcast-qual"
    3. #pragma GCC diagnostic ignored "-Wcast-align"
    4. #endif
  • Hi,
    We will look into this and see if we want to adjust the code to prevent these warnings.
    However, we are currently fully booked with projects and this is the first request regarding this, so I cannot say when we will be able to look into this.

    I would suggest that you suppress these warnings on your side for now, by wrapping the include of the header file in pragmas to disable/enable these warnings.

    C Source Code

    1. #ifdef __GNUC__
    3. _Pragma("GCC diagnostic push") \
    4. _Pragma("GCC diagnostic ignored \"-Wcast-qual\"") \
    5. _Pragma("GCC diagnostic ignored \"-Wcast-align\"")
    6. #define SPECIAL_WARNINGS_ENABLE() \
    7. _Pragma("GCC diagnostic pop")
    8. #else
    11. #endif
    12. // [...]
    14. #include "SEGGER_RTT.h"
    Display All
    That way you can still update the RTT sources without manually adding the pragmas.

    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.