This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

ITM debug issue with RTX

Hi:

I'm working on a LPC1768 board with MDK-4.11 and RTX-4.11, I sent some debug messages to
Debug(printf) viewer window simply by ITM_SendChar(), it works well before I use RTX.
but when I use this function in a RTX task, the execution hang in HardFault_Handler of
startup_LPC17xx.s. I can show this with following code snippet from the Keil example
RTX_Blinky.
Somebody pls help out, Thx a lot.

int main (void) {

  SystemInit();                             /* Initialize the MCU clocks     */
  LED_init ();                              /* Initialize the LEDs           */
  GLCD_Init();                              /* Initialize the GLCD           */
  GLCD_Clear(White);                        /* Clear the GLCD                */

/*! debug test begin */
  ITM_SendChar('M');   /* Here,"M" disply in viwer correctlly before RTX init */
/*! debug test end */

  os_sys_init(init);                        /* Initialize RTX and start init */
}

__task void phaseA (void) {
  for (;;) {
    os_evt_wait_and (0x0001, 0xffff);    /* wait for an event flag 0x0001    */
    LED_On (LED_A);
    signal_func (t_phaseB);              /* call common signal function      */
    LED_Off(LED_A);

/*! debug test begin */
  ITM_SendChar('A'); /* Here,"A" doesn't appear in viewer, program hangup in HardFault_Hander*/
/*! debug test end */
  }
}

  • Did you try to step into ITM_SendChar?
    Where does the failure occur? You can pinpoint it even using uv4's peripheral view.

  • Hi Michael:

    Thanks for your help.
    I tried to step in ITM_SendChar, the HardFault exception happens at the first statement,
    it seems the debug register is not accessible in the said task context, it's strange to me!

    static __INLINE uint32_t ITM_SendChar (uint32_t ch)
    {
      /*! HardFault exception happens at this if statement */
      if ((CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA_Msk)  &&      /* Trace enabled */
          (ITM->TCR & ITM_TCR_ITMENA_Msk)                  &&      /* ITM enabled */
          (ITM->TER & (1ul << 0)        )                    )     /* ITM Port #0 enabled */
      {
        while (ITM->PORT[0].u32 == 0);
        ITM->PORT[0].u8 = (uint8_t) ch;
      }
      return (ch);
    }
    

  • Is "CoreDebug" valid? I played with this once, but I don't remember if some initialization is required!

  • Hi:

    Eventually I found the reason, RTX creates unpreviliged tasks by default, all access to
    control/config and specail registers by unpreviliged code shall trigger a hard fault.
    so if user tasks want to sent out data via ITM_SendChar, they should issue a system call
    (ie.,SVC in CM3),ask kernel do it for them. I don't know if printf is implemented in this
    way? this makes something act like linux.

    Regards.