diff options
Diffstat (limited to 'os')
-rw-r--r-- | os/hal/ports/STM32/LLD/USBHv1/hal_usbh_lld.c | 29 | ||||
-rw-r--r-- | os/hal/src/hal_usbh.c | 54 | ||||
-rw-r--r-- | os/hal/src/usbh/hal_usbh_ftdi.c | 6 | ||||
-rw-r--r-- | os/various/fatfs_bindings/fatfs_diskio.c | 24 |
4 files changed, 43 insertions, 70 deletions
diff --git a/os/hal/ports/STM32/LLD/USBHv1/hal_usbh_lld.c b/os/hal/ports/STM32/LLD/USBHv1/hal_usbh_lld.c index 3944a79..4723508 100644 --- a/os/hal/ports/STM32/LLD/USBHv1/hal_usbh_lld.c +++ b/os/hal/ports/STM32/LLD/USBHv1/hal_usbh_lld.c @@ -244,7 +244,6 @@ static bool _activate_ep(USBHDriver *host, usbh_ep_t *ep) { ep->xfer.buf = urb->buff; } ep->xfer.error_count = 0; - //urb->status = USBH_URBSTATUS_QUEUED; } else { osalDbgCheck(urb->requestedLength >= urb->actualLength); @@ -1026,25 +1025,36 @@ static inline void _sof_int(USBHDriver *host) { #undef HPRT_PLSTS_MASK #define HPRT_PLSTS_MASK (3U<<10) if (host->check_ls_activity) { - uint16_t remaining = host->otg->HFNUM >> 16; + stm32_otg_t *const otg = host->otg; + uint16_t remaining = otg->HFNUM >> 16; if (remaining < 5975) { uwarnf("LS: ISR called too late (time=%d)", 6000 - remaining); return; } - /* 15us loop */ + /* 15us loop during which we check if the core generates an actual keep-alive + * (or activity other than idle) on the DP/DM lines. After 15us, we abort + * the loop and wait for the next SOF. If no activity is detected, the upper + * layer will time-out waiting for the reset to happen, and the port will remain + * enabled (though in a dumb state). This will be detected on the next port reset + * request and the OTG core will be reset. */ for (;;) { - uint32_t line_status = host->otg->HPRT & HPRT_PLSTS_MASK; - remaining = host->otg->HFNUM >> 16; + uint32_t line_status = otg->HPRT & HPRT_PLSTS_MASK; + remaining = otg->HFNUM >> 16; + if (!(otg->HPRT & HPRT_PENA)) { + uwarn("LS: Port disabled"); + return; + } if (line_status != HPRT_PLSTS_DM) { + /* success; report that the port is enabled */ uinfof("LS: activity detected, line=%d, time=%d", line_status >> 10, 6000 - remaining); host->check_ls_activity = FALSE; - host->otg->GINTMSK = (host->otg->GINTMSK & ~GINTMSK_SOFM) | (GINTMSK_HCM | GINTMSK_RXFLVLM); + otg->GINTMSK = (otg->GINTMSK & ~GINTMSK_SOFM) | (GINTMSK_HCM | GINTMSK_RXFLVLM); host->rootport.lld_status |= USBH_PORTSTATUS_ENABLE; host->rootport.lld_c_status |= USBH_PORTSTATUS_C_ENABLE; return; } if (remaining < 5910) { - uwarn("LS: No activity detected"); + udbg("LS: No activity detected"); return; } } @@ -1156,9 +1166,6 @@ static inline void _nptxfe_int(USBHDriver *host) { rem += _write_packet(&host->ep_active_lists[USBH_EPTYPE_BULK], otg->HNPTXSTS & HPTXSTS_PTXFSAVL_MASK); -// if (rem) -// otg->GINTMSK |= GINTMSK_NPTXFEM; - if (!rem) otg->GINTMSK &= ~GINTMSK_NPTXFEM; @@ -1655,7 +1662,7 @@ usbh_urbstatus_t usbh_lld_root_hub_request(USBHDriver *usbh, uint8_t bmRequestTy hprt = otg->HPRT; if (hprt & HPRT_PENA) { /* This can occur when the OTG core doesn't generate traffic - * despite reporting a successful por enable */ + * despite reporting a successful por enable. */ uerr("Detected enabled port; resetting OTG core"); otg->GAHBCFG = 0; osalThreadSleepS(MS2ST(20)); diff --git a/os/hal/src/hal_usbh.c b/os/hal/src/hal_usbh.c index a7ba236..7dff98a 100644 --- a/os/hal/src/hal_usbh.c +++ b/os/hal/src/hal_usbh.c @@ -233,11 +233,8 @@ void usbhURBSubmitI(usbh_urb_t *urb) { _usbh_urb_completeI(urb, USBH_URBSTATUS_STALL); return; } - if (ep->status != USBH_EPSTATUS_OPEN) { - _usbh_urb_completeI(urb, USBH_URBSTATUS_DISCONNECTED); - return; - } - if (!(usbhDeviceGetPort(ep->device)->status & USBH_PORTSTATUS_ENABLE)) { + if ((ep->status != USBH_EPSTATUS_OPEN) + || !(usbhDeviceGetPort(ep->device)->status & USBH_PORTSTATUS_ENABLE)) { _usbh_urb_completeI(urb, USBH_URBSTATUS_DISCONNECTED); return; } @@ -271,18 +268,11 @@ void _usbh_urb_abort_and_waitS(usbh_urb_t *urb, usbh_urbstatus_t status) { osalThreadSuspendS(&urb->abortingThread); osalDbgAssert(urb->abortingThread == 0, "maybe we should uncomment the line below"); //urb->abortingThread = 0; - } -#if !(USBH_DEBUG_ENABLE && USBH_DEBUG_ENABLE_WARNINGS) - else { + } else { /* This call is necessary because _usbh_urb_abortI may require a reschedule */ osalOsRescheduleS(); } -#else uwarn("URB aborted"); - osalOsRescheduleS(); /* debug printing functions call I-class functions inside - which may cause a priority violation without this call - Also, _usbh_urb_abortI may require a reschedule */ -#endif } /* usbhURBCancelI may require a reschedule if called from a S-locked state */ @@ -295,34 +285,14 @@ void usbhURBCancelAndWaitS(usbh_urb_t *urb) { } msg_t usbhURBWaitTimeoutS(usbh_urb_t *urb, systime_t timeout) { - msg_t ret; - osalDbgCheckClassS(); _check_urb(urb); - - switch (urb->status) { - case USBH_URBSTATUS_INITIALIZED: - case USBH_URBSTATUS_PENDING: - ret = osalThreadSuspendTimeoutS(&urb->waitingThread, timeout); - osalDbgAssert(urb->waitingThread == 0, "maybe we should uncomment the line below"); - //urb->waitingThread = 0; - break; - - case USBH_URBSTATUS_OK: - ret = MSG_OK; - break; - -/* case USBH_URBSTATUS_UNINITIALIZED: - * case USBH_URBSTATUS_ERROR: - * case USBH_URBSTATUS_TIMEOUT: - * case USBH_URBSTATUS_CANCELLED: - * case USBH_URBSTATUS_STALL: - * case USBH_URBSTATUS_DISCONNECTED: */ - default: - ret = MSG_RESET; - break; + if (urb->status == USBH_URBSTATUS_OK) { + return MSG_OK; + } else if (urb->status != USBH_URBSTATUS_PENDING) { + return MSG_RESET; } - return ret; + return osalThreadSuspendTimeoutS(&urb->waitingThread, timeout); } msg_t usbhURBSubmitAndWaitS(usbh_urb_t *urb, systime_t timeout) { @@ -844,9 +814,6 @@ bool usbhDeviceReadString(usbh_device_t *dev, char *dest, uint8_t size, return HAL_SUCCESS; } - - - /*===========================================================================*/ /* Port processing functions. */ /*===========================================================================*/ @@ -908,13 +875,13 @@ static void _port_process_status_change(usbh_port_t *port) { if (port->c_status & USBH_PORTSTATUS_C_RESET) { port->c_status &= ~USBH_PORTSTATUS_C_RESET; usbhhubClearFeaturePort(port, USBH_PORT_FEAT_C_RESET); - uinfof("Port %d: reset=%d", port->number, port->status & USBH_PORTSTATUS_RESET ? 1 : 0); + udbgf("Port %d: reset=%d", port->number, port->status & USBH_PORTSTATUS_RESET ? 1 : 0); } if (port->c_status & USBH_PORTSTATUS_C_ENABLE) { port->c_status &= ~USBH_PORTSTATUS_C_ENABLE; usbhhubClearFeaturePort(port, USBH_PORT_FEAT_C_ENABLE); - uinfof("Port %d: enable=%d", port->number, port->status & USBH_PORTSTATUS_ENABLE ? 1 : 0); + udbgf("Port %d: enable=%d", port->number, port->status & USBH_PORTSTATUS_ENABLE ? 1 : 0); } if (port->c_status & USBH_PORTSTATUS_C_OVERCURRENT) { @@ -1096,7 +1063,6 @@ void _usbh_port_disconnected(usbh_port_t *port) { } - /*===========================================================================*/ /* Hub processing functions. */ /*===========================================================================*/ diff --git a/os/hal/src/usbh/hal_usbh_ftdi.c b/os/hal/src/usbh/hal_usbh_ftdi.c index 6e33867..6fb556d 100644 --- a/os/hal/src/usbh/hal_usbh_ftdi.c +++ b/os/hal/src/usbh/hal_usbh_ftdi.c @@ -415,7 +415,7 @@ static void _out_cb(usbh_urb_t *urb) { return; case USBH_URBSTATUS_DISCONNECTED: uwarn("FTDI: URB OUT disconnected"); - chThdDequeueNextI(&ftdipp->oq_waiting, Q_RESET); + chThdDequeueAllI(&ftdipp->oq_waiting, Q_RESET); return; default: uerrf("FTDI: URB OUT status unexpected = %d", urb->status); @@ -516,12 +516,12 @@ static void _in_cb(usbh_urb_t *urb) { udbgf("FTDI: URB IN no data, status=%02x %02x", ((uint8_t *)urb->buff)[0], ((uint8_t *)urb->buff)[1]); - return; + // return; } break; case USBH_URBSTATUS_DISCONNECTED: uwarn("FTDI: URB IN disconnected"); - chThdDequeueNextI(&ftdipp->iq_waiting, Q_RESET); + chThdDequeueAllI(&ftdipp->iq_waiting, Q_RESET); return; default: uerrf("FTDI: URB IN status unexpected = %d", urb->status); diff --git a/os/various/fatfs_bindings/fatfs_diskio.c b/os/various/fatfs_bindings/fatfs_diskio.c index 6949310..9fa41e2 100644 --- a/os/various/fatfs_bindings/fatfs_diskio.c +++ b/os/various/fatfs_bindings/fatfs_diskio.c @@ -180,7 +180,6 @@ DRESULT disk_read ( /*-----------------------------------------------------------------------*/ /* Write Sector(s) */ -#if _USE_WRITE DRESULT disk_write ( BYTE pdrv, /* Physical drive nmuber (0..) */ const BYTE *buff, /* Data to be written */ @@ -226,14 +225,12 @@ DRESULT disk_write ( } return RES_PARERR; } -#endif /* _USE_WRITE */ /*-----------------------------------------------------------------------*/ /* Miscellaneous Functions */ -#if _USE_IOCTL DRESULT disk_ioctl ( BYTE pdrv, /* Physical drive nmuber (0..) */ BYTE cmd, /* Control code */ @@ -246,11 +243,13 @@ DRESULT disk_ioctl ( switch (cmd) { case CTRL_SYNC: return RES_OK; +#if _MAX_SS > _MIN_SS case GET_SECTOR_SIZE: *((WORD *)buff) = MMCSD_BLOCK_SIZE; return RES_OK; -#if _USE_ERASE - case CTRL_ERASE_SECTOR: +#endif +#if _USE_TRIM + case CTRL_TRIM: mmcErase(&MMCD1, *((DWORD *)buff), *((DWORD *)buff + 1)); return RES_OK; #endif @@ -265,14 +264,16 @@ DRESULT disk_ioctl ( case GET_SECTOR_COUNT: *((DWORD *)buff) = mmcsdGetCardCapacity(&SDCD1); return RES_OK; +#if _MAX_SS > _MIN_SS case GET_SECTOR_SIZE: *((WORD *)buff) = MMCSD_BLOCK_SIZE; return RES_OK; +#endif case GET_BLOCK_SIZE: *((DWORD *)buff) = 256; /* 512b blocks in one erase block */ return RES_OK; -#if _USE_ERASE - case CTRL_ERASE_SECTOR: +#if _USE_TRIM + case CTRL_TRIM: sdcErase(&SDCD1, *((DWORD *)buff), *((DWORD *)buff + 1)); return RES_OK; #endif @@ -288,12 +289,14 @@ DRESULT disk_ioctl ( case GET_SECTOR_COUNT: *((DWORD *)buff) = MSBLKD[0].info.blk_num; return RES_OK; +#if _MAX_SS > _MIN_SS case GET_SECTOR_SIZE: *((WORD *)buff) = MSBLKD[0].info.blk_size; return RES_OK; -#if _USE_ERASE +#endif +#if _USE_TRIM #error "unimplemented yet!" -// case CTRL_ERASE_SECTOR: +// case CTRL_TRIM: // .... // return RES_OK; #endif @@ -304,7 +307,6 @@ DRESULT disk_ioctl ( } return RES_PARERR; } -#endif /* _USE_IOCTL */ DWORD get_fattime(void) { #if HAL_USE_RTC @@ -316,5 +318,3 @@ DWORD get_fattime(void) { return ((uint32_t)0 | (1 << 16)) | (1 << 21); /* wrong but valid time */ #endif } - - |