How to output STM32-Printf in DMA mode
STM32-Printf how to use DMA mode output, for this problem, this article details the corresponding analysis and solution, hoping to help more want to solve this problem of small partners to find a simpler and easier way.
1. Simple printf print, rewrite the underlying fputc on the line
int fputc(int ch, FILE *f){ while (__HAL_UART_GET_FLAG(&huart1, UART_FLAG_TC) == RESET) {} HAL_UART_Transmit(&huart1, (uint8_t*) &ch,1,0xFF); return ch;}
2. Print via DMA
void Usart1DmaPrintf(const char *format,...) { uint16_t len; va_list args; va_start(args,format); len = vsnprintf((char*)UartTxBuf,sizeof(UartTxBuf)+1,(char*)format,args); va_end(args); HAL_UART_Transmit_DMA(&huart1, UartTxBuf, len);}
UartTxBuf inside can be applied as a global variable, as long as the length is appropriate. Or allocate memory dynamically, and then reclaim memory in DMA send completion interrupt. Local variables applied within a function may be recycled and used elsewhere, causing other effects.
About STM32-Printf how to use DMA mode output questions to share the answer here, I hope the above content can be of some help to everyone, if you still have a lot of doubts not solved, you can pay attention to the industry information channel to learn more related knowledge.