ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
dfu.cpp
Go to the documentation of this file.
1#include "dfu.h"
2
3#ifdef USE_NRF52_DFU
4
6#include "esphome/core/log.h"
8
9#include <hal/nrf_power.h>
10
11namespace esphome::nrf52 {
12
13static const char *const TAG = "dfu";
14
15static const uint32_t DFU_DBL_RESET_MAGIC = 0x5A1AD5; // SALADS
16static const uint8_t DFU_MAGIC_UF2_RESET = 0x57; // Adafruit nRF52 bootloader UF2 magic
17
19 if (this->reset_pin_ != nullptr) {
20 this->reset_pin_->setup();
21 }
22#if defined(CONFIG_CDC_ACM_DTE_RATE_CALLBACK_SUPPORT)
23 zephyr::global_cdc_acm->add_on_rate_callback([this](const device *, uint32_t rate) {
24 if (rate == 1200) {
25 volatile uint32_t *dbl_reset_mem = (volatile uint32_t *) 0x20007F7C;
26 (*dbl_reset_mem) = DFU_DBL_RESET_MAGIC;
27 if (this->reset_pin_ != nullptr) {
28 this->reset_pin_->digital_write(true);
29 } else {
30 NRF_POWER->GPREGRET = DFU_MAGIC_UF2_RESET;
31 App.reboot();
32 }
33 }
34 });
35#endif
36}
37
39 ESP_LOGCONFIG(TAG, "DFU:");
40 if (this->reset_pin_ != nullptr) {
41 LOG_PIN(" RESET Pin: ", this->reset_pin_);
42 } else {
43 ESP_LOGCONFIG(TAG, " Method: GPREGRET");
44 }
45}
46
47} // namespace esphome::nrf52
48
49#endif
virtual void setup()=0
virtual void digital_write(bool value)=0
void add_on_rate_callback(F &&callback)
Definition cdc_acm.h:14
CdcAcm * global_cdc_acm
Definition cdc_acm.cpp:26
Application App
Global storage of Application pointer - only one Application can exist.
static void uint32_t