Commit graph

139 commits

Author SHA1 Message Date
Johann Fischer 627c04f962 drivers: usb_dc_stm32: remove confusing comments
The comments at the beginning of the file are not quite correct
and instructions regarding configuration are not necessary at all.
Also remove the redundant first line.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-02-24 12:01:50 +01:00
Kumar Gala b275fec8c4 soc: stm32: convert to use DEVICE_DT_GET for clocks
Convert from device_get_binding to DEVICE_DT_GET.  In doing this we
no longer need the label in the devicetree node so we remove that.

Removed all __ASSERT_NO_MSG(clk) since we'll get a build error if
DEVICE_DT_GET cant be satisfied, and the clock control api's will
handle reporting if the device_is_ready.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-02-16 17:01:37 -06:00
Jacob Siverskog 6e0ef1cdd9 drivers: usb: stm32: fix potential null pointer dereference
perform null pointer check before dereferencing.

Signed-off-by: Jacob Siverskog <jacob@teenage.engineering>
2021-02-16 15:27:59 +03:00
Attie Grande 78627a5feb usb: stm32: added support for USB Device mode on STM32F105xx parts
The STM32F105xx USB clock goes through a prescaler either PLL1 x2 /2
or PLL1 x2 /3, the output of this must be 48 MHz. As such, the output
of PLL1 must be 48 MHz or 72 MHz.

NOTE: This requires that the system is running from PLL1 (PLLCLK).
      Support for running from PLL2 will be implemented in the future.

Signed-off-by: Attie Grande <attie.grande@argentum-systems.co.uk>
2021-01-10 12:42:40 -05:00
Martin Jäger 0636b42c81 drivers: usb: stm32: use generic LL headers
Use generic LL headers instead of depending on soc.h.

Signed-off-by: Martin Jäger <martin@libre.solar>
2020-11-30 15:50:03 +01:00
Erwan Gouriou a1cb59398b drivers/usb: stm32: Add support for pinctrl configuration
Enable configuration of USB signals in stm32 driver.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-10-22 10:34:14 -05:00
Erwan Gouriou 5a9eff1e1a drivers/usb: stm32: Clean up related to DT api usage
Few adjustments made to make the code a bit more readable.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-10-22 10:34:14 -05:00
Alexandre Bourdiol 5deb8ffe0c drivers: STM32: Rework CLK48 HSEM protection
Due to HSEM implementation #24862, USB CLK48 lock implementation
#25850 should be reworked.
And by the way, implement the same in entropy which is using the
same clock.

Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com>
2020-09-02 14:13:49 +02:00
Tomasz Bursztyka 4dcfb5531c isr: Normalize usage of device instance through ISR
The goal of this patch is to replace the 'void *' parameter by 'struct
device *' if they use such variable or just 'const void *' on all
relevant ISRs

This will avoid not-so-nice const qualifier tweaks when device instances
will be constant.

Note that only the ISR passed to IRQ_CONNECT are of interest here.

In order to do so, the script fix_isr.py below is necessary:

from pathlib import Path
import subprocess
import pickle
import mmap
import sys
import re
import os

cocci_template = """
@r_fix_isr_0
@
type ret_type;
identifier P;
identifier D;
@@
-ret_type <!fn!>(void *P)
+ret_type <!fn!>(const struct device *P)
{
 ...
(
 const struct device *D = (const struct device *)P;
|
 const struct device *D = P;
)
 ...
}

@r_fix_isr_1
@
type ret_type;
identifier P;
identifier D;
@@
-ret_type <!fn!>(void *P)
+ret_type <!fn!>(const struct device *P)
{
 ...
 const struct device *D;
 ...
(
 D = (const struct device *)P;
|
 D = P;
)
 ...
}

@r_fix_isr_2
@
type ret_type;
identifier A;
@@
-ret_type <!fn!>(void *A)
+ret_type <!fn!>(const void *A)
{
 ...
}

@r_fix_isr_3
@
const struct device *D;
@@
-<!fn!>((void *)D);
+<!fn!>(D);

@r_fix_isr_4
@
type ret_type;
identifier D;
identifier P;
@@
-ret_type <!fn!>(const struct device *P)
+ret_type <!fn!>(const struct device *D)
{
 ...
(
-const struct device *D = (const struct device *)P;
|
-const struct device *D = P;
)
 ...
}

@r_fix_isr_5
@
type ret_type;
identifier D;
identifier P;
@@
-ret_type <!fn!>(const struct device *P)
+ret_type <!fn!>(const struct device *D)
{
 ...
-const struct device *D;
...
(
-D = (const struct device *)P;
|
-D = P;
)
 ...
}
"""

def find_isr(fn):
    db = []
    data = None
    start = 0

    try:
        with open(fn, 'r+') as f:
            data = str(mmap.mmap(f.fileno(), 0).read())
    except Exception as e:
        return db

    while True:
        isr = ""
        irq = data.find('IRQ_CONNECT', start)
        while irq > -1:
            p = 1
            arg = 1
            p_o = data.find('(', irq)
            if p_o < 0:
                irq = -1
                break;

            pos = p_o + 1

            while p > 0:
                if data[pos] == ')':
                    p -= 1
                elif data[pos] == '(':
                    p += 1
                elif data[pos] == ',' and p == 1:
                    arg += 1

                if arg == 3:
                    isr += data[pos]

                pos += 1

            isr = isr.strip(',\\n\\t ')
            if isr not in db and len(isr) > 0:
                db.append(isr)

            start = pos
            break

        if irq < 0:
            break

    return db

def patch_isr(fn, isr_list):
    if len(isr_list) <= 0:
        return

    for isr in isr_list:
        tmplt = cocci_template.replace('<!fn!>', isr)
        with open('/tmp/isr_fix.cocci', 'w') as f:
            f.write(tmplt)

        cmd = ['spatch', '--sp-file', '/tmp/isr_fix.cocci', '--in-place', fn]

        subprocess.run(cmd)

def process_files(path):
    if path.is_file() and path.suffix in ['.h', '.c']:
        p = str(path.parent) + '/' + path.name
        isr_list = find_isr(p)
        patch_isr(p, isr_list)
    elif path.is_dir():
        for p in path.iterdir():
            process_files(p)

if len(sys.argv) < 2:
    print("You need to provide a dir/file path")
    sys.exit(1)

process_files(Path(sys.argv[1]))

And is run: ./fix_isr.py <zephyr root directory>

Finally, some files needed manual fixes such.

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-09-02 13:48:13 +02:00
Tomasz Bursztyka e18fcbba5a device: Const-ify all device driver instance pointers
Now that device_api attribute is unmodified at runtime, as well as all
the other attributes, it is possible to switch all device driver
instance to be constant.

A coccinelle rule is used for this:

@r_const_dev_1
  disable optional_qualifier
@
@@
-struct device *
+const struct device *

@r_const_dev_2
 disable optional_qualifier
@
@@
-struct device * const
+const struct device *

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-09-02 13:48:13 +02:00
Johann Fischer b95558dd9f drivers: usb: unify endpoint helper macros
Unify endpoint index and direction helper macros
across all usb device drivers.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-07-10 11:45:46 +02:00
Kumar Gala a1b77fd589 zephyr: replace zephyr integer types with C99 types
git grep -l 'u\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/u\(8\|16\|32\|64\)_t/uint\1_t/g"
	git grep -l 's\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/s\(8\|16\|32\|64\)_t/int\1_t/g"

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-06-08 08:23:57 -05:00
Pete Johanson f525a4b25a usb: stm32wb: Properly lock Sem5 before initializing USB.
* AN5289 notes that Sem5 should be held before configuring
  CLK48 for USB timing.

Signed-off-by: Pete Johanson <peter@peterjohanson.com>
2020-06-02 20:11:30 +02:00
Martí Bolívar 7e0eed9235 devicetree: allow access to all nodes
Usually, we want to operate only on "available" device
nodes ("available" means "status is okay and a matching binding is
found"), but that's not true in all cases.

Sometimes we want to operate on special nodes without matching
bindings, such as those describing memory.

To handle the distinction, change various additional devicetree APIs
making it clear that they operate only on available device nodes,
adjusting gen_defines and devicetree.h implementation details
accordingly:

- emit macros for all existing nodes in gen_defines.py, regardless
  of status or matching binding
- rename DT_NUM_INST to DT_NUM_INST_STATUS_OKAY
- rename DT_NODE_HAS_COMPAT to DT_NODE_HAS_COMPAT_STATUS_OKAY
- rename DT_INST_FOREACH to DT_INST_FOREACH_STATUS_OKAY
- rename DT_ANY_INST_ON_BUS to DT_ANY_INST_ON_BUS_STATUS_OKAY
- rewrite DT_HAS_NODE_STATUS_OKAY in terms of a new DT_NODE_HAS_STATUS
- resurrect DT_HAS_NODE in the form of DT_NODE_EXISTS
- remove DT_COMPAT_ON_BUS as a public API
- use the new default_prop_types edtlib parameter

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-05-08 19:37:18 -05:00
Pete Johanson 91d6139338 boards: arm: nucleo_wb55rg: Enable USB for stm32wb.
* Define USB driver for base stm32wb device.
* Enable USB for the nucleo_wb55rg board.
* Properly initialize USB power + clock for the platform.

Signed-off-by: Pete Johanson <peter@peterjohanson.com>
2020-05-06 10:46:23 -05:00
Kumar Gala 1ce133d0fe drivers: usb: usb_dc_stm32: Rename defines to remove DT_ prefix
We want to limit DT_ prefix to macros from devicetree.h and generation.
So rename DT_USB* to just USB*.

Also fixup how USB_MAXIMUM_SPEED was defined.  We should only define it
if the property exists.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-05-01 07:49:00 -05:00
Kumar Gala 22a41e4eb7 drivers: usb: usb_dc_stm32: Convert DT_COMPAT_ define usage to new macros
Convert driver from using DT_COMPAT_ST_STM32_* to new macro
DT_HAS_COMPAT(st_stm32_*).

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-23 05:58:17 -05:00
Kumar Gala 989484b4bf drivers: stm32: Convert STM32 drivers to new DT_INST macros
Convert older DT_INST_ macro use in STM32 drivers to the new
include/devicetree.h DT_INST macro APIs.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-26 12:22:12 -05:00
Erwan Gouriou 9367c6ad3f drivers/usb: usb_dc_stm32: Convert to DT_INST
Convert usb_stm32 driver to use of DT_INST macros.

Since driver is compatible with 3 different dt compatibles and
compatible string is included in DT_INST macros, I've kept the
DT_USB_ compatible agnostic macros based on DT_INST ones, which
allowed to remove fixup definitions.
Use of DT_USB symbols is now limited to usb_dc_stm32.

Additionally, compatible "st,stm32-otgfs" is removed from list
of compatibles for usbotg_hs ips.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-03-17 11:03:10 -06:00
Josh Gao b9d2028590 usb_dc_stm32: improve struct layout.
Put the one-byte sized fields next to each other to reduce padding.

Signed-off-by: Josh Gao <josh@jmgao.dev>
2020-03-10 18:32:47 +02:00
Josh Gao c4a7d96c04 usb_dc_stm32: reuse PMA buffer when possible.
Previously, endpoint configuration would reserve memory in the packet
memory area which would never be reclaimed. After this patch, endpoints
will reuse previously allocated memory when possible. We still leak
memory when reconfiguration increases the max packet size for a given
endpoint number, but this fixes the common case.

Bug: https://github.com/zephyrproject-rtos/zephyr/issues/23178
Signed-off-by: Josh Gao <josh@jmgao.dev>
2020-03-10 18:32:47 +02:00
Erwan Gouriou 557d263354 dts: stm32f3: Remap USB IRQ to avoid conflict with CAN
On stm32f302/3 series, USB and CAN_1 share same IRQ lines.
To use USB and CAN_1 together, USB IRQ could be remap to other
line numbers, on which there is no conflict.
Remap the USB IRQ lines by default:
-Assign remap number in matching dtsi files
-Perform remap before usb driver init

Additionally, fix compilation issue in usb driver.

Fixes #22343

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-02-18 18:44:42 +02:00
Yannis Damigos ee351328a4 usb_dc_stm32: Convert usb disconnect gpio to new gpio api
Convert usb disconnect gpio to new gpio api.
Updates device tree for the olimexino_stm32.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2020-02-05 12:00:36 +01:00
Peter Bigot 0b0d2e640b treewide: use full path to clock_control/stm32_clock_control.h header
The build infrastructure should not be adding the drivers subdirectory
to the include path.  Fix the legacy uses that depended on that
addition.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-01-26 17:52:12 +01:00
Erwan Gouriou 136d92de33 drivers/usb/device: stm32: Update due to API change on F0/F3/L0
Following update of STM32Cube packages for series F0/L0/F3,
a new file ll_usb.h is now available for these series.
As a consequence, specific hanlding is no more requested for this
series is stm32 usb_device driver.

Fixes #21962

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-01-16 10:09:58 -05:00
Johann Fischer d4ba8fff66 drivers: usb_dc_stm32: do not restrict out stage transfers to one MPS
Do not restrict control out stage transfers to one MPS.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-11-21 11:33:41 +01:00
Richard Osterloh 37514ae660 drivers: usb: Add STM32G4X USB support
Add USB driver support for STM32G4X SoC series.

Signed-off-by: Richard Osterloh <richard.osterloh@gmail.com>
2019-10-04 18:44:24 -07:00
Ulf Magnusson e833fafd4b drivers: usb: stm32: Fix broken DT_USB_ENABLE_PIN_REMAP test
'enable-pin-remap' is defined as 'type: boolean' in
dts/bindings/usb/st,stm32-usb.yaml, so it generates either

    #define DT_USB_ENABLE_PIN_REMAP 1

or

    #define DT_USB_ENABLE_PIN_REMAP 0

depending on if 'enable-pin-remap;' appears on the node or not.

Since a macro is always generated, #ifdef won't work. The test needs to
be this instead:

    #if DT_USB_ENABLE_PIN_REMAP == 1

(Should be careful with '#if HMZ == 0' though, because it's true even if
HMZ is undefined.)

This behavior was inherited from the old scripts, and some things depend
on it, e.g. by expanding macros in initializers.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-09-24 09:36:31 -07:00
Francois Ramu 474c99c9ef drivers: usb/stm32: use dts information to populate clock settings
This patch populates "clocks" property in stm32 usb nodes
for clock related usb configuration code of each  dtsi files

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2019-07-16 09:08:51 -04:00
Yannis Damigos 2d537f49a9 usb_dc_stm32: Don't update ret_bytes if send fails in usb_dc_ep_write()
Don't update ret_bytes if send fails in usb_dc_ep_write().

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2019-07-02 19:05:37 -04:00
Erwan Gouriou 6b40394df9 drivers/usb/device: stm32: Remove reference to unsupported low speed
Low speed isn't supported in device mode for any of the STM32
references.
Remove the code that refer to it.

Fixes #17114

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2019-06-28 06:16:10 -04:00
Anas Nashif a2fd7d70ec cleanup: include/: move misc/util.h to sys/util.h
move misc/util.h to sys/util.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 6aa9c3a68f cleanup: include/: move gpio.h to drivers/gpio.h
move gpio.h to drivers/gpio.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Andrei Emeltchenko d385db0884 usb: drivers: usb_dc_stm32: Fix coverity issue
Fixes coverity issue CID: 198865.

Fixes #16582

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-06-19 11:08:26 +02:00
Andrei Emeltchenko 1d61bef39e usb: drivers: usb_dc_stm32: Fix coverity issue
Add __ASSERT() for coverity issue CID: 198874. Assert is used instead
of check since this is callback we get from stm32cube.

Fixes #16573

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-06-19 11:08:26 +02:00
Kumar Gala a2693975d7 dts: Convert from DT_<COMPAT>_<INSTANCE>_<PROP> to DT_INST...
Change code from using now deprecated DT_<COMPAT>_<INSTANCE>_<PROP>
defines to using DT_INST_<INSTANCE>_<COMPAT>_<PROP>.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-06-14 08:02:15 -05:00
Yannis Damigos a1e3f39214 usb_dc_stm32: Check if functions' arguments are valid
Check if usb_dc_* functions' arguments are valid.
Fixes `tests/subsys/usb/device` on STM32 SoCs.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2019-05-20 13:01:41 -04:00
Andrei Emeltchenko 5a4a658de1 usb: usb_dc_stm32: Return EAGAIN on lock failure
Return -EAGAIN on k_sem_take() failure to take write lock, the error
code is similar to nrfx write_in_progress flag.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-05-06 11:14:24 +02:00
Andrei Emeltchenko 8d6fbde898 usb: Remove usb_dc_ep_set_callback return code
Make usb_dc_ep_set_callback() return void since the code is never
used.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-04-28 12:22:23 -04:00
Andrei Emeltchenko f6784ed1d7 usb: usb_dc_stm32: Add missing function
Add missing API functions which will be tested with harness tests.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-04-18 12:16:05 -04:00
Josef Gajdusek f01a7250f0 drivers: usb_dc_stm32: Reinitialize the write semaphores on bus reset
If the user attempts to send data before the USB connection is
established (see the HID sample for an example of such code), the
DataInCallback never gets called which leaves the write semaphore in a
taken state forever.

Signed-off-by: Josef Gajdusek <atx@atx.name>
2019-04-17 09:58:09 -05:00
Josef Gajdusek 29ffcae80c drivers: usb_dc_stm32: Make pin remapping part of the device tree
The SYSCFG_CFGR1_PA11_PA12_RMP define is present even on packages where
the remap isn't strictly required. This commit makes the remap optional
based on a DT property.

Also fixes syntax error caused by a missing );.

Signed-off-by: Josef Gajdusek <atx@atx.name>
2019-04-17 09:58:09 -05:00
Johann Fischer c13e201b18 usb: replace MAX_PACKET_SIZE0 with meaningful USB_MAX_CTRL_MPS
Replace MAX_PACKET_SIZE0 with meaningful USB_MAX_CTRL_MPS.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-04-11 13:35:24 -04:00
Andrei Emeltchenko 8ed215e011 usb: usb_dc_stm32: Fix reading invalid EP
Fix crash when reading invalid endpoint found in harness test.

Fixes #13560

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-04-05 16:12:46 -04:00
Andrei Emeltchenko 06ef0ca0fc usb: usb_dc_stm32: Add placeholders for missing API
Fix build error when executing sanitycheck on stm32 devices.

Command to execute tests:
sanitycheck --device-testing --device-serial /dev/ttyACM0 -p <board>
    -t usb

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-04-05 16:12:46 -04:00
Patrik Flykt 24d71431e9 all: Add 'U' suffix when using unsigned variables
Add a 'U' suffix to values when computing and comparing against
unsigned variables.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-28 17:15:58 -05:00
Carlos Stuart 75f77db432 include: misc: util.h: Rename min/max to MIN/MAX
There are issues using lowercase min and max macros when compiling a C++
application with a third-party toolchain such as GNU ARM Embedded when
using some STL headers i.e. <chrono>.

This is because there are actual C++ functions called min and max
defined in some of the STL headers and these macros interfere with them.
By changing the macros to UPPERCASE, which is consistent with almost all
other pre-processor macros this naming conflict is avoided.

All files that use these macros have been updated.

Signed-off-by: Carlos Stuart <carlosstuart1970@gmail.com>
2019-02-14 22:16:03 -05:00
Yannis Damigos 6a676caab6 usb_dc_stm32: Fix check endpoint capabilities
DT_USB_NUM_BIDIR_ENDPOINTS includes EP0, which we should not
take it into account when we check endpoint capabilities

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2019-02-09 16:58:22 -06:00
Kumar Gala 9e4016d8dc usb: usb_dc_stm32: Convert to DT instance defines to remove dts_fixup.h
Convert usb_dc_stm32 driver GPIO disconnect to use new defines so we
can remove the dts_fixup.h code for it.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-01 04:12:15 -06:00
Kumar Gala 0370dbee4a usb: usb_dc: Replace CONFIG_ symbols that should be DT_
1. Fix trailing comment for DT_USBHS_MAXIMUM_SPEED
2. Fix missed CONFIG_USB_HS_BASE_ADDRES that should be
   DT_USB_HS_BASE_ADDRESS

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-01 04:08:26 -06:00
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