From de0c3e70c689cb8861497c245904ab10001e0721 Mon Sep 17 00:00:00 2001 From: Nicolas Reinecke Date: Mon, 14 Nov 2016 01:32:28 +0100 Subject: [PATCH 1/4] usbh: cleanup --- os/hal/ports/STM32/LLD/USBHv1/hal_stm32_otg.h | 13 +++++----- os/hal/ports/STM32/LLD/USBHv1/hal_usbh_lld.c | 16 ++++++------- os/hal/ports/STM32/LLD/USBHv1/hal_usbh_lld.h | 6 ++--- os/hal/src/hal_usbh.c | 24 +++++++++---------- os/hal/src/usbh/hal_usbh_msd.c | 8 +++---- 5 files changed, 34 insertions(+), 33 deletions(-) diff --git a/os/hal/ports/STM32/LLD/USBHv1/hal_stm32_otg.h b/os/hal/ports/STM32/LLD/USBHv1/hal_stm32_otg.h index b88e6205..a0594a3c 100644 --- a/os/hal/ports/STM32/LLD/USBHv1/hal_stm32_otg.h +++ b/os/hal/ports/STM32/LLD/USBHv1/hal_stm32_otg.h @@ -1,5 +1,5 @@ /* - ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio + ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -23,8 +23,8 @@ */ -#ifndef HAL_STM32_OTG_H_ -#define HAL_STM32_OTG_H_ +#ifndef HAL_STM32_OTG_H +#define HAL_STM32_OTG_H /** * @brief Number of the implemented endpoints in OTG_FS. @@ -571,7 +571,7 @@ typedef struct { #define HCCHAR_EPDIR (1U<<15) /**< Endpoint direction. */ #define HCCHAR_EPNUM_MASK (15U<<11) /**< Endpoint number mask. */ #define HCCHAR_EPNUM(n) ((n)<<11) /**< Endpoint number value. */ -#define HCCHAR_MPS_MASK (0x7FFU<<0) /**< Maximum packet size mask. */ +#define HCCHAR_MPS_MASK (0x7FFU<<0) /**< Maximum packet size mask. */ #define HCCHAR_MPS(n) ((n)<<0) /**< Maximum packet size value. */ /** @} */ @@ -590,6 +590,7 @@ typedef struct { interrupt. */ #define HCINT_STALL (1U<<3) /**< STALL response received interrupt. */ +#define HCINT_AHBERR (1U<<2) /**< AHB error interrupt. */ #define HCINT_CHH (1U<<1) /**< Channel halted. */ #define HCINT_XFRC (1U<<0) /**< Transfer completed. */ /** @} */ @@ -611,7 +612,7 @@ typedef struct { interrupt mask. */ #define HCINTMSK_STALLM (1U<<3) /**< STALL response received interrupt mask. */ -#define HCINTMSK_AHBERRM (1U<<2) +#define HCINTMSK_AHBERRM (1U<<2) /**< AHB error interrupt mask. */ #define HCINTMSK_CHHM (1U<<1) /**< Channel halted mask. */ #define HCINTMSK_XFRCM (1U<<0) /**< Transfer completed mask. */ /** @} */ @@ -924,6 +925,6 @@ typedef struct { */ #define OTG_HS ((stm32_otg_t *)OTG_HS_ADDR) -#endif /* _STM32_OTG_H_ */ +#endif /* STM32_OTG_H */ /** @} */ 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 3abab1c8..0618d832 100644 --- a/os/hal/ports/STM32/LLD/USBHv1/hal_usbh_lld.c +++ b/os/hal/ports/STM32/LLD/USBHv1/hal_usbh_lld.c @@ -59,7 +59,7 @@ static void otg_rxfifo_flush(USBHDriver *usbp); static void otg_txfifo_flush(USBHDriver *usbp, uint32_t fifo); /*===========================================================================*/ -/* Little helper functions. */ +/* Little helper functions. */ /*===========================================================================*/ static inline void _move_to_pending_queue(usbh_ep_t *ep) { list_move_tail(&ep->node, ep->pending_list); @@ -84,7 +84,7 @@ static inline void _transfer_completed(usbh_ep_t *ep, usbh_urb_t *urb, usbh_urbs #endif /*===========================================================================*/ -/* Functions called from many places. */ +/* Functions called from many places. */ /*===========================================================================*/ static void _transfer_completedI(usbh_ep_t *ep, usbh_urb_t *urb, usbh_urbstatus_t status) { osalDbgCheckClassI(); @@ -487,7 +487,7 @@ static uint32_t _write_packet(struct list_head *list, uint32_t space_available) /*===========================================================================*/ -/* API. */ +/* API. */ /*===========================================================================*/ void usbh_lld_ep_object_init(usbh_ep_t *ep) { @@ -614,7 +614,7 @@ bool usbh_lld_urb_abort(usbh_urb_t *urb, usbh_urbstatus_t status) { /*===========================================================================*/ -/* Channel Interrupts. */ +/* Channel Interrupts. */ /*===========================================================================*/ //CTRL(IN) CTRL(OUT) INT(IN) INT(OUT) BULK(IN) BULK(OUT) ISO(IN) ISO(OUT) @@ -951,7 +951,7 @@ static inline void _hcint_int(USBHDriver *host) { /*===========================================================================*/ -/* Host interrupts. */ +/* Host interrupts. */ /*===========================================================================*/ static inline void _sof_int(USBHDriver *host) { udbg("SOF"); @@ -1214,7 +1214,7 @@ static void usb_lld_serve_interrupt(USBHDriver *host) { /*===========================================================================*/ -/* Interrupt handlers. */ +/* Interrupt handlers. */ /*===========================================================================*/ #if STM32_USBH_USE_OTG1 @@ -1239,7 +1239,7 @@ OSAL_IRQ_HANDLER(STM32_OTG2_HANDLER) { /*===========================================================================*/ -/* Initialization functions. */ +/* Initialization functions. */ /*===========================================================================*/ static void otg_core_reset(USBHDriver *usbp) { stm32_otg_t *const otgp = usbp->otg; @@ -1450,7 +1450,7 @@ void usbh_lld_start(USBHDriver *usbh) { } /*===========================================================================*/ -/* Root Hub request handler. */ +/* Root Hub request handler. */ /*===========================================================================*/ usbh_urbstatus_t usbh_lld_root_hub_request(USBHDriver *usbh, uint8_t bmRequestType, uint8_t bRequest, uint16_t wvalue, uint16_t windex, uint16_t wlength, uint8_t *buf) { diff --git a/os/hal/ports/STM32/LLD/USBHv1/hal_usbh_lld.h b/os/hal/ports/STM32/LLD/USBHv1/hal_usbh_lld.h index 5c0ac405..15413b42 100644 --- a/os/hal/ports/STM32/LLD/USBHv1/hal_usbh_lld.h +++ b/os/hal/ports/STM32/LLD/USBHv1/hal_usbh_lld.h @@ -15,8 +15,8 @@ limitations under the License. */ -#ifndef HAL_USBH_LLD_H_ -#define HAL_USBH_LLD_H_ +#ifndef HAL_USBH_LLD_H +#define HAL_USBH_LLD_H #include "hal.h" @@ -150,4 +150,4 @@ uint8_t usbh_lld_roothub_get_statuschange_bitmap(USBHDriver *usbh); #endif -#endif /* HAL_USBH_LLD_H_ */ +#endif /* HAL_USBH_LLD_H */ diff --git a/os/hal/src/hal_usbh.c b/os/hal/src/hal_usbh.c index 1caa183d..befe17f9 100644 --- a/os/hal/src/hal_usbh.c +++ b/os/hal/src/hal_usbh.c @@ -69,7 +69,7 @@ static bool _classdriver_load(usbh_device_t *dev, uint8_t class, /*===========================================================================*/ -/* Checks. */ +/* Checks. */ /*===========================================================================*/ static inline void _check_dev(usbh_device_t *dev) { @@ -92,7 +92,7 @@ static inline void _check_urb(usbh_urb_t *urb) { } /*===========================================================================*/ -/* Main driver API. */ +/* Main driver API. */ /*===========================================================================*/ void usbhObjectInit(USBHDriver *usbh) { @@ -143,7 +143,7 @@ void usbhResume(USBHDriver *usbh) { } /*===========================================================================*/ -/* Endpoint API. */ +/* Endpoint API. */ /*===========================================================================*/ void usbhEPObjectInit(usbh_ep_t *ep, usbh_device_t *dev, const usbh_endpoint_descriptor_t *desc) { @@ -183,7 +183,7 @@ static void _ep0_object_init(usbh_device_t *dev, uint16_t wMaxPacketSize) { /*===========================================================================*/ -/* URB API. */ +/* URB API. */ /*===========================================================================*/ void usbhURBObjectInit(usbh_urb_t *urb, usbh_ep_t *ep, usbh_completion_cb callback, @@ -350,7 +350,7 @@ void _usbh_urb_completeI(usbh_urb_t *urb, usbh_urbstatus_t status) { } /*===========================================================================*/ -/* Synchronous API. */ +/* Synchronous API. */ /*===========================================================================*/ usbh_urbstatus_t usbhBulkTransfer(usbh_ep_t *ep, @@ -419,7 +419,7 @@ usbh_urbstatus_t usbhControlRequest(usbh_device_t *dev, } /*===========================================================================*/ -/* Standard request helpers. */ +/* Standard request helpers. */ /*===========================================================================*/ #define USBH_GET_DESCRIPTOR(type, value, index) \ @@ -523,7 +523,7 @@ bool usbhStdReqGetInterface(usbh_device_t *dev, /*===========================================================================*/ -/* Device-related functions. */ +/* Device-related functions. */ /*===========================================================================*/ static uint8_t _find_address(USBHDriver *host) { @@ -846,7 +846,7 @@ bool usbhDeviceReadString(usbh_device_t *dev, char *dest, uint8_t size, /*===========================================================================*/ -/* Port processing functions. */ +/* Port processing functions. */ /*===========================================================================*/ static void _port_connected(usbh_port_t *port); @@ -1078,7 +1078,7 @@ void _usbh_port_disconnected(usbh_port_t *port) { /*===========================================================================*/ -/* Hub processing functions. */ +/* Hub processing functions. */ /*===========================================================================*/ #if HAL_USBH_USE_HUB @@ -1176,7 +1176,7 @@ static void _hub_process(USBHDriver *host) { #endif /*===========================================================================*/ -/* Main processing loop (enumeration, loading/unloading drivers, etc). */ +/* Main processing loop (enumeration, loading/unloading drivers, etc). */ /*===========================================================================*/ void usbhMainLoop(USBHDriver *usbh) { @@ -1200,7 +1200,7 @@ void usbhMainLoop(USBHDriver *usbh) { /*===========================================================================*/ -/* IAD class driver. */ +/* IAD class driver. */ /*===========================================================================*/ #if HAL_USBH_USE_IAD static usbh_baseclassdriver_t *iad_load(usbh_device_t *dev, const uint8_t *descriptor, uint16_t rem); @@ -1258,7 +1258,7 @@ static void iad_unload(usbh_baseclassdriver_t *drv) { /*===========================================================================*/ -/* Class driver loader. */ +/* Class driver loader. */ /*===========================================================================*/ static const usbh_classdriverinfo_t *usbh_classdrivers_lookup[] = { diff --git a/os/hal/src/usbh/hal_usbh_msd.c b/os/hal/src/usbh/hal_usbh_msd.c index 6869a745..7a4f8269 100644 --- a/os/hal/src/usbh/hal_usbh_msd.c +++ b/os/hal/src/usbh/hal_usbh_msd.c @@ -68,7 +68,7 @@ /*===========================================================================*/ -/* USB Class driver loader for MSD */ +/* USB Class driver loader for MSD */ /*===========================================================================*/ USBHMassStorageDriver USBHMSD[HAL_USBHMSD_MAX_INSTANCES]; @@ -234,7 +234,7 @@ static void _msd_unload(usbh_baseclassdriver_t *drv) { /*===========================================================================*/ -/* MSD Class driver operations (Bulk-Only transport) */ +/* MSD Class driver operations (Bulk-Only transport) */ /*===========================================================================*/ @@ -290,7 +290,7 @@ typedef struct { /* ----------------------------------------------------- */ -/* SCSI Commands */ +/* SCSI Commands */ /* ----------------------------------------------------- */ /* Read 10 and Write 10 */ @@ -584,7 +584,7 @@ static msd_result_t scsi_write10(USBHMassStorageLUNDriver *lunp, uint32_t lba, u /*===========================================================================*/ -/* Block driver data/functions */ +/* Block driver data/functions */ /*===========================================================================*/ USBHMassStorageLUNDriver MSBLKD[HAL_USBHMSD_MAX_LUNS]; From 580af16b82c465835801102fe1879f7fffa3296a Mon Sep 17 00:00:00 2001 From: Nicolas Reinecke Date: Mon, 14 Nov 2016 01:33:46 +0100 Subject: [PATCH 2/4] usbh: add otg stepping 2 code --- os/hal/ports/STM32/LLD/USBHv1/hal_stm32_otg.h | 4 ++++ os/hal/ports/STM32/LLD/USBHv1/hal_usbh_lld.c | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/os/hal/ports/STM32/LLD/USBHv1/hal_stm32_otg.h b/os/hal/ports/STM32/LLD/USBHv1/hal_stm32_otg.h index a0594a3c..3322e511 100644 --- a/os/hal/ports/STM32/LLD/USBHv1/hal_stm32_otg.h +++ b/os/hal/ports/STM32/LLD/USBHv1/hal_stm32_otg.h @@ -430,12 +430,16 @@ typedef struct { * @name GCCFG register bit definitions * @{ */ +/* Definitions for stepping 1.*/ #define GCCFG_NOVBUSSENS (1U<<21) /**< VBUS sensing disable. */ #define GCCFG_SOFOUTEN (1U<<20) /**< SOF output enable. */ #define GCCFG_VBUSBSEN (1U<<19) /**< Enable the VBUS sensing "B" device. */ #define GCCFG_VBUSASEN (1U<<18) /**< Enable the VBUS sensing "A" device. */ + +/* Definitions for stepping 2.*/ +#define GCCFG_VBDEN (1U<<21) /**< VBUS sensing enable. */ #define GCCFG_PWRDWN (1U<<16) /**< Power down. */ /** @} */ 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 0618d832..523f14d0 100644 --- a/os/hal/ports/STM32/LLD/USBHv1/hal_usbh_lld.c +++ b/os/hal/ports/STM32/LLD/USBHv1/hal_usbh_lld.c @@ -1386,12 +1386,20 @@ static void _usbh_start(USBHDriver *usbh) { otgp->PCGCCTL = 0; /* Internal FS PHY activation.*/ +#if STM32_OTG_STEPPING == 1 #if defined(BOARD_OTG_NOVBUSSENS) otgp->GCCFG = GCCFG_NOVBUSSENS | GCCFG_PWRDWN; #else otgp->GCCFG = GCCFG_PWRDWN; #endif +#elif STM32_OTG_STEPPING == 2 +#if defined(BOARD_OTG_NOVBUSSENS) + otgp->GCCFG = GCCFG_PWRDWN; +#else + otgp->GCCFG = (GCCFG_VBDEN | GCCFG_PWRDWN); +#endif +#endif /* 48MHz 1.1 PHY.*/ otgp->HCFG = HCFG_FSLSS | HCFG_FSLSPCS_48; From c7d33767e06000f9da3befd6a7954b82c42d080d Mon Sep 17 00:00:00 2001 From: Peter Date: Sat, 10 Sep 2016 15:13:23 +0200 Subject: [PATCH 3/4] change qei types to int16_t --- os/hal/ports/NRF5/LLD/hal_qei_lld.h | 2 +- os/hal/ports/STM32/LLD/TIMv1/hal_qei_lld.h | 2 +- os/hal/src/hal_qei.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/os/hal/ports/NRF5/LLD/hal_qei_lld.h b/os/hal/ports/NRF5/LLD/hal_qei_lld.h index 6328babb..85c96a50 100644 --- a/os/hal/ports/NRF5/LLD/hal_qei_lld.h +++ b/os/hal/ports/NRF5/LLD/hal_qei_lld.h @@ -166,7 +166,7 @@ typedef enum { /** * @brief QEI counter type. */ -typedef int32_t qeicnt_t; +typedef int16_t qeicnt_t; /** * @brief QEI delta type. diff --git a/os/hal/ports/STM32/LLD/TIMv1/hal_qei_lld.h b/os/hal/ports/STM32/LLD/TIMv1/hal_qei_lld.h index c708b5ef..ba33a291 100644 --- a/os/hal/ports/STM32/LLD/TIMv1/hal_qei_lld.h +++ b/os/hal/ports/STM32/LLD/TIMv1/hal_qei_lld.h @@ -251,7 +251,7 @@ typedef enum { /** * @brief QEI counter type. */ -typedef uint16_t qeicnt_t; +typedef int16_t qeicnt_t; /** * @brief QEI delta type. diff --git a/os/hal/src/hal_qei.c b/os/hal/src/hal_qei.c index eb6223e0..9b084f70 100644 --- a/os/hal/src/hal_qei.c +++ b/os/hal/src/hal_qei.c @@ -364,7 +364,7 @@ qeidelta_t qeiUpdateI(QEIDriver *qeip) { "invalid state"); cnt = qei_lld_get_count(qeip); - delta = cnt - qeip->last; + delta = (qeicnt_t)(cnt - qeip->last); qeip->last = cnt; return delta; From 546ac1d584b7b43cb05954164ea05431d2f00796 Mon Sep 17 00:00:00 2001 From: Nicolas Reinecke Date: Mon, 5 Dec 2016 01:37:32 +0100 Subject: [PATCH 4/4] STM32: fix USB HOST HS when cpu is in sleep mode --- os/hal/ports/STM32/LLD/USBHv1/hal_usbh_lld.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 523f14d0..89474903 100644 --- a/os/hal/ports/STM32/LLD/USBHv1/hal_usbh_lld.c +++ b/os/hal/ports/STM32/LLD/USBHv1/hal_usbh_lld.c @@ -1361,7 +1361,8 @@ static void _usbh_start(USBHDriver *usbh) { if (&USBHD2 == usbh) { #endif /* OTG HS clock enable and reset.*/ - rccEnableOTG_HS(FALSE); + rccEnableOTG_HS(TRUE); // Enable HS clock when cpu is in sleep mode + rccDisableOTG_HSULPI(TRUE); // Disable HS ULPI clock when cpu is in sleep mode rccResetOTG_HS(); otgp->GINTMSK = 0;