cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 MotorControl Workbench Printf debug message

kaps
Associate II

Hello STM32 Community,

I am currently working with the STM32 MotorControl Workbench framework, specifically using the EVSPIN32G4 demo board. For development, I'm utilizing the STM32CubeMX and STM32CubeIDE tools.

My issue lies with debugging. I'm attempting to use printf statements for debugging purposes through the ITM (Instrumentation Trace Macrocell) debugger interface. However, this is not working as expected. The printf messages are not being displayed.

I'm wondering if anyone can shed light on why this might be happening. Are there specific settings or configurations within STM32CubeMX or STM32CubeIDE that I need to adjust to enable ITM debugging correctly?

Additionally, I'm open to suggestions for alternative methods to output debug messages effectively in this setup. Any insights or experiences shared would be greatly appreciated!

Thank you in advance for your help and support.

Best regards,

 

int _write(int file, char *ptr, int len)
{
  (void)file;
  int DataIdx;

  for (DataIdx = 0; DataIdx < len; DataIdx++)
  {
    ITM_SendChar(*ptr++);
  }
  return len;
}
10 REPLIES 10
Johi
Senior III

See attached document (it is in dutch, but the images should be point into a direction).

Pavel A.
Evangelist III

In addition to what @Johi advises: 

Do a quick test of  ITM_SendChar, to exclude any C library/printf etc complications: just call  your _write directly from your main() after setting the sysclock: for example _write(1, "\nboo!\n", 6); 

the CubeProgrammer and some other tools also can display ITM output, without the rest of the IDE and debugger.

kaps
Associate II

Hello again,

Thank you so much for your response and suggestions. Unfortunately, I'm still facing the same issue where the ITM debugging is not functioning correctly with the STM32 MotorControl Workbench.

I've attached images showing my current settings to give you a better understanding of my setup. Interestingly, when I use the project without the STM32 MotorControl Workbench, the ITM debug messages work perfectly. It's only when I integrate the STM32 MotorControl Workbench that I encounter this problem.

Could there be a compatibility issue between the MotorControl Workbench and ITM debugging? Or perhaps there's a specific setting within the Workbench that needs to be configured for ITM?

Any further assistance or insights would be greatly appreciated, as this issue is proving to be quite perplexing.

Thank you once again for your time and help.

 

  while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */

	  _write(1, "\nboo!\n", 6);

 

 

 

 

kaps_0-1702907780412.png

kaps_1-1702907860109.png

 

kaps_2-1702907917682.png

 

 

cedric H
ST Employee

Hello @kaps,

We do not use printf to debug the Motor Control lib, therefore I need to investigate a bit more to be able to answer your question. But as you are interested to debug with alternatives methods, let me advise you to have a look at the data log feature of the motor control Pilot. Running the UART at roughly 2 Mbps allows you to dump data at PWM frequency without any loss. Additionally, you can also send digital data to DAC output and then look at them at the scope. Could you tell us what kind of data do you want to dump ? 

Best Regards

Cedric

My primary aim is to output short messages and variable values from my own software components for debugging purposes. The data log feature of the Motor Control Pilot and the idea of using UART at approximately 2 Mbps sound promising.

Could you please provide more details on how to access the UART interface for this purpose? Is there a specific logging function in the Motor Control Workbench that I should use? Additionally, I would like to know which header files are necessary to include in my own software components to utilize this logging capability.

cedric H
ST Employee

If you have never used the Motor control Pilot, then I strongly advise you to have a look at the following documentation:

cedricH_0-1702913588454.png

 

I you use the MCSDK 6.2.1 to generate your project, and are able to connect the MC Pilot to your board, then you can have a quick look at the following page:  https://wiki.st.com/stm32mcu/wiki/STM32MotorControl:STM32_MC_Motor_Pilot_-_Start-up_guide#Viewing_and_plotting_registers_with_high-speed_plotting

Loggin feature is enabled by default with STM32G4 series. If you want to check whether it is the case in your project, you can have a quick look at my answer to this post:

USB/com interface not working in STEVAL-SPIN3204/W... - STMicroelectronics Community

Regards

Cedric

 

I am familiar with the Motor Control Pilot, and I've found it to be a useful tool. However, I have a specific question regarding its capabilities: is it possible to output custom log messages?

I am interested in integrating my own log messages within the Motor Control Pilot environment. These messages would include specific information from my custom software components for more effective debugging. Could you please advise if the Motor Control Pilot supports this functionality, and if so, how I might go about implementing it?

Any information or guidance on how to add custom log messages would be greatly appreciated.

 

Like this:

int var_1 = 0;
while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
    var_1++;
    log_message("Test: %i \n", var_1);
    HAL_Delay(1000);

  }
  /* USER CODE END 3 */

 

 

 

Pavel A.
Evangelist III

Please try a minimal ITM_SendChar test, immediately after the programs sets the MCU core clock  - before touching  other peripherals, calling any other libraries...

kaps
Associate II

I have performed the test as you described, ensuring that the ITM_SendChar function is executed right after setting the core clock. Unfortunately, I must report that the issue persists, and I am still unable to output messages using ITM.

 

 

int main(void)
{
  /* USER CODE BEGIN 1 */

	ITM_SendChar('a');

	//printf("Start \n");

  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  ITM_SendChar('b');

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */


  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_ADC1_Init();
  MX_ADC2_Init();
  MX_COMP1_Init();
  MX_COMP2_Init();
  MX_COMP4_Init();
  MX_CORDIC_Init();
  MX_DAC3_Init();
  MX_I2C3_Init();
  MX_OPAMP1_Init();
  MX_OPAMP2_Init();
  MX_TIM1_Init();
  MX_TIM4_Init();
  MX_USART1_UART_Init();
  MX_MotorControl_Init();
  MX_SPI1_Init();

  /* Initialize interrupts */
  MX_NVIC_Init();
  /* USER CODE BEGIN 2 */