AnsweredAssumed Answered

Debug with SWO on stm32f4discovery and IAR EW

Question asked by Trackk on Jan 21, 2015
Latest reply on Jan 21, 2015 by Trackk
I read absolutely all the posts in this forum plus some other posts online and I can't still make this work with IAR and the Terminal I/O screen.

I can however make it work using the ST-Link Utility and the Printf via SWO. But I can't have both running at the same time and I would like to debug completely with IAR.

SWO Config on debug screen:
  • SWO Configuration CPU Clock set to: 144 MHz (the one that works with St-link utility)
  • ITM Stimulus Ports all the 0 ports checked.
  • SWO Clock: Autodetect.
General Options >  Library Configuration:
  • Library: Full
  • Semihosted
  • stdout/stderr Via SWO
ST-LINK option in IAR:
  • Interface: SWD
  • CPU Clock: 144MHz
  • SWO Clock: Auto (2000Khz same as St-link utility)

And the code to summarize what I added:
#include "stdio.h"
static void TextOut(const char *str);
int main(void)
  TextOut("It works!");
void TextOut(const char *str)
  do {
    if(*str=='\n') ITM_SendChar('\r');
  } while(*str++);

This works perfectly in ST-Link Utility, and I can read the "It works!".
But if I debug it with IAR it gets stuck inside core_cm4.h:
01.__STATIC_INLINE uint32_t ITM_SendChar (uint32_t ch)
03.  if ((ITM->TCR & ITM_TCR_ITMENA_Msk)                  &&      /* ITM enabled */
04.      (ITM->TER & (1UL << 0)        )                    )     /* ITM Port #0 enabled */
05.  {
06.    while (ITM->PORT[0].u32 == 0);
07.    ITM->PORT[0].u8 = (uint8_t) ch;
08.  }
09.  return (ch);

It gets stuck on line 6: while (ITM->PORT[0].u32 == 0);
And nothing shows up in the Terminal I/O screen.

Any ideas why is this happening? And why the exact same code would work on ST-Link Utility?