Skip to content

Commit 0db7dda

Browse files
lemreycarlescufi
authored andcommitted
Bluetooth: hci: h4: use GPIO reset for nrf52840_pca10090 controllers
This patch adds support to the nRF9160 for using a dedicated GPIO pin to reset controllers running on nrf52840_pca10090. It resets the controller before opening the H4 device, and it delays the controller from booting until all bytes traveling to the host have been received and drained from the UART, thus ensuring that communication can begin from a clean state. Signed-off-by: Emanuele Di Santo <[email protected]> Signed-off-by: Carles Cufi <[email protected]>
1 parent bca3deb commit 0db7dda

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Copyright (c) 2019 Nordic Semiconductor ASA.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
if(CONFIG_BOARD_NRF52840_GPIO_RESET)
5+
zephyr_library()
6+
zephyr_library_sources(nrf52840_reset.c)
7+
endif()

boards/arm/nrf9160_pca10090/Kconfig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,23 @@
66

77
if BOARD_NRF9160_PCA10090 || BOARD_NRF9160_PCA10090NS
88

9+
config BOARD_NRF52840_GPIO_RESET
10+
bool "Use nRF52840 PCA10090 GPIO reset pin"
11+
default y if BT_H4
12+
help
13+
Use a GPIO pin to reset the nRF52840 controller and let it wait
14+
until all bytes traveling to the H4 device have been received
15+
and drained, thus ensuring communication can begin correctly.
16+
17+
if BOARD_NRF52840_GPIO_RESET
18+
19+
config BOARD_NRF52840_GPIO_RESET_PIN
20+
int "Reset pin"
21+
range 17 23
22+
default 23
23+
help
24+
GPIO pin on the nRF9160 used to reset the nRF52840.
25+
26+
endif
27+
928
endif # BOARD_NRF9160_PCA10090 || BOARD_NRF9160_PCA10090NS
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright (c) 2019 Nordic Semiconductor ASA.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <gpio.h>
8+
#include <uart.h>
9+
#include <device.h>
10+
11+
#define RESET_PIN CONFIG_BOARD_NRF52840_GPIO_RESET_PIN
12+
13+
/* Must be a pin from 17 to 23.
14+
* Only those can be connected to the nRF52840.
15+
*/
16+
BUILD_ASSERT_MSG(RESET_PIN > 16 && RESET_PIN < 24,
17+
"Selected pin is not connected to nRF52840");
18+
19+
int bt_hci_transport_setup(struct device *h4)
20+
{
21+
int err;
22+
char c;
23+
struct device *port;
24+
25+
port = device_get_binding(DT_GPIO_P0_DEV_NAME);
26+
if (!port) {
27+
return -EIO;
28+
}
29+
30+
/* Pull the pin low before configuring it as output, to ensure that
31+
* it is driven to the correct level as soon as it is configured.
32+
*/
33+
err = gpio_pin_write(port, RESET_PIN, 0);
34+
if (err) {
35+
return err;
36+
}
37+
38+
err = gpio_pin_configure(port, RESET_PIN, GPIO_DIR_OUT);
39+
if (err) {
40+
return err;
41+
}
42+
43+
/* Reset the nRF52840 and let it wait until the pin is
44+
* pulled low again before running to main to ensure
45+
* that it won't send any data until the H4 device
46+
* is setup and ready to receive.
47+
*/
48+
err = gpio_pin_write(port, RESET_PIN, 1);
49+
if (err) {
50+
return err;
51+
}
52+
53+
/* Wait for the nRF52840 peripheral to stop sending data.
54+
*
55+
* It is critical (!) to wait here, so that all bytes
56+
* on the lines are received and drained correctly.
57+
*/
58+
k_sleep(1);
59+
60+
/* Drain bytes */
61+
while (uart_fifo_read(h4, &c, 1)) {
62+
continue;
63+
}
64+
65+
/* We are ready, let the nRF52840 run to main */
66+
err = gpio_pin_write(port, RESET_PIN, 0);
67+
if (err) {
68+
return err;
69+
}
70+
71+
return 0;
72+
}

0 commit comments

Comments
 (0)