[SOLVED] SEGGER_RTT_LOCK/UNLOCK code wrong?

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

  • [SOLVED] SEGGER_RTT_LOCK/UNLOCK code wrong?

    Hello,

    I have the "strong" feeling, that the lock/unlock code in SEGGER_RTT_Conf.h is not correct. At least with nRF52840 without OS, but I think this actually doesn't matter.

    I'm currently playing around with SystemView and with just a main "thread" (i.e. without interrupts) the SystemView data stream is ok. Events arrive correctly at SystemView and are displayed accordingly.

    But if there is an additional SystemTick interrupt (123/s), then SystemView eventually shows messed up data like "ISR 17" or "ISR 8738" (at the moment of writing I have 10000 regular SysTicks and 5 wrong ISRs). Randomly data recording is aborted or SystemView even crahses.

    Changing the lock/unlock code to:

    C Source Code

    1. #ifndef SEGGER_RTT_ASM
    2. __attribute__((always_inline)) static inline void __enable_irqXX(void)
    3. {
    4. __asm volatile ("cpsie i" : : : "memory");
    5. }
    6. __attribute__((always_inline)) static inline void __disable_irqXX(void)
    7. {
    8. __asm volatile ("cpsid i" : : : "memory");
    9. }
    10. __attribute__((always_inline)) static inline unsigned __get_PRIMASKXX(void)
    11. {
    12. unsigned result;
    13. __asm volatile ("MRS %0, primask" : "=r" (result) );
    14. return(result);
    15. }
    16. #define SEGGER_RTT_LOCK() unsigned __prim = __get_PRIMASKXX(); __disable_irqXX();
    17. #define SEGGER_RTT_UNLOCK() if (!__prim) { __enable_irqXX(); }
    18. #endif
    Display All
    ...the problem disappears (150000 SysTicks and counting).

    Now I'm wondering (because I'm by no means a Cortex-Mx assembler guru) if I'm completely mistaken or if there is really something broken.

    An example project can be found here: github.com/rgrr/playground/tre…ure/xray/tools/SystemView (see last section of README for some images).

    Data is pulled out of the device via RTT with my own probe: github.com/rgrr/yapicoprobe/tree/feature/systemview-rndis


    Both repos are work-in-progress.

    Regards
    Hardy

    The post was edited 1 time, last by rgrr: - made the code more eye friendly - note about README ().

  • Haha, my bad. Sometimes it is useful to read comments documenting the source code. And then start thinking.

    My actual problem was, that I did not initialize the priority of the SysTick interrupt. And reset priority is 0 which means, that SysTick can interrupt SEGGER_RTT_LOCK() which sets BASEPRI to 0x20 on a Cortex-M4.

    So my "strong" feeling from above was wrong. Learned another lesson ;)

    H.