summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhathach <[email protected]>2019-03-05 05:45:42 -0800
committerGitHub <[email protected]>2019-03-05 05:45:42 -0800
commit8418cb816bbc0b760c102921875016a8ba31167d (patch)
treec9c0e1718779d889aaa47979f3c5b3c4d423297b /src
parent49aa6ec2516eddb2202c82a415b89be919bf1dd1 (diff)
parenta19455d1ff2581b07b1ace00f5a2820165bd8e98 (diff)
Merge branch 'master' into stm32f4
Diffstat (limited to 'src')
-rw-r--r--src/class/cdc/cdc_device.c2
-rw-r--r--src/class/hid/hid_device.c2
-rw-r--r--src/class/msc/msc.h4
-rw-r--r--src/class/msc/msc_device.c46
-rw-r--r--src/device/usbd.c5
-rw-r--r--src/host/usbh.c3
-rw-r--r--src/portable/microchip/samd21/dcd_samd21.c2
-rw-r--r--src/portable/nordic/nrf5x/hal_nrf5x.c14
-rw-r--r--src/tusb.c5
-rw-r--r--src/tusb.h3
10 files changed, 56 insertions, 30 deletions
diff --git a/src/class/cdc/cdc_device.c b/src/class/cdc/cdc_device.c
index b8678c1c4..0cfb2377b 100644
--- a/src/class/cdc/cdc_device.c
+++ b/src/class/cdc/cdc_device.c
@@ -85,7 +85,7 @@ typedef struct
//--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+
-CFG_TUSB_MEM_SECTION static cdcd_interface_t _cdcd_itf[CFG_TUD_CDC];
+CFG_TUSB_MEM_SECTION static cdcd_interface_t _cdcd_itf[CFG_TUD_CDC] = { { 0 } };
//--------------------------------------------------------------------+
// APPLICATION API
diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c
index 3b882f705..5f6843d90 100644
--- a/src/class/hid/hid_device.c
+++ b/src/class/hid/hid_device.c
@@ -91,7 +91,7 @@ typedef struct
hidd_interface_t* itf;
} hidd_report_t ;
-CFG_TUSB_MEM_SECTION static hidd_interface_t _hidd_itf[ITF_COUNT];
+CFG_TUSB_MEM_SECTION static hidd_interface_t _hidd_itf[ITF_COUNT] = { { 0 } };
#if CFG_TUD_HID_KEYBOARD
diff --git a/src/class/msc/msc.h b/src/class/msc/msc.h
index 10a73bb1c..15fcea572 100644
--- a/src/class/msc/msc.h
+++ b/src/class/msc/msc.h
@@ -284,8 +284,10 @@ typedef struct ATTR_PACKED
{
uint8_t data_len;
uint8_t medium_type;
- bool write_protected : 1;
+
uint8_t reserved : 7;
+ bool write_protected : 1;
+
uint8_t block_descriptor_len;
} scsi_mode_sense6_resp_t;
diff --git a/src/class/msc/msc_device.c b/src/class/msc/msc_device.c
index 5d2758414..b9eaa4933 100644
--- a/src/class/msc/msc_device.c
+++ b/src/class/msc/msc_device.c
@@ -83,7 +83,7 @@ typedef struct {
uint8_t add_sense_qualifier;
}mscd_interface_t;
-CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static mscd_interface_t _mscd_itf;
+CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static mscd_interface_t _mscd_itf = { 0 };
CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static uint8_t _mscd_buf[CFG_TUD_MSC_BUFSIZE];
//--------------------------------------------------------------------+
@@ -265,14 +265,20 @@ int32_t proc_builtin_scsi(msc_cbw_t const * p_cbw, uint8_t* buffer, uint32_t buf
.is_removable = 1,
.version = 2,
.response_data_format = 2,
- .vendor_id = "Adafruit",
- .product_id = "Feather52840",
- .product_rev = "1.0"
+ // vendor_id, product_id, product_rev is space padded string
+ .vendor_id = "",
+ .product_id = "",
+ .product_rev = "",
};
- strncpy((char*) inquiry_rsp.vendor_id , CFG_TUD_MSC_VENDOR , sizeof(inquiry_rsp.vendor_id));
- strncpy((char*) inquiry_rsp.product_id , CFG_TUD_MSC_PRODUCT , sizeof(inquiry_rsp.product_id));
- strncpy((char*) inquiry_rsp.product_rev, CFG_TUD_MSC_PRODUCT_REV, sizeof(inquiry_rsp.product_rev));
+ memset(inquiry_rsp.vendor_id, ' ', sizeof(inquiry_rsp.vendor_id));
+ memcpy(inquiry_rsp.vendor_id, CFG_TUD_MSC_VENDOR, tu_min32(strlen(CFG_TUD_MSC_VENDOR), sizeof(inquiry_rsp.vendor_id)));
+
+ memset(inquiry_rsp.product_id, ' ', sizeof(inquiry_rsp.product_id));
+ memcpy(inquiry_rsp.product_id, CFG_TUD_MSC_PRODUCT, tu_min32(strlen(CFG_TUD_MSC_PRODUCT), sizeof(inquiry_rsp.product_id)));
+
+ memset(inquiry_rsp.product_rev, ' ', sizeof(inquiry_rsp.product_rev));
+ memcpy(inquiry_rsp.product_rev, CFG_TUD_MSC_PRODUCT_REV, tu_min32(strlen(CFG_TUD_MSC_PRODUCT_REV), sizeof(inquiry_rsp.product_rev)));
ret = sizeof(inquiry_rsp);
memcpy(buffer, &inquiry_rsp, ret);
@@ -525,6 +531,12 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
}
else
{
+ // Move to default CMD stage when sending status
+ p_msc->stage = MSC_STAGE_CMD;
+
+ // Send SCSI Status
+ TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_in , (uint8_t*) &p_msc->csw, sizeof(msc_csw_t)) );
+
// Invoke complete callback if defined
if ( SCSI_CMD_READ_10 == p_cbw->command[0])
{
@@ -539,12 +551,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
if ( tud_msc_scsi_complete_cb ) tud_msc_scsi_complete_cb(p_cbw->lun, p_cbw->command);
}
- // Move to default CMD stage after sending status
- p_msc->stage = MSC_STAGE_CMD;
-
- TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_in , (uint8_t*) &p_msc->csw, sizeof(msc_csw_t)) );
-
- //------------- Queue the next CBW -------------//
+ // Queue for the next CBW
TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cbw_t)) );
}
}
@@ -594,6 +601,19 @@ static void proc_read10_cmd(uint8_t rhport, mscd_interface_t* p_msc)
static void proc_write10_cmd(uint8_t rhport, mscd_interface_t* p_msc)
{
msc_cbw_t const * p_cbw = &p_msc->cbw;
+ bool writable = true;
+ if (tud_msc_is_writable_cb) {
+ writable = tud_msc_is_writable_cb(p_cbw->lun);
+ }
+ if (!writable) {
+ msc_csw_t* p_csw = &p_msc->csw;
+ p_csw->data_residue = p_cbw->total_bytes;
+ p_csw->status = MSC_CSW_STATUS_FAILED;
+
+ tud_msc_set_sense(p_cbw->lun, SCSI_SENSE_DATA_PROTECT, 0x27, 0x00); // Sense = Write protected
+ dcd_edpt_stall(rhport, p_msc->ep_out);
+ return;
+ }
// remaining bytes capped at class buffer
int32_t nbytes = (int32_t) tu_min32(sizeof(_mscd_buf), p_cbw->total_bytes-p_msc->xferred_len);
diff --git a/src/device/usbd.c b/src/device/usbd.c
index 9c08a7932..5baea8460 100644
--- a/src/device/usbd.c
+++ b/src/device/usbd.c
@@ -61,7 +61,7 @@ typedef struct {
}usbd_device_t;
-static usbd_device_t _usbd_dev;
+static usbd_device_t _usbd_dev = { 0 };
// Auto descriptor is enabled, descriptor set point to auto generated one
#if CFG_TUD_DESC_AUTO
@@ -240,6 +240,9 @@ static void usbd_reset(uint8_t rhport)
*/
void tud_task (void)
{
+ // Skip if stack is not initialized
+ if ( !tusb_inited() ) return;
+
// Loop until there is no more events in the queue
while (1)
{
diff --git a/src/host/usbh.c b/src/host/usbh.c
index 4334729e9..a7e7c2acd 100644
--- a/src/host/usbh.c
+++ b/src/host/usbh.c
@@ -620,6 +620,9 @@ bool enum_task(hcd_event_t* event)
*/
void tuh_task(void)
{
+ // Skip if stack is not initialized
+ if ( !tusb_inited() ) return;
+
// Loop until there is no more events in the queue
while (1)
{
diff --git a/src/portable/microchip/samd21/dcd_samd21.c b/src/portable/microchip/samd21/dcd_samd21.c
index 7b2a57eeb..6140812bc 100644
--- a/src/portable/microchip/samd21/dcd_samd21.c
+++ b/src/portable/microchip/samd21/dcd_samd21.c
@@ -296,7 +296,7 @@ void maybe_transfer_complete(void) {
uint32_t epintflag = ep->EPINTFLAG.reg;
- uint16_t total_transfer_size;
+ uint16_t total_transfer_size = 0;
// Handle IN completions
if ((epintflag & USB_DEVICE_EPINTFLAG_TRCPT1) != 0) {
diff --git a/src/portable/nordic/nrf5x/hal_nrf5x.c b/src/portable/nordic/nrf5x/hal_nrf5x.c
index f0a0b9632..52743ce6f 100644
--- a/src/portable/nordic/nrf5x/hal_nrf5x.c
+++ b/src/portable/nordic/nrf5x/hal_nrf5x.c
@@ -49,16 +49,9 @@
#ifdef SOFTDEVICE_PRESENT
#include "nrf_sdm.h"
#include "nrf_soc.h"
+#endif
-// TODO fully move to nrfx
-enum {
- NRFX_POWER_USB_EVT_DETECTED, /**< USB power detected on the connector (plugged in). */
- NRFX_POWER_USB_EVT_REMOVED, /**< USB power removed from the connector. */
- NRFX_POWER_USB_EVT_READY /**< USB power regulator ready. */
-};
-#else
#include "nrfx_power.h"
-#endif
#include "tusb_hal.h"
#include "device/dcd.h"
@@ -66,8 +59,6 @@ enum {
/*------------------------------------------------------------------*/
/* MACRO TYPEDEF CONSTANT ENUM
*------------------------------------------------------------------*/
-#define USB_NVIC_PRIO 7
-
void tusb_hal_nrf_power_event(uint32_t event);
/*------------------------------------------------------------------*/
@@ -239,8 +230,7 @@ void tusb_hal_nrf_power_event (uint32_t event)
NRF_USBD->INTENSET = USBD_INTEN_USBRESET_Msk | USBD_INTEN_USBEVENT_Msk | USBD_INTEN_EPDATA_Msk |
USBD_INTEN_EP0SETUP_Msk | USBD_INTEN_EP0DATADONE_Msk | USBD_INTEN_ENDEPIN0_Msk | USBD_INTEN_ENDEPOUT0_Msk;
- // Enable interrupt, Priorities 0,1,4,5 (nRF52) are reserved for SoftDevice
- NVIC_SetPriority(USBD_IRQn, USB_NVIC_PRIO);
+ // Enable interrupt, priorities should be set by application
NVIC_ClearPendingIRQ(USBD_IRQn);
NVIC_EnableIRQ(USBD_IRQn);
diff --git a/src/tusb.c b/src/tusb.c
index ad2dcbfd3..566d74df7 100644
--- a/src/tusb.c
+++ b/src/tusb.c
@@ -68,6 +68,11 @@ bool tusb_init(void)
return TUSB_ERROR_NONE;
}
+bool tusb_inited(void)
+{
+ return _initialized;
+}
+
/*------------------------------------------------------------------*/
/* Debug
*------------------------------------------------------------------*/
diff --git a/src/tusb.h b/src/tusb.h
index fb20c5ff7..69c4d16d2 100644
--- a/src/tusb.h
+++ b/src/tusb.h
@@ -108,6 +108,9 @@
// Initialize device/host stack
bool tusb_init(void);
+// Check if stack is initialized
+bool tusb_inited(void);
+
// TODO
// bool tusb_teardown(void);