2020-04-19 07:36 PM
Hello everyone, I hope you're well and safe.
I'm working with the
I'm trying to debug a simple application with the printf() function
#include "main.h"
#include "stdio.h"
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
while (1)
{
printf("hello");
ITM_SendChar('a');
HAL_GPIO_TogglePin(LED_BUILTIN_GPIO_Port ,LED_BUILTIN_Pin);
HAL_Delay(1000);
}
}
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
{
Error_Handler();
}
}
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
HAL_GPIO_WritePin(LED_BUILTIN_GPIO_Port, LED_BUILTIN_Pin, GPIO_PIN_RESET);
GPIO_InitStruct.Pin = LED_BUILTIN_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(LED_BUILTIN_GPIO_Port, &GPIO_InitStruct);
}
void Error_Handler(void)
{
}
#ifdef USE_FULL_ASSERT
void assert_failed(uint8_t *file, uint32_t line)
{
}
#endif
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
But it's not working when I start the debugger and I open the printf window it's empty and and I noticed a message below on Keil µVision "Trace: No Synchronization"
So, I hope you can help me and thank you in advance.
Solved! Go to Solution.
2020-08-05 08:37 AM
Hi KHADRAOUI Ibrahim ,
At first look at the problem seems like your code is missing:
In order to activate the ITM trace (printf) you need to add the fputc function definition just after the main function in your code as below:
/*----------------------------------------------------------------------------
Write character to Serial Port
*----------------------------------------------------------------------------*/
int SER_PutChar (int c) {
ITM_SendChar (c);
return (c);
}
int fputc(int c, FILE *f) {
return (SER_PutChar(c));
}
You can add it in the main.c file, or do it in a separate file, usually called Retarget.c for MDK-ARM.
This should work, if not make sure you use the correct "core clock" in the MDK-arm options.
Also you can ceck with the User manual in case there is a hardware modification (switch, SB etc)
PS: The SWV is not supported when using ST-LINK Shared mode, so make sure it is not checked as in the photo I attached.
I hope this help!
-Imen
2020-08-05 08:37 AM
Hi KHADRAOUI Ibrahim ,
At first look at the problem seems like your code is missing:
In order to activate the ITM trace (printf) you need to add the fputc function definition just after the main function in your code as below:
/*----------------------------------------------------------------------------
Write character to Serial Port
*----------------------------------------------------------------------------*/
int SER_PutChar (int c) {
ITM_SendChar (c);
return (c);
}
int fputc(int c, FILE *f) {
return (SER_PutChar(c));
}
You can add it in the main.c file, or do it in a separate file, usually called Retarget.c for MDK-ARM.
This should work, if not make sure you use the correct "core clock" in the MDK-arm options.
Also you can ceck with the User manual in case there is a hardware modification (switch, SB etc)
PS: The SWV is not supported when using ST-LINK Shared mode, so make sure it is not checked as in the photo I attached.
I hope this help!
-Imen
2020-08-06 04:03 PM
Hi @Imen Ezzine !
Thank you for your reply.
I tried what you advised me, but it also doesn't work, However I tried with a stm32 discovery board with an integrated ST-LINK and it worked, I deduce that the ST-LINK that I used is a cheap Chinese one (on the photo above) is not compatible with the TRACE.
Regards.
@KHADRAOUI Ibrahim .