Merge pull request #2402 from Okarss/master
[STM32 FSDEV] Fix ISR race conditions
This commit is contained in:
		@@ -128,8 +128,8 @@
 | 
			
		||||
#  define DCD_STM32_BTABLE_BASE 0U
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef DCD_STM32_BTABLE_LENGTH
 | 
			
		||||
#  define DCD_STM32_BTABLE_LENGTH (PMA_LENGTH - DCD_STM32_BTABLE_BASE)
 | 
			
		||||
#ifndef DCD_STM32_BTABLE_SIZE
 | 
			
		||||
#  define DCD_STM32_BTABLE_SIZE (FSDEV_PMA_SIZE - DCD_STM32_BTABLE_BASE)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/***************************************************
 | 
			
		||||
@@ -137,7 +137,7 @@
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
TU_VERIFY_STATIC((MAX_EP_COUNT) <= STFSDEV_EP_COUNT, "Only 8 endpoints supported on the hardware");
 | 
			
		||||
TU_VERIFY_STATIC(((DCD_STM32_BTABLE_BASE) + (DCD_STM32_BTABLE_LENGTH))<=(PMA_LENGTH), "BTABLE does not fit in PMA RAM");
 | 
			
		||||
TU_VERIFY_STATIC(((DCD_STM32_BTABLE_BASE) + (DCD_STM32_BTABLE_SIZE)) <= (FSDEV_PMA_SIZE), "BTABLE does not fit in PMA RAM");
 | 
			
		||||
TU_VERIFY_STATIC(((DCD_STM32_BTABLE_BASE) % 8) == 0, "BTABLE base must be aligned to 8 bytes");
 | 
			
		||||
 | 
			
		||||
//--------------------------------------------------------------------+
 | 
			
		||||
@@ -559,7 +559,7 @@ static void dcd_ep_ctr_rx_handler(uint32_t wIstr)
 | 
			
		||||
      // Must reset EP to NAK (in case it had been stalling) (though, maybe too late here)
 | 
			
		||||
      pcd_set_ep_rx_status(USB,0u,USB_EP_RX_NAK);
 | 
			
		||||
      pcd_set_ep_tx_status(USB,0u,USB_EP_TX_NAK);
 | 
			
		||||
#ifdef PMA_32BIT_ACCESS
 | 
			
		||||
#ifdef FSDEV_BUS_32BIT
 | 
			
		||||
      dcd_event_setup_received(0, (uint8_t*)(USB_PMAADDR + pcd_get_ep_rx_address(USB, EPindex)), true);
 | 
			
		||||
#else
 | 
			
		||||
      // The setup_received function uses memcpy, so this must first copy the setup data into
 | 
			
		||||
@@ -673,13 +673,13 @@ void dcd_int_handler(uint8_t rhport) {
 | 
			
		||||
 | 
			
		||||
  /* Put SOF flag at the beginning of ISR in case to get least amount of jitter if it is used for timing purposes */
 | 
			
		||||
  if(int_status & USB_ISTR_SOF) {
 | 
			
		||||
    USB->ISTR &=~USB_ISTR_SOF;
 | 
			
		||||
    USB->ISTR = (fsdev_bus_t)~USB_ISTR_SOF;
 | 
			
		||||
    dcd_event_sof(0, USB->FNR & USB_FNR_FN, true);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if(int_status & USB_ISTR_RESET) {
 | 
			
		||||
    // USBRST is start of reset.
 | 
			
		||||
    USB->ISTR &=~USB_ISTR_RESET;
 | 
			
		||||
    USB->ISTR = (fsdev_bus_t)~USB_ISTR_RESET;
 | 
			
		||||
    dcd_handle_bus_reset();
 | 
			
		||||
    dcd_event_bus_reset(0, TUSB_SPEED_FULL, true);
 | 
			
		||||
    return; // Don't do the rest of the things here; perhaps they've been cleared?
 | 
			
		||||
@@ -697,7 +697,7 @@ void dcd_int_handler(uint8_t rhport) {
 | 
			
		||||
    USB->CNTR &= ~USB_CNTR_LPMODE;
 | 
			
		||||
    USB->CNTR &= ~USB_CNTR_FSUSP;
 | 
			
		||||
 | 
			
		||||
    USB->ISTR &=~USB_ISTR_WKUP;
 | 
			
		||||
    USB->ISTR = (fsdev_bus_t)~USB_ISTR_WKUP;
 | 
			
		||||
    dcd_event_bus_signal(0, DCD_EVENT_RESUME, true);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -711,7 +711,7 @@ void dcd_int_handler(uint8_t rhport) {
 | 
			
		||||
    USB->CNTR |= USB_CNTR_LPMODE;
 | 
			
		||||
 | 
			
		||||
    /* clear of the ISTR bit must be done after setting of CNTR_FSUSP */
 | 
			
		||||
    USB->ISTR &=~USB_ISTR_SUSP;
 | 
			
		||||
    USB->ISTR = (fsdev_bus_t)~USB_ISTR_SUSP;
 | 
			
		||||
    dcd_event_bus_signal(0, DCD_EVENT_SUSPEND, true);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -724,7 +724,7 @@ void dcd_int_handler(uint8_t rhport) {
 | 
			
		||||
    {
 | 
			
		||||
      remoteWakeCountdown--;
 | 
			
		||||
    }
 | 
			
		||||
    USB->ISTR &=~USB_ISTR_ESOF;
 | 
			
		||||
    USB->ISTR = (fsdev_bus_t)~USB_ISTR_ESOF;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -786,7 +786,7 @@ static uint16_t dcd_pma_alloc(uint8_t ep_addr, uint16_t length)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Ensure allocated buffer is aligned
 | 
			
		||||
#ifdef PMA_32BIT_ACCESS
 | 
			
		||||
#ifdef FSDEV_BUS_32BIT
 | 
			
		||||
  length = (length + 3) & ~0x03;
 | 
			
		||||
#else
 | 
			
		||||
  length = (length + 1) & ~0x01;
 | 
			
		||||
@@ -798,7 +798,7 @@ static uint16_t dcd_pma_alloc(uint8_t ep_addr, uint16_t length)
 | 
			
		||||
  ep_buf_ptr = (uint16_t)(ep_buf_ptr + length); // increment buffer pointer
 | 
			
		||||
 | 
			
		||||
  // Verify no overflow
 | 
			
		||||
  TU_ASSERT(ep_buf_ptr <= PMA_LENGTH, 0xFFFF);
 | 
			
		||||
  TU_ASSERT(ep_buf_ptr <= FSDEV_PMA_SIZE, 0xFFFF);
 | 
			
		||||
 | 
			
		||||
  epXferCtl->pma_ptr = addr;
 | 
			
		||||
  epXferCtl->pma_alloc_size = length;
 | 
			
		||||
@@ -1227,7 +1227,7 @@ void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr)
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifdef PMA_32BIT_ACCESS
 | 
			
		||||
#ifdef FSDEV_BUS_32BIT
 | 
			
		||||
static bool dcd_write_packet_memory(uint16_t dst, const void *__restrict src, uint16_t wNBytes)
 | 
			
		||||
{
 | 
			
		||||
  const uint8_t* srcVal = src;
 | 
			
		||||
@@ -1283,7 +1283,7 @@ static bool dcd_write_packet_memory(uint16_t dst, const void *__restrict src, ui
 | 
			
		||||
  __IO uint16_t *pdwVal;
 | 
			
		||||
 | 
			
		||||
  srcVal = src;
 | 
			
		||||
  pdwVal = &pma[PMA_STRIDE*(dst>>1)];
 | 
			
		||||
  pdwVal = &pma[FSDEV_PMA_STRIDE * (dst >> 1)];
 | 
			
		||||
 | 
			
		||||
  while (n--)
 | 
			
		||||
  {
 | 
			
		||||
@@ -1291,7 +1291,7 @@ static bool dcd_write_packet_memory(uint16_t dst, const void *__restrict src, ui
 | 
			
		||||
    srcVal++;
 | 
			
		||||
    temp2 = temp1 | ((uint16_t)(((uint16_t)(*srcVal)) << 8U)) ;
 | 
			
		||||
    *pdwVal = temp2;
 | 
			
		||||
    pdwVal += PMA_STRIDE;
 | 
			
		||||
    pdwVal += FSDEV_PMA_STRIDE;
 | 
			
		||||
    srcVal++;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -1323,7 +1323,7 @@ static bool dcd_write_packet_memory_ff(tu_fifo_t * ff, uint16_t dst, uint16_t wN
 | 
			
		||||
  // We want to read from the FIFO and write it into the PMA, if LIN part is ODD and has WRAPPED part,
 | 
			
		||||
  // last lin byte will be combined with wrapped part
 | 
			
		||||
  // To ensure PMA is always access aligned (dst aligned to 16 or 32 bit)
 | 
			
		||||
#ifdef PMA_32BIT_ACCESS
 | 
			
		||||
#ifdef FSDEV_BUS_32BIT
 | 
			
		||||
  if((cnt_lin & 0x03) && cnt_wrap)
 | 
			
		||||
  {
 | 
			
		||||
    // Copy first linear part
 | 
			
		||||
@@ -1386,7 +1386,7 @@ static bool dcd_write_packet_memory_ff(tu_fifo_t * ff, uint16_t dst, uint16_t wN
 | 
			
		||||
  return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifdef PMA_32BIT_ACCESS
 | 
			
		||||
#ifdef FSDEV_BUS_32BIT
 | 
			
		||||
static bool dcd_read_packet_memory(void *__restrict dst, uint16_t src, uint16_t wNBytes)
 | 
			
		||||
{
 | 
			
		||||
  uint8_t* dstVal = dst;
 | 
			
		||||
@@ -1434,13 +1434,13 @@ static bool dcd_read_packet_memory(void *__restrict dst, uint16_t src, uint16_t
 | 
			
		||||
  __IO const uint16_t *pdwVal;
 | 
			
		||||
  uint32_t temp;
 | 
			
		||||
 | 
			
		||||
  pdwVal = &pma[PMA_STRIDE*(src>>1)];
 | 
			
		||||
  pdwVal = &pma[FSDEV_PMA_STRIDE * (src >> 1)];
 | 
			
		||||
  uint8_t *dstVal = (uint8_t*)dst;
 | 
			
		||||
 | 
			
		||||
  while (n--)
 | 
			
		||||
  {
 | 
			
		||||
    temp = *pdwVal;
 | 
			
		||||
    pdwVal += PMA_STRIDE;
 | 
			
		||||
    pdwVal += FSDEV_PMA_STRIDE;
 | 
			
		||||
    *dstVal++ = ((temp >> 0) & 0xFF);
 | 
			
		||||
    *dstVal++ = ((temp >> 8) & 0xFF);
 | 
			
		||||
  }
 | 
			
		||||
@@ -1448,7 +1448,7 @@ static bool dcd_read_packet_memory(void *__restrict dst, uint16_t src, uint16_t
 | 
			
		||||
  if (wNBytes & 0x01)
 | 
			
		||||
  {
 | 
			
		||||
    temp = *pdwVal;
 | 
			
		||||
    pdwVal += PMA_STRIDE;
 | 
			
		||||
    pdwVal += FSDEV_PMA_STRIDE;
 | 
			
		||||
    *dstVal++ = ((temp >> 0) & 0xFF);
 | 
			
		||||
  }
 | 
			
		||||
  return true;
 | 
			
		||||
@@ -1475,7 +1475,7 @@ static bool dcd_read_packet_memory_ff(tu_fifo_t * ff, uint16_t src, uint16_t wNB
 | 
			
		||||
  // We want to read from PMA and write it into the FIFO, if LIN part is ODD and has WRAPPED part,
 | 
			
		||||
  // last lin byte will be combined with wrapped part
 | 
			
		||||
  // To ensure PMA is always access aligned (src aligned to 16 or 32 bit)
 | 
			
		||||
#ifdef PMA_32BIT_ACCESS
 | 
			
		||||
#ifdef FSDEV_BUS_32BIT
 | 
			
		||||
  if((cnt_lin & 0x03) && cnt_wrap)
 | 
			
		||||
  {
 | 
			
		||||
    // Copy first linear part
 | 
			
		||||
 
 | 
			
		||||
@@ -28,7 +28,7 @@
 | 
			
		||||
 | 
			
		||||
// This file contains source copied from ST's HAL, and thus should have their copyright statement.
 | 
			
		||||
 | 
			
		||||
// PMA_LENGTH is PMA buffer size in bytes.
 | 
			
		||||
// FSDEV_PMA_SIZE is PMA buffer size in bytes.
 | 
			
		||||
// On 512-byte devices, access with a stride of two words (use every other 16-bit address)
 | 
			
		||||
// On 1024-byte devices, access with a stride of one word (use every 16-bit address)
 | 
			
		||||
 | 
			
		||||
@@ -37,7 +37,7 @@
 | 
			
		||||
 | 
			
		||||
#if CFG_TUSB_MCU == OPT_MCU_STM32F0
 | 
			
		||||
  #include "stm32f0xx.h"
 | 
			
		||||
  #define PMA_LENGTH (1024u)
 | 
			
		||||
  #define FSDEV_PMA_SIZE (1024u)
 | 
			
		||||
  // F0x2 models are crystal-less
 | 
			
		||||
  // All have internal D+ pull-up
 | 
			
		||||
  // 070RB:    2 x 16 bits/word memory     LPM Support, BCD Support
 | 
			
		||||
@@ -45,7 +45,7 @@
 | 
			
		||||
 | 
			
		||||
#elif CFG_TUSB_MCU == OPT_MCU_STM32F1
 | 
			
		||||
  #include "stm32f1xx.h"
 | 
			
		||||
  #define PMA_LENGTH (512u)
 | 
			
		||||
  #define FSDEV_PMA_SIZE (512u)
 | 
			
		||||
  // NO internal Pull-ups
 | 
			
		||||
  //         *B, and *C:    2 x 16 bits/word
 | 
			
		||||
 | 
			
		||||
@@ -56,7 +56,7 @@
 | 
			
		||||
      defined(STM32F303xB) || defined(STM32F303xC) || \
 | 
			
		||||
      defined(STM32F373xC)
 | 
			
		||||
  #include "stm32f3xx.h"
 | 
			
		||||
  #define PMA_LENGTH (512u)
 | 
			
		||||
  #define FSDEV_PMA_SIZE (512u)
 | 
			
		||||
  // NO internal Pull-ups
 | 
			
		||||
  //         *B, and *C:    1 x 16 bits/word
 | 
			
		||||
  // PMA dedicated to USB (no sharing with CAN)
 | 
			
		||||
@@ -65,27 +65,27 @@
 | 
			
		||||
      defined(STM32F302xD) || defined(STM32F302xE) || \
 | 
			
		||||
      defined(STM32F303xD) || defined(STM32F303xE)
 | 
			
		||||
  #include "stm32f3xx.h"
 | 
			
		||||
  #define PMA_LENGTH (1024u)
 | 
			
		||||
  #define FSDEV_PMA_SIZE (1024u)
 | 
			
		||||
  // NO internal Pull-ups
 | 
			
		||||
  // *6, *8, *D, and *E:    2 x 16 bits/word     LPM Support
 | 
			
		||||
  // When CAN clock is enabled, USB can use first 768 bytes ONLY.
 | 
			
		||||
 | 
			
		||||
#elif CFG_TUSB_MCU == OPT_MCU_STM32L0
 | 
			
		||||
  #include "stm32l0xx.h"
 | 
			
		||||
  #define PMA_LENGTH (1024u)
 | 
			
		||||
  #define FSDEV_PMA_SIZE (1024u)
 | 
			
		||||
 | 
			
		||||
#elif CFG_TUSB_MCU == OPT_MCU_STM32L1
 | 
			
		||||
  #include "stm32l1xx.h"
 | 
			
		||||
  #define PMA_LENGTH (512u)
 | 
			
		||||
  #define FSDEV_PMA_SIZE (512u)
 | 
			
		||||
 | 
			
		||||
#elif CFG_TUSB_MCU == OPT_MCU_STM32G4
 | 
			
		||||
  #include "stm32g4xx.h"
 | 
			
		||||
  #define PMA_LENGTH (1024u)
 | 
			
		||||
  #define FSDEV_PMA_SIZE (1024u)
 | 
			
		||||
 | 
			
		||||
#elif CFG_TUSB_MCU == OPT_MCU_STM32G0
 | 
			
		||||
  #include "stm32g0xx.h"
 | 
			
		||||
  #define PMA_32BIT_ACCESS
 | 
			
		||||
  #define PMA_LENGTH (2048u)
 | 
			
		||||
  #define FSDEV_BUS_32BIT
 | 
			
		||||
  #define FSDEV_PMA_SIZE (2048u)
 | 
			
		||||
  #undef USB_PMAADDR
 | 
			
		||||
  #define USB_PMAADDR USB_DRD_PMAADDR
 | 
			
		||||
  #define USB_TypeDef USB_DRD_TypeDef
 | 
			
		||||
@@ -112,8 +112,8 @@
 | 
			
		||||
 | 
			
		||||
#elif CFG_TUSB_MCU == OPT_MCU_STM32H5
 | 
			
		||||
  #include "stm32h5xx.h"
 | 
			
		||||
  #define PMA_32BIT_ACCESS
 | 
			
		||||
  #define PMA_LENGTH (2048u)
 | 
			
		||||
  #define FSDEV_BUS_32BIT
 | 
			
		||||
  #define FSDEV_PMA_SIZE (2048u)
 | 
			
		||||
  #undef USB_PMAADDR
 | 
			
		||||
  #define USB_PMAADDR USB_DRD_PMAADDR
 | 
			
		||||
  #define USB_TypeDef USB_DRD_TypeDef
 | 
			
		||||
@@ -141,18 +141,18 @@
 | 
			
		||||
 | 
			
		||||
#elif CFG_TUSB_MCU == OPT_MCU_STM32WB
 | 
			
		||||
  #include "stm32wbxx.h"
 | 
			
		||||
  #define PMA_LENGTH (1024u)
 | 
			
		||||
  #define FSDEV_PMA_SIZE (1024u)
 | 
			
		||||
  /* ST provided header has incorrect value */
 | 
			
		||||
  #undef USB_PMAADDR
 | 
			
		||||
  #define USB_PMAADDR USB1_PMAADDR
 | 
			
		||||
 | 
			
		||||
#elif CFG_TUSB_MCU == OPT_MCU_STM32L4
 | 
			
		||||
  #include "stm32l4xx.h"
 | 
			
		||||
  #define PMA_LENGTH (1024u)
 | 
			
		||||
  #define FSDEV_PMA_SIZE (1024u)
 | 
			
		||||
 | 
			
		||||
#elif CFG_TUSB_MCU == OPT_MCU_STM32L5
 | 
			
		||||
  #include "stm32l5xx.h"
 | 
			
		||||
  #define PMA_LENGTH (1024u)
 | 
			
		||||
  #define FSDEV_PMA_SIZE (1024u)
 | 
			
		||||
 | 
			
		||||
  #ifndef USB_PMAADDR
 | 
			
		||||
    #define USB_PMAADDR (USB_BASE + (USB_PMAADDR_NS - USB_BASE_NS))
 | 
			
		||||
@@ -164,24 +164,28 @@
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
// For purposes of accessing the packet
 | 
			
		||||
#if ((PMA_LENGTH) == 512u)
 | 
			
		||||
  #define PMA_STRIDE  (2u)
 | 
			
		||||
#elif ((PMA_LENGTH) == 1024u)
 | 
			
		||||
  #define PMA_STRIDE  (1u)
 | 
			
		||||
#if ((FSDEV_PMA_SIZE) == 512u)
 | 
			
		||||
  #define FSDEV_PMA_STRIDE  (2u)
 | 
			
		||||
#elif ((FSDEV_PMA_SIZE) == 1024u)
 | 
			
		||||
  #define FSDEV_PMA_STRIDE  (1u)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
// The fsdev_bus_t type can be used for both register and PMA access necessities
 | 
			
		||||
// For type-safety create a new macro for the volatile address of PMAADDR
 | 
			
		||||
// The compiler should warn us if we cast it to a non-volatile type?
 | 
			
		||||
#ifdef PMA_32BIT_ACCESS
 | 
			
		||||
#ifdef FSDEV_BUS_32BIT
 | 
			
		||||
typedef uint32_t fsdev_bus_t;
 | 
			
		||||
static __IO uint32_t * const pma32 = (__IO uint32_t*)USB_PMAADDR;
 | 
			
		||||
 | 
			
		||||
#else
 | 
			
		||||
typedef uint16_t fsdev_bus_t;
 | 
			
		||||
// Volatile is also needed to prevent the optimizer from changing access to 32-bit (as 32-bit access is forbidden)
 | 
			
		||||
static __IO uint16_t * const pma = (__IO uint16_t*)USB_PMAADDR;
 | 
			
		||||
 | 
			
		||||
TU_ATTR_ALWAYS_INLINE static inline __IO uint16_t * pcd_btable_word_ptr(USB_TypeDef * USBx, size_t x)
 | 
			
		||||
{
 | 
			
		||||
  size_t total_word_offset = (((USBx)->BTABLE)>>1) + x;
 | 
			
		||||
  total_word_offset *= PMA_STRIDE;
 | 
			
		||||
  total_word_offset *= FSDEV_PMA_STRIDE;
 | 
			
		||||
  return &(pma[total_word_offset]);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -212,7 +216,7 @@ TU_ATTR_ALWAYS_INLINE static inline uint16_t pcd_aligned_buffer_size(uint16_t si
 | 
			
		||||
/* SetENDPOINT */
 | 
			
		||||
TU_ATTR_ALWAYS_INLINE static inline void pcd_set_endpoint(USB_TypeDef * USBx, uint32_t bEpIdx, uint32_t wRegValue)
 | 
			
		||||
{
 | 
			
		||||
#ifdef PMA_32BIT_ACCESS
 | 
			
		||||
#ifdef FSDEV_BUS_32BIT
 | 
			
		||||
  (void) USBx;
 | 
			
		||||
  __O uint32_t *reg = (__O uint32_t *)(USB_DRD_BASE + bEpIdx*4);
 | 
			
		||||
  *reg = wRegValue;
 | 
			
		||||
@@ -224,7 +228,7 @@ TU_ATTR_ALWAYS_INLINE static inline void pcd_set_endpoint(USB_TypeDef * USBx, ui
 | 
			
		||||
 | 
			
		||||
/* GetENDPOINT */
 | 
			
		||||
TU_ATTR_ALWAYS_INLINE static inline uint32_t pcd_get_endpoint(USB_TypeDef * USBx, uint32_t bEpIdx) {
 | 
			
		||||
#ifdef PMA_32BIT_ACCESS
 | 
			
		||||
#ifdef FSDEV_BUS_32BIT
 | 
			
		||||
  (void) USBx;
 | 
			
		||||
  __I uint32_t *reg = (__I uint32_t *)(USB_DRD_BASE + bEpIdx*4);
 | 
			
		||||
#else
 | 
			
		||||
@@ -279,7 +283,7 @@ TU_ATTR_ALWAYS_INLINE static inline void pcd_clear_tx_ep_ctr(USB_TypeDef * USBx,
 | 
			
		||||
  */
 | 
			
		||||
TU_ATTR_ALWAYS_INLINE static inline uint32_t pcd_get_ep_tx_cnt(USB_TypeDef * USBx, uint32_t bEpIdx)
 | 
			
		||||
{
 | 
			
		||||
#ifdef PMA_32BIT_ACCESS
 | 
			
		||||
#ifdef FSDEV_BUS_32BIT
 | 
			
		||||
  (void) USBx;
 | 
			
		||||
  return (pma32[2*bEpIdx] & 0x03FF0000) >> 16;
 | 
			
		||||
#else
 | 
			
		||||
@@ -290,7 +294,7 @@ TU_ATTR_ALWAYS_INLINE static inline uint32_t pcd_get_ep_tx_cnt(USB_TypeDef * USB
 | 
			
		||||
 | 
			
		||||
TU_ATTR_ALWAYS_INLINE static inline uint32_t pcd_get_ep_rx_cnt(USB_TypeDef * USBx, uint32_t bEpIdx)
 | 
			
		||||
{
 | 
			
		||||
#ifdef PMA_32BIT_ACCESS
 | 
			
		||||
#ifdef FSDEV_BUS_32BIT
 | 
			
		||||
  (void) USBx;
 | 
			
		||||
  return (pma32[2*bEpIdx + 1] & 0x03FF0000) >> 16;
 | 
			
		||||
#else
 | 
			
		||||
@@ -317,7 +321,7 @@ TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_address(USB_TypeDef * USBx,
 | 
			
		||||
 | 
			
		||||
TU_ATTR_ALWAYS_INLINE static inline uint32_t pcd_get_ep_tx_address(USB_TypeDef * USBx, uint32_t bEpIdx)
 | 
			
		||||
{
 | 
			
		||||
#ifdef PMA_32BIT_ACCESS
 | 
			
		||||
#ifdef FSDEV_BUS_32BIT
 | 
			
		||||
  (void) USBx;
 | 
			
		||||
  return pma32[2*bEpIdx] & 0x0000FFFFu ;
 | 
			
		||||
#else
 | 
			
		||||
@@ -327,7 +331,7 @@ TU_ATTR_ALWAYS_INLINE static inline uint32_t pcd_get_ep_tx_address(USB_TypeDef *
 | 
			
		||||
 | 
			
		||||
TU_ATTR_ALWAYS_INLINE static inline uint32_t pcd_get_ep_rx_address(USB_TypeDef * USBx, uint32_t bEpIdx)
 | 
			
		||||
{
 | 
			
		||||
#ifdef PMA_32BIT_ACCESS
 | 
			
		||||
#ifdef FSDEV_BUS_32BIT
 | 
			
		||||
  (void) USBx;
 | 
			
		||||
  return pma32[2*bEpIdx + 1] & 0x0000FFFFu;
 | 
			
		||||
#else
 | 
			
		||||
@@ -337,7 +341,7 @@ TU_ATTR_ALWAYS_INLINE static inline uint32_t pcd_get_ep_rx_address(USB_TypeDef *
 | 
			
		||||
 | 
			
		||||
TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_tx_address(USB_TypeDef * USBx, uint32_t bEpIdx, uint32_t addr)
 | 
			
		||||
{
 | 
			
		||||
#ifdef PMA_32BIT_ACCESS
 | 
			
		||||
#ifdef FSDEV_BUS_32BIT
 | 
			
		||||
  (void) USBx;
 | 
			
		||||
  pma32[2*bEpIdx] = (pma32[2*bEpIdx] & 0xFFFF0000u) | (addr & 0x0000FFFCu);
 | 
			
		||||
#else
 | 
			
		||||
@@ -347,7 +351,7 @@ TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_tx_address(USB_TypeDef * USB
 | 
			
		||||
 | 
			
		||||
TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_rx_address(USB_TypeDef * USBx, uint32_t bEpIdx, uint32_t addr)
 | 
			
		||||
{
 | 
			
		||||
#ifdef PMA_32BIT_ACCESS
 | 
			
		||||
#ifdef FSDEV_BUS_32BIT
 | 
			
		||||
  (void) USBx;
 | 
			
		||||
  pma32[2*bEpIdx + 1] = (pma32[2*bEpIdx + 1] & 0xFFFF0000u) | (addr & 0x0000FFFCu);
 | 
			
		||||
#else
 | 
			
		||||
@@ -357,7 +361,7 @@ TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_rx_address(USB_TypeDef * USB
 | 
			
		||||
 | 
			
		||||
TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_tx_cnt(USB_TypeDef * USBx, uint32_t bEpIdx, uint32_t wCount)
 | 
			
		||||
{
 | 
			
		||||
#ifdef PMA_32BIT_ACCESS
 | 
			
		||||
#ifdef FSDEV_BUS_32BIT
 | 
			
		||||
  (void) USBx;
 | 
			
		||||
  pma32[2*bEpIdx] = (pma32[2*bEpIdx] & ~0x03FF0000u) | ((wCount & 0x3FFu) << 16);
 | 
			
		||||
#else
 | 
			
		||||
@@ -368,7 +372,7 @@ TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_tx_cnt(USB_TypeDef * USBx, u
 | 
			
		||||
 | 
			
		||||
TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_rx_cnt(USB_TypeDef * USBx, uint32_t bEpIdx, uint32_t wCount)
 | 
			
		||||
{
 | 
			
		||||
#ifdef PMA_32BIT_ACCESS
 | 
			
		||||
#ifdef FSDEV_BUS_32BIT
 | 
			
		||||
  (void) USBx;
 | 
			
		||||
  pma32[2*bEpIdx + 1] = (pma32[2*bEpIdx + 1] & ~0x03FF0000u) | ((wCount & 0x3FFu) << 16);
 | 
			
		||||
#else
 | 
			
		||||
@@ -380,7 +384,7 @@ TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_rx_cnt(USB_TypeDef * USBx, u
 | 
			
		||||
TU_ATTR_ALWAYS_INLINE static inline void pcd_set_ep_blsize_num_blocks(USB_TypeDef * USBx, uint32_t rxtx_idx, uint32_t blocksize, uint32_t numblocks)
 | 
			
		||||
{
 | 
			
		||||
  /* Encode into register. When BLSIZE==1, we need to subtract 1 block count */
 | 
			
		||||
#ifdef PMA_32BIT_ACCESS
 | 
			
		||||
#ifdef FSDEV_BUS_32BIT
 | 
			
		||||
  (void) USBx;
 | 
			
		||||
  pma32[rxtx_idx] = (pma32[rxtx_idx] & 0x0000FFFFu) | (blocksize << 31) | ((numblocks - blocksize) << 26);
 | 
			
		||||
#else
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user