I'm new to development with the Nordic SDK for the nRF52840 and during evaluation I run into the following problem with the UART ports, which I cannot resolve after hours.
I'm using Segger Studio 4.16, the Nordic nRF52840 DK ( PCA10056), Nordic SDK 15.3.
Since the overall concept of the SDK is new to me, I likely have some misunderstanding how some includes and macros should work. The SDK examples\peripheral\spi can be used to reproduce my problem. The spi example already provides support for the NRF LOG, so by configuring SDK_CONFIG.h I can either use RTT backend (nrf_log_backend_rtt.c) or UART backend (nrf_log_backend_uart.c) or even both. I want to use this and it works fine.
So for my scenario UARTE0 is already used by the NRF LOG. Since I also want to use another UART port for communcation, I thought that it should be easy to use UARTE1 for this purpose. (or use UARTE0 and let the LOG use UARTE1) . Looking at the various options / levels how to use the UART, I decided to use a "low level" driver level API, just like nrf_log_backend_uart.c does.
This means that I need to fill some variable structures, make a call to nrf_drv_uart_init and then continue with TX and RX functions.
There is a very basic Macro NRF_DRV_UART_INSTANCE which I think I have to use:
nrf_drv_uart_t m_uart = NRF_DRV_UART_INSTANCE(0); ... ret_code_t err_code = nrf_drv_uart_init(&m_uart, &config, async_mode ? uart_evt_handler : NULL);
But if I change the parameter for NRF_DRV_UART_INSTANCE from 0 to 1, then the code will not compile without error.
4> In file included from ../../../../../../modules/nrfx/nrfx.h:45, 4> from ../../../../../../integration/nrfx/legacy/nrf_drv_uart.h:44, 4> from D:\BLE\Nordic\NRF5_SDK_15.3_Work\components\libraries\log\src\nrf_log_backend_uart.c:45: 4> ../../../../../../modules/nrfx/drivers/include/nrfx_uarte.h:89:35: error: 'NRFX_UARTE1_INST_IDX' undeclared here (not in a function); did you mean 'NRFX_UARTE0_INST_IDX'? 4> ../../../../../../modules/nrfx/drivers/nrfx_common.h:117:37: note: in definition of macro 'NRFX_CONCAT_3_' 4> ../../../../../../modules/nrfx/drivers/include/nrfx_uarte.h:89:21: note: in expansion of macro 'NRFX_CONCAT_3' 4> ../../../../../../integration/nrfx/legacy/nrf_drv_uart.h:56:18: note: in expansion of macro 'NRFX_UARTE_INSTANCE' 4> ../../../../../../integration/nrfx/legacy/nrf_drv_uart.h:171:5: note: in expansion of macro 'NRF_DRV_UART_CREATE_UARTE' 4> D:\BLE\Nordic\NRF5_SDK_15.3_Work\components\libraries\log\src\nrf_log_backend_uart.c:48:25: note: in expansion of macro 'NRF_DRV_UART_INSTANCE' Build failed
At the first glance, it seems to be clear, why I receive this error, which manifests in nrfx_uarte.h
The NRFX_CONCAT_3 macro correctly forms the NRFX_UARTE1_INST_ID. But since the part with UARTE1 of the enum is grayed out, there is no suitable definition in line 89, which then results in the error
#if NRFX_CHECK(NRFX_UARTE1_ENABLED)
NRFX_UARTE1_INST_IDX,
#endif
I checked the settings in sdk_config.h and tried almost any combination.
// <e> NRFX_UARTE_ENABLED - nrfx_uarte - UARTE peripheral driver //========================================================== #ifndef NRFX_UARTE_ENABLED #define NRFX_UARTE_ENABLED 1 #endif // <o> NRFX_UARTE0_ENABLED - Enable UARTE0 instance #ifndef NRFX_UARTE0_ENABLED #define NRFX_UARTE0_ENABLED 0 #endif // <o> NRFX_UARTE1_ENABLED - Enable UARTE1 instance #ifndef NRFX_UARTE1_ENABLED #define NRFX_UARTE1_ENABLED 0 #endif
It makes no difference whether NRFX_UARTE1_ENABLED is 0 or 1.
It even does not make a difference of whether NRFX_UARTE1_ENABLED is defined or not. (commenting out)
So nrfx_uarte.h gets its definitions for NRFX_UARTE0from somewhere else, but I cannot find out, from where.
Or more likely I do not understand how this mechanism works.
How can I use NRF_DRV_UART_INSTANCE (1) without error, or how should I used UARTE1 at all ?