|
STM32 USART DMA Printf不定长收发,HAL库程序.
[复制链接]
双11时候淘的L011,现在才拿出来吹灰,先实现一个Printf的例子.就是空闲中断和vsnprintf发送.
- void dma_printf(const char *format, ...)
- {
- uint32_t length;
- va_list args;
- va_start(args, format);
- length = vsnprintf((char *)txbuf2, sizeof(txbuf2), (char *)format, args);
- va_end(args);
- HAL_UART_Transmit_DMA(&huart2, (uint8_t *)txbuf2, length);
- }
- void HAL_UART_IdleCpltCallback(UART_HandleTypeDef *huart)
- {
- uint32_t temp;
- if((__HAL_UART_GET_FLAG(huart, UART_FLAG_IDLE) != RESET))
- {
- __HAL_UART_CLEAR_IDLEFLAG(huart);
- HAL_UART_DMAStop(huart);
- temp = huart->hdmarx->Instance->CNDTR;
- rx2_len = RX_BUF_LEN - temp;
- __HAL_UART_ENABLE_IT(huart, UART_IT_IDLE);
- huart->hdmarx->State = HAL_DMA_STATE_READY;
- HAL_UART_Receive_DMA(huart, rxbuf2, RX_BUF_LEN);
- }
- }
复制代码
USART_DMA_STM32L011_Prinf.zip
(3.91 MB, 下载次数: 354)
|
|