Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix USB buffer description table corruption #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ccid/CCIDHID_USB/CCIDHID_usb_prop.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ void USB_CCID_Reset (void)

/* Initialize Endpoint 4 */
SetEPType (ENDP4, EP_INTERRUPT);
SetEPTxAddr (ENDP4, ENDP4_TXADDR);
SetEPTxAddr (ENDP4, CCID_ENDP4_TXADDR);
// SetEPTxCount(ENDP4, 8);
SetEPRxStatus (ENDP4, EP_RX_DIS);
SetEPTxStatus (ENDP4, EP_TX_NAK);
Expand Down
45 changes: 24 additions & 21 deletions src/inc/CCIDHID_usb_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,30 @@
/*-------------------------------------------------------------*/
/* buffer table base address */

#define BTABLE_ADDRESS (0x00)

/* EP0 */
/* rx/tx buffer base address */
#define CCID_ENDP0_RXADDR (0x18)
#define CCID_ENDP0_TXADDR (0x58)

/* EP1 */
/* tx buffer base address */
#define CCID_ENDP1_TXADDR (0x98)

/* EP2 */
/* Rx buffer base address */
#define CCID_ENDP2_RXADDR (0xD8)
/* Tx buffer base address */
#define CCID_ENDP2_TXADDR (0x118)

/* EP3 */
/* tx buffer base address */
// #define ENDP3_TXADDR (0x158)
#define ENDP4_TXADDR (0x19C)
#define BTABLE_ADDRESS (0x00)

// Entries in the Buffer Description Table describe each endpoint buffer location and size:

// BTABLE_ADDRESS + EPn * 8 + 0: USB_ADDRn_TX (TX buffer address inside the PMA)
// BTABLE_ADDRESS + EPn * 8 + 2: USB_COUNTn_TX (bytes present in the TX buffer)
// BTABLE_ADDRESS + EPn * 8 + 4: USB_ADDRn_RX (RX buffer address inside the PMA)
// BTABLE_ADDRESS + EPn * 8 + 6: USB_COUNTn_RX (bytes available/present for the RX buffer)

// EP0, size = 64
#define CCID_ENDP0_RXADDR (0x40) // BTABLE_ADDRESS + BTABLE max size (64)
#define CCID_ENDP0_TXADDR (0x80)

// EP1, size = 64 (needs to be checked, found nothing using over 4 bytes in code)
#define CCID_ENDP1_TXADDR (0xC0)

// EP2, size = 64
#define CCID_ENDP2_RXADDR (0x100)
#define CCID_ENDP2_TXADDR (0x140)

// EP4, size = 8
#define CCID_ENDP4_TXADDR (0x180)

// PMA size is 512 bytes, last buffer address + size must be < 0x200

/* ISTR events */
/* IMR_MSK */
Expand Down
4 changes: 2 additions & 2 deletions src/keyboard/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "usb_lib.h"
#include "hw_config.h"
#include "usb_pwr.h"
#include "CCID_usb.h"
#include "CCIDHID_usb_conf.h"
#include "keyboard.h"
#include "AccessInterface.h"
#include "hotp.h"
Expand Down Expand Up @@ -82,7 +82,7 @@ void sendKeys (uint8_t * buffer)

PrevXferComplete = 0;
/* Use the memory interface function to write to the selected endpoint */
UserToPMABufferCopy (buffer, ENDP4_TXADDR, 8);
UserToPMABufferCopy (buffer, CCID_ENDP4_TXADDR, 8);

/* Update the data length in the control register */
SetEPTxCount (ENDP4, 8);
Expand Down