@@ -91,7 +91,6 @@ static int serial_fops_open(struct dfs_file *fd)
9191 if ((fd -> flags & O_ACCMODE ) != O_WRONLY )
9292 rt_device_set_rx_indicate (device , serial_fops_rx_ind );
9393
94- rt_device_close (device );
9594 ret = rt_device_open (device , flags | RT_SERIAL_RX_BLOCKING | RT_SERIAL_TX_BLOCKING );
9695 if (ret == RT_EOK )
9796 {
@@ -1183,12 +1182,18 @@ static rt_err_t rt_serial_open(struct rt_device *dev, rt_uint16_t oflag)
11831182{
11841183 struct rt_serial_device * serial ;
11851184 rt_err_t result = RT_EOK ;
1186-
1185+ rt_uint16_t stream_flag = 0 ;
11871186 RT_ASSERT (dev != RT_NULL );
11881187 serial = (struct rt_serial_device * )dev ;
11891188
11901189 LOG_D ("open serial device: 0x%08x with open flag: 0x%04x" , dev , oflag );
1190+
1191+ /* set steam flag */
1192+ if ((oflag & RT_DEVICE_FLAG_STREAM ) || (dev -> open_flag & RT_DEVICE_FLAG_STREAM ))
1193+ stream_flag |= RT_DEVICE_FLAG_STREAM ;
11911194
1195+ dev -> open_flag = 0 ;
1196+
11921197 /* By default, the receive mode of a serial devide is RT_SERIAL_RX_NON_BLOCKING */
11931198 if ((oflag & RT_SERIAL_RX_BLOCKING ) == RT_SERIAL_RX_BLOCKING )
11941199 dev -> open_flag |= RT_SERIAL_RX_BLOCKING ;
@@ -1201,9 +1206,7 @@ static rt_err_t rt_serial_open(struct rt_device *dev, rt_uint16_t oflag)
12011206 else
12021207 dev -> open_flag |= RT_SERIAL_TX_BLOCKING ;
12031208
1204- /* set steam flag */
1205- if ((oflag & RT_DEVICE_FLAG_STREAM ) || (dev -> open_flag & RT_DEVICE_FLAG_STREAM ))
1206- dev -> open_flag |= RT_DEVICE_FLAG_STREAM ;
1209+ dev -> open_flag |= stream_flag ;
12071210
12081211 /* initialize the Rx structure according to open flag */
12091212 if (serial -> serial_rx == RT_NULL )
0 commit comments