ESPHome
2026.6.0-dev
Loading...
Searching...
No Matches
esphome
components
nrf52
dfu.cpp
Go to the documentation of this file.
1
#include "
dfu.h
"
2
3
#ifdef USE_NRF52_DFU
4
5
#include "
esphome/core/application.h
"
6
#include "
esphome/core/log.h
"
7
#include "
esphome/components/zephyr/cdc_acm.h
"
8
9
#include <hal/nrf_power.h>
10
11
namespace
esphome::nrf52
{
12
13
static
const
char
*
const
TAG =
"dfu"
;
14
15
static
const
uint32_t
DFU_DBL_RESET_MAGIC = 0x5A1AD5;
// SALADS
16
static
const
uint8_t DFU_MAGIC_UF2_RESET = 0x57;
// Adafruit nRF52 bootloader UF2 magic
17
18
void
DeviceFirmwareUpdate::setup
() {
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
38
void
DeviceFirmwareUpdate::dump_config
() {
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
application.h
cdc_acm.h
esphome::Application::reboot
void reboot()
Definition
application.cpp:263
esphome::GPIOPin::setup
virtual void setup()=0
esphome::GPIOPin::digital_write
virtual void digital_write(bool value)=0
esphome::nrf52::DeviceFirmwareUpdate::dump_config
void dump_config() override
Definition
dfu.cpp:38
esphome::nrf52::DeviceFirmwareUpdate::reset_pin_
GPIOPin * reset_pin_
Definition
dfu.h:16
esphome::nrf52::DeviceFirmwareUpdate::setup
void setup() override
Definition
dfu.cpp:18
esphome::zephyr::CdcAcm::add_on_rate_callback
void add_on_rate_callback(F &&callback)
Definition
cdc_acm.h:14
dfu.h
log.h
esphome::nrf52
Definition
dfu.cpp:11
esphome::zephyr::global_cdc_acm
CdcAcm * global_cdc_acm
Definition
cdc_acm.cpp:26
esphome::App
Application App
Global storage of Application pointer - only one Application can exist.
uint32_t
static void uint32_t
Definition
crash_handler.cpp:141
Generated by
1.12.0