Skip to content
Closed
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
29 changes: 19 additions & 10 deletions drivers/serial/uart_nrfx_uarte.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,16 +353,16 @@ static void uarte_nrfx_isr_int(const void *arg)
if (txstopped && (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME) || LOW_POWER_ENABLED(config))) {
unsigned int key = irq_lock();

if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME) &&
(data->flags & UARTE_FLAG_POLL_OUT)) {
data->flags &= ~UARTE_FLAG_POLL_OUT;
pm_device_runtime_put(dev);
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
if (data->flags & UARTE_FLAG_POLL_OUT) {
data->flags &= ~UARTE_FLAG_POLL_OUT;
pm_device_runtime_put_async(dev, K_NO_WAIT);
}
} else {
nrf_uarte_disable(uarte);
}

#ifdef UARTE_INTERRUPT_DRIVEN
if (!data->int_driven || data->int_driven->fifo_fill_lock == 0)
if (!data->int_driven)
#endif
{
nrf_uarte_int_disable(uarte, NRF_UARTE_INT_TXSTOPPED_MASK);
Expand All @@ -378,16 +378,20 @@ static void uarte_nrfx_isr_int(const void *arg)

if (txstopped) {
data->int_driven->fifo_fill_lock = 0;
if (!data->int_driven->tx_irq_enabled) {

nrf_uarte_int_disable(uarte, NRF_UARTE_INT_TXSTOPPED_MASK);
}

if (data->int_driven->disable_tx_irq) {
nrf_uarte_int_disable(uarte,
NRF_UARTE_INT_TXSTOPPED_MASK);
data->int_driven->disable_tx_irq = false;
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
pm_device_runtime_put_async(dev, K_NO_WAIT);
}
return;
}

}


if (nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_ERROR)) {
nrf_uarte_event_clear(uarte, NRF_UARTE_EVENT_ERROR);
}
Expand Down Expand Up @@ -1892,6 +1896,11 @@ static void uarte_nrfx_irq_tx_enable(const struct device *dev)
{
NRF_UARTE_Type *uarte = get_uarte_instance(dev);
struct uarte_nrfx_data *data = dev->data;

if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
pm_device_runtime_get(dev);
}

unsigned int key = irq_lock();

data->int_driven->disable_tx_irq = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dut: &uart135 {
pinctrl-1 = <&uart135_sleep_alt>;
pinctrl-names = "default", "sleep";
current-speed = <115200>;
zephyr,pm-device-runtime-auto;
};

&pinctrl {
Expand Down Expand Up @@ -59,4 +60,5 @@ dut_aux: &uart137 {
pinctrl-1 = <&uart137_sleep_alt>;
pinctrl-names = "default", "sleep";
current-speed = <115200>;
zephyr,pm-device-runtime-auto;
};
28 changes: 25 additions & 3 deletions tests/drivers/uart/uart_elementary/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/

#include <zephyr/drivers/uart.h>
#include <zephyr/pm/device_runtime.h>
#include <zephyr/ztest.h>

#if DT_NODE_EXISTS(DT_NODELABEL(dut))
Expand Down Expand Up @@ -268,15 +269,25 @@ ZTEST(uart_elementary, test_uart_dual_port_transmission)
(void *)test_buffer_aux);
zassert_equal(err, 0, "Unexpected error when setting user data for UART1 callback %d", err);

if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
int usage = pm_device_runtime_usage(uart_dev);
int usage_aux = pm_device_runtime_usage(uart_dev_aux);

zassert_equal(usage, 0);
zassert_equal(usage_aux, 0);
pm_device_runtime_get(uart_dev);
pm_device_runtime_get(uart_dev_aux);
}

uart_irq_err_enable(uart_dev);
uart_irq_err_enable(uart_dev_aux);

uart_irq_tx_enable(uart_dev);
uart_irq_tx_enable(uart_dev_aux);

uart_irq_rx_enable(uart_dev);
uart_irq_rx_enable(uart_dev_aux);

uart_irq_tx_enable(uart_dev);
uart_irq_tx_enable(uart_dev_aux);

/* wait for the tramission to finish (no polling is intentional) */
k_sleep(K_USEC(100 * SLEEP_TIME_US));

Expand All @@ -287,6 +298,17 @@ ZTEST(uart_elementary, test_uart_dual_port_transmission)
uart_irq_err_disable(uart_dev);
uart_irq_err_disable(uart_dev_aux);

if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
pm_device_runtime_put(uart_dev);
pm_device_runtime_put(uart_dev_aux);

int usage = pm_device_runtime_usage(uart_dev);
int usage_aux = pm_device_runtime_usage(uart_dev_aux);

zassert_equal(usage, 0);
zassert_equal(usage_aux, 0);
}

#if defined(CONFIG_SETUP_MISMATCH_TEST)
TC_PRINT("Mismatched configuration test\n");
zassert_not_equal(uart_error_counter + aux_uart_error_counter, 0,
Expand Down
9 changes: 9 additions & 0 deletions tests/drivers/uart/uart_elementary/testcase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ tests:
extra_args: DTC_OVERLAY_FILE="boards/nrf54h20dk_nrf54h20_cpuapp_dual_uart.overlay"
extra_configs:
- CONFIG_DUAL_UART_TEST=y
drivers.uart.uart_elementary_dual_nrf54h.pm:
filter: CONFIG_SERIAL_SUPPORT_INTERRUPT
platform_allow:
- nrf54h20dk/nrf54h20/cpuapp
extra_args: DTC_OVERLAY_FILE="boards/nrf54h20dk_nrf54h20_cpuapp_dual_uart.overlay"
extra_configs:
- CONFIG_DUAL_UART_TEST=y
- CONFIG_PM_DEVICE=y
- CONFIG_PM_DEVICE_RUNTIME=y
drivers.uart.uart_elementary_dual_setup_mismatch_nrf54h:
filter: CONFIG_SERIAL_SUPPORT_INTERRUPT
platform_allow:
Expand Down
Loading