做了一个STM32G030F6P6实验板,测试UART时发现一个关于接收超时的问题,直接在cubeMX 生成代码中增加receive timeout设置(在STM32G431中就是如此使用,很正常),代码如下: void MX_USART2_UART_Init(void) { /* USER CODE BEGIN USART2_Init 0 */ /* USER CODE END USART2_Init 0 */ /* USER CODE BEGIN USART2_Init 1 */ /* USER CODE END USART2_Init 1 */ huart2.Instance = USART2; huart2.Init.BaudRate = 115200; huart2.Init.WordLength = UART_WORDLENGTH_8B; huart2.Init.StopBits = UART_STOPBITS_1; huart2.Init.Parity = UART_PARITY_NONE; huart2.Init.Mode = UART_MODE_TX_RX; huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; huart2.Init.OverSampling = UART_OVERSAMPLING_16; huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; huart2.Init.ClockPrescaler = UART_PRESCALER_DIV1; huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_DMADISABLEONERROR_INIT; huart2.AdvancedInit.DMADisableonRxError = UART_ADVFEATURE_DMA_DISABLEONRXERROR; if (HAL_UART_Init(&huart2) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN USART2_Init 2 */ HAL_UART_EnableReceiverTimeout(&huart2); HAL_UART_ReceiverTimeout_Config(&huart2, 5); HAL_UART_Receive_IT(&huart2, uart_rxBuffer, UART_RXBUFFER_SIZE); /* USER CODE END USART2_Init 2 */ } 添加接收回调(为了更清楚显示效果添加了一些输出代码): void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) { g_uart_received_completed = true; g_uart_received_counter = huart->RxXferSize - huart->RxXferCount; printf("CP_Callback Counter : %d RxXferSize : %d RxXferCount : %d\r\n", g_uart_received_counter, huart->RxXferSize, huart->RxXferCount); memcpy(g_uart_rxBuffer, uart_rxBuffer, g_uart_received_counter); printf("CP_Data : %s\r\n", g_uart_rxBuffer); memset(g_uart_rxBuffer, 0, UART_RXBUFFER_SIZE); HAL_UART_Receive_IT(&huart2, uart_rxBuffer, UART_RXBUFFER_SIZE); } void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart) { g_uart_received_completed = true; g_uart_received_counter = huart->RxXferSize - huart->RxXferCount; printf("ER_Callback Counter : %d RxXferSize : %d RxXferCount : %d\r\n", g_uart_received_counter, huart->RxXferSize, huart->RxXferCount); memcpy(g_uart_rxBuffer, uart_rxBuffer, g_uart_received_counter); printf("ER_Data : %s\r\n", g_uart_rxBuffer); memset(g_uart_rxBuffer, 0, UART_RXBUFFER_SIZE); HAL_UART_Receive_IT(&huart2, uart_rxBuffer, UART_RXBUFFER_SIZE); } 下载到MCU后执行UART输入(输入内容是“123456789abcdef\r\n”),显示数据如下: CP_Callback Counter : 128 RxXferSize : 128 RxXferCount : 0 CP_Data : 123456789abcdef 123456789abcdef 123456789abcdef 123456789abcdef 123456789abcdef 123456789abcdef 123456789abcdef 123456789 ER_Callback Counter : 1 RxXferSize : 128 RxXferCount : 127 ER_Data : a CP_Callback Counter : 128 RxXferSize : 128 RxXferCount : 0 CP_Data : 123456789abcdef 123456789abcdef 123456789abcdef 123456789abcdef 123456789abcdef 123456789abcdef 123456789abcdef 123456789 ER_Callback Counter : 1 RxXferSize : 128 RxXferCount : 127 ER_Data : a 每次输入数据后(123456789abcdef\r\n)mcu并未触发RTOF中断,而是等到触发缓冲区满中断后紧接着触发一次RTOF中断,看了一下标准库代码,还未发现什么问题,感觉是MCU本身问题造成,G030其他封装形式的还未测试。 |
STM32G030F6 ADC+DMA多通道非连续采样无法正常工作?
STM32G0B1VE的CAN过滤器个数问题
STM32G0B1adc+dma采样数据错位
有没有stm32g071 Discovery kit的micropython的固件
STM32G0B1CBT6 Flash 不能写擦除,更不要说写入?fal库示例代码哪里有,分享一下,谢谢
STM32G031G6U6 PA8无法输出高低电平
STM32G071CBT6技术支持
基于GCC编译器的initcall在STM32如何实现?
stm32cubeide新用户无法注册
关于stm32g系列usart5的问题
你说 每次输入数据后(123456789abcdef\r\n)mcu并未触发RTOF中断,而是等到触发缓冲区满中断后紧接着触发一次RTOF中断。
RTO中断不是要等到收到1个字符后空闲超过RTO设置值后才可能触发吗?你现在输入数据时是连续的还是间隔的,如果间隔的,
间隔是否满足触发RTO中断?
在测试STM32G030C8T6时我使用的UART是UART1,前边确实没注意UART2是没有RTOF功能的,今天再测试一下.
确实没注意到UART2不支持RTOF,刚才测试了一下,没问题,谢谢!!!