Commit graph

139 commits

Author SHA1 Message Date
Loic Poulain a32a39f3d2 drivers: usb_dc_stm32: Add support for MSI clock
When MSI clock is available and in PLL-Mode (high accuracy), use it as
USB source clock. This allows to enable USB on STM34l475 disco iot
board without having to add external oscillator.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2019-01-02 09:33:21 -05:00
Aurelien Jarno c52a64624e drivers: usb_dc_stm32: add support for SoF event
Add support for SoF events to the USB STM32 device driver. When
CONFIG_USB_DEVICE_SOF is enabled, enable the corresponding interrupt
and provide a non-weak callback function calling status_cb.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-12-17 08:17:58 -06:00
Erwan Gouriou 9062e97a45 drivers: stm32: check clock_control_on return value
Check clock_control_on return value now that it is checking appropriate
bus is used in the request.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2018-12-07 11:31:48 -05:00
Patrik Flykt 8ff96b5a57 drivers: Add 'U' to unsigned variable assignments
Add 'U' to a value when assigning it to an unsigned variable.
MISRA-C rule 7.2

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-12-04 22:51:56 -05:00
Yannis Damigos 954a943854 drivers: usb_dc_stm32: Use DT to check if USBPHYC exists
Use DT to check if SoC has a USBPHYC controller.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-11-15 07:27:23 -06:00
Andrzej Głąbek 20202902f2 dts_fixups: Use DT_ prefix in all defined labels not related to Kconfig
These changes were obtained by running a script  created by
Ulf Magnusson <Ulf.Magnusson@nordicsemi.no> for the following
specification:

1. Read the contents of all dts_fixup.h files in Zephyr
2. Check the left-hand side of the #define macros (i.e. the X in
   #define X Y)
3. Check if that name is also the name of a Kconfig option
   3.a If it is, then do nothing
   3.b If it is not, then replace CONFIG_ with DT_ or add DT_ if it
       has neither of these two prefixes
4. Replace the use of the changed #define in the code itself
   (.c, .h, .ld)

Additionally, some tweaks had to be added to this script to catch some
of the macros used in the code in a parameterized form, e.g.:
- CONFIG_GPIO_STM32_GPIO##__SUFFIX##_BASE_ADDRESS
- CONFIG_UART_##idx##_TX_PIN
- I2C_SBCON_##_num##_BASE_ADDR
and to prevent adding DT_ prefix to the following symbols:
- FLASH_START
- FLASH_SIZE
- SRAM_START
- SRAM_SIZE
- _ROM_ADDR
- _ROM_SIZE
- _RAM_ADDR
- _RAM_SIZE
which are surprisingly also defined in some dts_fixup.h files.

Finally, some manual corrections had to be done as well:
- name##_IRQ -> DT_##name##_IRQ in uart_stm32.c

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2018-11-13 10:44:42 -06:00
Andrei Emeltchenko 17f7abd3dc usb: logs: Rename USB_ERR to LOG_ERR
Since logger is now suitable for our logs use it directly.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-08 08:35:20 -05:00
Andrei Emeltchenko 92c7ab74c0 usb: logs: Rename USB_DBG to LOG_DBG
Since logger is now suitable for our logs use it directly.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-08 08:35:20 -05:00
Yannis Damigos c9007f0daf drivers: usb_dc_stm32: Add HIGH and HIGH_IN_FULL defines for L4 series
STM32L4 series USB LL API doesn't provide HIGH and HIGH_IN_FULL speed.
Define them on drivers level.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-10-10 12:27:55 -05:00
Carles Cufi 4fe661181c drivers: usb: stm32: Limit the amount of bytes to write
Limit the amount of bytes to write to EP0 to 64 bytes so that there is
no overflow or error when sending.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-10-09 21:37:51 +02:00
Yannis Damigos 3c9f1c9627 drivers: usb_dc_stm32: Get maximum-speed from DT
Get maximum-speed from device tree for OTG FS/HS.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-10-09 12:59:34 -04:00
Yannis Damigos 452c3d6a87 include/usb/usb_device: Add USB_* log macros
Add USB_DBG, USB_WRN, USB_ERR, USB_INF macros
in usb_device header file and remove them
from usb device drivers.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-10-08 12:54:57 -04:00
Yannis Damigos 1674d061b6 drivers: usb: device: Migrate to new logger
Move to new logger subsystem.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-10-08 12:54:57 -04:00
Andrei Emeltchenko 1f4e8d679b usb_dc_stm32: Fix FS mode
Fixes FS mode for STM32F7XX devices.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-07-24 22:27:17 -04:00
Yannis Damigos 48de3ec616 drivers: usb_dc_stm32: Add OTG HS full-speed PHY support
Enable the driver to work in full-speed mode on OTG HS
controller using its full-speed or high-speed internal
PHY.

Please note that only one interface should be enabled
at a time, OTG FS or OTG HS. The driver will raise an
error if both are enabled.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-07-24 22:27:17 -04:00
Johannes Hutter 6c0d089594 drivers: usb_dc_stm32: don't wait for semaphore in ISR context
usb_dc_ep_write may be executed in an ISR context and should therefore
not take a semaphore with a timeout. The semaphore was initially
introduced to prevent USB buffer overwrite when writing to an endpoint
in a loop. This is not requested anymore since there is an existing USB
transfer API available.

Signed-off-by: Johannes Hutter <johannes@proglove.de>
2018-07-05 11:06:30 -04:00
Aurelien Jarno 7688f49065 drivers: usb_dc_stm32: change all endpoints to bidirectional
The various STM32 reference manuals sometimes define the USB endpoints
as IN or OUT only and sometimes as bidirectional, even in the same
manual. This is likely because the OTG implementation has one set of
registers for the IN endpoints and one other set for OUT endpoints.
However at the end a given endpoint address can both transmit and
receive data.

This causes some confusion how to declare the endpoints in the device
tree, and depending on the SoC, they are either the same number of IN
and OUT endpoints declared, or they are declared as bidirectional. At
the end it doesn't really matter given how the driver uses those values:

    #define NUM_IN_EP (CONFIG_USB_NUM_BIDIR_ENDPOINTS + \
                       CONFIG_USB_NUM_IN_ENDPOINTS)

    #define NUM_OUT_EP (CONFIG_USB_NUM_BIDIR_ENDPOINTS + \
                        CONFIG_USB_NUM_OUT_ENDPOINTS)

    #define NUM_BIDIR_EP NUM_OUT_EP

This patch therefore cleanup the driver, the DTS, and the DTS fixups to
only define the number of bidirectional endpoints.

In addition to the cleanup, that fixes a regression introduced by commit
52eacf16a2 ("driver: usb: add check for endpoint capabilities"), which
introduced a wrong check for SoC only defining the number of
bidirectional endpoints.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-06-18 15:24:15 -04:00
Istvan Bisz 49554dd35a drivers: usb_dc_stm32: Change SYS_LOG_LEVEL
Suppress messages by DBG SYS_LOG_LEVEL setting:
[general] [ERR] usb_dc_ep_check_cap: ep 81, mps 64, type 2
[general] [ERR] usb_dc_ep_check_cap: ep 1, mps 64, type 2

Signed-off-by: Istvan Bisz <istvan.bisz@t-online.hu>
2018-06-17 10:49:16 -04:00
Johann Fischer 52eacf16a2 driver: usb: add check for endpoint capabilities
Add function to check capabilities of an endpoint.
Only basic properties are checked, especially on STM32
capabilities of different USB controller configurations
have to be considered in the future.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-06-15 11:02:05 +02:00
Aurelien Jarno 80a9b02200 drivers: usb_dc_stm32: enable VDDUSB on STM32L4x2
The STM32L4x2 SoCs need to control the isolation of the USB features
from VDDUSB. This is done through the PWR_CR2 bit USV, however the
current code checks for the PWR_CR2_PVME1 bit instead, which is only
available on Cat. 3 devices. This bug is also present int the HAL and
likely copied from there.

Replace the check by PWR_CR2_USV instead.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-05-24 09:42:30 -05:00
Yannis Damigos aec465968c drivers/usb_dc_stm32: Check if SYSCFG is enabled
Add a check to raise an error if SYSCFG is disabled,
before doing the pin remaping for F0 SoCs on QFN28
and TSSOP20 packages.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-05-14 09:45:40 -05:00
Yannis Damigos c9d5b56140 drivers/usb_dc_stm32: HSI48 requires VREFINT in L0
In STM32L0 series, HSI48 requires VREFINT and its buffer
with 48 MHz RC to be enabled. This patch enables
VREFINT reference for HSI48 oscillator.

Signed-off-by: Ilya Tagunov <tagunil@gmail.com>
Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-05-14 09:33:29 -05:00
Yannis Damigos 2a55fcf607 drivers/usb/usb_dc_stm32: Provide EP_TYPE_* defines for L0
USB LL API provides the EP_TYPE_* defines. STM32Cube does not
provide USB LL API for STM32L0 family. Map EP_TYPE_* defines
to PCD_EP_TYPE_* defines.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-05-14 09:33:29 -05:00
Yannis Damigos 3bbe87e171 dts/arm/st: Add usbotg_fs node to stm32l4 DT
Add otgfs (USB) node to stm32l4.dtsi.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-05-10 07:47:13 -05:00
Pushpal Sidhu e2b27d820d drivers: usb_dc_stm32: enable VDDUSB if needed
This is required on boards that isolate VDDUSB from the system.

Signed-off-by: Pushpal Sidhu <psidhu.devel@gmail.com>
2018-05-10 07:47:13 -05:00
Pushpal Sidhu b1478518c0 drivers: usb_dc_stm32: use HSI48 if available
This clock was designed to power crystal-less usb if available.

Signed-off-by: Pushpal Sidhu <psidhu.devel@gmail.com>
2018-05-10 07:47:13 -05:00
Yannis Damigos 47fe4ee78b dts/arm/st: Add USB support for stm32f070/72
Add USB support for stm32f072 and stm32f070 SoCs

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-05-10 07:47:13 -05:00
Yannis Damigos 38d2567e08 boards: olimexino_stm32: Add USB support
Add USB support to OLIMEXINO-STM32 board

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-05-10 07:47:13 -05:00
Yannis Damigos 55dada2592 drivers: usb_dc_stm32: Add usb disconnect pin support
Add usb disconnect pin support.
Some boards use a GPIO pin to controll a transistor,
which drives the pull-up resistor on USB DP pin.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-05-10 07:47:13 -05:00
Yannis Damigos 921bfeb05a drivers: usb_dc_stm32: Add support for all STM32 families
Add support for all STM32 families

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
Signed-off-by: qianfan Zhao <qianfanguijin@163.com>
2018-05-10 07:47:13 -05:00
Loic Poulain 9d1957fae1 usb_dc: Add usb_dc_ep_mps function
This function returns endpoint max packet size (mps).

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2018-03-16 14:45:24 -07:00
Loic Poulain 10923173a6 Revert "usb: stm32: Introduce transfer method"
This reverts commit b23d599682.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2018-03-16 14:45:24 -07:00
Yannis Damigos 899ed91506 drivers: usb_dc_stm32: Get USB configuration from DT
Use defines generated from DT.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-02-21 09:17:12 -06:00
Loic Poulain b23d599682 usb: stm32: Introduce transfer method
Transfer is an important concept of USB specification.
During a transfer, several packets can be transmitted.
Today the usb API only provides ep_read and ep_write
functions but the transfer concept is missing.

This is typically ok for basic drivers which don't have
to take care of how data is transfered/splitted.
However there are some drivers like CDC EEM, in which
transfer concept is important for packet management.

Moreover, current ep-write and ep_read method have a
different implementation in usb_dc_dw and usb_dc_stm32
device drivers. For example usb_dc_dw supports only
1-data-packet transfers due to its implementation.
This can increase latency and reduce performance.

I think this is something we need to fix/improve by
implementing better transfer management.

This patch introduces usb_dc_ ep_transfer method which
can be used to configure IN/OUT transfers. This allows
to configure and request different transfer sizes and
should prevent usage of the current stm32 temporary
buffer.

This method has asynchronous and synchronous mode.
Synchronous mode waits for transfer completion before
returning. Asynchronouse mode (irq safe) configures
the transfer and returns immediately, the provided
callback will be then called on transfer completion.

This also update ep_write and ep_read stm32 implementation
to use this new method but keep their behavior unchanged
for legacy reasons.

Note that for now this method is local to stm32 device
driver, however the goal would be to expose this function
as a new USB device driver API method so that class
drivers use it. This will request same implementation in
the usb_dc_dw_driver.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2018-01-29 11:26:48 -06:00
qianfan Zhao cd931bb7c4 usb: stm32: add usb_dc_ep_read_wait/conitinue
usb mass example need usb_dc_ep_read_wait/continue API.
test usb mass storage with RAM DISK on stm32f4 series.

Signed-off-by: qianfan Zhao <qianfanguijin@163.com>
2018-01-29 11:26:48 -06:00
Loic Poulain fa2da6713b usb: stm32: Fix null dereference in ep_write
ret_bytes param is optional and then can be NULL.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2017-11-09 09:13:14 -05:00
Loic Poulain 4a2e967a87 usb: stm32: Fix TX FIFO overwrite
In the same way as dw driver, check that FIFO is empty before
writing any new data. This patch introduces a boolean semaphore
which is requested before any new TX transfer and released on
transfer completion.

This fixes usb-ecm support on 96b_carbon board.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2017-11-09 09:13:14 -05:00
David B. Kinder 4600c37ff1 doc: Fix misspellings in header/doxygen comments
Occasional scan for misspellings missed during PR reviews

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-10-17 19:40:29 -04:00
Loic Poulain 8a11f91252 usb: Add support for STM32 family USB driver
This is a USB controller driver for STM32F4xx devices using
the STM32 Cube HAL_PCD framework. This has been tested with
the cdc_acm driver on a 96b_carbon board (STM32F401RE).

This is a refactoring of:
usb: usb_dc_stm: Add support for STM32Cube HAL_PCD USB driver
Signed-off-by: Christer Weinigel <christer@weinigel.se>
[daniel.thompson@linaro.org: Removed STM32F40(157) defconfig changes
together with STM32F4Discovery pinmux and defconfig changes, updated
clock settings and pad configuration to match latest mainline]
Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>
[giannis.damigos@gmail.com: Change uint*_t types to u*_t types,
change SYS_LOG_USB_DC_STM_LEVEL to SYS_LOG_USB_DRIVER_LEVEL and
update pinmux to match latest arm branch]
Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2017-10-17 09:14:47 -04:00