Skip to content

Commit 889053d

Browse files
committed
Implemented support of double buffer for CDC read and write
1 parent 722cc9a commit 889053d

File tree

4 files changed

+49
-21
lines changed

4 files changed

+49
-21
lines changed

firmware/libs/spl/usb_conf.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,16 @@
5858

5959
/* EP1 */
6060
/* tx buffer base address */
61-
#define ENDP1_TXADDR (0xC0)
62-
#define ENDP2_TXADDR (0x100)
63-
#define ENDP3_RXADDR (0x110)
61+
#define ENDP1_BUF0_ADDR (0xC0)
62+
#define ENDP1_BUF1_ADDR (0x100)
6463

64+
/* EP2 */
65+
#define ENDP2_TXADDR (0x140)
66+
67+
/* EP3 */
68+
/* rx buffer base address*/
69+
#define ENDP3_BUF0_ADDR (0x180)
70+
#define ENDP3_BUF1_ADDR (0x1c0)
6571

6672
/*-------------------------------------------------------------*/
6773
/* ------------------- ISTR events -------------------------*/

firmware/usb_cdc/hw_config.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -366,22 +366,27 @@ static void IntToUnicode (uint32_t value , uint8_t *pbuf , uint8_t len)
366366
* Output : None.
367367
* Return : None.
368368
*******************************************************************************/
369-
uint32_t CDC_Send_DATA (uint8_t *ptrBuffer, uint8_t Send_length)
369+
uint32_t CDC_Send_DATA(uint8_t *ptrBuffer, uint8_t Send_length)
370370
{
371-
/*if max buffer is Not reached*/
372-
if(Send_length < VIRTUAL_COM_PORT_DATA_SIZE)
371+
if (Send_length > VIRTUAL_COM_PORT_DATA_SIZE)
372+
return 0;
373+
374+
/* Sent flag */
375+
packet_sent = 0;
376+
377+
if (!(GetENDPOINT(ENDP1) & EP_DTOG_RX))
373378
{
374-
/*Sent flag*/
375-
packet_sent = 0;
376-
/* send packet to PMA*/
377-
UserToPMABufferCopy((unsigned char*)ptrBuffer, ENDP1_TXADDR, Send_length);
378-
SetEPTxCount(ENDP1, Send_length);
379-
SetEPTxValid(ENDP1);
379+
UserToPMABufferCopy(ptrBuffer, ENDP1_BUF0_ADDR, Send_length);
380+
SetEPDblBuf0Count(ENDP1, EP_DBUF_IN, Send_length);
380381
}
381382
else
382383
{
383-
return 0;
384-
}
384+
UserToPMABufferCopy(ptrBuffer, ENDP1_BUF1_ADDR, Send_length);
385+
SetEPDblBuf1Count(ENDP1, EP_DBUF_IN, Send_length);
386+
}
387+
388+
FreeUserBuffer(ENDP1, EP_DBUF_IN);
389+
385390
return 1;
386391
}
387392

firmware/usb_cdc/usb_endp.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,18 @@ void EP1_IN_Callback (void)
7070
*******************************************************************************/
7171
void EP3_OUT_Callback(void)
7272
{
73-
packet_receive = 1;
74-
Receive_length = GetEPRxCount(ENDP3);
75-
PMAToUserBufferCopy((unsigned char*)Receive_Buffer, ENDP3_RXADDR, Receive_length);
73+
if (GetENDPOINT(ENDP3) & EP_DTOG_TX)
74+
{
75+
Receive_length = GetEPDblBuf0Count(ENDP3);
76+
PMAToUserBufferCopy((uint8_t *)Receive_Buffer, ENDP3_BUF0_ADDR, Receive_length);
77+
}
78+
else
79+
{
80+
Receive_length = GetEPDblBuf1Count(ENDP3);
81+
PMAToUserBufferCopy((uint8_t *)Receive_Buffer, ENDP3_BUF1_ADDR, Receive_length);
82+
}
83+
84+
FreeUserBuffer(ENDP3, EP_DBUF_OUT);
7685
}
7786

7887
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

firmware/usb_cdc/usb_prop.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,12 @@ void Virtual_Com_Port_Reset(void)
167167

168168
/* Initialize Endpoint 1 */
169169
SetEPType(ENDP1, EP_BULK);
170-
SetEPTxAddr(ENDP1, ENDP1_TXADDR);
171-
SetEPTxStatus(ENDP1, EP_TX_NAK);
170+
SetEPDoubleBuff(ENDP1);
171+
SetEPDblBuffAddr(ENDP1, ENDP1_BUF0_ADDR, ENDP1_BUF1_ADDR);
172+
ClearDTOG_TX(ENDP1);
173+
ClearDTOG_RX(ENDP1);
174+
ToggleDTOG_RX(ENDP1);
175+
SetEPTxStatus(ENDP1, EP_TX_VALID);
172176
SetEPRxStatus(ENDP1, EP_RX_DIS);
173177

174178
/* Initialize Endpoint 2 */
@@ -179,8 +183,12 @@ void Virtual_Com_Port_Reset(void)
179183

180184
/* Initialize Endpoint 3 */
181185
SetEPType(ENDP3, EP_BULK);
182-
SetEPRxAddr(ENDP3, ENDP3_RXADDR);
183-
SetEPRxCount(ENDP3, VIRTUAL_COM_PORT_DATA_SIZE);
186+
SetEPDoubleBuff(ENDP3);
187+
SetEPDblBuffAddr(ENDP3, ENDP3_BUF0_ADDR, ENDP3_BUF1_ADDR);
188+
SetEPDblBuffCount(ENDP3, EP_DBUF_OUT, VIRTUAL_COM_PORT_DATA_SIZE);
189+
ClearDTOG_RX(ENDP3);
190+
ClearDTOG_TX(ENDP3);
191+
ToggleDTOG_RX(ENDP3);
184192
SetEPRxStatus(ENDP3, EP_RX_VALID);
185193
SetEPTxStatus(ENDP3, EP_TX_DIS);
186194

0 commit comments

Comments
 (0)