Commit graph

243 commits

Author SHA1 Message Date
Michael Hope 11ed1e1faf spi: sam0: use Device Tree for configuration.
Define a Device Tree binding for the SAM0 SPI and use it instead of
Kconfig for enabling / disabaling instances

Signed-off-by: Michael Hope <mlhx@google.com>
2018-02-23 21:24:59 +01:00
Anas Nashif 8949233390 kconfig: fix more help spacing issues
Fix Kconfig help sections and add spacing to be consistent across all
Kconfig file. In a previous run we missed a few.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-02-15 23:20:55 -05:00
Michael Hope 247782a7b3 sam0: move the UART and SPI configuration into pinmux.
Also pull out the SERCOM pads configuration to defines.  Note that the
SAM0 has a two level configuration - a signal (like TX) is mapped to a
pad, and then a pad is mapped to a function on a pin.

Signed-off-by: Michael Hope <mlhx@google.com>
2018-02-08 12:09:46 -06:00
Michael Hope ebfed3dca7 spi: sam0: fix txrx, NULL buffers, and add a stub async method.
This patches fixes a few bugs with the SAM0 driver:

- txrx was trasnmitting too many bytes
- adds support for NULL buffers to the fast paths
- fixes a NULL dereference on the rx buffer slow path

The tests under tests/driver/spi/spi_loopback now pass.

Signed-off-by: Michael Hope <mlhx@google.com>
2018-02-05 07:42:58 -08:00
Yannis Damigos a3474a2e2e drivers: spi_ll_stm32: Protect against null TX/RX buffer
TX/RX buffer may be NULL, so check them before use.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-02-01 08:19:49 -06:00
Yannis Damigos af0c9fc349 drivers: spi_ll_stm32: Enable SPI driver for F1 family
Enables SPI driver for STM32F1 SoCs

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-02-01 08:19:49 -06:00
Tomasz Bursztyka c968a85d85 drivers/spi: Properly check for rx/tx and buffering on
Current buffers might be configured to skip data, thus only len will be
set, buf will be NULL. Buffer should be used if only len is > 0 and
buffer is valid as well.

tx/rx are "on" if len is > 0
tx/rx buf should be touched if only len is > 0 _and_ buf != NULL.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2018-01-29 23:30:55 -05:00
Kumar Gala f06a1d84ed spi: sort drivers into legacy or not in CMakeLists.txt
Sort the drivers to make it explicit of which drivers are supporting
the legacy API vs the new API.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-01-24 18:27:27 +05:30
Kumar Gala 80c4985342 spi: cleanup whitespace in CMakeLists.txt
Use tabs everywhere instead of spaces and tabs.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-01-24 18:27:27 +05:30
Erwin Rol 23bb4e6101 drivers: spi: stm32: use Kconfig to select HAL/LL sources
Use "select USE_STM32_LL_SPI" to select the needed STM32 LL files,
instead of editing ext/hal/st/stm32cube/CMakeLists.txt

Signed-off-by: Erwin Rol <erwin@erwinrol.com>
2018-01-23 08:46:16 -06:00
Yannis Damigos 3a03b28f87 drivers: spi_ll_stm32: Get SPI configuration from DT
Get SPI_*_BASE_ADDRESS, SPI_*_NAME, SPI_*_IRQ and
SPI_*_IRQ_PRI from DT.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-01-17 11:51:48 -06:00
Michael Hope 73d045e281 spi: add a SPI driver for the SAM0 series.
Impleentation is master only and uses polling to read and write.

Signed-off-by: Michael Hope <mlhx@google.com>
2018-01-13 07:39:05 -05:00
Michael Hope af0718dc3a spi: add Kconfig entries for SPI4 and SPI5.
The SAM0 series has up to 6 SPI ports.  Add Kconfig options to match.

Similar to the 9033fb2f01, this patch
only defines the fields that are currently used and skips ones like
GPIO and IRQ priority that aren't.

Signed-off-by: Michael Hope <mlhx@google.com>
2018-01-13 07:39:05 -05:00
Florian Vaussard 59f0c99f0e spi: stm32: Correctly apply CPOL and CPHA settings
SPI_MODE_GET() returns a bitfield. It is thus wrong to test if a bit is
set using the equality operator. The bit-wise AND operator must be used
instead.

This can be tested by setting the SPI in mode 3 (CPOL + CPHA). Currently
both tests will fail and the result is a SPI configured in mode 0. This
was confirmed using an oscilloscope. Applying the patch fixes the
polarity.

Signed-off-by: Florian Vaussard <florian.vaussard@gmail.com>
2018-01-11 19:00:19 -05:00
Neil Armstrong 7caa56f608 spi: spi_ll_stm32: Add support for STM32F0
Add support for STM32F0 similar to STM32F3 and STM32L4

Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
2018-01-11 19:00:19 -05:00
Vincent Veron aff88a2249 drivers: spi: add 16 bits word size support for stm32
Add 16 bits support when using SPI in master mode.

Signed-off-by: Vincent Veron <vincent.veron@st.com>
2017-11-15 07:19:34 -06:00
Sebastian Bøe 0829ddfe9a kbuild: Removed KBuild
Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
Sebastian Bøe 12f8f76165 Introduce cmake-based rewrite of KBuild
Introducing CMake is an important step in a larger effort to make
Zephyr easy to use for application developers working on different
platforms with different development environment needs.

Simplified, this change retains Kconfig as-is, and replaces all
Makefiles with CMakeLists.txt. The DSL-like Make language that KBuild
offers is replaced by a set of CMake extentions. These extentions have
either provided simple one-to-one translations of KBuild features or
introduced new concepts that replace KBuild concepts.

This is a breaking change for existing test infrastructure and build
scripts that are maintained out-of-tree. But for FW itself, no porting
should be necessary.

For users that just want to continue their work with minimal
disruption the following should suffice:

Install CMake 3.8.2+

Port any out-of-tree Makefiles to CMake.

Learn the absolute minimum about the new command line interface:

$ cd samples/hello_world
$ mkdir build && cd build
$ cmake -DBOARD=nrf52_pca10040 ..

$ cd build
$ make

PR: zephyrproject-rtos#4692
docs: http://docs.zephyrproject.org/getting_started/getting_started.html

Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
Andrew Boie 0cb0447493 drivers: spi: add system call handlers
spi_transceive_async() omitted as we don't support k_poll objects
in user mode (yet).

The checking for spi_transceive() is fairly complex as we have to
validate the config struct passed in along with device instances
contained within it.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-10-30 13:20:19 -07:00
Sebastian Bøe b7eaeb9f0a cleanup: Use quote include instead of system include
When the header file is located in the same directory as the source
file it is better to use a relative quote-include, e.g.

than a system include like

Avoiding the use of system includes in these cases is beneficial
because;

* The source code will be easier to build because there will be fewer
system include paths.

* It is easier for a user to determine where a quote-include header
  file is located than where a system include is located.

* You are less likely to encounter aliasing issues if the list of
  system include paths is minimized.

Authors:
Anas Nashif
Sebastian Bøe

Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-10-28 07:11:53 -04:00
Marti Bolivar 1f244a7b1e drivers: spi: fix SPI_QMSI_SS typo
Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-10-16 11:58:50 -04:00
Marti Bolivar 5cb9578942 spi: stm32: fix clock prescaler calculation
The current prescaler calculation incorrectly fails to configure the
desired frequency when it is possible to match it exactly. Fix this.

Without this patch, if the user requests frequency N Hz, and there is
a SPI prescaler that can match this frequency exactly, the actual
frequency chosen by spi_stm32_configure() will be N/2 Hz.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-10-16 08:56:29 -07:00
Tomasz Bursztyka 53ca9a3f9b drivers/spi: Run CS/GPIO logic only when relevant
If given gpio dev pointer is NULL, it will silently ignore the CS
control.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-10-10 09:42:45 -04:00
Tomasz Bursztyka 24199b234c drivers/spi/stm32_ll: Configure NSS behavior according to cs pointer
If CS (Chip Select, known also as Slave Select...) is managed externaly
of the stm32_ll SPI controller, just config NSS line management
accordingly.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-10-10 09:42:45 -04:00
Anas Nashif 38e6e60dc5 spi: fix including spi_ll_stm32.h
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-10-03 14:50:14 -04:00
Tomasz Bursztyka 5405e93852 drivers/spi: Use sync_status relevantly in DW driver
Removing internal boolean in order to use the proper error code hold in
spi_context which was relevantly added in commit 6c717095b8.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-09-15 08:07:41 -04:00
Michał Kruszewski 12faf2cf92 spi: Allow updating TX and RX of spi context by multiple words.
Previous approach allowed only single word update for single
function call. Updating context in ISR was inefficient for
controllers supporting automatic multiple data packets transaction.

Signed-off-by: Michał Kruszewski <michal.kruszewski@nordicsemi.no>
2017-09-13 09:26:49 -04:00
Anas Nashif de8b88bb0b license: fix license identifiers
Also add copyright headers and license tags where missing.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-08-29 07:42:09 -04:00
Michał Kruszewski ddef35c1da spi context: Add function for getting single transfer buffers length.
Added function helps setting the longest possible rx and tx buffers for
single SPI transfer. Each of these buffers is a continuous memory
region. It is useful for example when peripheral supports easyDMA.

Signed-off-by: Michał Kruszewski <michal.kruszewski@nordicsemi.no>
2017-08-09 08:46:37 -04:00
Florian Vaussard 71b25a12c3 spim_nrf52: Prevent glitch on CS line in spim_nrf52_init()
The output state of the CS GPIO must be configured with a pull-up while
setting the GPIO as output. Otherwise the GPIO will be forced low,
before being set high by the call to spim_nrf52_csn(). This results in a
glitch of 1us on the CS line, which may confuse some ICs in the worst
case.

Signed-off-by: Florian Vaussard <florian.vaussard@gmail.com>
2017-08-08 11:20:46 -05:00
Florian Vaussard 9e0d1e4232 spim_nrf52: Fix fall-through in switch statement
When setting the SPIM speed to 8 MHz, the driver will return an error
due to a missing "break" causing the execution flow to reach the default
case.

Signed-off-by: Florian Vaussard <florian.vaussard@gmail.com>
2017-08-08 11:20:46 -05:00
Marti Bolivar f3b18bc2e9 drivers: spi: stm32: fix transmit/receive procedure
The transmit and receive procedure used in the STM32 SPI driver is not
correct.

On STM32F4, this is causing OVR errors (per the logged error mask) and
transmission of undesired 0x00 bytes (verified with a logic analyzer).

The root cause is that the receive register is not read (via DR, when
RXNE is set) each time the transmit register is written (also via DR,
when TXE is set). This clearly causes OVR errors when there is no
FIFO, as the receive register needs to be read each time a frame is
transceived, or the IP block has no way of knowing that the
overwritten data were not important.

Adapt the I/O procedure so that every DR write is matched by a DR
read, blocking until the relevant flags are set if necessary.

This behavior is suboptimal for targets such as STM32L4, where there
is a SPI FIFO. However, SPI I/O is broken on those targets, and this
patch fixes them as well. Further optimizations for targets with FIFOs
is left to future work.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-08-08 07:45:35 -04:00
Marti Bolivar 4298772248 drivers: spi: stm32: add error checking to polled mode
With some other issues in polled mode now resolved, add error handling
and report a valid error status when releasing the context.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-08-08 07:45:35 -04:00
Marti Bolivar d5ee0cfbf9 drivers: spi: stm32: remove extraneous unaligned macros
Byte access is always naturally aligned; there's no need to use
UNALIGNED_GET or UNALIGNED_PUT. Those would only be needed when
supporting 16-bit data frames.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-08-08 07:45:35 -04:00
Marti Bolivar 78214d0569 drivers: spi: stm32: fix SPI being left on in slave mode
The current implementation unconditionally enables the SPI (sets
SPI_CR1_SPE) in transceive(), but disables it only in master mode.

The peripheral should only be enabled while the user has specifically
requested I/O. Fix this by always disabling the peripheral when I/O is
complete.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-08-08 07:45:35 -04:00
Marti Bolivar b13b2c591e drivers: spi: stm32: factor out completion routine
Polled and IRQ-driven SPI I/O share code for cleanup and completion,
which can now be factored into its own routine.

This keeps a single point of truth for common paths, which will allow
a subsequent bug fix to happen in one place, and help avoid future
regressions.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-08-08 07:45:35 -04:00
Marti Bolivar a6c481d36d drivers: spi: stm32: fix bugs in polled mode
In polled mode, the STM32 SPI driver is signaling completion when
there are no waiters:

- the only spi_context_wait_for_completion() caller in this driver is
  in the IRQ-driven portion of transceive() itself, which isn't
  compiled in polled mode.

- the "asynchronous completion + polled I/O" combination is not
  supported by the driver, so there are no other threads polling on
  this I/O we need to signal completion to.

What should be happening instead of signaling completion is releasing
the chip select pin, which polled I/O currently doesn't do.

Fix these issues.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-08-08 07:45:35 -04:00
Marti Bolivar 7b0f0f801c drivers: spi: stm32: fix hardware NSS management
The LL_SPI_NSS_* macros used in spi_stm32_configure() when
hardware-based NSS management is requested are incorrect; fix them.

In master mode, this seems like a copy/paste error. The slave mode
case is likely due to following incorrect documentation in the ST LL
headers.

Note that in my testing on STM32F4, NSS appears to be open drain when
managed by hardware, making that configuration harder to test (and
probably less useful).

Details for the curious:

    The ST LL headers (for example stm32f4xx_ll_spi.h) claim
    LL_SPI_NSS_HARD_INPUT is to be used only in master mode, and
    LL_SPI_NSS_HARD_OUTPUT is to be used in slave mode.

    The opposite is true: when NSS is not handled by software, the SPI
    peripheral is responsible for driving NSS as an output, and the
    slave peripheral is responsible for reading it as an input.

    This is an error in the LL header files; the reference manuals and
    the other LL code make this clear.

    - The ST reference manuals specify that LL_SPI_HARD_OUTPUT (which
      corresponds to SSM unset, SSOE set) is a master-only
      configuration.  For example, STM32 RM0368 says:

        "NSS output enabled (SSM = 0, SSOE = 1)

        This configuration is used only when the device operates in
        master mode."

    - LL_SPI_HARD_INPUT (SSM unset, SSOE unset) is either a master or
      a slave configuration; in the slave case (which is what we're
      interested in here), it corresponds to the "usual" NSS
      input. RM0368, again:

        "NSS output disabled (SSM = 0, SSOE = 0)

        This configuration allows multimaster capability for devices
        operating in master mode. For devices set as slave, the NSS
        pin acts as a classical NSS input: the slave is selected when
        NSS is low and deselected when NSS high."

      The LL_SPI_StructInit() implementations similarly combine
      LL_SPI_MODE_SLAVE with LL_SPI_NSS_HARD_INPUT.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-08-08 07:45:35 -04:00
Marti Bolivar 69bc5ebdf3 drivers: spi: stm32: add error checking to IRQ mode
Now that struct spi_context supports passing errors from
interrupt-driven I/O handlers to waiting threads, we can enable error
interrupts and propagate errors to spi_transceive() callers.

To make it easier for users to debug SPI-related issues, log any error
bits set in SR when failures occur.

A subsequent patch will add error checking to polled mode as well, but
other cleanups and fixes will go in first to make this easier.

Note that this breaks the spi_loopback test on some targets, but it's
not a regression, as it wasn't working properly anyway. Subsequent
patches the bugs that this error checking has exposed.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-08-08 07:45:35 -04:00
Marti Bolivar 6c717095b8 drivers: spi: report synchronous completion status
The SPI API allows waiters to block until SPI I/O has completed. The
asynchronous subset of the API allows waiters to learn a status value
for the result of the I/O. However, the synchronous API does not allow
this.

Due to this limitation, synchronous API users cannot learn when
interrupt-driven I/O fails, which precludes proper error handling.

Resolve this limitation by adding a sync_status field to struct
spi_context, and using it to return operation results to the waiter.

Since there is only one status field, reduce the maximum number of
supported waiters from UINT_MAX to 1. This is not a problem for
current users, which all wait with the entire context locked.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-08-08 07:45:35 -04:00
Marti Bolivar ec3aece97c drivers: spi: avoid undefined behavior
Void pointer arithmetic is undefined behavior (UB).

It's OK for struct spi_buf to contain a void *, because those values
are only ever stored, read, and compared. However, pointer arithmetic
is done on the tx_buf and rx_buf fields in struct spi_context, so
those need to be u8_t * to avoid UB.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-08-08 07:45:35 -04:00
Nathan Loretan 88e166f6e9 drivers: spi: nRF5x: Fix clock polarity and phase config
Fix clock polarity and phase configuration by using correct
bit shifted configuration values.

Also, fixed SPIM1 config struct initialization that referred
to wrong SPI0 value.

Signed-off-by: Nathan Loretan <nathan.loretan@nordicsemi.no>
2017-08-01 12:51:06 -05:00
Michał Kruszewski afa90859e9 nrf5: spi: Mark SPI drivers as conforming to legacy SPI API
Signed-off-by: Michał Kruszewski <michal.kruszewski@nordicsemi.no>
2017-07-31 10:05:19 -05:00
Leandro Pereira 732424f065 drivers, net: Clean up semaphore initialization
Change the common "init with 0" + "give" idiom to "init with 1".  This
won't change the behavior or performance, but should decrease the size
ever so slightly.

This change has been performed mechanically with the following
Coccinelle script:

    @@
    expression SEM;
    expression LIMIT;
    expression TIMEOUT;
    @@

    - k_sem_init(SEM, 0, LIMIT);
    - k_sem_give(SEM);
    + k_sem_init(SEM, 1, LIMIT);

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-07-27 15:23:07 -04:00
Marti Bolivar 3ac9ca0859 spi: dw: fix spi_dw_init()
It is incorrect to call spi_context_release() on a
spi_dw_data object's ctx field before data->ctx->config is first
set in spi_dw_configure(). This is because spi_context_release()
reads ctx->config->operation. In particular, during spi_dw_init(),
calling spi_context_release() reads the uninitialized memory in
spi->ctx->config->operation.

Call spi_context_unlock_unconditionally() instead to properly increase
the semaphore count.

Without this patch, the first call to spi_transceive() can block
forever depending on the value of the uninitialized memory holding
spi->ctx->config->operation.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-07-14 18:10:38 +03:00
Marti Bolivar 6318750837 spi: stm32: fix spi_stm32_init()
It is incorrect to call spi_context_release() on an STM32
spi_stm32_data object's ctx field before data->ctx->config is first
set in spi_stm32_configure(). This is because spi_context_release()
reads ctx->config->operation. In particular, during spi_stm32_init(),
calling spi_context_release() reads the uninitialized memory in
data->ctx->config->operation.

Call spi_context_unlock_unconditionally() instead to properly increase
the semaphore count.

Without this patch, the first call to spi_transceive() can block
forever depending on the value of the uninitialized memory holding
data->ctx->config->operation.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-07-14 18:10:38 +03:00
Andrew Boie 65a9d2a94a kernel: make K_.*_INITIALIZER private to kernel
Upcoming memory protection features will be placing some additional
constraints on kernel objects:

- They need to reside in memory owned by the kernel and not the
application
- Certain kernel object validation schemes will require some run-time
initialization of all kernel objects before they can be used.

Per Ben these initializer macros were never intended to be public. It is
not forbidden to use them, but doing so requires care: the memory being
initialized must reside in kernel space, and extra runtime
initialization steps may need to be peformed before they are fully
usable as kernel objects. In particular, kernel subsystems or drivers
whose objects are already in kernel memory may still need to use these
macros if they define kernel objects as members of a larger data
structure.

It is intended that application developers instead use the
K_<object>_DEFINE macros, which will automatically put the object in the
right memory and add them to a section which can be iterated over at
boot to complete initiailization.

There was no K_WORK_DEFINE() macro for creating struct k_work objects,
this is now added.

k_poll_event and k_poll_signal are intended to be instatiated from
application memory and have not been changed.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-07-10 11:44:56 -07:00
Neil Armstrong 9033fb2f01 spi: add SPI driver for STM32 family
Add a SPI master and slave driver for the L4, F4 and F3 STM32
SoCs families.

Change-Id: I1faf5c97f992c91eba852fd126e7d3b83158993d
Origin: Original
Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
Tested-by: Jorge Ramirez-Ortiz <jorge.ramirez-ortiz@linaro.org>
Tested-by: Lee Jones <lee.jones@linaro.org>
2017-07-01 08:36:51 -04:00
Savinay Dharmappa 114db109ef samples: drivers/net: apps: Resolve Kconfig dependency
as config SPI_CS_GPIO was selecting GPIO instead it
should just depend on it. This patch is a fix for
ZEP-2071 jira.

Signed-off-by: Savinay Dharmappa <savinay.dharmappa@intel.com>
2017-06-22 19:51:05 -04:00
Kumar Gala b71b86ed03 spi: Cleanup use of C99 types
We introduced some see C99 types, so convert them over to the Zephyr
types.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-06-22 13:47:28 -04:00