@@ -1725,54 +1725,51 @@ HAL_StatusTypeDef USB_ActivateEndpoint(USB_TypeDef *USBx, USB_EPTypeDef *ep)
1725
1725
1726
1726
if (ep -> doublebuffer == 0 )
1727
1727
{
1728
- if (ep -> is_in )
1728
+ if (ep -> is_in == 1 )
1729
1729
{
1730
- /*Set the endpoint Transmit buffer address */
1730
+ /* Set the endpoint Transmit buffer address */
1731
1731
PCD_SET_EP_TX_ADDRESS (USBx , ep -> num , ep -> pmaadress );
1732
1732
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 );
1735
1735
}
1736
1736
else
1737
1737
{
1738
- /*Set the endpoint Receive buffer address */
1738
+ /* Set the endpoint Receive buffer address */
1739
1739
PCD_SET_EP_RX_ADDRESS (USBx , ep -> num , ep -> pmaadress );
1740
- /*Set the endpoint Receive buffer counter*/
1740
+ /* Set the endpoint Receive buffer counter */
1741
1741
PCD_SET_EP_RX_CNT (USBx , ep -> num , ep -> maxpacket );
1742
1742
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 );
1745
1745
}
1746
1746
}
1747
- /*Double Buffer*/
1747
+ /* Double Buffer */
1748
1748
else
1749
1749
{
1750
- /*Set the endpoint as double buffered*/
1750
+ /* Set the endpoint as double buffered */
1751
1751
PCD_SET_EP_DBUF (USBx , ep -> num );
1752
- /*Set buffer address for double buffered mode*/
1752
+ /* Set buffer address for double buffered mode */
1753
1753
PCD_SET_EP_DBUF_ADDR (USBx , ep -> num ,ep -> pmaaddr0 , ep -> pmaaddr1 );
1754
1754
1755
- if (ep -> is_in == 0 )
1755
+ if (ep -> is_in == 1 )
1756
1756
{
1757
- /* Clear the data toggle bits for the endpoint IN/OUT*/
1757
+ /* Clear the data toggle bits for the endpoint IN/OUT */
1758
1758
PCD_CLEAR_RX_DTOG (USBx , ep -> num );
1759
1759
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 );
1766
1762
}
1767
1763
else
1768
1764
{
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 */
1770
1767
PCD_CLEAR_RX_DTOG (USBx , ep -> num );
1771
1768
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 );
1774
1772
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 );
1776
1773
}
1777
1774
}
1778
1775
@@ -1789,11 +1786,11 @@ HAL_StatusTypeDef USB_DeactivateEndpoint(USB_TypeDef *USBx, USB_EPTypeDef *ep)
1789
1786
{
1790
1787
if (ep -> doublebuffer == 0 )
1791
1788
{
1792
- if (ep -> is_in )
1789
+ if (ep -> is_in == 1 )
1793
1790
{
1794
1791
PCD_CLEAR_TX_DTOG (USBx , ep -> num );
1795
1792
/* 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 );
1797
1794
}
1798
1795
else
1799
1796
{
@@ -1805,27 +1802,25 @@ HAL_StatusTypeDef USB_DeactivateEndpoint(USB_TypeDef *USBx, USB_EPTypeDef *ep)
1805
1802
/*Double Buffer*/
1806
1803
else
1807
1804
{
1808
- if (ep -> is_in == 0 )
1805
+ if (ep -> is_in == 1 )
1809
1806
{
1810
1807
/* Clear the data toggle bits for the endpoint IN/OUT*/
1811
1808
PCD_CLEAR_RX_DTOG (USBx , ep -> num );
1812
1809
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*/
1818
1812
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 );
1819
1814
}
1820
1815
else
1821
1816
{
1822
1817
/* Clear the data toggle bits for the endpoint IN/OUT*/
1823
1818
PCD_CLEAR_RX_DTOG (USBx , ep -> num );
1824
1819
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 );
1828
1822
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 );
1829
1824
}
1830
1825
}
1831
1826
0 commit comments