Commit graph

103 commits

Author SHA1 Message Date
Henrik Brix Andersen c0c8952739 shell: do not enable subsystem/driver shell modules by default
Do not enable subsystem/driver shell modules by default and stop abusing
CONFIG_SHELL_MINIMAL, which is internal to the shell subsystem, to decide
when to enable a driver shell.

The list of shell modules has grown considerably through the
years. Enabling CONFIG_SHELL for doing e.g. an interactive debug session
leads to a large number of shell modules also being enabled unless
explicitly disabled, which again leads to non-negligible increases in
RAM/ROM usage.

This commit attempts to establish a policy of subsystem/driver shell
modules being disabled by default, requiring the user/application to
explicitly enable only those needed.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-11-20 09:21:40 +01:00
Nick Ward 2d65acca3a drivers: gpio: use gpio_is_ready_dt helper function
Update `struct gpio_dt_spec` use with gpio_is_ready_dt()

Signed-off-by: Nick Ward <nix.ward@gmail.com>
2023-08-28 08:48:35 -05:00
Petr Sharshavin 2489416ec2 drivers: lora: shell: fix invalid range in config bw param
'bw' parameter in 'lora config' command has a range of 0 to INT8_MAX.
However possible values of 'bw' (125, 250, 500) don't fit this range
and we need to extend it to 0 to INT16_MAX.

This fix has been tested on custom board with STM32L4 and SX1276.

Signed-off-by: Petr Sharshavin <sharshavin@mail.ru>
2023-05-25 08:22:08 +00:00
Kenneth J. Miller e78e8d7c3f drivers: lora: sx126x: Support fine-grained STM32WL PA config
Add STM32WL-specific sx126x_set_tx_params function based on the
STM32CubeWL modifications to LoRaMac-node.

Add the "power-amplifier-output" DT property to
"st,stm32wl-subghz-radio" for selecting between the RFO_LP and RFO_HP
output configurations provided by the above mentioned function.

Add the "rfo-lp-max-power" and "rfo-hp-max-power" DT properties for
defining the maximum design power of the respective outputs' matching
networks.

closes #48511

Signed-off-by: Kenneth J. Miller <ken@miller.ec>
2023-04-24 13:33:25 +02:00
Gerard Marull-Paretas 667eeb11fb shell: fix MISRA 5.7 violations on struct shell
MISRA Rule 5.7 requires uniqueness of tag identifiers. Shell is
frequently problematic because many code uses `const struct shell
*shell`. This causes CI noise every time one of these shell files is
edited, so let's update all of them with `const struct shell *sh`
instead.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-14 12:21:08 +02:00
Jordan Yates 41d83d7ea2 lora: compile drivers based on devicetree
Similar to the changes made in #48048, compile in the appropriate lora
modem driver when `CONFIG_LORA=y`. The `LORA_SX12XX` symbol has no
use now so remove. LoRa and LoRaWAN subsystems are still marked as
unstable so no additional deprecation cycle is needed.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2023-03-31 09:20:22 +02:00
Henrik Brix Andersen c41dd36de2 drivers: kconfig: unify menuconfig title strings
Unify the drivers/*/Kconfig menuconfig title strings to the format
"<class> [(acronym)] [bus] drivers".

Including both the full name of the driver class and an acronym makes
menuconfig more user friendly as some of the acronyms are less well-known
than others. It also improves Kconfig search, both via menuconfig and via
the generated Kconfig documentation.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-03-28 15:06:06 +02:00
Petr Sharshavin f5ae6ccfa8 drivers: lora: fix busy after sx12xx_lora_test_cw
The LoRa modem has been staying in STATE_BUSY
after sx12xx_lora_test_cw() call
because Radio.SetTxContinuousWave() doesn't configure the PHY
to raise 'TX done' event.

It runs TxTimeoutTimer instead,
so we have to handle 'TX timeout' event to correctly release the modem.

This fix has been tested on custom board with STM32L4 and SX1276.

Signed-off-by: Petr Sharshavin <sharshavin@mail.ru>
2023-02-23 09:25:39 +01:00
Bartosz Bilas e077fb73ec drivers: tests: replace usage of spi_is_ready with spi_is_ready_dt
`spi_is_ready` function is being deprecated in favor of
`spi_is_ready_dt` so let's replace the old usage in the tree.

Signed-off-by: Bartosz Bilas <bartosz.bilas@hotmail.com>
2022-12-07 09:40:23 -06:00
Gerard Marull-Paretas 178bdc4afc include: add missing zephyr/irq.h include
Change automated searching for files using "IRQ_CONNECT()" API not
including <zephyr/irq.h>.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-10-17 22:57:39 +09:00
Attie Grande c75fe75a23 drivers: lora: Return error from lora_send()
Previously, the lora_send() function would have returned zero regardless
of any error encountered while waiting for the transmit to complete.

Signed-off-by: Attie Grande <attie.grande@argentum-systems.co.uk>
2022-09-14 09:34:40 +00:00
Gerard Marull-Paretas 79e6b0e0f6 includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.

The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.

NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-09-05 16:31:47 +02:00
Kumar Gala 91fedca6e2 drivers: lora: Update drivers to use devicetree Kconfig symbol
Update lora drivers to use DT_HAS_<compat>_ENABLED Kconfig symbol
to expose the driver and enable it by default based on devicetree.

Signed-off-by: Kumar Gala <galak@kernel.org>
2022-09-01 10:25:51 +02:00
Tim Cooijmans 4c285fc53c drivers: lora: Add support for setting sync-word and iq-inverted
Add support for setting sync-word and iq-inverted in lora_modem_config. By
being able to set the sync-word it's possible to send "raw" public-network
packets using lora_send and using iq-inverted both uplink and downlink
messages can be sent.

Signed-off-by: Tim Cooijmans <timcooijmans@gmail.com>
2022-08-16 18:06:18 +02:00
Kumar Gala 998c03a603 drivers: lora: sx126x: Replace use of DT_INST_LABEL
As we work to phase out devicetree 'label' properties, convert
driver to just use sx126x instead of DT_INST_LABEL for logging
purposes.

Signed-off-by: Kumar Gala <galak@kernel.org>
2022-07-02 18:11:10 -05:00
Jordan Yates f12d36a51e lorawan: move REQUIRES_FULL_LIBC dependency
Move the `REQUIRES_FULL_LIBC` dependency from `config LORA` to
`config LORAWAN`. The commit that added the `select` (f590d4fa) mentions
that this is required by `loramac-node`, which is only used by LoRaWAN,
not the base LoRa code.

This results in small FLASH savings when compiling the samples, but can
result in larger savings in more complex applications:
```
// With REQUIRES_FULL_LIBC
west build -b 96b_wistrio zephyr/samples/drivers/lora/send/
[162/162] Linking C executable zephyr/zephyr.elf
Memory region         Used Size  Region Size  %age Used
           FLASH:       37708 B       128 KB     28.77%
            SRAM:        8832 B        32 KB     26.95%
        IDT_LIST:          0 GB         2 KB      0.00%

// Without REQUIRES_FULL_LIBC
[181/181] Linking C executable zephyr/zephyr.elf
Memory region         Used Size  Region Size  %age Used
           FLASH:       37444 B       128 KB     28.57%
            SRAM:        8832 B        32 KB     26.95%
        IDT_LIST:          0 GB         2 KB      0.00%
```

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2022-07-02 14:16:18 +02:00
Kumar Gala 7bb17e6fb7 lora: shell: Remove use of DT_LABEL
Remove DT_LABEL usage that is needed for device_get_binding, replace
this with DEVICE_DT_GET.

Signed-off-by: Kumar Gala <galak@kernel.org>
2022-06-09 22:01:00 -05:00
Gerard Marull-Paretas fb60aab245 drivers: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all drivers to the new
prefix <zephyr/...>. Note that the conversion has been scripted, refer
to #45388 for more details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-06 19:58:21 +02:00
Adrien Rouault bc47f66062 drivers: lora: sx127x: fix missing reset gpio instantiation
Instantiate the value of `sx127x` reset GPIO

Signed-off-by: Adrien Rouault <adrien.rouault@nemeus.fr>
2022-04-29 15:30:10 +02:00
Henrik Brix Andersen d4023b3c1b drivers: gpio: move non-standard dts flags to be soc specific
Reserve the upper 8 bits of gpio_dt_flags_t for SoC specific flags and
move the non-standard, hardware-specific GPIO devicetree flags (IO
voltage level, drive strength, debounce filter) from the generic
dt-bindings/gpio/gpio.h header to SoC specific dt-bindings headers.

Some of the SoC specific dt-bindings flags take up more bits than
necessary in order to retain backwards compatibility with the deprecated
GPIO flags. The width of these fields can be reduced/optimized once the
deprecated flags are removed.

Remove hardcoded use of GPIO_INT_DEBOUNCE in GPIO client drivers. This
flag can now be set in the devicetree for boards/SoCs with debounce
filter support. The SoC specific debounce flags have had the _INT part
of their name removed since these flag must be passed to
gpio_pin_configure(), not gpio_pin_interrupt_configure().

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-03-10 13:46:34 -05:00
Gerard Marull-Paretas 95fb0ded6b kconfig: remove Enable from boolean prompts
According to Kconfig guidelines, boolean prompts must not start with
"Enable...". The following command has been used to automate the changes
in this patch:

sed -i "s/bool \"[Ee]nables\? \(\w\)/bool \"\U\1/g" **/Kconfig*

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-03-09 15:35:54 +01:00
Krzysztof Chruscinski 47ae656cc1 all: Deprecate UTIL_LISTIFY and replace with LISTIFY
UTIL_LISTIFY is deprecated. Replacing it with LISTIFY.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-03-08 11:03:30 +01:00
Jordan Yates d9a74dda54 lora: sx126x: fix missing GPIO instantiation
Instantiate the values of `sx126x` GPIO's when they are present in
devicetree. This was missed in #42230.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2022-02-28 10:52:23 +01:00
Gerard Marull-Paretas ca7f291dd4 drivers: lora: sx12xx: use gpio_dt_spec
Simplify driver implementation by using gpio_dt_spec.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-02-21 22:16:10 -05:00
Gerard Marull-Paretas dc2c889948 drivers: lora: sx127x: use spi_dt_spec
Simplify driver implementation by using spi_dt_spec.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-02-21 22:16:10 -05:00
Gerard Marull-Paretas 4bcbbe571e drivers: lora: sx126x: use spi_dt_spec
Simplify driver implementation by using spi_dt_spec.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-02-21 22:16:10 -05:00
Marcin Niestroj becc1efe51 drivers: lora: shell: fix 'long' specifier in shell_error()
Replace '%s' with '%ld', so that 'long' value is properly printed with
shell_error(). This suppresses following warning:

  zephyr/drivers/lora/shell.c:181:23: warning: format '%s' expects \
      argument of type 'char *', but argument 4 has type 'long int' \
      [-Wformat=]
    181 |    shell_error(shell, "Invalid bandwidth: %s", lval);
        |                       ^~~~~~~~~~~~~~~~~~~~~~~  ~~~~
        |                                                |
        |                                                long int

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2022-02-01 14:25:38 -06:00
Jordan Yates 1bb7aa21b8 lora: sx126x: don't re-enable interrupt in sleep
Don't re-enable the DIO1 interrupt when the modem is in sleep mode. This
fixes the power regression introduced in Zephyr v2.7.0 #41026.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2022-01-04 10:02:24 -05:00
Gerard Marull-Paretas c759a35d08 drivers: use DT_INST_ENUM_IDX(_OR) macros
Replace `DT_ENUM_IDX(_OR)(DT_DRV_INST(...),` pattern with
`DT_INST_ENUM_IDX(_OR)(...,`.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-11-18 19:12:07 -05:00
Jordan Yates 526b3e9605 lora: asynchronous packet reception
Adds functionality to receive LoRa packets asynchronously. Reception
runs continuously until cancelled by another call to `lora_recv_async`.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2021-10-26 15:48:09 +02:00
Torsten Rasmussen bd61122aa2 kconfig: drivers: experimental settings now uses select EXPERIMENTAL
With the introduction of `EXPERIMENTAL` and `WARN_EXPERIMENTAL` in
Zephyr all drivers settings having `[EXPERIMENTAL]` in their
prompt has has been updated to include `select EXPERIMENTAL` so that
developers can enable warnings when experimental features are enabled.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2021-10-25 10:46:48 +02:00
Marcin Niestroj 47e10a6830 drivers: lora: fix RtcGetCalendarTime()
Uptime in milliseconds is assigned to uint32_t variable, which results
in integer overflow after enough time has expired. Additionally
milliseconds part (which should be 0-999) is assigned directly from
uptime, without subtracting full seconds.

Fix both issues by using int64_t variable and calculating milliseconds
with modulo.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-10-05 19:24:58 -04:00
Fabio Baltieri 23fbb19ed5 drivers: sx126x_stm32wl: clear the radio IRQ before reenabling it
The stm32wl version of the sx126x driver disables the NVIC interrupt in
the radio isr to prevent retriggering while the event gets handled in
the workqueue. Since the interrupt condition is still present while the
line is disabled, the interrupt pending bit remains set in the NVIC, so
after the handler finished, when irq_enable() gets called, the interrupt
fires immediately again with no status bit set in the radio registers.

Apart from the no-op interrupt, this has the side effect of bringing
the radio out of sleep as soon as the interrupt bit are read and
cleared, which increases the idle state power consumption.

Adding a NVIC_ClearPendingIRQ() before irq_enable() seems to fix the
problem. It should not cause any issue with missing interrupt events, as
if there are pending bit on the Radio, the NVIC pending bit would be
re-set immediately.

Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
2021-09-22 21:10:05 -05:00
Marcin Niestroj c910138ade drivers: lora: sx12xx: fix atomic include
Include sys/atomic.h instead of sys/atomic_builtin.h, so that build for
platforms with non-default atomic implementation will still succeed.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2021-08-20 11:32:45 -04:00
Jordan Yates 3cec3ac2a4 lora: detect failed transmissions
Detect failed transmissions using `lora_send` by only waiting for some
multiple of the actual on-air time before giving up.

We use this instead of the inbuilt TxTimeout functionality because the
value of this timeout is set by `lora_configure`, and therefore doesn't
change with different packet lengths. This is a limitation of the
underlying `RadioSend` function, not the Zephyr driver.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2021-08-18 05:16:46 -04:00
Jordan Yates 93b4dbcc19 lora: lora_send blocks until completion
Change the behaviour of `lora_send` to block until the transmission
completes. The current asynchronous behaviour is exposed through the
new function `lora_send_async`. This naming convention brings LoRa in
line with other asynchronous subsystems.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2021-08-18 05:16:46 -04:00
Fabio Baltieri d6731819e3 drivers: sx126x_standalone: use the correct dev_data for dio1 callback
The current code uses dev->data for finding back the instance data
structure in various places, but for the dio1 irq callback, dev refers
to the GPIO device node (not the LORA radio one), so dev->data returns a
pointer to the GPIO data rather than a "struct sx126x_data".

Fix that by using CONTAINER_OF to find back the correct structure from
the callback pointer.

The bug was introduced in:

  74efaa920a drivers: sx126x: refactor few functions for stm32wl support

Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
2021-08-16 04:57:41 -04:00
Jordan Yates d2363be091 lora: sx12xx_common: thread safe RX
Make the `lora_recv` operation thread safe by copying memory directly
in the callback instead of deferring copying to the original caller.

To ensure pointer validity, this requires performing operations "inside"
the `modem_release` context.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2021-08-08 04:19:27 -04:00
Jordan Yates 586a4bfc7d lora: sx12xx_common: thread-safe API
Ensure that the modem is not asked to perform new operations before the
previous operation completes.

An atomic variable is used instead of a mutex as multiple threads need
to release the lock. A semaphore isn't used as there is no indication
whether `k_sem_give` gives the semaphore or not, which is required to
determine if `Radio.Sleep()` should be run.

`Radio.Sleep()` is only ever run by the context that successfully
releases the modem usage, to guard against double calls.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2021-08-08 04:19:27 -04:00
Jordan Yates 4b370fb5e3 lora: sx12xx_common: transition to k_poll_signal
Transition the receive synchronisation method from a single driver
semaphore to a function specific k_poll_signal. This is required to
allow the modem to be released without introducing race conditions on
the signalling mechanism.

Without this change, the RX can either be signalled before the modem is
released, unblocking the calling thread before the modem is put back to
sleep, or after the modem is released, in which case a second thread
could start using the semaphore before the original thread is signalled.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2021-08-08 04:19:27 -04:00
Jordan Yates f397361c8a lora: sx12xx_common: sleep after RX timeout
If no packet was received in the provided timeout, manually transition
to sleep mode. If a packet was received, the rx_done callback
automatically transitions the modem to sleep.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2021-08-08 04:19:27 -04:00
Fabio Baltieri accb71ec9e drivers: sx126x: add support for the stm32wl chip
Add support for the STM32WL integrated radio, based on the sx1262. The
STM32WL implementation does not use any GPIO, and the signals are routed
to other units of the SoC and accessed with the ST HAL.

Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
2021-07-15 21:30:28 -04:00
Fabio Baltieri 2916133b06 drivers: sx126x_standalone: convert to gpio_dt_spec APIs
Convert the standalone part of the sx126x driver to the new gpio_dt_spec
APIs. This allows moving the specific GPIOs in that part of the driver
and out of struct sx126x_data.

Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
2021-07-15 21:30:28 -04:00
Fabio Baltieri 74efaa920a drivers: sx126x: refactor few functions for stm32wl support
Move few functions around in preparation of adding the STM32WL variant
of the driver.

Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
2021-07-15 21:30:28 -04:00
Ilya Tagunov 63dbc1f4e0 drivers: lora: sx126x: cosmetic fixes
Fix minor cosmetic issues discovered while updating driver.

Signed-off-by: Ilya Tagunov <tagunil@gmail.com>
2021-06-18 11:22:03 +02:00
Ilya Tagunov 05957b66cb lorawan: update LoRaMac-node and move CMakeLists.txt to the main repo
Update the LoRaMac-node library to the last stable release and fix
the Zephyr glue code to match it. Move CMakeLists.txt to the main
Zephyr repository to simplify loramac-node module maintenance.

Signed-off-by: Ilya Tagunov <tagunil@gmail.com>
2021-06-18 11:22:03 +02:00
Gerard Marull-Paretas 496cdac71d drivers: lora: remove usage of device_pm_control_nop
device_pm_control_nop is now deprecated in favour of NULL.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-04-28 11:25:42 -04:00
James Harris b10428163a kernel: sem: add K_SEM_MAX_LIMIT
Currently there is no way to distinguish between a caller
explicitly asking for a semaphore with a limit that
happens to be `UINT_MAX` and a semaphore that just
has a limit "as large as possible".

Add `K_SEM_MAX_LIMIT`, currently defined to `UINT_MAX`, and akin
to `K_FOREVER` versus just passing some very large wait time.

In addition, the `k_sem_*` APIs were type-confused, where
the internal data structure was `uint32_t`, but the APIs took
and returned `unsigned int`. This changes the underlying data
structure to also use `unsigned int`, as changing the APIs
would be a (potentially) breaking change.

These changes are backwards-compatible, but it is strongly suggested
to take a quick scan for `k_sem_init` and `K_SEM_DEFINE` calls with
`UINT_MAX` (or `UINT32_MAX`) and replace them with `K_SEM_MAX_LIMIT`
where appropriate.

Signed-off-by: James Harris <james.harris@intel.com>
2021-03-05 08:13:53 -06:00
Ilya Tagunov 62d4c6947c drivers: lora: sx127x: rework SX1276 driver to add SX1272 support
SX1272 chip is very similar to the already supported SX1276;
unfortunately, Semtech provides a completely separate driver
for this one. This commit marks an attempt to avoid code
duplication by means of some not-very-pretty ifdefery.

Signed-off-by: Ilya Tagunov <tagunil@gmail.com>
2021-02-28 16:36:35 -05:00
Jordan Yates e756ad6c0f lora: sx126x: disable DIO1 in sleep mode
Disable the DIO1 interrupt when the sx126x modem is in sleep mode.
On nRF hardware, this lets the `GPIOTE` hardware be switched off, saving
15uA.

Fixes #31569.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2021-02-10 08:55:15 -05:00