Skip to content

[Bug][serial_v1] 主频较高时可能会导致发送不完整 #9964

@kaidegit

Description

@kaidegit

RT-Thread Version

master

Hardware Type/Architectures

H730 with internal flash

Develop Toolchain

MDK Keil

Describe the bug

在主频550M,打开优化时,使用rt_kprintf只能打出首字符。

调查发现在stm32的serial_v1驱动中,会使用一个较为硬编码(由库中define)的值检查是否发送超时。在主频较高且波特率较低时可能会触发。

static int stm32_putc(struct rt_serial_device *serial, char c)
{
struct stm32_uart *uart;
RT_ASSERT(serial != RT_NULL);
uart = rt_container_of(serial, struct stm32_uart, serial);
rt_uint32_t block_timeout = uart->tx_block_timeout;
UART_INSTANCE_CLEAR_FUNCTION(&(uart->handle), UART_FLAG_TC);
#if defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32WL) || defined(SOC_SERIES_STM32F7) || defined(SOC_SERIES_STM32F0) \
|| defined(SOC_SERIES_STM32L0) || defined(SOC_SERIES_STM32G0) || defined(SOC_SERIES_STM32H7) || defined(SOC_SERIES_STM32L5) \
|| defined(SOC_SERIES_STM32G4) || defined(SOC_SERIES_STM32MP1) || defined(SOC_SERIES_STM32WB) || defined(SOC_SERIES_STM32F3) \
|| defined(SOC_SERIES_STM32U5) || defined(SOC_SERIES_STM32H5) || defined(SOC_SERIES_STM32H7RS)
uart->handle.Instance->TDR = c;
#else
uart->handle.Instance->DR = c;
#endif
while (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_TC) == RESET && --block_timeout);
return (block_timeout != 0) ? 1 : -1;

rt_kpinrtf调用_kputs发送时未处理rt_device_write的返回值,没有重发。

rt-thread/src/kservice.c

Lines 312 to 335 in 0cc4dc4

static void _kputs(const char *str, long len)
{
#ifdef RT_USING_DEVICE
rt_device_t console_device = rt_console_get_device();
#endif /* RT_USING_DEVICE */
CONSOLE_TAKE;
#ifdef RT_USING_DEVICE
if (console_device == RT_NULL)
{
rt_hw_console_output(str);
}
else
{
rt_device_write(console_device, 0, str, len);
}
#else
RT_UNUSED(len);
rt_hw_console_output(str);
#endif /* RT_USING_DEVICE */
CONSOLE_RELEASE;
}

相关PR:#9543

这个PR把代码改正确了,但是导致了这个问题 改回去会导致没发完就接着发中间缺字符🤦‍♂️

Other additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions