AnsweredAssumed Answered

STM32F407 ITM

Question asked by pipon.herve.001 on Jul 1, 2015
Latest reply on Jul 17, 2015 by pipon.herve.001
Hello

I want to use ITM Port 0 on a STM32F407 with a Keil µVision

I wrote
printf("TEST");

with the following hook
int fputc(int c, FILE *stream)
{
   return(ITM_SendChar(c));
}
 
static __INLINE uint32_t ITM_SendChar (uint32_t ch)
{
  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);
}


I reached the line
ITM->PORT[0].u8 = (uint8_t) ch;

but On Keil's Debug (printf) Viewer window nothing appeared


I then tried to add some init function:
/* Debug MCU registers base address */
#define DBGMCU_BASE           ((uint32_t )0xE0042000)
#define DBGMCU              ((DBGMCU_TypeDef *) DBGMCU_BASE)
 
void itm_init(void) {
    uint32_t SWOSpeed = 3000000;
    uint32_t SWOPrescaler = (120000000 / SWOSpeed) - 1; // SWOSpeed in Hz
 
    CoreDebug->DEMCR = 1 << CoreDebug_DEMCR_TRCENA_Pos;
 
    DBGMCU->CR = 0x00000027; //Enabling TRACE_IOEN, DBG_STANDBY, DBG_STOP, DBG_SLEEP
    //Set TPIU register->Selected pinprotocol = 10b: Serial Wire Output - NRZ, 01b = SerialWire Output (Manchester)
    *((volatile unsigned *) 0xE00400F0) = 0x00000002; // "Selected PIN Protocol Register": Select which protocol to use for trace output (2: SWO)
    //Set TPIU -> Async Clock Prescaler Register [bits 0-12]
    *((volatile unsigned *) 0xE0040010) = SWOPrescaler; // "Async Clock Prescaler Register". Scale the baud rate of the asynchronous output
    //Lock Access Register
    *((volatile unsigned *) 0xE0000FB0) = 0xC5ACCE55; // ITM Lock Access Register, C5ACCE55 enables more write access to Control Register 0xE00 :: 0xFFC
    *((volatile unsigned *) 0xE0000E80) = 0x0001000D; // ITM Trace Control Register
    *((volatile unsigned *) 0xE0000E40) = 0x0000000F; // ITM Trace Privilege Register
    *((volatile unsigned *) 0xE0000E00) = 0x00000001; // ITM Trace Enable Register. Enabled tracing on stimulus ports. One bit per stimulus port.
    *((volatile unsigned *) 0xE0001000) = 0x400003FE; // DWT_CTRL
    //And this is really tricky!
    *((volatile unsigned *) 0xE0040304) = 0x00000100; // Formatter and Flush Control Register
}

without any improvement....

Does anybody have an idea ?

Outcomes