drivers: serial: nrfx_uarte: Allow use of legacy shim on RISCV cores

Legacy shim takes less flash so it should be a first choice on cores
with less code memory (like RISCV cores on nrf54h20). Adding new
instances support to the legacy shim.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
Krzysztof Chruściński 2024-05-29 16:13:31 +02:00 committed by Carles Cufí
commit d07b13dbc2
3 changed files with 38 additions and 37 deletions

View file

@ -31,7 +31,8 @@ config UART_NRFX_UARTE
config UART_NRFX_UARTE_LEGACY_SHIM config UART_NRFX_UARTE_LEGACY_SHIM
bool "Legacy UARTE shim" bool "Legacy UARTE shim"
depends on UART_NRFX_UARTE depends on UART_NRFX_UARTE
depends on !SOC_SERIES_NRF54LX && !SOC_SERIES_NRF54HX depends on !SOC_SERIES_NRF54LX
depends on RISCV || !SOC_SERIES_NRF54HX
# New shim takes more ROM. Until it is fixed use legacy shim. # New shim takes more ROM. Until it is fixed use legacy shim.
default y default y

View file

@ -54,6 +54,7 @@ config UART_$(nrfx_uart_num)_NRF_HW_ASYNC
depends on HAS_HW_NRF_UARTE$(nrfx_uart_num) depends on HAS_HW_NRF_UARTE$(nrfx_uart_num)
depends on UART_ASYNC_API depends on UART_ASYNC_API
depends on UART_NRFX_UARTE_LEGACY_SHIM depends on UART_NRFX_UARTE_LEGACY_SHIM
depends on HAS_HW_NRF_PPI || HAS_HW_NRF_DPPIC
select NRFX_PPI if HAS_HW_NRF_PPI select NRFX_PPI if HAS_HW_NRF_PPI
select NRFX_DPPI if HAS_HW_NRF_DPPIC select NRFX_DPPI if HAS_HW_NRF_DPPIC
help help

View file

@ -25,12 +25,12 @@ LOG_MODULE_REGISTER(uart_nrfx_uarte, CONFIG_UART_LOG_LEVEL);
#include <zephyr/drivers/pinctrl.h> #include <zephyr/drivers/pinctrl.h>
/* Generalize PPI or DPPI channel management */ /* Generalize PPI or DPPI channel management */
#if defined(CONFIG_HAS_HW_NRF_PPI) #if defined(PPI_PRESENT)
#include <nrfx_ppi.h> #include <nrfx_ppi.h>
#define gppi_channel_t nrf_ppi_channel_t #define gppi_channel_t nrf_ppi_channel_t
#define gppi_channel_alloc nrfx_ppi_channel_alloc #define gppi_channel_alloc nrfx_ppi_channel_alloc
#define gppi_channel_enable nrfx_ppi_channel_enable #define gppi_channel_enable nrfx_ppi_channel_enable
#elif defined(CONFIG_HAS_HW_NRF_DPPIC) #elif defined(DPPI_PRESENT)
#include <nrfx_dppi.h> #include <nrfx_dppi.h>
#define gppi_channel_t uint8_t #define gppi_channel_t uint8_t
#define gppi_channel_alloc nrfx_dppi_channel_alloc #define gppi_channel_alloc nrfx_dppi_channel_alloc
@ -39,39 +39,49 @@ LOG_MODULE_REGISTER(uart_nrfx_uarte, CONFIG_UART_LOG_LEVEL);
#error "No PPI or DPPI" #error "No PPI or DPPI"
#endif #endif
/* Execute macro f(x) for all instances. */
#define UARTE_FOR_EACH_INSTANCE(f, sep, off_code) \
NRFX_FOREACH_PRESENT(UARTE, f, sep, off_code, _)
#if (defined(CONFIG_HAS_HW_NRF_UARTE0) && \ /* Determine if any instance is using interrupt driven API. */
defined(CONFIG_UART_0_INTERRUPT_DRIVEN)) || \ #define IS_INT_DRIVEN(unused, prefix, i, _) \
(defined(CONFIG_HAS_HW_NRF_UARTE1) && \ (IS_ENABLED(CONFIG_HAS_HW_NRF_UARTE##prefix##i) && \
defined(CONFIG_UART_1_INTERRUPT_DRIVEN)) || \ IS_ENABLED(CONFIG_UART_##prefix##i##_INTERRUPT_DRIVEN))
(defined(CONFIG_HAS_HW_NRF_UARTE2) && \
defined(CONFIG_UART_2_INTERRUPT_DRIVEN)) || \ #if UARTE_FOR_EACH_INSTANCE(IS_INT_DRIVEN, (||), (0))
(defined(CONFIG_HAS_HW_NRF_UARTE3) && \
defined(CONFIG_UART_3_INTERRUPT_DRIVEN))
#define UARTE_INTERRUPT_DRIVEN 1 #define UARTE_INTERRUPT_DRIVEN 1
#endif #endif
#if (defined(CONFIG_HAS_HW_NRF_UARTE0) && !defined(CONFIG_UART_0_ASYNC)) || \ /* Determine if any instance is not using asynchronous API. */
(defined(CONFIG_HAS_HW_NRF_UARTE1) && !defined(CONFIG_UART_1_ASYNC)) || \ #define IS_NOT_ASYNC(unused, prefix, i, _) \
(defined(CONFIG_HAS_HW_NRF_UARTE2) && !defined(CONFIG_UART_2_ASYNC)) || \ (IS_ENABLED(CONFIG_HAS_HW_NRF_UARTE##prefix##i) && \
(defined(CONFIG_HAS_HW_NRF_UARTE3) && !defined(CONFIG_UART_3_ASYNC)) !IS_ENABLED(CONFIG_UART_##prefix##i##_ASYNC))
#if UARTE_FOR_EACH_INSTANCE(IS_NOT_ASYNC, (||), (0))
#define UARTE_ANY_NONE_ASYNC 1 #define UARTE_ANY_NONE_ASYNC 1
#endif #endif
#if (defined(CONFIG_HAS_HW_NRF_UARTE0) && defined(CONFIG_UART_0_ASYNC)) || \ /* Determine if any instance is using asynchronous API. */
(defined(CONFIG_HAS_HW_NRF_UARTE1) && defined(CONFIG_UART_1_ASYNC)) || \ #define IS_ASYNC(unused, prefix, i, _) \
(defined(CONFIG_HAS_HW_NRF_UARTE2) && defined(CONFIG_UART_2_ASYNC)) || \ (IS_ENABLED(CONFIG_HAS_HW_NRF_UARTE##prefix##i) && \
(defined(CONFIG_HAS_HW_NRF_UARTE3) && defined(CONFIG_UART_3_ASYNC)) IS_ENABLED(CONFIG_UART_##prefix##i##_ASYNC))
#if UARTE_FOR_EACH_INSTANCE(IS_ASYNC, (||), (0))
#define UARTE_ANY_ASYNC 1 #define UARTE_ANY_ASYNC 1
#endif #endif
#if defined(CONFIG_UART_0_NRF_HW_ASYNC) || defined(CONFIG_UART_1_NRF_HW_ASYNC) || \ /* Determine if any instance is using asynchronous API with HW byte counting. */
defined(CONFIG_UART_2_NRF_HW_ASYNC) || defined(CONFIG_UART_3_NRF_HW_ASYNC) #define IS_HW_ASYNC(unused, prefix, i, _) IS_ENABLED(CONFIG_UART_##prefix##i##_NRF_HW_ASYNC)
#if UARTE_FOR_EACH_INSTANCE(IS_HW_ASYNC, (||), (0))
#define UARTE_HW_ASYNC 1 #define UARTE_HW_ASYNC 1
#endif #endif
#if defined(CONFIG_UART_0_ENHANCED_POLL_OUT) || defined(CONFIG_UART_1_ENHANCED_POLL_OUT) || \ /* Determine if any instance is using enhanced poll_out feature. */
defined(CONFIG_UART_2_ENHANCED_POLL_OUT) || defined(CONFIG_UART_3_ENHANCED_POLL_OUT) #define IS_ENHANCED_POLL_OUT(unused, prefix, i, _) \
IS_ENABLED(CONFIG_UART_##prefix##i##_ENHANCED_POLL_OUT)
#if UARTE_FOR_EACH_INSTANCE(IS_ENHANCED_POLL_OUT, (||), (0))
#define UARTE_ENHANCED_POLL_OUT 1 #define UARTE_ENHANCED_POLL_OUT 1
#endif #endif
@ -2074,18 +2084,7 @@ static int uarte_nrfx_pm_action(const struct device *dev,
DT_PHANDLE(UARTE(idx), memory_regions)))))), \ DT_PHANDLE(UARTE(idx), memory_regions)))))), \
()) ())
#ifdef CONFIG_HAS_HW_NRF_UARTE0 #define COND_UART_NRF_UARTE_DEVICE(unused, prefix, i, _) \
UART_NRF_UARTE_DEVICE(0); IF_ENABLED(CONFIG_HAS_HW_NRF_UARTE##prefix##i, (UART_NRF_UARTE_DEVICE(prefix##i);))
#endif
#ifdef CONFIG_HAS_HW_NRF_UARTE1 UARTE_FOR_EACH_INSTANCE(COND_UART_NRF_UARTE_DEVICE, (), ())
UART_NRF_UARTE_DEVICE(1);
#endif
#ifdef CONFIG_HAS_HW_NRF_UARTE2
UART_NRF_UARTE_DEVICE(2);
#endif
#ifdef CONFIG_HAS_HW_NRF_UARTE3
UART_NRF_UARTE_DEVICE(3);
#endif