Skip to content

Commit d3f8470

Browse files
samples: 802154_sniffer: add bootloader command.
Add `bootloader` command that allows nRF52840 dongle to reboot into bootloader by pulling the P0.19 GPIO pim connected to reset to GND. This allows easy reflashing of the dongle without physical access to the device. Signed-off-by: Maciej Baczmanski <[email protected]>
1 parent 63630fa commit d3f8470

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

samples/peripheral/802154_sniffer/README.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,21 @@ The ``sleep`` command disables the radio and ends the receive process.
9090
9191
sleep
9292
93+
bootloader - reboot the device to the bootloader
94+
================================================
95+
96+
The ``bootloader`` command reboots the device in bootloader mode.
97+
98+
.. parsed-literal::
99+
:class: highlight
100+
101+
bootloader
102+
103+
The device reboots into bootloader mode, and the red LED starts pulsing.
104+
105+
.. note::
106+
The ``bootloader`` command is available only for the ``nrf52840dongle/nrf52840`` board.
107+
93108
Configuration
94109
*************
95110

samples/peripheral/802154_sniffer/src/main.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
#include <stdlib.h>
1515
#include <dk_buttons_and_leds.h>
1616

17+
#if defined(CONFIG_BOARD_NRF52840DONGLE)
18+
#include <zephyr/drivers/gpio.h>
19+
static const struct device *const gpio_dev = DEVICE_DT_GET(DT_NODELABEL(gpio0));
20+
#endif
21+
1722
#define HEX_STRING_LENGTH (2 * MAX_PACKET_SIZE + 1)
1823

1924
static const struct device *radio_dev =
@@ -128,6 +133,34 @@ static int cmd_sleep(const struct shell *shell, size_t argc, char **argv)
128133
}
129134
SHELL_CMD_ARG_REGISTER(sleep, NULL, "Disable the radio", cmd_sleep, 1, 0);
130135

136+
#if defined(CONFIG_BOARD_NRF52840DONGLE)
137+
static int cmd_bootloader(const struct shell *shell, size_t argc, char **argv)
138+
{
139+
/*
140+
* nRF52840 dongle has pin P0.19 connected to reset. By setting it
141+
* in `GPIO_OUTPUT_LOW` mode, reset is pulled to GND,
142+
* which results in device rebooting without skipping the bootloader.
143+
*/
144+
ARG_UNUSED(shell);
145+
ARG_UNUSED(argc);
146+
ARG_UNUSED(argv);
147+
148+
if (!device_is_ready(gpio_dev)) {
149+
shell_print(shell, "GPIO device not ready");
150+
return 0;
151+
}
152+
153+
int err = gpio_pin_configure(gpio_dev, 19, GPIO_OUTPUT_LOW);
154+
155+
if (err) {
156+
shell_print(shell, "Failed to configure GPIO pin. Error code: %d", err);
157+
}
158+
159+
return 0;
160+
}
161+
SHELL_CMD_ARG_REGISTER(bootloader, NULL, "Reboot into bootloader", cmd_bootloader, 1, 0);
162+
#endif /* CONFIG_BOARD_NRF52840DONGLE */
163+
131164
int main(void)
132165
{
133166
(void) dk_leds_init();

0 commit comments

Comments
 (0)