0

I am using STM32CubeMX to generate code into IAR, and I am using a stm32f051r8t6 microcontroller, The problem I am having is that when first loading the code onto the chip, it all works perfect, however after pressing restart on either the board or IAR debugger, the TIM14 interrupt handler is not entered, but as soon as I leave the debugger and enter again, it starts working until I press restart. Has anybody come across this problem before? My code is below

static void MX_TIM14_Init(void);

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
  if (htim->Instance == TIM14)
  {
    HAL_GPIO_WritePin(GPIOA, USART1_TE_Pin, GPIO_PIN_SET);
  }
}

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();

 /* 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_ADC_Init();
  MX_USART1_UART_Init();
  MX_USART2_UART_Init();
  MX_TIM14_Init();

  HAL_TIM_Base_Start(&htim14);
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
 while (1)
{
FslBufferControl();
MimModeCheck();
/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
static void MX_TIM14_Init(void)
{

 /* USER CODE BEGIN TIM14_Init 0 */

 /* USER CODE END TIM14_Init 0 */

 /* USER CODE BEGIN TIM14_Init 1 */

 /* USER CODE END TIM14_Init 1 */
 htim14.Instance = TIM14;
 htim14.Init.Prescaler = 47999;
 htim14.Init.CounterMode = TIM_COUNTERMODE_UP;
 htim14.Init.Period = 1;
 htim14.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
 htim14.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
 if (HAL_TIM_Base_Init(&htim14) != HAL_OK)
 {
  Error_Handler();
 }
 /* USER CODE BEGIN TIM14_Init 2 */

 /* USER CODE END TIM14_Init 2 */

 }

1 Answers1

1

You need to add to enable the interrupt.

  MX_TIM14_Init();

  HAL_NVIC_EnableIRQ(TIM14_IRQn);   // <----------------------------

  HAL_TIM_Base_Start(&htim14);

Just check the IRQn TIM14 UG event number. They are defined in the IRQn_Type enum type defined in the STM32F___.h file where ___ is the model of your micro (you will find it in the include folder)

0___________
  • 60,014
  • 4
  • 34
  • 74
  • Thankyou very much! TIM14 IRQn is 19, so do I need to write 'HAL_NVIC_EnableIRQ(TIM14_IRQ19)? – user10451545 Jan 02 '19 at 14:27
  • Hi, I have added that line to my code and unfortunately the same thing is happening, on initial load of the debugger it works fine, however after pressing restart it does not enter the 'void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)' function – user10451545 Jan 02 '19 at 14:36
  • `TIM14_IRQn` ---- – 0___________ Jan 02 '19 at 14:44
  • Hi, I have just realised my mistake, as I am using a new IDE (from keil to IAR) I did not realise the debugger was automatically set to 'software reset' not 'hardware rest pin', I have altered this setting and it is now working fine with the debugger and without, thank you for your help – user10451545 Jan 02 '19 at 14:49