cancel
Showing results for 
Search instead for 
Did you mean: 

Enabling printf on NUCLEO-N657 in STM32CubeIDE

kag_embedded
Associate III

I have enabled Serial Wire Viewer (SWV) in my m55 application as I have done with my m4 and m33 projects, but the printf is not appearing in the SWV view.

Are there additional setup required on the NUCLEO-N657 board such as jumper settings or additional software setup?

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions

@KDJEM.1 Thank you. Dividing the CPU clock by 8 resolved my issue.

View solution in original post

2 REPLIES 2
KDJEM.1
ST Employee

Hello @kag_embedded;

Could you please make sure that you:

- Enable TRACE CLOCK AND DEBUG CLOCK in DBGMCU register

- The SWV core clock in STM32CUBEIDE should always be CPU clock/8, the SWV core clock should be 8Mhz

- Configure the SWV ITM Data console

KDJEM1_0-1748614081081.png

KDJEM1_1-1748614093012.png

KDJEM1_2-1748614117827.png

Below an code example of printf:

################CODE BEGIN####################

int __io_putchar(int ch)
 {
   ITM_SendChar(ch);
   return(ch);
 }


int main(void)
{
 GPIO_InitTypeDef gpio_init;

DBGMCU->CR |=0x00300000;
 ITM->TER |= 0x1;
 ITM->TCR |= 0x00001;

  //SWO is Ball U12 or PB5 label on N6
  __HAL_RCC_GPIOB_CLK_ENABLE();
  gpio_init.Mode   = GPIO_MODE_AF_PP;
  gpio_init.Pull   = GPIO_PULLUP;
  gpio_init.Speed   = GPIO_SPEED_FREQ_HIGH;
  gpio_init.Pin    = GPIO_PIN_5;
  gpio_init.Alternate = GPIO_AF0_TRACE;
  HAL_GPIO_Init(GPIOB, &gpio_init);


  HAL_Init();

  /* Initialize LED1 */
  BSP_LED_Init(LED_GREEN);

  while (1)
  {
    /* Toggle LED1 every 500ms */
    BSP_LED_Toggle(LED_GREEN);
    HAL_Delay(500);
    printf("Hello world\n");
  }
}

################CODE END####################

 

For more information about  Serial Wire Viewer I recommend you to look at AN4948 precisely section "7.3 Printf via SWO/SWV"

If you want also to see the UART output message on the HyperTerminal, I recommend you to look at UART_Printf example. 

I hope this help you.

Thank you.

Kaouthar

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

@KDJEM.1 Thank you. Dividing the CPU clock by 8 resolved my issue.