2022-11-24 04:34 AM
Hello All,
We are trying to get some debug trace info from our project and trying to use ITM for the same.
For our product we are using the follwoing:
STM32H743
Keil Version 5.24.1
ULINK 2 debugger
I created a simple project following many forum topics and the source code is:
/* USER CODE END 0 */
void SWD_Init(void)
{
*(__IO uint32_t*)(0x5C001004) |= 0x00700000; // DBGMCU_CR D3DBGCKEN D1DBGCKEN TRACECLKEN
//UNLOCK FUNNEL
*(__IO uint32_t*)(0x5C004FB0) = 0xC5ACCE55; // SWTF_LAR
*(__IO uint32_t*)(0x5C003FB0) = 0xC5ACCE55; // SWO_LAR
//SWO current output divisor register
//This divisor value (0x000000C7) corresponds to 400Mhz
//To change it, you can use the following rule
// value = (CPU Freq/sw speed )-1
*(__IO uint32_t*)(0x5C003010) = ((SystemCoreClock / 2000000) - 1); // SWO_CODR
//SWO selected pin protocol register
*(__IO uint32_t*)(0x5C0030F0) = 0x00000002; // SWO_SPPR
//Enable ITM input of SWO trace funnel
*(__IO uint32_t*)(0x5C004000) |= 0x00000001; // SWFT_CTRL
//RCC_AHB4ENR enable GPIOB clock
*(__IO uint32_t*)(0x580244E0) |= 0x00000002;
// Configure GPIOB pin 3 as AF
*(__IO uint32_t*)(0x58020400) = (*(__IO uint32_t*)(0x58020400) & 0xffffff3f) | 0x00000080;
// Configure GPIOB pin 3 Speed
*(__IO uint32_t*)(0x58020408) |= 0x00000080;
// Force AF0 for GPIOB pin 3
*(__IO uint32_t*)(0x58020420) &= 0xFFFF0FFF;
}
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
SWD_Init();
HAL_Delay(500);
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART1_UART_Init();
/* USER CODE BEGIN 2 */
ITM_SendChar('a');
printf("Hello World");
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
ITM_SendChar('a');
HAL_Delay(500);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
and using Keil's retarget_io.c
Our trace settings looks like this:
The trace seems to be running but no output.
Can someone guide us as to what is missing.
2022-11-24 05:17 AM
The enabling code was for the ST-LINK originally, not the U-LINK, so you'd need to know the clocking, and its not 1 MHz. The ST-LINK/V2 SWO Clock was 2 MHz, the V3 I think is 15 MHz, the current DLLs might be more aware now.
Typically you need to setup the Trace with the Frequency you're running the MCU, and look at the SWO clock.
Port 7..0 should be checked too.
2022-11-24 07:00 AM
In the Core Clock field put the value of SystemCoreClock global variable after SystemClock_Config call (in MHz: 400000000 -> 400.0)
ITM_SendChar should work after the core clock becomes equal to that value.
Check in port 0 should be enough for ITM_SendChar.
2022-11-28 02:22 AM
Hello,
Many thanks for your reply. I have now done the setup as per your suggestion (i.e removed call to SWD_Init and changed core clock):
But now getting "Trace No synchronization" and also still can't see any message
2022-11-28 02:48 AM
What version of Keil?
Still suggestive of pin level connective or clock disparity.
Sorry know nothing about your design or implementation.
2022-11-28 02:54 AM
Hello,
Below is our Keil Version
Also I have set the clock to be 400 Mhz:
We have our custom board with 20 Mhz crystal and also SWD pins are corrected to micro correctly.
2022-11-30 04:38 AM
Hello
Can someone please guide me to resolve this issue
2022-11-30 07:41 AM
For STM32H7 you likely have the full version of MDK. So, https://www.keil.com/support/