Skip to content

Commit ee78138

Browse files
committed
Endpoint activation fixes:
- Transmit endpoint over receive endpoint in both branches (style correction). - Initialize receive buffer for the double-buffered endpoint (as single buffered already have) - In double buffering transmission, set EP to valid, and set DTOG-s to the same buffer for NAK-ing After activation, all endpoint would NAK-ing for any host attempt to receive anything,
1 parent 8cec0a8 commit ee78138

File tree

1 file changed

+29
-34
lines changed

1 file changed

+29
-34
lines changed

system/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_usb.c

+29-34
Original file line numberDiff line numberDiff line change
@@ -1725,54 +1725,51 @@ HAL_StatusTypeDef USB_ActivateEndpoint(USB_TypeDef *USBx, USB_EPTypeDef *ep)
17251725

17261726
if (ep->doublebuffer == 0)
17271727
{
1728-
if (ep->is_in)
1728+
if (ep->is_in == 1)
17291729
{
1730-
/*Set the endpoint Transmit buffer address */
1730+
/* Set the endpoint Transmit buffer address */
17311731
PCD_SET_EP_TX_ADDRESS(USBx, ep->num, ep->pmaadress);
17321732
PCD_CLEAR_TX_DTOG(USBx, ep->num);
1733-
/* Configure NAK status for the Endpoint*/
1734-
PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_NAK);
1733+
/* Configure NAK status for the Endpoint */
1734+
PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_NAK);
17351735
}
17361736
else
17371737
{
1738-
/*Set the endpoint Receive buffer address */
1738+
/* Set the endpoint Receive buffer address */
17391739
PCD_SET_EP_RX_ADDRESS(USBx, ep->num, ep->pmaadress);
1740-
/*Set the endpoint Receive buffer counter*/
1740+
/* Set the endpoint Receive buffer counter */
17411741
PCD_SET_EP_RX_CNT(USBx, ep->num, ep->maxpacket);
17421742
PCD_CLEAR_RX_DTOG(USBx, ep->num);
1743-
/* Configure VALID status for the Endpoint*/
1744-
PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_VALID);
1743+
/* All ep must NAK to every host request before PrepareReceive */
1744+
PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_NAK);
17451745
}
17461746
}
1747-
/*Double Buffer*/
1747+
/* Double Buffer */
17481748
else
17491749
{
1750-
/*Set the endpoint as double buffered*/
1750+
/* Set the endpoint as double buffered */
17511751
PCD_SET_EP_DBUF(USBx, ep->num);
1752-
/*Set buffer address for double buffered mode*/
1752+
/* Set buffer address for double buffered mode */
17531753
PCD_SET_EP_DBUF_ADDR(USBx, ep->num,ep->pmaaddr0, ep->pmaaddr1);
17541754

1755-
if (ep->is_in==0)
1755+
if (ep->is_in == 1)
17561756
{
1757-
/* Clear the data toggle bits for the endpoint IN/OUT*/
1757+
/* Clear the data toggle bits for the endpoint IN/OUT */
17581758
PCD_CLEAR_RX_DTOG(USBx, ep->num);
17591759
PCD_CLEAR_TX_DTOG(USBx, ep->num);
1760-
1761-
/* Reset value of the data toggle bits for the endpoint out*/
1762-
PCD_TX_DTOG(USBx, ep->num);
1763-
1764-
PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_VALID);
1765-
PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS);
1760+
PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_RX_VALID);
1761+
PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_DIS);
17661762
}
17671763
else
17681764
{
1769-
/* Clear the data toggle bits for the endpoint IN/OUT*/
1765+
PCD_SET_EP_DBUF_CNT(USBx, ep->num, ep->is_in, ep->maxpacket);
1766+
/* Clear the data toggle bits for the endpoint IN/OUT */
17701767
PCD_CLEAR_RX_DTOG(USBx, ep->num);
17711768
PCD_CLEAR_TX_DTOG(USBx, ep->num);
1772-
PCD_RX_DTOG(USBx, ep->num);
1773-
/* Configure DISABLE status for the Endpoint*/
1769+
/* All ep must NAK to every host request before PrepareReceive */
1770+
/* Reset value of the data toggle bits for the endpoint out */
1771+
PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_VALID);
17741772
PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS);
1775-
PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_DIS);
17761773
}
17771774
}
17781775

@@ -1789,11 +1786,11 @@ HAL_StatusTypeDef USB_DeactivateEndpoint(USB_TypeDef *USBx, USB_EPTypeDef *ep)
17891786
{
17901787
if (ep->doublebuffer == 0)
17911788
{
1792-
if (ep->is_in)
1789+
if (ep->is_in == 1)
17931790
{
17941791
PCD_CLEAR_TX_DTOG(USBx, ep->num);
17951792
/* Configure DISABLE status for the Endpoint*/
1796-
PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS);
1793+
PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS);
17971794
}
17981795
else
17991796
{
@@ -1805,27 +1802,25 @@ HAL_StatusTypeDef USB_DeactivateEndpoint(USB_TypeDef *USBx, USB_EPTypeDef *ep)
18051802
/*Double Buffer*/
18061803
else
18071804
{
1808-
if (ep->is_in==0)
1805+
if (ep->is_in == 1)
18091806
{
18101807
/* Clear the data toggle bits for the endpoint IN/OUT*/
18111808
PCD_CLEAR_RX_DTOG(USBx, ep->num);
18121809
PCD_CLEAR_TX_DTOG(USBx, ep->num);
1813-
1814-
/* Reset value of the data toggle bits for the endpoint out*/
1815-
PCD_TX_DTOG(USBx, ep->num);
1816-
1817-
PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_DIS);
1810+
PCD_RX_DTOG(USBx, ep->num);
1811+
/* Configure DISABLE status for the Endpoint*/
18181812
PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS);
1813+
PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_DIS);
18191814
}
18201815
else
18211816
{
18221817
/* Clear the data toggle bits for the endpoint IN/OUT*/
18231818
PCD_CLEAR_RX_DTOG(USBx, ep->num);
18241819
PCD_CLEAR_TX_DTOG(USBx, ep->num);
1825-
PCD_RX_DTOG(USBx, ep->num);
1826-
/* Configure DISABLE status for the Endpoint*/
1827-
PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS);
1820+
/* Reset value of the data toggle bits for the endpoint out*/
1821+
PCD_TX_DTOG(USBx, ep->num);
18281822
PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_DIS);
1823+
PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS);
18291824
}
18301825
}
18311826

0 commit comments

Comments
 (0)