cancel
Showing results for 
Search instead for 
Did you mean: 

UART Interrupt callback calling only when running in debugging mode using Stlink-V2 Debugger

ZMohd.7
Associate III

Hi,

I am working on STM303CBT6 MCU custom design board, USART3 Interrupt callback working fine when program is running in debugging mode.

If program running in Normal mode without debugger, USART3 Callback function not calling.

Note, MCU BOOT0 pin is connected to GND

Code is below for you reference.

uint8_t Rx_indx, Rx_data[2];

uint8_t tx_data[11] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0X11};

//Interrupt callback routine

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)  

{

  if (huart->Instance == USART3) //current UART

    {

        HAL_UART_Transmit(&huart3, Rx_data, 1, 50);

        HAL_UART_Receive_IT(&huart3, Rx_data, 1);  //activate UART receive interrupt every time

  

    }

}

int main(void)

{

 HAL_Init();

 SystemClock_Config();

 MX_GPIO_Init();

 MX_USART3_UART_Init();

 HAL_UART_Receive_IT(&huart3, Rx_data, 1);

 /* Infinite loop */

 /* USER CODE BEGIN WHILE */

 while (1)

 {

  /* USER CODE END WHILE */

  HAL_UART_Transmit(&huart3, tx_data, 11, 100);

  /* USER CODE BEGIN 3 */

 }

 /* USER CODE END 3 */

}

/**

 * @brief System Clock Configuration

 * @retval None

 */

void SystemClock_Config(void)

{

 RCC_OscInitTypeDef RCC_OscInitStruct = {0};

 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

 RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};

 /** Initializes the CPU, AHB and APB busses clocks 

 */

 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;

 RCC_OscInitStruct.HSIState = RCC_HSI_ON;

 RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;

 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;

 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

 {

  Error_Handler();

 }

 /** Initializes the CPU, AHB and APB busses clocks 

 */

 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK

               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;

 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;

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

 }

 PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART3;

 PeriphClkInit.Usart3ClockSelection = RCC_USART3CLKSOURCE_PCLK1;

 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)

 {

  Error_Handler();

 }

}

/**

 * @brief USART3 Initialization Function

 * @param None

 * @retval None

 */

static void MX_USART3_UART_Init(void)

{

 /* USER CODE BEGIN USART3_Init 0 */

 /* USER CODE END USART3_Init 0 */

 /* USER CODE BEGIN USART3_Init 1 */

 /* USER CODE END USART3_Init 1 */

 huart3.Instance = USART3;

 huart3.Init.BaudRate = 9600;

 huart3.Init.WordLength = UART_WORDLENGTH_8B;

 huart3.Init.StopBits = UART_STOPBITS_1;

 huart3.Init.Parity = UART_PARITY_NONE;

 huart3.Init.Mode = UART_MODE_TX_RX;

 huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;

 huart3.Init.OverSampling = UART_OVERSAMPLING_16;

 huart3.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;

 huart3.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;

 if (HAL_UART_Init(&huart3) != HAL_OK)

 {

  Error_Handler();

 }

 /* USER CODE BEGIN USART3_Init 2 */

 /* USER CODE END USART3_Init 2 */

}

2 REPLIES 2
PPate.1029
Associate II

I am facing same problem with stm32h743, did you get any solution for this problem?

ZMohd.7
Associate III

Hi Pate,

After adding 2 second delay before calling NVIC configuration HAL_UART_Receive_IT() in Main function, and it's working fine.

 HAL_Delay(2000);

 HAL_UART_Receive_IT(&huart3, Rx_data, 1);

Rest code same as above, Hope it will helps.

Best Regards,

Zafar