STM32 and ITM Viewer

I'am using the STM32 and tried to use the ITM-Viewer. At the Keil documentation "Using the ITM Viewer" is a code example of the fputc() function.

int fputc(int ch, FILE *f) {
  if (DEMCR & TRCENA) {
    while (ITM_Port32(0) == 0);
    ITM_Port8(0) = ch;
  }
  return(ch);
}

This function call will end at a hardware fault. The check if the trace is activated ( if (DEMCR & TRCENA) { )seems to be the source of this hardware fault. If I keep a way this check the ITM Viewer is working fine. Does anybody know, if I have to be at privileged mode to have access to the DEMCR register?

Thanks for help.

Parents
  • CPU can access DEMCR (Debug Exception and Monitor Control Register) only from Privileged Mode just like you assumed.

    You can omit the checking if Trace is activated via DEMCR in order to use Unprivileged Mode however then this code will hang when the debugger is not connected.

    The reference example runs when debugger is connected or not (and it runs in Privileged Mode).

Reply
  • CPU can access DEMCR (Debug Exception and Monitor Control Register) only from Privileged Mode just like you assumed.

    You can omit the checking if Trace is activated via DEMCR in order to use Unprivileged Mode however then this code will hang when the debugger is not connected.

    The reference example runs when debugger is connected or not (and it runs in Privileged Mode).

Children
More questions in this forum