cancel
Showing results for 
Search instead for 
Did you mean: 

Code Debugging using STLINKV2

JerryMC22
Associate

Hello,

I bought STLINKV2 + small board with STM32F103C8T6. I tried to create a simple program - LED blinking - according to example in here:  https://deepbluembedded.com/stm32-gpio-write-pin-digital-output-lab/   and I have STMCubeIDE + MX + others.My STLINKV2 has newest firmware.

Compilation of my example algorithm (in IDE) is ok (see below) , programming is ok, but debugging shows me an error:

**************************************

Target is not responding, retrying...
Target is not responding, retrying...
Shutting down...

*************************************

Can someone help me where is problem ? I would like to try "JTAG/SWD debugging funtion" of my program - i.e. functions "stepOver", "stepInto" etc. Program on processor is running ok and LEDs are blinking ok.

 

*************************************

STMicroelectronics ST-LINK GDB server. Version 7.9.0
Copyright (c) 2024, STMicroelectronics. All rights reserved.

Starting server with the following options:
Persistent Mode : Disabled
Logging Level : 1
Listen Port Number : 61234
Status Refresh Delay : 15s
Verbose Mode : Disabled
SWD Debug : Enabled
InitWhile : Enabled

Waiting for debugger connection...
Debugger connected
Waiting for debugger connection...
Debugger connected
Waiting for debugger connection...
-------------------------------------------------------------------
STM32CubeProgrammer v2.18.0
-------------------------------------------------------------------

 

Log output file: C:\Users\Jerry\AppData\Local\Temp\STM32CubeProgrammer_a04988.log
ST-LINK SN :
ST-LINK FW : V2J45S7
Board : --
Voltage : 3.20V
SWD freq : 4000 KHz
Connect mode: Under Reset
Reset mode : Hardware reset
Device ID : 0x410
Revision ID : Rev X
Device name : STM32F101/F102/F103 Medium-density
Flash size : 64 KBytes
Device type : MCU
Device CPU : Cortex-M3
BL Version : --

Opening and parsing file: ST-LINK_GDB_server_a04988.srec


Memory Programming ...
File : ST-LINK_GDB_server_a04988.srec
Size : 4.65 KB
Address : 0x08000000


Erasing memory corresponding to segment 0:
Erasing internal memory sectors [0 4]
Download in Progress:


File download complete
Time elapsed during download operation: 00:00:00.692

 

Verifying ...

 


Download verified successfully


Target is not responding, retrying...
Target is not responding, retrying...
Shutting down...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...

*************************************

 

*************************************

 

#include "main.h"

void SystemClock_Config(void);
static void MX_GPIO_Init(void);

int main(void)
{
  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();

  /* Infinite loop */
  while (1)
  {
          // LED ON
          HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET);
          HAL_GPIO_WritePin(GPIOB, GPIO_PIN_15, GPIO_PIN_RESET);
          HAL_Delay(500);

          // LED OFF
          HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET);
          HAL_GPIO_WritePin(GPIOB, GPIO_PIN_15, GPIO_PIN_SET);
          HAL_Delay(500);
  }
}
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

  /** Initializes the CPU, AHB and APB buses clocks
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                                |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSE;
  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();
  }
}

/* @brief GPIO Initialization Function
static void MX_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};

/* USER CODE BEGIN MX_GPIO_Init_1 */
/* USER CODE END MX_GPIO_Init_1 */

  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOD_CLK_ENABLE();
  __HAL_RCC_GPIOB_CLK_ENABLE();

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14|GPIO_PIN_15, GPIO_PIN_RESET);

  /*Configure GPIO pins : PB14 PB15 */
  GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
}
/**
  * @brief  This function is executed in case of error occurrence.
  * @retval None
void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state
  __disable_irq();
  while (1)
  {
  }
  /* USER CODE END Error_Handler_Debug */
}
 
#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @PAram  file: pointer to the source file name
  * @PAram  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
*************************************

 


Edited to apply proper code formatting; please see How to insert source code for future reference

17 REPLIES 17

Debug mode is finally running after settings in CubeMX - see image below. I am able to use the "StepOver" and "StepInto" functions. I also re-set the frequency to 1000kHz. It is lower than 4000kHz.

 

Running in debug mode:

debug run.jpg

cubeMX nastaveni pinu pro debug .jpg

Time to mark a solution, then?

https://community.st.com/t5/community-guidelines/help-others-to-solve-their-issues/ta-p/575256

 


@JerryMC22 wrote:

 I bought the STLINKV2 and demoboard from Aliexpress as well because of the price 16USD 


Could have got a Nucleo for that - which includes a genuine ST-Link.

 


@JerryMC22 wrote:

By the way if I am changing something in CubeMX in my project using the .ioc file (+GENERATE button) whole the main.c code is set to init state and everything I wrote to main.c is deleted (I am sad). It is suspicious. Is it possible to change the pin configuration in CubeMX without deleting the code I already wrote to main.c ?


That's a separate question - please start a new thread for that.

TL;DR you need to keep your code within the USER CODE section; eg,

https://community.st.com/t5/stm32cubeide-mcus/code-generation-would-clear-my-code-in-main-c/m-p/720044

AndrewNeil_0-1738144322733.png

https://www.st.com/resource/en/user_manual/um1718-stm32cubemx-for-stm32-configuration-and-initialization-c-code-generation-stmicroelectronics.pdf#page=503

 

 


@JerryMC22 wrote:

I also re-set the frequency to 1000kHz. It is lower than 4000kHz.


 Did you try 'Auto' ?

 

 

So, thank you very much for you help. I finally solve the problem and everything is working ok for mw now. :)

I am happy. :)

1/ I can not change the FRQ to any value. There in DropDownList and in it I see the following values: Auto, 100kHz, 1000kHz, 8000kHz, 24000kHz  - it is the predefinned set. I can not put down my own value. 

 

2/  If I am using set of several pins of my STM32F103C8T6 for JTAG purposes I can not use them for normal functions - it is a pitty, I am sad. :( 

JerryMC22
Associate

I know, I have this:

 

IMG A01.jpg

yes STM32C0116 very nice 278CZK without TAX 21% and without postal charge 130CZK = 466CZK too expensive. 

:(

 

https://cz.mouser.com/ProductDetail/STMicroelectronics/STM32C0116-DK?qs=IPgv5n7u5QYv9B%252BqttgZUQ%3D%3D&mgh=1&utm_id=20241108148&gad_source=1&gclid=EAIaIQobChMI6qua6OyaiwMVGJODBx1H_REjEAYYASABEgKP-fD_BwE

 

Aliexpress has no postal charge and no tax

the "Auto" set the FRQ to 4000kHz.