printf latency improvement#265
Conversation
There was a problem hiding this comment.
Code Review
This pull request implements DMA support for UART transmissions and introduces a uart_send_buf function to facilitate zero-copy transfers of static buffers. The printf implementation has been refactored to use this new functionality, increasing the buffer pool size and utilizing binary semaphores for safe release from interrupts. Review feedback identified several compilation errors in the newly added test files where printf_init was called with insufficient arguments. Additionally, recommendations were made to add Doxygen documentation for the new UART API and to improve code clarity and type safety by using NULL for pointer arguments and removing redundant logic.
| husart3->Init.Mode = UART_MODE_TX_RX; | ||
| husart3->Init.HwFlowCtl = UART_HWCONTROL_NONE; | ||
| husart3->Init.OverSampling = UART_OVERSAMPLING_16; | ||
| printf_init(husart3); |
| husart1->Init.HwFlowCtl = UART_HWCONTROL_NONE; | ||
| husart1->Init.OverSampling = UART_OVERSAMPLING_16; | ||
|
|
||
| printf_init(husart1); |
| husart3->Init.Mode = UART_MODE_TX_RX; | ||
| husart3->Init.HwFlowCtl = UART_HWCONTROL_NONE; | ||
| husart3->Init.OverSampling = UART_OVERSAMPLING_16; | ||
| printf_init(husart3); |
| husart1->Init.HwFlowCtl = UART_HWCONTROL_NONE; | ||
| husart1->Init.OverSampling = UART_OVERSAMPLING_16; | ||
|
|
||
| printf_init(husart1); |
| */ | ||
| uart_status_t uart_send(UART_HandleTypeDef* handle, const uint8_t* data, uint16_t length, TickType_t delay_ticks); | ||
|
|
||
| uart_status_t uart_send_buf(UART_HandleTypeDef* handle, const uint8_t* data, uint16_t length, SemaphoreHandle_t release_sem, TickType_t delay_ticks); |
There was a problem hiding this comment.
The new function uart_send_buf is missing a Doxygen comment explaining what it does, its parameters, and what it returns. Please add a comprehensive comment for better maintainability.
| uart_status_t uart_send_buf(UART_HandleTypeDef* handle, const uint8_t* data, uint16_t length, SemaphoreHandle_t release_sem, TickType_t delay_ticks); | |
| /** | |
| * @brief Transmits a static buffer over UART without copying its contents. | |
| * @details This function is designed for performance-critical sections where data is in a static or long-lived buffer. | |
| * It queues a pointer to the data, avoiding a memcpy. A semaphore is given back by the UART driver upon transmission completion. | |
| * The caller is expected to take this semaphore before calling this function to ensure the buffer is not modified during transmission. | |
| * @param handle Pointer to the UART handle. | |
| * @param data Pointer to the static buffer containing data to send. | |
| * @param length Number of bytes to transmit. | |
| * @param release_sem Semaphore to be released upon completion of the transmission. | |
| * @param delay_ticks Ticks to wait if TX queue is full (0 = no wait, portMAX_DELAY = wait indefinitely). | |
| * @return uart_status_t Returns UART_OK on success, UART_ERR on failure. | |
| */ | |
| uart_status_t uart_send_buf(UART_HandleTypeDef* handle, const uint8_t* data, uint16_t length, SemaphoreHandle_t release_sem, TickType_t delay_ticks); |
| if(HAL_DMA_Init(hdma_uart_tx) != HAL_OK) return false; | ||
| else __HAL_LINKDMA(huart,hdmatx,*hdma_uart_tx); |
| husart2->Init.HwFlowCtl = UART_HWCONTROL_NONE; | ||
| husart2->Init.OverSampling = UART_OVERSAMPLING_16; | ||
| printf_init(husart2); | ||
| printf_init(husart2, false); |
Uh oh!
There was an error while loading. Please reload this page.