|
14 | 14 | #include <stdlib.h> |
15 | 15 | #include <dk_buttons_and_leds.h> |
16 | 16 |
|
| 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 | + |
17 | 22 | #define HEX_STRING_LENGTH (2 * MAX_PACKET_SIZE + 1) |
18 | 23 |
|
19 | 24 | static const struct device *radio_dev = |
@@ -128,6 +133,34 @@ static int cmd_sleep(const struct shell *shell, size_t argc, char **argv) |
128 | 133 | } |
129 | 134 | SHELL_CMD_ARG_REGISTER(sleep, NULL, "Disable the radio", cmd_sleep, 1, 0); |
130 | 135 |
|
| 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 | + |
131 | 164 | int main(void) |
132 | 165 | { |
133 | 166 | (void) dk_leds_init(); |
|
0 commit comments