I get this message error when I click "Run" in debug session:
Debugger - Cortex-M Error Cannot access de target. Shutting down debug session.
the program worked before, and I tried changing the ST-Link, upgrading the firmware of the ST-Link and changing the microcontroller (STM32F103C8T6).
I generated the configuration with STM32CubeMX and the "useful" code is next
/* Includes ------------------------------------------------------------------*/ #include "main.h" #include "stm32f1xx_hal.h" /* USER CODE BEGIN Includes */ #define PERIOD 6400 /* USER CODE END Includes */ /* Private variables ---------------------------------------------------------*/ ADC_HandleTypeDef hadc1; TIM_HandleTypeDef htim4; /* USER CODE BEGIN PV */ /* Private variables ---------------------------------------------------------*/ volatile uint16_t adc_value; /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); void Error_Handler(void); static void MX_GPIO_Init(void); static void MX_TIM4_Init(void); static void MX_ADC1_Init(void); void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim); /* USER CODE BEGIN PFP */ /* Private function prototypes -----------------------------------------------*/ /* USER CODE END PFP */ /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_TIM4_Init(); MX_ADC1_Init(); /* USER CODE BEGIN 2 */ HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_1); HAL_ADC_Start_DMA(&hadc1, (uint32_t*) &adc_value, 1); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ TIM4->CCR1 = (PERIOD/4096)*adc_value; } /* USER CODE END 3 */ } /********************************************/ // Configuration down here