cancel
Showing results for 
Search instead for 
Did you mean: 

Enable SWO on CubeIDE 1.12.1 - Board used Nucleo-H755ZI

MD
Associate II

Hello,

I went through all the SWO related topics, and it was a bit confusing for me to get it running, so I summarized the steps to have it working on a Nucleo H755.

In my project I have the main clock set at 400MHz, Timer2 running at 1Hz and Debug set as "Trace Asyncronous Sw"

In my main.c I have added just this:

 

 

 

  /* USER CODE BEGIN 2 */
#define SWO_BASE (0x5C003000UL)
#define SWTF_BASE (0x5C004000UL)

 uint32_t SWOSpeed = 2000000; // [Hz] we have 2 Mbps SWO speed in ST-Link SWV viewer
 uint32_t SWOPrescaler = (SystemCoreClock / SWOSpeed) - 1; /* divider value */

 //enable debug clocks
 DBGMCU->CR = 0x00700000; //enable debug clocks

 //UNLOCK FUNNEL
 //SWTF->LAR unlock
 *((__IO uint32_t *)(SWTF_BASE + 0xFB0)) = 0xC5ACCE55; //unlock SWTF

 //SWO->LAR unlock
 *((uint32_t *)(SWO_BASE + 0xFB0)) = 0xC5ACCE55; //unlock SWO

 //SWO divider setting
 //This divider value (0x000000C7) corresponds to 400Mhz core clock
 //SWO->CODR = PRESCALER[12:0]
 *((__IO uint32_t *)(SWO_BASE + 0x010)) = SWOPrescaler; //clock divider

 //SWO set the protocol
 //SWO->SPPR = PPROT[1:0] = NRZ
 *((__IO uint32_t *)(SWO_BASE + 0x0F0)) = 0x00000002; //set to NRZ

 //Enable ITM input of SWO trace funnel, slave 0
 //SWTF->CTRL bit 0 ENSO = Enable
 *((__IO uint32_t *)(SWTF_BASE + 0x000)) |= 0x00000001; //enable

 LL_TIM_EnableCounter(TIM2);  //Used for LED toggle

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
	  if (LL_TIM_IsActiveFlag_UPDATE(TIM2)) {
		  LL_TIM_ClearFlag_UPDATE(TIM2);
		  LL_GPIO_TogglePin(LD1_GPIO_Port,LD1_Pin);
		  ITM_SendChar(0x55);
		  ITM_SendChar('0');
		  ITM_SendChar('\n');
	  }
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }

 

 

 

Once you compile and run the debug, activate the SWO and limit the frequency at 2MHz (otherwise it will run at 12)

MD_1-1687436178095.png

After the program is loaded and the execution stops at the beginning of the main, add the toolbar for the SWV ITM Data Console:

MD_5-1687437990558.png

and add the port 0 on the settings:

MD_2-1687436299945.png

then press the "Start Trace" button before resuming the code execution:

MD_3-1687437584204.png

 

At this point you will see the output:

MD_4-1687437630766.png

and this is what the pin is doing:

MD_0-1687436141463.png

 

 

Hope this will help developers that stumbled on the same problem.

 

P.S. The ST-Link V3 can work also at 12MHz, as I set-up in the project in attach. You will need to remove the tick "Limit SWO clock" in the debugger configuration and change to 12000 the variable SWOSpeed into the main.c.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
MD
Associate II

I've tested the SWV at 12MHz and integrated that in my post above.

View solution in original post

2 REPLIES 2
MD
Associate II

I've tested the SWV at 12MHz and integrated that in my post above.

AScha.3
Chief II

well, i tried "your way" ... just get nothing than >hard fault. (on F303 cpu )

on cubeIDE 

AScha3_0-1687462674448.png

 

 

then removed some lines...then all.

nothing from itm.

using open ocd :

AScha3_0-1687462524971.png

 

so removed all , again set only:

 

 

 

 

/* USER CODE BEGIN 4 */

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

 

 

 

 

 

with:

AScha3_1-1687457556136.png

 

 

then it worked...

AScha3_0-1687457267796.png

try it. (but i can promise, it is more hit and hope game ! )

If you feel a post has answered your question, please click "Accept as Solution".