Core/Src/stm32h7xx_it.c
void USART3_IRQHandler(void)
{
  /* USER CODE BEGIN USART3_IRQn 0 */
    // The information is received in bytes, but we need a buffer to store complete commands
    static uint8_t buffer[256];
    static uint8_t current_point = 0;
    volatile uint32_t a = 0;

    // Handle any received bytes
    // Note that, since the FIFO is active, one interrupt call may amount to more than 1 byte. This is why we're using a
    // loop instead of a condition.
    while (LL_USART_IsActiveFlag_RXNE_RXFNE(USART3)) {
        // Perform an explicit copy, since every read from the RDR gets a new byte from the FIFO
        uint8_t data = USART3->RDR;
        if (data == '\n' || data == '\r') {
            // New command received! Add it to the queue
            char * copied_command = malloc(current_point + 1);
            memcpy(copied_command, buffer, current_point);
            copied_command[current_point] = '\0'; // Add null byte so we can call strlen() later
            command_queue[(command_queue_write++) % COMMAND_QUEUE_SIZE] = copied_command;

            // Notify the PendSV interrupt handler that there are new items in the queue
            SCB->ICSR |= SCB_ICSR_PENDSVSET_Msk;

            // Reset the received buffer
            current_point = 0;

            // Close indicator LED when reception is complete
            HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_RESET);
        } else {
            if (current_point >= sizeof(buffer)) {
                log_error("Input buffer is full, forgetting everything");
                current_point = 0;
            }

            // Add the new data to the buffer and move on
            buffer[current_point++] = data;

            // Enable indicator LED to show that there is pending reception
            HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_SET);
        }
    }
    if (LL_USART_IsActiveFlag_ORE(USART3)) {
        log_error("UART RX overrun error detected");
        LL_USART_ClearFlag_ORE(USART3);
    }
  /* USER CODE END USART3_IRQn 0 */
  /* USER CODE BEGIN USART3_IRQn 1 */

  /* USER CODE END USART3_IRQn 1 */
}
/**
  * @brief This function handles USART3 global interrupt.
  */
@brief This function handles USART3 global interrupt.
@brief This function handles USART3 global interrupt .
void USART3_IRQHandler(void)
{
    static uint8_t buffer[256];
    static uint8_t current_point = 0;
    volatile uint32_t a = 0;
    while (LL_USART_IsActiveFlag_RXNE_RXFNE(USART3)) {
        uint8_t data = USART3->RDR;
        if (data == '\n' || data == '\r') {
            char * copied_command = malloc(current_point + 1);
            memcpy(copied_command, buffer, current_point);
            copied_command[current_point] = '\0'; 
            command_queue[(command_queue_write++) % COMMAND_QUEUE_SIZE] = copied_command;
            SCB->ICSR |= SCB_ICSR_PENDSVSET_Msk;
            current_point = 0;
            HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_RESET);
        } else {
            if (current_point >= sizeof(buffer)) {
                log_error("Input buffer is full, forgetting everything");
                current_point = 0;
            }
            buffer[current_point++] = data;
            HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_SET);
        }
    }
    if (LL_USART_IsActiveFlag_ORE(USART3)) {
        log_error("UART RX overrun error detected");
        LL_USART_ClearFlag_ORE(USART3);
    }
}
void USART3_IRQHandler ( void ) { static uint8_t buffer [ 256 ] ; static uint8_t current_point = 0 ; volatile uint32_t a = 0 ; while ( LL_USART_IsActiveFlag_RXNE_RXFNE ( USART3 ) ) { uint8_t data = USART3 -> RDR ; if ( data == ' \n ' || data == ' \r ' ) { char * copied_command = malloc ( current_point + 1 ) ; memcpy ( copied_command , buffer , current_point ) ; copied_command [ current_point ] = ' \0 ' ; command_queue [ ( command_queue_write ++ ) % COMMAND_QUEUE_SIZE ] = copied_command ; SCB -> ICSR |= SCB_ICSR_PENDSVSET_Msk ; current_point = 0 ; HAL_GPIO_WritePin ( LD3_GPIO_Port , LD3_Pin , GPIO_PIN_RESET ) ; } else { if ( current_point >= sizeof ( buffer ) ) { log_error ( " " ) ; current_point = 0 ; } buffer [ current_point ++ ] = data ; HAL_GPIO_WritePin ( LD3_GPIO_Port , LD3_Pin , GPIO_PIN_SET ) ; } } if ( LL_USART_IsActiveFlag_ORE ( USART3 ) ) { log_error ( " " ) ; LL_USART_ClearFlag_ORE ( USART3 ) ; } }
@brief This function handles USART3 global interrupt.
@brief This function handles USART3 global interrupt .
/* USER CODE BEGIN USART3_IRQn 0 */ // The information is received in bytes, but we need a buffer to store complete commands // Handle any received bytes // Note that, since the FIFO is active, one interrupt call may amount to more than 1 byte. This is why we're using a // loop instead of a condition. // Perform an explicit copy, since every read from the RDR gets a new byte from the FIFO // New command received! Add it to the queue // Add null byte so we can call strlen() later // Notify the PendSV interrupt handler that there are new items in the queue // Reset the received buffer // Close indicator LED when reception is complete // Add the new data to the buffer and move on // Enable indicator LED to show that there is pending reception /* USER CODE END USART3_IRQn 0 */ /* USER CODE BEGIN USART3_IRQn 1 */ /* USER CODE END USART3_IRQn 1 */