@@ -99,7 +99,6 @@ __IO uint32_t UserRxBufPtrOut = 0; /* Increment this pointer or roll it back to
99
99
__IO uint32_t SLP ;
100
100
__IO uint32_t GetRxCount ;
101
101
__IO uint32_t lineState = 0 ;
102
- uint8_t cptlineState = 0 ;
103
102
volatile uint32_t USB_received = 0 ;
104
103
uint8_t USBBuffer [64 ];
105
104
uint8_t USBPackSize ;
@@ -238,9 +237,7 @@ static int8_t CDC_Control_FS (uint8_t cmd, uint8_t* pbuf, uint16_t length)
238
237
break ;
239
238
240
239
case CDC_SET_CONTROL_LINE_STATE :
241
- cptlineState ++ ;
242
- if (cptlineState == 2 )
243
- lineState = 1 ;
240
+ lineState = (((USBD_SetupReqTypedef * )pbuf )-> wValue & 0x01 ) != 0 ; // Check DTR state
244
241
break ;
245
242
246
243
case CDC_SEND_BREAK :
@@ -314,28 +311,22 @@ void CDC_flush(void)
314
311
memcpy ((uint8_t * )& StackTxBufferFS [APP_TX_DATA_SIZE - UserTxBufPtrOut ], (uint8_t * )& UserTxBufferFS [0 ], UserTxBufPtrIn );
315
312
316
313
USBD_CDC_SetTxBuffer (& hUSBD_Device_CDC , (uint8_t * )& StackTxBufferFS [0 ], (APP_TX_DATA_SIZE - UserTxBufPtrOut + UserTxBufPtrIn ));
317
-
318
- do {
319
- status = USBD_CDC_TransmitPacket (& hUSBD_Device_CDC );
320
- } while (status == USBD_BUSY );
321
-
322
- if (status == USBD_OK )
323
- {
324
- UserTxBufPtrOut = UserTxBufPtrIn ;
325
- }
326
314
}
327
- else
315
+ else
328
316
{
329
317
USBD_CDC_SetTxBuffer (& hUSBD_Device_CDC , (uint8_t * )& UserTxBufferFS [UserTxBufPtrOut ], (UserTxBufPtrIn - UserTxBufPtrOut ));
318
+ }
330
319
331
- do {
320
+ do {
321
+ if (lineState == 0 ) // Device disconnected
322
+ status = USBD_OK ;
323
+ else
332
324
status = USBD_CDC_TransmitPacket (& hUSBD_Device_CDC );
333
- } while (status == USBD_BUSY );
325
+ } while (status == USBD_BUSY );
334
326
335
- if (status == USBD_OK )
336
- {
337
- UserTxBufPtrOut = UserTxBufPtrIn ;
338
- }
327
+ if (status == USBD_OK )
328
+ {
329
+ UserTxBufPtrOut = UserTxBufPtrIn ;
339
330
}
340
331
}
341
332
}
@@ -396,25 +387,21 @@ void TIM6_PeriodElapsedCallback(stimer_t *htim)
396
387
memcpy ((uint8_t * )& StackTxBufferFS [APP_TX_DATA_SIZE - UserTxBufPtrOut ], (uint8_t * )& UserTxBufferFS [0 ], UserTxBufPtrIn );
397
388
398
389
USBD_CDC_SetTxBuffer (& hUSBD_Device_CDC , (uint8_t * )& StackTxBufferFS [0 ], (APP_TX_DATA_SIZE - UserTxBufPtrOut + UserTxBufPtrIn ));
399
-
400
- do {
401
- status = USBD_CDC_TransmitPacket (& hUSBD_Device_CDC );
402
- } while (status == USBD_BUSY );
403
-
404
- if (status == USBD_OK ) {
405
- UserTxBufPtrOut = UserTxBufPtrIn ;
406
- }
407
390
}
408
- else {
391
+ else
392
+ {
409
393
USBD_CDC_SetTxBuffer (& hUSBD_Device_CDC , (uint8_t * )& UserTxBufferFS [UserTxBufPtrOut ], (UserTxBufPtrIn - UserTxBufPtrOut ));
394
+ }
410
395
411
- do {
412
- status = USBD_CDC_TransmitPacket (& hUSBD_Device_CDC );
413
- } while (status == USBD_BUSY );
396
+ do {
397
+ if (lineState == 0 ) // Device disconnected
398
+ status = USBD_OK ;
399
+ else
400
+ status = USBD_CDC_TransmitPacket (& hUSBD_Device_CDC );
401
+ } while (status == USBD_BUSY );
414
402
415
- if (status == USBD_OK ) {
416
- UserTxBufPtrOut = UserTxBufPtrIn ;
417
- }
403
+ if (status == USBD_OK ) {
404
+ UserTxBufPtrOut = UserTxBufPtrIn ;
418
405
}
419
406
}
420
407
}
0 commit comments