cancel
Showing results for 
Search instead for 
Did you mean: 

Debugging with STM32CubeIDE and STM32F407Discovery

TThie.1
Associate II

Hi,

try debug with SWV my simple blinky programm but it dosn't work correct.

I use a simple USB-cable (ST-LINK)to connect with my Win10 PC. STMCube is updated to 1.2.1

Here the code of the _write function:

int _write(int file, char *ptr, int len)
{
  /* Implement your write code here, this is used by puts and printf for example */
  int i=0;
  for(i=0 ; i<len ; i++)
    ITM_SendChar((*ptr++));
  return len;
}

So i've a few questions ...

A) At Debug configuration: I found several values for core Clock and SWOClock.

I think coreclock is the same value like my controller but were i find the correct value for SWO-clock?

B) Data trace: which is the correct addres and where i can find it?

Currently i can read the variable (counter i of a "for"-loop) via "view memeory".

But it dosn't work at runtime ... i have to pasue and then values of the memory-view will updated. If i click on "play"-Button values are frezzed -> ...pause -> new value.

My goal is to print in the SWV ITM Data Console via prinft-commando .

By the way... why does it different if i uncomment the "_write"-function???

Thank you for your help,

Günther

here you found my main function:

int main(void)
{
	HAL_Init();
  /* USER CODE BEGIN 1 */
 
	    int i;
 
	    __HAL_RCC_GPIOD_CLK_ENABLE();
	    __HAL_RCC_GPIOA_CLK_ENABLE();
	    GPIOD -> MODER |= (1<<24);  // Set pin 12 (orange LED)to be general purpose output in GPIO port mode register
	    GPIOD -> MODER |= (1<<26);  // Set pin 13 (orange LED)to be general purpose output in GPIO port mode register
	    GPIOD -> MODER |= (1<<28);  // Set pin 13 (orange LED)to be general purpose output in GPIO port mode register
	    //    GPIOD -> MODER |= (1<<30);  // Set pin 13 (orange LED)to be general purpose output in GPIO port mode register
 
	 //   void GPIO_config(void);
 
	    while(1)
	    {
	        for (i = 0; i < 1000000; ++i);  // Delay
	    		GPIOD -> ODR |= (1<<13);  // Turn GPIOD pin13 (orange LED) ON
	    		printf("Hello World!");
	    		//	GPIOD -> ODR |= (1<<14);  // Turn GPIOD pin13 (orange LED) ON
	        //	GPIOD -> ODR |= (1<<15);  // Turn GPIOD pin13 (orange LED) ON
	    		ITM_SendChar( 65 );   //  Send ASCII code 65 = ’A’
	    	for (i = 0; i < 1000000; ++i);  // Delay
	        	GPIOD -> ODR &= ~(1<<13);  // Turn GPIOD pin13 (orange LED) OFF
	       // 	GPIOD -> ODR &= ~(1<<14);  // Turn GPIOD pin13 (orange LED) OFF
	       // 	GPIOD -> ODR &= ~(1<<15);  // Turn GPIOD pin13 (orange LED) OFF
 
	    	ITM_SendChar( 65 );   //  Send ASCII code 65 = ’A’
	    	printf("TEst %i",i);
	    }
 
  /* USER CODE END 1 */
  
 
  /* MCU Configuration--------------------------------------------------------*/
 
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
 
 
  /* USER CODE BEGIN Init */
 
  /* 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_CAN1_Init();
  MX_I2C1_Init();
  MX_SPI2_Init();
  MX_UART4_Init();
  MX_ADC1_Init();
  /* USER CODE BEGIN 2 */
 
/*
int Get_ADC_Converted_Value(){
    ADC_SoftwareStartConv(ADC2);
    while(ADC_GetFlagStatus(ADC2, ADC_FLAG_EOC))
    {
      return ADC_GetConversionValue(ADC2);
    }
}
*/
  /* USER CODE END 2 */
 
 
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
//  while (1)
//  {
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
 // }
  /* USER CODE END 3 */
}

1 REPLY 1
TThie.1
Associate II

I think i found my mistake ... CPUClock frequency was not correct.

Default CPU Clock is (in my case) 16Mhz and SWOClock 500kHz.

If the SWO-clock wrong SWV ITM Data Console works but show different ASCII-signs.

Now data will show at the SWV ITM Data Console works fine.