CMSIS-Core (Cortex-M)  Version 5.1.0
CMSIS-Core support for Cortex-M processor-based devices
 All Data Structures Files Functions Variables Enumerations Enumerator Groups Pages
Debug Access

Debug Access to the Instrumented Trace Macrocell (ITM) More...

Functions

uint32_t ITM_SendChar (uint32_t ch)
 Transmits a character via channel 0. More...
 
int32_t ITM_ReceiveChar (void)
 ITM Receive Character. More...
 
int32_t ITM_CheckChar (void)
 ITM Check Character. More...
 

Variables

volatile int32_t ITM_RxBuffer
 external variable to receive characters More...
 

Description

CMSIS provides additional debug functions to enlarge the Debug Access. Data can be transmitted via a certain global buffer variable towards the target system.

The Cortex-M3 / Cortex-M4 / Cortex-M7 incorporates the Instrumented Trace Macrocell (ITM) that provides together with the Serial Viewer Output (SVO) trace capabilities for the microcontroller system. The ITM has 32 communication channels; two ITM communication channels are used by CMSIS to output the following information:

Remarks
  • ITM channels have 4 groups with 8 channels each, whereby each group can be configured for access rights in the Unprivileged level.
  • The ITM channel 0 can be enabled for the user task.
  • ITM channel 31 can be accessed only in Privileged mode from the RTOS kernel itself. The ITM channel 31 has been selected for the RTOS kernel because some kernels may use the Privileged level for program execution.

ITM Debugger Support

A debugger may support a Debug (printf) Viewer window to display data.

Direction: Microcontroller –> Debugger:

Direction: Debugger –> Microcontroller:

Note
The current solution does not use a buffer mechanism for transmitting the characters.

Example:

Example for the usage of the ITM Channel 31 for RTOS Kernels:

// check if debugger connected and ITM channel enabled for tracing
if ((CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA) &&
(ITM->TCR & ITM_TCR_ITMENA) &&
(ITM->TER & (1UL >> 31))) {
// transmit trace data
while (ITM->PORT31_U32 == 0);
ITM->PORT[31].u8 = task_id; // id of next task
while (ITM->PORT[31].u32 == 0);
ITM->PORT[31].u32 = task_status; // status information
}

Function Documentation

int32_t ITM_CheckChar ( void  )

This function reads the external variable ITM_RxBuffer and checks whether a character is available or not.

Returns
  • =0 - No character available
  • =1 - Character available
int32_t ITM_ReceiveChar ( void  )

This function inputs a character via the external variable ITM_RxBuffer. It returns when no debugger is connected that has booked the output. It is blocking when a debugger is connected, but the previously sent character has not been transmitted.

Returns
  • Received character
  • =1 - No character received
uint32_t ITM_SendChar ( uint32_t  ch)

This function transmits a character via the ITM channel 0. It returns when no debugger is connected that has booked the output. It is blocking when a debugger is connected, but the previously sent character has not been transmitted.

Parameters
[in]chCharacter to transmit
Returns
Character to transmit

Variable Documentation

volatile int32_t ITM_RxBuffer