Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: serial: nrfx_uarte: Add support for ENDTX_STOPTX short #78179

Merged
merged 3 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion drivers/serial/Kconfig.nrfx_uart_instance
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ config UART_$(nrfx_uart_num)_ASYNC

config UART_$(nrfx_uart_num)_ENHANCED_POLL_OUT
bool "Efficient poll out on port $(nrfx_uart_num)"
depends on !SOC_SERIES_NRF54LX
depends on !$(dt_nodelabel_has_prop,uart$(nrfx_uart_num),short-endtx-stoptx)
default y
depends on HAS_HW_NRF_UARTE$(nrfx_uart_num)
depends on HAS_HW_NRF_PPI || HAS_HW_NRF_DPPIC
Expand Down
52 changes: 34 additions & 18 deletions drivers/serial/uart_nrfx_uarte.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@
#error "No PPI or DPPI"
#endif

#define UARTE(idx) DT_NODELABEL(uart##idx)
#define UARTE_HAS_PROP(idx, prop) DT_NODE_HAS_PROP(UARTE(idx), prop)
#define UARTE_PROP(idx, prop) DT_PROP(UARTE(idx), prop)

/* Execute macro f(x) for all instances. */
#define UARTE_FOR_EACH_INSTANCE(f, sep, off_code) \
NRFX_FOREACH_PRESENT(UARTE, f, sep, off_code, _)
#define UARTE_FOR_EACH_INSTANCE(f, sep, off_code, ...) \
NRFX_FOREACH_PRESENT(UARTE, f, sep, off_code, __VA_ARGS__)

/* Determine if any instance is using interrupt driven API. */
#define IS_INT_DRIVEN(unused, prefix, i, _) \
Expand Down Expand Up @@ -85,6 +89,15 @@
#define UARTE_ENHANCED_POLL_OUT 1
#endif

#define INSTANCE_PROP(unused, prefix, i, prop) UARTE_PROP(prefix##i, prop)
#define INSTANCE_PRESENT(unused, prefix, i, prop) 1

/* Driver supports case when all or none instances support that HW feature. */
#if (UARTE_FOR_EACH_INSTANCE(INSTANCE_PROP, (+), (0), endtx_stoptx_supported)) == \
(UARTE_FOR_EACH_INSTANCE(INSTANCE_PRESENT, (+), (0), endtx_stoptx_supported))

Check notice on line 97 in drivers/serial/uart_nrfx_uarte.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

drivers/serial/uart_nrfx_uarte.c:97 -#define INSTANCE_PROP(unused, prefix, i, prop) UARTE_PROP(prefix##i, prop) +#define INSTANCE_PROP(unused, prefix, i, prop) UARTE_PROP(prefix##i, prop) #define INSTANCE_PRESENT(unused, prefix, i, prop) 1 /* Driver supports case when all or none instances support that HW feature. */ -#if (UARTE_FOR_EACH_INSTANCE(INSTANCE_PROP, (+), (0), endtx_stoptx_supported)) == \ +#if (UARTE_FOR_EACH_INSTANCE(INSTANCE_PROP, (+), (0), endtx_stoptx_supported)) == \
#define UARTE_HAS_ENDTX_STOPTX_SHORT 1
#endif

/*
* RX timeout is divided into time slabs, this define tells how many divisions
* should be made. More divisions - higher timeout accuracy and processor usage.
Expand Down Expand Up @@ -269,9 +282,10 @@
/* If interrupt driven and asynchronous APIs are disabled then UART
* interrupt is still called to stop TX. Unless it is done using PPI.
*/
if (nrf_uarte_int_enable_check(uarte, NRF_UARTE_INT_ENDTX_MASK) &&
if (!IS_ENABLED(UARTE_HAS_ENDTX_STOPTX_SHORT) &&
nrf_uarte_int_enable_check(uarte, NRF_UARTE_INT_ENDTX_MASK) &&
nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_ENDTX)) {
endtx_isr(dev);

Check notice on line 288 in drivers/serial/uart_nrfx_uarte.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

drivers/serial/uart_nrfx_uarte.c:288 - nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_ENDTX)) { + nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_ENDTX)) {
}

if (config->flags & UARTE_CFG_FLAG_LOW_POWER) {
Expand Down Expand Up @@ -455,7 +469,8 @@
{
const struct uarte_nrfx_config *config = dev->config;
NRF_UARTE_Type *uarte = get_uarte_instance(dev);
bool ppi_endtx = config->flags & UARTE_CFG_FLAG_PPI_ENDTX;
bool ppi_endtx = config->flags & UARTE_CFG_FLAG_PPI_ENDTX ||
IS_ENABLED(UARTE_HAS_ENDTX_STOPTX_SHORT);

return nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_TXSTOPPED) ||
(!ppi_endtx ?
Expand Down Expand Up @@ -1450,14 +1465,14 @@
rxto_isr(dev);
}

if (nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_ENDTX)
&& nrf_uarte_int_enable_check(uarte, NRF_UARTE_INT_ENDTX_MASK)) {
if (!IS_ENABLED(UARTE_HAS_ENDTX_STOPTX_SHORT) &&
(nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_ENDTX) &&
nrf_uarte_int_enable_check(uarte, NRF_UARTE_INT_ENDTX_MASK))) {
endtx_isr(dev);
}

if (nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_TXSTOPPED)
&& nrf_uarte_int_enable_check(uarte,
NRF_UARTE_INT_TXSTOPPED_MASK)) {
if (nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_TXSTOPPED) &&
nrf_uarte_int_enable_check(uarte, NRF_UARTE_INT_TXSTOPPED_MASK)) {
txstopped_isr(dev);
}
}
Expand Down Expand Up @@ -1739,6 +1754,7 @@
#endif /* UARTE_INTERRUPT_DRIVEN */
};

#ifdef UARTE_ENHANCED_POLL_OUT
static int endtx_stoptx_ppi_init(NRF_UARTE_Type *uarte,
struct uarte_nrfx_data *data)
{
Expand All @@ -1757,6 +1773,7 @@

return 0;
}
#endif /* UARTE_ENHANCED_POLL_OUT */

static int uarte_instance_init(const struct device *dev,
uint8_t interrupts_active)
Expand Down Expand Up @@ -1790,14 +1807,16 @@
nrf_uarte_configure(uarte, &cfg->hw_config);
#endif

if (IS_ENABLED(UARTE_ENHANCED_POLL_OUT) &&
cfg->flags & UARTE_CFG_FLAG_PPI_ENDTX) {
#ifdef UARTE_HAS_ENDTX_STOPTX_SHORT
nrf_uarte_shorts_enable(uarte, NRF_UARTE_SHORT_ENDTX_STOPTX);
#elif defined(UARTE_ENHANCED_POLL_OUT)
if (cfg->flags & UARTE_CFG_FLAG_PPI_ENDTX) {
err = endtx_stoptx_ppi_init(uarte, data);
if (err < 0) {
return err;
}
}

#endif

#ifdef UARTE_ANY_ASYNC
if (data->async) {
Expand All @@ -1819,7 +1838,7 @@
}
}

if (!(cfg->flags & UARTE_CFG_FLAG_PPI_ENDTX)) {
if (!IS_ENABLED(UARTE_HAS_ENDTX_STOPTX_SHORT) && !(cfg->flags & UARTE_CFG_FLAG_PPI_ENDTX)) {
nrf_uarte_int_enable(uarte, NRF_UARTE_INT_ENDTX_MASK);
}

Expand Down Expand Up @@ -1850,7 +1869,8 @@
static void wait_for_tx_stopped(const struct device *dev)
{
const struct uarte_nrfx_config *config = dev->config;
bool ppi_endtx = config->flags & UARTE_CFG_FLAG_PPI_ENDTX;
bool ppi_endtx = (config->flags & UARTE_CFG_FLAG_PPI_ENDTX) ||
IS_ENABLED(UARTE_HAS_ENDTX_STOPTX_SHORT);
NRF_UARTE_Type *uarte = get_uarte_instance(dev);
bool res;

Expand Down Expand Up @@ -1982,10 +2002,6 @@
}
#endif /* CONFIG_PM_DEVICE */

#define UARTE(idx) DT_NODELABEL(uart##idx)
#define UARTE_HAS_PROP(idx, prop) DT_NODE_HAS_PROP(UARTE(idx), prop)
#define UARTE_PROP(idx, prop) DT_PROP(UARTE(idx), prop)

#define UARTE_IRQ_CONFIGURE(idx, isr_handler) \
do { \
IRQ_CONNECT(DT_IRQN(UARTE(idx)), DT_IRQ(UARTE(idx), priority), \
Expand Down
6 changes: 6 additions & 0 deletions dts/bindings/serial/nordic,nrf-uarte.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ description: Nordic nRF family UARTE (UART with EasyDMA)
compatible: "nordic,nrf-uarte"

include: ["nordic,nrf-uart-common.yaml", "memory-region.yaml"]

properties:
endtx-stoptx-supported:
type: boolean
description: |
UARTE has ENDTX_STOPTX HW short.
9 changes: 9 additions & 0 deletions dts/common/nordic/nrf54h20.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@
status = "disabled";
interrupts = <230 NRF_DEFAULT_IRQ_PRIORITY>;
clocks = <&hsfll120>;
endtx-stoptx-supported;
anangl marked this conversation as resolved.
Show resolved Hide resolved
};

spi121: spi@8e7000 {
Expand Down Expand Up @@ -933,6 +934,7 @@
interrupts = <421 NRF_DEFAULT_IRQ_PRIORITY>;
clocks = <&fll16m>;
nordic,clockpin-enable = <NRF_FUN_UART_TX>;
endtx-stoptx-supported;
};

i2c131: i2c@9a6000 {
Expand Down Expand Up @@ -973,6 +975,7 @@
interrupts = <422 NRF_DEFAULT_IRQ_PRIORITY>;
clocks = <&fll16m>;
nordic,clockpin-enable = <NRF_FUN_UART_TX>;
endtx-stoptx-supported;
};

dppic134: dppic@9b1000 {
Expand Down Expand Up @@ -1050,6 +1053,7 @@
interrupts = <437 NRF_DEFAULT_IRQ_PRIORITY>;
clocks = <&fll16m>;
nordic,clockpin-enable = <NRF_FUN_UART_TX>;
endtx-stoptx-supported;
};

i2c133: i2c@9b6000 {
Expand Down Expand Up @@ -1090,6 +1094,7 @@
interrupts = <438 NRF_DEFAULT_IRQ_PRIORITY>;
clocks = <&fll16m>;
nordic,clockpin-enable = <NRF_FUN_UART_TX>;
endtx-stoptx-supported;
};

dppic135: dppic@9c1000 {
Expand Down Expand Up @@ -1167,6 +1172,7 @@
interrupts = <453 NRF_DEFAULT_IRQ_PRIORITY>;
clocks = <&fll16m>;
nordic,clockpin-enable = <NRF_FUN_UART_TX>;
endtx-stoptx-supported;
};

i2c135: i2c@9c6000 {
Expand Down Expand Up @@ -1207,6 +1213,7 @@
interrupts = <454 NRF_DEFAULT_IRQ_PRIORITY>;
clocks = <&fll16m>;
nordic,clockpin-enable = <NRF_FUN_UART_TX>;
endtx-stoptx-supported;
};

dppic136: dppic@9d1000 {
Expand Down Expand Up @@ -1284,6 +1291,7 @@
interrupts = <469 NRF_DEFAULT_IRQ_PRIORITY>;
clocks = <&fll16m>;
nordic,clockpin-enable = <NRF_FUN_UART_TX>;
endtx-stoptx-supported;
};

i2c137: i2c@9d6000 {
Expand Down Expand Up @@ -1324,6 +1332,7 @@
interrupts = <470 NRF_DEFAULT_IRQ_PRIORITY>;
clocks = <&fll16m>;
nordic,clockpin-enable = <NRF_FUN_UART_TX>;
endtx-stoptx-supported;
};
};
};
Expand Down
5 changes: 5 additions & 0 deletions dts/common/nordic/nrf54l15.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
reg = <0x4a000 0x1000>;
interrupts = <74 NRF_DEFAULT_IRQ_PRIORITY>;
status = "disabled";
endtx-stoptx-supported;
};

cpuflpr_vpr: vpr@4c000 {
Expand Down Expand Up @@ -266,6 +267,7 @@
reg = <0xc6000 0x1000>;
interrupts = <198 NRF_DEFAULT_IRQ_PRIORITY>;
status = "disabled";
endtx-stoptx-supported;
};

i2c21: i2c@c7000 {
Expand Down Expand Up @@ -303,6 +305,7 @@
reg = <0xc7000 0x1000>;
interrupts = <199 NRF_DEFAULT_IRQ_PRIORITY>;
status = "disabled";
endtx-stoptx-supported;
};

i2c22: i2c@c8000 {
Expand Down Expand Up @@ -340,6 +343,7 @@
reg = <0xc8000 0x1000>;
interrupts = <200 NRF_DEFAULT_IRQ_PRIORITY>;
status = "disabled";
endtx-stoptx-supported;
};

egu20: egu@c9000 {
Expand Down Expand Up @@ -548,6 +552,7 @@
reg = <0x104000 0x1000>;
interrupts = <260 NRF_DEFAULT_IRQ_PRIORITY>;
status = "disabled";
endtx-stoptx-supported;
};

#ifdef USE_NON_SECURE_ADDRESS_MAP
Expand Down
5 changes: 5 additions & 0 deletions dts/common/nordic/nrf54l20.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
reg = <0x4d000 0x1000>;
interrupts = <77 NRF_DEFAULT_IRQ_PRIORITY>;
status = "disabled";
endtx-stoptx-supported;
};

gpio2: gpio@50400 {
Expand Down Expand Up @@ -217,6 +218,7 @@
reg = <0xc6000 0x1000>;
interrupts = <198 NRF_DEFAULT_IRQ_PRIORITY>;
status = "disabled";
endtx-stoptx-supported;
};

i2c21: i2c@c7000 {
Expand Down Expand Up @@ -254,6 +256,7 @@
reg = <0xc7000 0x1000>;
interrupts = <199 NRF_DEFAULT_IRQ_PRIORITY>;
status = "disabled";
endtx-stoptx-supported;
};

i2c22: i2c@c8000 {
Expand Down Expand Up @@ -291,6 +294,7 @@
reg = <0xc8000 0x1000>;
interrupts = <200 NRF_DEFAULT_IRQ_PRIORITY>;
status = "disabled";
endtx-stoptx-supported;
};

egu20: egu@c9000 {
Expand Down Expand Up @@ -490,6 +494,7 @@
reg = <0x104000 0x1000>;
interrupts = <260 NRF_DEFAULT_IRQ_PRIORITY>;
status = "disabled";
endtx-stoptx-supported;
};

wdt30: watchdog@108000 {
Expand Down
9 changes: 9 additions & 0 deletions dts/common/nordic/nrf9280.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@
reg = <0x8e6000 0x1000>;
status = "disabled";
interrupts = <230 NRF_DEFAULT_IRQ_PRIORITY>;
endtx-stoptx-supported;
};

spi121: spi@8e7000 {
Expand Down Expand Up @@ -844,6 +845,7 @@
status = "disabled";
interrupts = <421 NRF_DEFAULT_IRQ_PRIORITY>;
nordic,clockpin-enable = <NRF_FUN_UART_TX>;
endtx-stoptx-supported;
};

i2c131: i2c@9a6000 {
Expand Down Expand Up @@ -881,6 +883,7 @@
status = "disabled";
interrupts = <422 NRF_DEFAULT_IRQ_PRIORITY>;
nordic,clockpin-enable = <NRF_FUN_UART_TX>;
endtx-stoptx-supported;
};

dppic134: dppic@9b1000 {
Expand Down Expand Up @@ -952,6 +955,7 @@
status = "disabled";
interrupts = <437 NRF_DEFAULT_IRQ_PRIORITY>;
nordic,clockpin-enable = <NRF_FUN_UART_TX>;
endtx-stoptx-supported;
};

i2c133: i2c@9b6000 {
Expand Down Expand Up @@ -989,6 +993,7 @@
status = "disabled";
interrupts = <438 NRF_DEFAULT_IRQ_PRIORITY>;
nordic,clockpin-enable = <NRF_FUN_UART_TX>;
endtx-stoptx-supported;
};

dppic135: dppic@9c1000 {
Expand Down Expand Up @@ -1060,6 +1065,7 @@
status = "disabled";
interrupts = <453 NRF_DEFAULT_IRQ_PRIORITY>;
nordic,clockpin-enable = <NRF_FUN_UART_TX>;
endtx-stoptx-supported;
};

i2c135: i2c@9c6000 {
Expand Down Expand Up @@ -1097,6 +1103,7 @@
status = "disabled";
interrupts = <454 NRF_DEFAULT_IRQ_PRIORITY>;
nordic,clockpin-enable = <NRF_FUN_UART_TX>;
endtx-stoptx-supported;
};

dppic136: dppic@9d1000 {
Expand Down Expand Up @@ -1168,6 +1175,7 @@
status = "disabled";
interrupts = <469 NRF_DEFAULT_IRQ_PRIORITY>;
nordic,clockpin-enable = <NRF_FUN_UART_TX>;
endtx-stoptx-supported;
};

i2c137: i2c@9d6000 {
Expand Down Expand Up @@ -1205,6 +1213,7 @@
status = "disabled";
interrupts = <470 NRF_DEFAULT_IRQ_PRIORITY>;
nordic,clockpin-enable = <NRF_FUN_UART_TX>;
endtx-stoptx-supported;
};
};
};
Expand Down
4 changes: 2 additions & 2 deletions samples/boards/nrf/nrfx/Kconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright (c) 2021 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0

source "Kconfig.zephyr"

config NRFX_DPPI
default $(dt_has_compat,$(DT_COMPAT_NORDIC_NRF_DPPIC))

Expand All @@ -16,5 +18,3 @@ config NRFX_GPIOTE0
config NRFX_GPIOTE1
default y if (SOC_SERIES_NRF53X && TRUSTED_EXECUTION_NONSECURE) || \
(SOC_SERIES_NRF91X && TRUSTED_EXECUTION_NONSECURE)

source "Kconfig.zephyr"
Loading