Skip to main content
Graduate II
May 8, 2025
Question

Debugger not entering the Callback interrupt functions

  • May 8, 2025
  • 2 replies
  • 537 views

I wrote a simple program using interrupts:

 

Turns on the LD2 the diode if signs "O", "N" and enter are received respectively, turns off if "O", "F", "F" and enter are received otherwise (Im passing only the parts where I made changes :(

 

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include <stdio.h>
#include <string.h>

/* USER CODE END Includes */

......

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */

#define LINE_MAX_LENGTH 80
static char line_buffer[LINE_MAX_LENGTH + 1];
static uint32_t line_length;
void line_append(uint8_t value)
{
 if (value == '\r' || value == '\n') {
 if (line_length > 0) {
 line_buffer[line_length] = '\0';
 if (strcmp(line_buffer, "on") == 0) {
 HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET);
 } else if (strcmp(line_buffer, "off") == 0) {
 HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);
 }
 line_length = 0;
 }
 }
 else {
 if (line_length >= LINE_MAX_LENGTH) {
 line_length = 0;
 }
 line_buffer[line_length++] = value;
 }
}

uint8_t uart_rx_buffer;
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
 if (huart == &huart2) {
 line_append(uart_rx_buffer);
 HAL_UART_Receive_IT(&huart2, &uart_rx_buffer, 1);
 }
}

/* USER CODE END 0 */

MichalPorazko_0-1746719418082.png

Unfortunately, as it is shown in the picture up, the debugger is not entering the interrupt code part and I don't know why 

    This topic has been closed for replies.

    2 replies

    Super User
    May 8, 2025

    What board are you using?

    Before getting into interrupts, have you checked that you can received characters using simple polling?

    Can you transmit OK?

     


    @MichalPorazko wrote:

     as it is shown in the picture up, the debugger is not entering the interrupt code part and I don't know why 


    All that picture shows is that you weren't in the interrupt at the time you took the screenshot.

    The code you posted doesn't show anything which enables interrupts.

    Please post a minimum but complete example which illustrates the issue.

    Have you tried one of the standard ST examples?

    Graduate II
    May 10, 2025

    Board: NUCLEO-L476RG

     

    I changed nothing in the main method

     
    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_USART2_UART_Init();
    
     /* USER CODE BEGIN 2 */
     /* USER CODE END 2 */
    
     /* Infinite loop */
     /* USER CODE BEGIN WHILE */
     while (1)
     {
     /* USER CODE END WHILE */
    
     /* USER CODE BEGIN 3 */
     }
     /* USER CODE END 3 */
    }

    I have enabled the interrupt

    MichalPorazko_0-1746897964910.png

    MichalPorazko_1-1746898016130.png

     

    I don't really know how to check these:


    @Andrew Neil wrote:

    Before getting into interrupts, have you checked that you can received characters using simple polling?

    Can you transmit OK?


     


    Post edited to apply source code formatting - please see How to insert source code for future reference.

    See also: How to write your question to maximize your chances to find a solution.

    Super User
    May 12, 2025

    You forgot the source code formatting!

     


    @MichalPorazko wrote:

    Board: NUCLEO-L476RG


    So are you using the on-board ST-Link's VCP (Virtual COM Port) for sending & receiving?

    This does use USART2 by default - so be sure that you (or any previous users of this board) haven't changed any links. Also that no "shield" is connected which uses these pins:

    AndrewNeil_0-1747039804867.png

     

     


    @MichalPorazko wrote:

    I don't really know how to check these.


    Then you really do need to spend some time on basics before moving on to interrupts!

    Simply transmit in a loop using HAL_UART_Transmit():  this function is blocking - ie, it does not return until the transmission is complete.

    Once you've got that working, then try reception in a simple loop using HAL_UART_Receive():  again, this function is blocking - ie, it does not return until the reception is complete.

    CubeIDE has examples for doing this on your Nucleo board.

    Graduate II
    May 8, 2025

    Not showing code the initializes the NVIC, the USART2_IRQHandler() dispatching into HAL, or the initial priming of the HAL_UART_Receive_IT(&huart2, &uart_rx_buffer, 1)

    Any functions reporting errors or failure status?

    An error call-back?

    Are other interrupts working? Would prove the Vector Table is being used.