Core/Src/stm32h7xx_it.c
void PendSV_Handler(void)
{
  /* USER CODE BEGIN PendSV_IRQn 0 */
    // Handle UART RX queue
    while (command_queue_write - command_queue_read > 0) {
        uint32_t command_queue_mod = (command_queue_read++) % COMMAND_QUEUE_SIZE;
        uart_command_received(command_queue[command_queue_mod], strlen(command_queue[command_queue_mod]));
        free(command_queue[command_queue_mod]);
    }
    // Handle UART TX queue
    while (uart_write - uart_read > 0) {
        volatile uint32_t uart_write_clone = uart_write; // Get value once, explicitly, to ease atomic operations
        uint32_t messages_to_read = uart_write_clone - uart_read;

        for (int i = 0; i < messages_to_read; i++) {
            char * message = (char*) uart_buffer[(uart_read + i) % UART_BUFFER_SIZE];
            for (int j = 0; j < strlen(message); j++) {
                // Wait until the UART can take more data to transmit
                while (!LL_USART_IsActiveFlag_TXE_TXFNF(USART3)) {}
                LL_USART_TransmitData8(USART3, message[j]);
            }
        }

        // Wait until all data has been transmitted
        while (!LL_USART_IsActiveFlag_TC(USART3)) {}

        uart_read += messages_to_read;
    }

  /* USER CODE END PendSV_IRQn 0 */
  /* USER CODE BEGIN PendSV_IRQn 1 */
    NVIC_ClearPendingIRQ(PendSV_IRQn);
  /* USER CODE END PendSV_IRQn 1 */
}
/**
  * @brief This function handles Pendable request for system service.
  */
@brief This function handles Pendable request for system service.
@brief This function handles Pendable request for system service .
void PendSV_Handler(void)
{
    while (command_queue_write - command_queue_read > 0) {
        uint32_t command_queue_mod = (command_queue_read++) % COMMAND_QUEUE_SIZE;
        uart_command_received(command_queue[command_queue_mod], strlen(command_queue[command_queue_mod]));
        free(command_queue[command_queue_mod]);
    }
    while (uart_write - uart_read > 0) {
        volatile uint32_t uart_write_clone = uart_write; 
        uint32_t messages_to_read = uart_write_clone - uart_read;
        for (int i = 0; i < messages_to_read; i++) {
            char * message = (char*) uart_buffer[(uart_read + i) % UART_BUFFER_SIZE];
            for (int j = 0; j < strlen(message); j++) {
                while (!LL_USART_IsActiveFlag_TXE_TXFNF(USART3)) {}
                LL_USART_TransmitData8(USART3, message[j]);
            }
        }
        while (!LL_USART_IsActiveFlag_TC(USART3)) {}
        uart_read += messages_to_read;
    }
    NVIC_ClearPendingIRQ(PendSV_IRQn);
}
void PendSV_Handler ( void ) { while ( command_queue_write - command_queue_read > 0 ) { uint32_t command_queue_mod = ( command_queue_read ++ ) % COMMAND_QUEUE_SIZE ; uart_command_received ( command_queue [ command_queue_mod ] , strlen ( command_queue [ command_queue_mod ] ) ) ; free ( command_queue [ command_queue_mod ] ) ; } while ( uart_write - uart_read > 0 ) { volatile uint32_t uart_write_clone = uart_write ; uint32_t messages_to_read = uart_write_clone - uart_read ; for ( int i = 0 ; i < messages_to_read ; i ++ ) { char * message = ( char * ) uart_buffer [ ( uart_read + i ) % UART_BUFFER_SIZE ] ; for ( int j = 0 ; j < strlen ( message ) ; j ++ ) { while ( ! LL_USART_IsActiveFlag_TXE_TXFNF ( USART3 ) ) { } LL_USART_TransmitData8 ( USART3 , message [ j ] ) ; } } while ( ! LL_USART_IsActiveFlag_TC ( USART3 ) ) { } uart_read += messages_to_read ; } NVIC_ClearPendingIRQ ( PendSV_IRQn ) ; }
@brief This function handles Pendable request for system service.
@brief This function handles Pendable request for system service .
/* USER CODE BEGIN PendSV_IRQn 0 */ // Handle UART RX queue // Handle UART TX queue // Get value once, explicitly, to ease atomic operations // Wait until the UART can take more data to transmit // Wait until all data has been transmitted /* USER CODE END PendSV_IRQn 0 */ /* USER CODE BEGIN PendSV_IRQn 1 */ /* USER CODE END PendSV_IRQn 1 */