Skip to content

Commit a600dfc

Browse files
samples: bluetooth: ble_nus: use board-config for uarte pin and inst cfg
Use board-config.h for uarte pin and instance config. Signed-off-by: Eivind Jølsgard <[email protected]>
1 parent 3a05008 commit a600dfc

File tree

2 files changed

+10
-51
lines changed

2 files changed

+10
-51
lines changed

samples/bluetooth/ble_nus/Kconfig

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,12 @@ config BLE_UART_IRQ_PRIO
1010
int "BLE UART IRQ priority"
1111
default 3
1212

13-
config BLE_UART_PIN_TX
14-
int "BLE UART TX pin"
15-
default 6 if SOC_SERIES_NRF52X
16-
default 0
17-
18-
config BLE_UART_PIN_RX
19-
int "BLE UART RX pin"
20-
default 8 if SOC_SERIES_NRF52X
21-
default 1
22-
2313
config BLE_UART_PARITY
2414
bool "BLE UART use parity"
2515

2616
config BLE_UART_HWFC
2717
bool "BLE UART use HWFC"
2818

29-
if BLE_UART_HWFC
30-
31-
config BLE_UART_PIN_CTS
32-
int "BLE UART CTS pin"
33-
default 7 if SOC_SERIES_NRF52X
34-
default 3
35-
36-
config BLE_UART_PIN_RTS
37-
int "BLE UART RTS pin"
38-
default 5 if SOC_SERIES_NRF52X
39-
default 2
40-
41-
endif #BLE_UART_HWFC
42-
4319
endmenu # "BLE NUS sample"
4420

4521
module=BLE_NUS_SAMPLE

samples/bluetooth/ble_nus/src/main.c

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include <zephyr/logging/log_ctrl.h>
2020
#include <zephyr/sys/util.h>
2121

22+
#include <board-config.h>
23+
2224
LOG_MODULE_REGISTER(app, CONFIG_BLE_NUS_SAMPLE_LOG_LEVEL);
2325

2426
BLE_ADV_DEF(ble_adv); /* BLE advertising instance */
@@ -29,11 +31,7 @@ BLE_QWR_DEF(ble_qwr); /* BLE QWR instance */
2931
static uint16_t conn_handle = BLE_CONN_HANDLE_INVALID;
3032

3133
/** NUS UARTE instance */
32-
#if defined(CONFIG_SOC_SERIES_NRF52X)
33-
static const nrfx_uarte_t uarte_inst = NRFX_UARTE_INSTANCE(0);
34-
#elif defined(CONFIG_SOC_SERIES_NRF54LX)
35-
static const nrfx_uarte_t uarte_inst = NRFX_UARTE_INSTANCE(30);
36-
#endif
34+
static const nrfx_uarte_t uarte_inst = NRF_UARTE_INST_GET(BOARD_APP_UARTE_INST);
3735

3836
/* Maximum length of data (in bytes) that can be transmitted to the peer by the
3937
* Nordic UART service module.
@@ -290,13 +288,13 @@ static int uarte_init(void)
290288
{
291289
int err;
292290

293-
nrfx_uarte_config_t uarte_config = NRFX_UARTE_DEFAULT_CONFIG(CONFIG_BLE_UART_PIN_TX,
294-
CONFIG_BLE_UART_PIN_RX);
291+
nrfx_uarte_config_t uarte_config = NRFX_UARTE_DEFAULT_CONFIG(BOARD_APP_UARTE_PIN_TX,
292+
BOARD_APP_UARTE_PIN_RX);
295293

296294
#if defined(CONFIG_BLE_UART_HWFC)
297295
uarte_config.config.hwfc = NRF_UARTE_HWFC_ENABLED;
298-
uarte_config.cts_pin = CONFIG_BLE_UART_PIN_CTS;
299-
uarte_config.rts_pin = CONFIG_BLE_UART_PIN_RTS;
296+
uarte_config.cts_pin = BOARD_APP_UARTE_PIN_CTS;
297+
uarte_config.rts_pin = BOARD_APP_UARTE_PIN_RTS;
300298
#endif
301299

302300
#if defined(CONFIG_BLE_UART_PARITY)
@@ -306,32 +304,17 @@ static int uarte_init(void)
306304
uarte_config.interrupt_priority = CONFIG_BLE_UART_IRQ_PRIO;
307305

308306
/** We need to connect the IRQ ourselves. */
309-
#if defined(CONFIG_SOC_SERIES_NRF52X)
310-
IRQ_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_UARTE_INST_GET(0)), CONFIG_BLE_UART_IRQ_PRIO,
311-
NRFX_UARTE_INST_HANDLER_GET(0), 0, 0);
312-
313-
irq_enable(NRFX_IRQ_NUMBER_GET(NRF_UARTE_INST_GET(0)));
314-
#elif defined(CONFIG_SOC_SERIES_NRF54LX)
315-
IRQ_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_UARTE_INST_GET(30)), CONFIG_BLE_UART_IRQ_PRIO,
316-
NRFX_UARTE_INST_HANDLER_GET(30), 0, 0);
307+
IRQ_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_UARTE_INST_GET(BOARD_APP_UARTE_INST)), CONFIG_BLE_UART_IRQ_PRIO,
308+
NRFX_UARTE_INST_HANDLER_GET(BOARD_APP_UARTE_INST), 0, 0);
317309

318-
irq_enable(NRFX_IRQ_NUMBER_GET(NRF_UARTE_INST_GET(30)));
319-
#endif
310+
irq_enable(NRFX_IRQ_NUMBER_GET(NRF_UARTE_INST_GET(BOARD_APP_UARTE_INST)));
320311

321312
err = nrfx_uarte_init(&uarte_inst, &uarte_config, uarte_evt_handler);
322313
if (err != NRFX_SUCCESS) {
323314
LOG_ERR("Failed to initialize UART, nrfx err %d", err);
324315
return err;
325316
}
326317

327-
/* optional: enable pull-up on RX pin in case pin may become floating.
328-
* Induced noise on a floating RX input may lead to an UARTE error condition
329-
*/
330-
#if defined(CONFIG_SOC_SERIES_NRF52X)
331-
NRF_GPIO->PIN_CNF[uarte_config.rxd_pin] |=
332-
(GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos);
333-
#endif
334-
335318
return 0;
336319
}
337320

0 commit comments

Comments
 (0)