[fix] components: serial_v2: preserve RT_DEVICE_FLAG_STREAM when reopening serial device

- The serial_fops_open function closes and reopens the serial device,but the RT_DEVICE_FLAG_STREAM flag was not preserved across the close/open cycle. This change saves the STREAM flag before close and restores it during reopen to ensure consistent behavior.

Signed-off-by: Runcheng Lu <runcheng.lu@hpmicro.com>
This commit is contained in:
Runcheng Lu 2026-04-28 15:36:40 +08:00 committed by Rbb666
parent ad205d2bf3
commit ec9eaadf85
1 changed files with 10 additions and 1 deletions

View File

@ -92,8 +92,17 @@ static int serial_fops_open(struct dfs_file *fd)
if ((fd->flags & O_ACCMODE) != O_WRONLY)
rt_device_set_rx_indicate(device, serial_fops_rx_ind);
flags |= RT_SERIAL_RX_BLOCKING | RT_SERIAL_TX_BLOCKING;
/* preserve RT_DEVICE_FLAG_STREAM if it was set before close */
if (device->open_flag & RT_DEVICE_FLAG_STREAM)
{
flags |= RT_DEVICE_FLAG_STREAM;
}
rt_device_close(device);
ret = rt_device_open(device, flags | RT_SERIAL_RX_BLOCKING | RT_SERIAL_TX_BLOCKING);
ret = rt_device_open(device, flags);
if (ret == RT_EOK)
{
serial = (struct rt_serial_device *)device;