ESPHome 2025.9.1
Loading...
Searching...
No Matches
dfu.cpp
Go to the documentation of this file.
1#include "dfu.h"
2
3#ifdef USE_NRF52_DFU
4
5#include <zephyr/device.h>
6#include <zephyr/drivers/uart.h>
7#include <zephyr/drivers/uart/cdc_acm.h>
8#include "esphome/core/log.h"
9
10namespace esphome {
11namespace nrf52 {
12
13static const char *const TAG = "dfu";
14
15volatile bool goto_dfu = false; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
16
17static const uint32_t DFU_DBL_RESET_MAGIC = 0x5A1AD5; // SALADS
18
19#define DEVICE_AND_COMMA(node_id) DEVICE_DT_GET(node_id),
20
21static void cdc_dte_rate_callback(const struct device * /*unused*/, uint32_t rate) {
22 if (rate == 1200) {
23 goto_dfu = true;
24 }
25}
27 this->reset_pin_->setup();
28 const struct device *cdc_dev[] = {DT_FOREACH_STATUS_OKAY(zephyr_cdc_acm_uart, DEVICE_AND_COMMA)};
29 for (auto &idx : cdc_dev) {
30 cdc_acm_dte_rate_callback_set(idx, cdc_dte_rate_callback);
31 }
32}
33
35 if (goto_dfu) {
36 goto_dfu = false;
37 volatile uint32_t *dbl_reset_mem = (volatile uint32_t *) 0x20007F7C;
38 (*dbl_reset_mem) = DFU_DBL_RESET_MAGIC;
39 this->reset_pin_->digital_write(true);
40 }
41}
42
44 ESP_LOGCONFIG(TAG, "DFU:");
45 LOG_PIN(" RESET Pin: ", this->reset_pin_);
46}
47
48} // namespace nrf52
49} // namespace esphome
50
51#endif
virtual void setup()=0
virtual void digital_write(bool value)=0
volatile bool goto_dfu
Definition dfu.cpp:15
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7