diff options
| author | Nathan Conrad <[email protected]> | 2019-10-02 01:15:47 -0400 |
|---|---|---|
| committer | Nathan Conrad <[email protected]> | 2019-10-02 01:15:47 -0400 |
| commit | cef388b7bd956adbc6af4904d4d95ca4120ebb7b (patch) | |
| tree | 61541614bb829acde7088c99d1c69a31070db32b /src | |
| parent | 4ea2a4ed60c41c8b55bfb40459e5f54615e2dc72 (diff) | |
| parent | d84a31fd5fd62b9458504615983591a4c4c34f89 (diff) | |
Merge branch 'master' into ZLP_Request2
Diffstat (limited to 'src')
| -rw-r--r-- | src/class/hid/hid_device.c | 2 | ||||
| -rw-r--r-- | src/class/midi/midi_device.c | 13 | ||||
| -rw-r--r-- | src/device/usbd.c | 31 | ||||
| -rw-r--r-- | src/device/usbd_pvt.h | 11 | ||||
| -rw-r--r-- | src/osal/osal_none.h | 4 | ||||
| -rw-r--r-- | src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c | 45 | ||||
| -rw-r--r-- | src/portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h | 2 | ||||
| -rw-r--r-- | src/portable/st/synopsys/dcd_synopsys.c | 10 |
8 files changed, 74 insertions, 44 deletions
diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index ff8e7dc9a..9e7bad976 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -74,7 +74,7 @@ bool tud_hid_ready(void) {
uint8_t itf = 0;
uint8_t const ep_in = _hidd_itf[itf].ep_in;
- return tud_ready() && (ep_in != 0) && !usbd_edpt_busy(TUD_OPT_RHPORT, ep_in);
+ return tud_ready() && (ep_in != 0) && usbd_edpt_ready(TUD_OPT_RHPORT, ep_in);
}
bool tud_hid_report(uint8_t report_id, void const* report, uint8_t len)
diff --git a/src/class/midi/midi_device.c b/src/class/midi/midi_device.c index 50826a1f4..11fe06e38 100644 --- a/src/class/midi/midi_device.c +++ b/src/class/midi/midi_device.c @@ -86,16 +86,19 @@ bool tud_midi_n_mounted (uint8_t itf) //--------------------------------------------------------------------+
uint32_t tud_midi_n_available(uint8_t itf, uint8_t jack_id)
{
+ (void) jack_id;
return tu_fifo_count(&_midid_itf[itf].rx_ff);
}
uint32_t tud_midi_n_read(uint8_t itf, uint8_t jack_id, void* buffer, uint32_t bufsize)
{
+ (void) jack_id;
return tu_fifo_read_n(&_midid_itf[itf].rx_ff, buffer, bufsize);
}
void tud_midi_n_read_flush (uint8_t itf, uint8_t jack_id)
{
+ (void) jack_id;
tu_fifo_clear(&_midid_itf[itf].rx_ff);
}
@@ -128,6 +131,8 @@ void midi_rx_done_cb(midid_interface_t* midi, uint8_t const* buffer, uint32_t bu static bool maybe_transmit(midid_interface_t* midi, uint8_t itf_index)
{
+ (void) itf_index;
+
// skip if previous transfer not complete
TU_VERIFY( !usbd_edpt_busy(TUD_OPT_RHPORT, midi->ep_in) );
@@ -309,11 +314,15 @@ bool midid_open(uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, bool midid_control_complete(uint8_t rhport, tusb_control_request_t const * p_request)
{
- return false;
+ (void) rhport;
+ (void) p_request;
+ return true;
}
bool midid_control_request(uint8_t rhport, tusb_control_request_t const * p_request)
{
+ (void) rhport;
+
//------------- Class Specific Request -------------//
if (p_request->bmRequestType_bit.type != TUSB_REQ_TYPE_CLASS) return false;
@@ -322,6 +331,8 @@ bool midid_control_request(uint8_t rhport, tusb_control_request_t const * p_requ bool midid_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
{
+ (void) result;
+
// TODO Support multiple interfaces
uint8_t const itf = 0;
midid_interface_t* p_midi = &_midid_itf[itf];
diff --git a/src/device/usbd.c b/src/device/usbd.c index 3700fb988..14e56a9b7 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -52,14 +52,19 @@ typedef struct { uint8_t self_powered : 1; // configuration descriptor's attribute
};
- uint8_t ep_busy_map[2]; // bit mask for busy endpoint
- uint8_t ep_stall_map[2]; // bit map for stalled endpoint
-
uint8_t itf2drv[16]; // map interface number to driver (0xff is invalid)
uint8_t ep2drv[8][2]; // map endpoint to driver ( 0xff is invalid )
+
+ struct TU_ATTR_PACKED
+ {
+ volatile bool busy : 1;
+ volatile bool stalled : 1;
+
+ // TODO merge ep2drv here, 4-bit should be sufficient
+ }ep_status[8][2];
}usbd_device_t;
-static usbd_device_t _usbd_dev = { 0 };
+static usbd_device_t _usbd_dev;
// Invalid driver ID in itf2drv[] ep2drv[][] mapping
enum { DRVID_INVALID = 0xFFu };
@@ -310,7 +315,7 @@ void tud_task (void) uint8_t const epnum = tu_edpt_number(ep_addr);
uint8_t const ep_dir = tu_edpt_dir(ep_addr);
- _usbd_dev.ep_busy_map[ep_dir] = (uint8_t) tu_bit_clear(_usbd_dev.ep_busy_map[ep_dir], epnum);
+ _usbd_dev.ep_status[epnum][ep_dir].busy = false;
if ( 0 == epnum )
{
@@ -864,8 +869,7 @@ bool usbd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t uint8_t const dir = tu_edpt_dir(ep_addr);
TU_VERIFY( dcd_edpt_xfer(rhport, ep_addr, buffer, total_bytes) );
-
- _usbd_dev.ep_busy_map[dir] = (uint8_t) tu_bit_set(_usbd_dev.ep_busy_map[dir], epnum);
+ _usbd_dev.ep_status[epnum][dir].busy = true;
return true;
}
@@ -877,18 +881,17 @@ bool usbd_edpt_busy(uint8_t rhport, uint8_t ep_addr) uint8_t const epnum = tu_edpt_number(ep_addr);
uint8_t const dir = tu_edpt_dir(ep_addr);
- return tu_bit_test(_usbd_dev.ep_busy_map[dir], epnum);
+ return _usbd_dev.ep_status[epnum][dir].busy;
}
-
void usbd_edpt_stall(uint8_t rhport, uint8_t ep_addr)
{
uint8_t const epnum = tu_edpt_number(ep_addr);
uint8_t const dir = tu_edpt_dir(ep_addr);
dcd_edpt_stall(rhport, ep_addr);
- _usbd_dev.ep_stall_map[dir] = (uint8_t) tu_bit_set(_usbd_dev.ep_stall_map[dir], epnum);
- _usbd_dev.ep_busy_map[dir] = (uint8_t) tu_bit_set(_usbd_dev.ep_busy_map[dir], epnum);
+ _usbd_dev.ep_status[epnum][dir].stalled = true;
+ _usbd_dev.ep_status[epnum][dir].busy = true;
}
void usbd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
@@ -897,8 +900,8 @@ void usbd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr) uint8_t const dir = tu_edpt_dir(ep_addr);
dcd_edpt_clear_stall(rhport, ep_addr);
- _usbd_dev.ep_busy_map[dir] = (uint8_t) tu_bit_clear(_usbd_dev.ep_busy_map[dir], epnum);
- _usbd_dev.ep_stall_map[dir] = (uint8_t) tu_bit_clear(_usbd_dev.ep_stall_map[dir], epnum);
+ _usbd_dev.ep_status[epnum][dir].stalled = false;
+ _usbd_dev.ep_status[epnum][dir].busy = false;
}
bool usbd_edpt_stalled(uint8_t rhport, uint8_t ep_addr)
@@ -908,7 +911,7 @@ bool usbd_edpt_stalled(uint8_t rhport, uint8_t ep_addr) uint8_t const epnum = tu_edpt_number(ep_addr);
uint8_t const dir = tu_edpt_dir(ep_addr);
- return tu_bit_test(_usbd_dev.ep_stall_map[dir], epnum);
+ return _usbd_dev.ep_status[epnum][dir].stalled;
}
#endif
diff --git a/src/device/usbd_pvt.h b/src/device/usbd_pvt.h index fbf030ce3..892680142 100644 --- a/src/device/usbd_pvt.h +++ b/src/device/usbd_pvt.h @@ -47,10 +47,21 @@ bool usbd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t // Check if endpoint transferring is complete bool usbd_edpt_busy(uint8_t rhport, uint8_t ep_addr); +// Stall endpoint void usbd_edpt_stall(uint8_t rhport, uint8_t ep_addr); + +// Clear stalled endpoint void usbd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr); + +// Check if endpoint is stalled bool usbd_edpt_stalled(uint8_t rhport, uint8_t ep_addr); +static inline +bool usbd_edpt_ready(uint8_t rhport, uint8_t ep_addr) +{ + return !usbd_edpt_busy(rhport, ep_addr) && !usbd_edpt_stalled(rhport, ep_addr); +} + /*------------------------------------------------------------------*/ /* Helper *------------------------------------------------------------------*/ diff --git a/src/osal/osal_none.h b/src/osal/osal_none.h index 7780345df..fa581215d 100644 --- a/src/osal/osal_none.h +++ b/src/osal/osal_none.h @@ -145,6 +145,8 @@ typedef osal_queue_def_t* osal_queue_t; // lock queue by disable usb isr
static inline void _osal_q_lock(osal_queue_t qhdl)
{
+ (void) qhdl;
+
#if TUSB_OPT_DEVICE_ENABLED
if (qhdl->role == OPT_MODE_DEVICE) dcd_int_disable(TUD_OPT_RHPORT);
#endif
@@ -157,6 +159,8 @@ static inline void _osal_q_lock(osal_queue_t qhdl) // unlock queue
static inline void _osal_q_unlock(osal_queue_t qhdl)
{
+ (void) qhdl;
+
#if TUSB_OPT_DEVICE_ENABLED
if (qhdl->role == OPT_MODE_DEVICE) dcd_int_enable(TUD_OPT_RHPORT);
#endif
diff --git a/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c b/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c index 00f5b1239..c33f9b865 100644 --- a/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c +++ b/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c @@ -103,17 +103,17 @@ #include "tusb_option.h" -#define STM32F1_FSDEV ( \ - defined(STM32F102x6) || defined(STM32F102xB) || \ +#if defined(STM32F102x6) || defined(STM32F102xB) || \ defined(STM32F103x6) || defined(STM32F103xB) || \ - defined(STM32F103xE) || defined(STM32F103xG) \ -) + defined(STM32F103xE) || defined(STM32F103xG) +#define STM32F1_FSDEV +#endif #if (TUSB_OPT_DEVICE_ENABLED) && ( \ - (CFG_TUSB_MCU == OPT_MCU_STM32F0 ) || \ - (CFG_TUSB_MCU == OPT_MCU_STM32F1 && STM32F1_FSDEV ) || \ - (CFG_TUSB_MCU == OPT_MCU_STM32F3 ) || \ - (CFG_TUSB_MCU == OPT_MCU_STM32L0 ) \ + (CFG_TUSB_MCU == OPT_MCU_STM32F0 ) || \ + (CFG_TUSB_MCU == OPT_MCU_STM32F1 && defined(STM32F1_FSDEV)) || \ + (CFG_TUSB_MCU == OPT_MCU_STM32F3 ) || \ + (CFG_TUSB_MCU == OPT_MCU_STM32L0 ) \ ) // In order to reduce the dependance on HAL, we undefine this. @@ -252,7 +252,9 @@ void dcd_init (uint8_t rhport) void dcd_int_enable (uint8_t rhport) { (void)rhport; - + // Member here forces write to RAM before allowing ISR to execute + __DSB(); + __ISB(); #if CFG_TUSB_MCU == OPT_MCU_STM32F0 || CFG_TUSB_MCU == OPT_MCU_STM32L0 NVIC_EnableIRQ(USB_IRQn); #elif CFG_TUSB_MCU == OPT_MCU_STM32F3 @@ -276,10 +278,7 @@ void dcd_int_disable(uint8_t rhport) #else #error Unknown arch in USB driver #endif - // I'm not convinced that memory synchronization is completely necessary, but - // it isn't a bad idea. - __DSB(); - __ISB(); + // CMSIS has a membar after disabling interrupts } // Receive Set Address request, mcu port must also include status IN response @@ -419,10 +418,15 @@ static uint16_t dcd_ep_ctr_handler(void) uint8_t userMemBuf[8]; /* Get SETUP Packet*/ count = pcd_get_ep_rx_cnt(USB, EPindex); - //TU_ASSERT_ERR(count == 8); - dcd_read_packet_memory(userMemBuf, *pcd_ep_rx_address_ptr(USB,EPindex), 8); + if(count == 8) // Setup packet should always be 8 bytes. If not, ignore it, and try again. + { + // 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); + dcd_read_packet_memory(userMemBuf, *pcd_ep_rx_address_ptr(USB,EPindex), 8); + dcd_event_setup_received(0, (uint8_t*)userMemBuf, true); + } /* SETUP bit kept frozen while CTR_RX = 1*/ - dcd_event_setup_received(0, (uint8_t*)userMemBuf, true); pcd_clear_rx_ep_ctr(USB, EPindex); } else if ((wEPVal & USB_EP_CTR_RX) != 0U) // OUT @@ -440,10 +444,6 @@ static uint16_t dcd_ep_ctr_handler(void) } /* Process Control Data OUT status Packet*/ - if(EPindex == 0u && xfer->total_len == 0u) - { - pcd_clear_ep_kind(USB,0); // Good, so allow non-zero length packets now. - } dcd_event_xfer_complete(0, EPindex, xfer->total_len, XFER_RESULT_SUCCESS, true); pcd_set_ep_rx_cnt(USB, EPindex, CFG_TUD_ENDPOINT0_SIZE); @@ -627,7 +627,9 @@ bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc } pcd_set_ep_address(USB, epnum, epnum); - pcd_clear_ep_kind(USB,0); // Be normal, for now, instead of only accepting zero-byte packets + // Be normal, for now, instead of only accepting zero-byte packets (on control endpoint) + // or being double-buffered (bulk endpoints) + pcd_clear_ep_kind(USB,0); if(dir == TUSB_DIR_IN) { @@ -688,7 +690,6 @@ bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t if (epnum == 0 && buffer == NULL) { xfer->buffer = (uint8_t*)_setup_packet; - pcd_set_ep_kind(USB,0); // Expect a zero-byte INPUT } if(total_bytes > xfer->max_packet_size) { diff --git a/src/portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h b/src/portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h index 30538541a..bbaa52eae 100644 --- a/src/portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h +++ b/src/portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h @@ -52,7 +52,7 @@ // 070RB: 2 x 16 bits/word memory LPM Support, BCD Support // PMA dedicated to USB (no sharing with CAN) -#elif STM32F1_FSDEV +#elif defined(STM32F1_FSDEV) #include "stm32f1xx.h" #define PMA_LENGTH (512u) // NO internal Pull-ups diff --git a/src/portable/st/synopsys/dcd_synopsys.c b/src/portable/st/synopsys/dcd_synopsys.c index 1a7f86219..7929b6916 100644 --- a/src/portable/st/synopsys/dcd_synopsys.c +++ b/src/portable/st/synopsys/dcd_synopsys.c @@ -27,19 +27,19 @@ #include "tusb_option.h" -#define STM32L4_SYNOPSYS ( \ - defined (STM32L475xx) || defined (STM32L476xx) || \ +#if defined (STM32L475xx) || defined (STM32L476xx) || \ defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || \ defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || \ - defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx) \ -) + defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx) +#define STM32L4_SYNOPSYS +#endif #if TUSB_OPT_DEVICE_ENABLED && \ ( CFG_TUSB_MCU == OPT_MCU_STM32F2 || \ CFG_TUSB_MCU == OPT_MCU_STM32F4 || \ CFG_TUSB_MCU == OPT_MCU_STM32F7 || \ CFG_TUSB_MCU == OPT_MCU_STM32H7 || \ - (CFG_TUSB_MCU == OPT_MCU_STM32L4 && STM32L4_SYNOPSYS) \ + (CFG_TUSB_MCU == OPT_MCU_STM32L4 && defined(STM32L4_SYNOPSYS)) \ ) // TODO Support OTG_HS |
