[nrf52] make reset pin optional (#11684)

Co-authored-by: J. Nick Koston <nick@home-assistant.io>
This commit is contained in:
tomaszduda23
2026-04-28 19:20:38 +02:00
committed by GitHub
parent 968878a62d
commit 6b3df66bdc
5 changed files with 53 additions and 26 deletions
+20 -8
View File
@@ -141,6 +141,22 @@ CONF_UICR_ERASE = "uicr_erase"
VOLTAGE_LEVELS = [1.8, 2.1, 2.4, 2.7, 3.0, 3.3]
_DFU_SCHEMA = cv.Schema(
{
cv.GenerateID(): cv.declare_id(DeviceFirmwareUpdate),
cv.Optional(CONF_RESET_PIN): pins.gpio_output_pin_schema,
}
)
def _dfu_schema(value: bool | ConfigType) -> ConfigType:
if isinstance(value, bool):
if not value:
raise cv.Invalid("Use 'dfu: true' or specify a configuration dict")
return _DFU_SCHEMA({})
return _DFU_SCHEMA(value)
CONFIG_SCHEMA = cv.All(
_detect_bootloader,
set_core_data,
@@ -150,12 +166,7 @@ CONFIG_SCHEMA = cv.All(
cv.string_strict, cv.ByteLength(max=BOARD_MAX_LENGTH)
),
cv.Optional(KEY_BOOTLOADER): cv.one_of(*BOOTLOADERS, lower=True),
cv.Optional(CONF_DFU): cv.Schema(
{
cv.GenerateID(): cv.declare_id(DeviceFirmwareUpdate),
cv.Required(CONF_RESET_PIN): pins.gpio_output_pin_schema,
}
),
cv.Optional(CONF_DFU): _dfu_schema,
cv.Optional(CONF_DCDC, default=True): cv.boolean,
cv.Optional(CONF_REG0): cv.Schema(
{
@@ -321,8 +332,9 @@ async def to_code(config: ConfigType) -> None:
async def _dfu_to_code(dfu_config):
cg.add_define("USE_NRF52_DFU")
var = cg.new_Pvariable(dfu_config[CONF_ID])
pin = await cg.gpio_pin_expression(dfu_config[CONF_RESET_PIN])
cg.add(var.set_reset_pin(pin))
if CONF_RESET_PIN in dfu_config:
pin = await cg.gpio_pin_expression(dfu_config[CONF_RESET_PIN])
cg.add(var.set_reset_pin(pin))
zephyr_add_prj_conf("CDC_ACM_DTE_RATE_CALLBACK_SUPPORT", True)
await cg.register_component(var, dfu_config)
+20 -7
View File
@@ -2,24 +2,34 @@
#ifdef USE_NRF52_DFU
#include "esphome/core/application.h"
#include "esphome/core/log.h"
#include "esphome/components/zephyr/cdc_acm.h"
namespace esphome {
namespace nrf52 {
#include <hal/nrf_power.h>
namespace esphome::nrf52 {
static const char *const TAG = "dfu";
static const uint32_t DFU_DBL_RESET_MAGIC = 0x5A1AD5; // SALADS
static const uint8_t DFU_MAGIC_UF2_RESET = 0x57; // Adafruit nRF52 bootloader UF2 magic
void DeviceFirmwareUpdate::setup() {
this->reset_pin_->setup();
if (this->reset_pin_ != nullptr) {
this->reset_pin_->setup();
}
#if defined(CONFIG_CDC_ACM_DTE_RATE_CALLBACK_SUPPORT)
zephyr::global_cdc_acm->add_on_rate_callback([this](const device *, uint32_t rate) {
if (rate == 1200) {
volatile uint32_t *dbl_reset_mem = (volatile uint32_t *) 0x20007F7C;
(*dbl_reset_mem) = DFU_DBL_RESET_MAGIC;
this->reset_pin_->digital_write(true);
if (this->reset_pin_ != nullptr) {
this->reset_pin_->digital_write(true);
} else {
NRF_POWER->GPREGRET = DFU_MAGIC_UF2_RESET;
App.reboot();
}
}
});
#endif
@@ -27,10 +37,13 @@ void DeviceFirmwareUpdate::setup() {
void DeviceFirmwareUpdate::dump_config() {
ESP_LOGCONFIG(TAG, "DFU:");
LOG_PIN(" RESET Pin: ", this->reset_pin_);
if (this->reset_pin_ != nullptr) {
LOG_PIN(" RESET Pin: ", this->reset_pin_);
} else {
ESP_LOGCONFIG(TAG, " Method: GPREGRET");
}
}
} // namespace nrf52
} // namespace esphome
} // namespace esphome::nrf52
#endif
+3 -5
View File
@@ -5,8 +5,7 @@
#include "esphome/core/component.h"
#include "esphome/core/gpio.h"
namespace esphome {
namespace nrf52 {
namespace esphome::nrf52 {
class DeviceFirmwareUpdate : public Component {
public:
void setup() override;
@@ -14,10 +13,9 @@ class DeviceFirmwareUpdate : public Component {
void dump_config() override;
protected:
GPIOPin *reset_pin_;
GPIOPin *reset_pin_{nullptr};
};
} // namespace nrf52
} // namespace esphome
} // namespace esphome::nrf52
#endif
@@ -0,0 +1,9 @@
nrf52:
dfu:
reset_pin:
number: 14
inverted: true
mode:
output: true
reg0:
voltage: 1.8V
@@ -1,9 +1,4 @@
nrf52:
dfu:
reset_pin:
number: 14
inverted: true
mode:
output: true
dfu: true
reg0:
voltage: 1.8V