Added separate ota config file based on the prj file.

Parameters are based on the zigbee light switch example from nrf-connect toolkit.
clang-format with vs code.
This commit is contained in:
Ole Odendahl 2024-04-28 14:49:23 +02:00
parent a15bd37a1a
commit 61533da1b6
No known key found for this signature in database
GPG key ID: 116D1FA8CD50CD0B
2 changed files with 132 additions and 46 deletions

View file

@ -0,0 +1,89 @@
CONFIG_LOG=y
CONFIG_PWM=y
CONFIG_I2C=y
CONFIG_ADC=y
CONFIG_GPIO=y
CONFIG_USE_SEGGER_RTT=y
CONFIG_SEGGER_RTT_BUFFER_SIZE_UP=4096
CONFIG_NEWLIB_LIBC=y
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
CONFIG_SERIAL=n
CONFIG_HEAP_MEM_POOL_SIZE=2048
CONFIG_MAIN_THREAD_PRIORITY=7
CONFIG_ZIGBEE=y
CONFIG_ZIGBEE_APP_UTILS=y
CONFIG_ZIGBEE_ROLE_END_DEVICE=y
# This example requires more workqueue stack
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
# Enable nRF ECB driver
CONFIG_CRYPTO=y
CONFIG_CRYPTO_NRF_ECB=y
CONFIG_CRYPTO_INIT_PRIORITY=80
# Networking
CONFIG_NET_IPV6=n
CONFIG_NET_IPV6_MLD=n
CONFIG_NET_IPV6_NBR_CACHE=n
CONFIG_NET_IPV6_RA_RDNSS=n
CONFIG_NET_IP_ADDR_CHECK=n
CONFIG_NET_UDP=n
##
## ZigBee Channel Selection
##
# Get Zigbee to scan every channel.
CONFIG_ZIGBEE_CHANNEL_SELECTION_MODE_MULTI=y
# By default only scans channel 11 (ZigBee2MQTT default) and 15 (ZHA default).
# Comment to scan all channels - this will make pairing consume more energy.
# CONFIG_ZIGBEE_CHANNEL_MASK=0x8800
# Uncomment to set a specific channel - this will make pairing more energy efficient.
# CONFIG_ZIGBEE_CHANNEL=15
# Enable API for powering down unused RAM parts.
# https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.7.1/nrf/ug_zigbee_configuring.html#power-saving-during-sleep
CONFIG_RAM_POWER_DOWN_LIBRARY=y
# LittleFS.
CONFIG_MAIN_STACK_SIZE=2048
CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FILE_SYSTEM=y
CONFIG_FILE_SYSTEM_LITTLEFS=y
CONFIG_WATCHDOG=y
CONFIG_HWINFO=y
CONFIG_ASSERT=y
# Uncomment for debug log level.
# CONFIG_LOG_DEFAULT_LEVEL=4
# Factory reset method selection. Only hardware revision 2.0.0+ has button SW1. Earlier
# revisions must select a different method. See Kconfig for options.
# CONFIG_PRST_ZB_FACTORY_RESET_VIA_SW1=y
# Disable factory reset.
# OTA update configuration. This is based on the zigbee light switch example from the nrf-connect toolkit.
CONFIG_ZIGBEE_FOTA=y
CONFIG_ZIGBEE_FOTA_ENDPOINT=5
CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION="1.0.0" # Increase this version for generating an update for the devices.
CONFIG_ZIGBEE_FOTA_COMMENT="b_parasite"
# Ensure an MCUboot-compatible binary is generated.
CONFIG_IMG_MANAGER=y
CONFIG_STREAM_FLASH=y
CONFIG_DFU_TARGET_MCUBOOT=y
CONFIG_IMG_ERASE_PROGRESSIVELY=y
CONFIG_ZIGBEE_FOTA_PROGRESS_EVT=y
# Increase the number of RX buffers
CONFIG_NRF_802154_RX_BUFFERS=32

View file

@ -17,9 +17,9 @@
#include <zigbee/zigbee_error_handler.h>
#if CONFIG_ZIGBEE_FOTA
#include <zigbee/zigbee_fota.h>
#include <zephyr/sys/reboot.h>
#include <zephyr/dfu/mcuboot.h>
#include <zephyr/sys/reboot.h>
#include <zigbee/zigbee_fota.h>
#endif
#include "debug_counters.h"
@ -123,8 +123,8 @@ PRST_ZB_DECLARE_ENDPOINT(
#ifndef CONFIG_ZIGBEE_FOTA
ZBOSS_DECLARE_DEVICE_CTX_1_EP(
app_template_ctx,
app_template_ep);
app_template_ctx,
app_template_ep);
#else
extern zb_af_endpoint_desc_t zigbee_fota_client_ep;
@ -134,51 +134,48 @@ ZBOSS_DECLARE_DEVICE_CTX_2_EP(
zigbee_fota_client_ep,
app_template_ep);
static void confirm_image(void)
{
if (!boot_is_img_confirmed()) {
int ret = boot_write_img_confirmed();
static void confirm_image(void) {
if (!boot_is_img_confirmed()) {
int ret = boot_write_img_confirmed();
if (ret) {
LOG_ERR("Couldn't confirm image: %d", ret);
} else {
LOG_INF("Marked image as OK");
}
}
if (ret) {
LOG_ERR("Couldn't confirm image: %d", ret);
} else {
LOG_INF("Marked image as OK");
}
}
}
static void ota_evt_handler(const struct zigbee_fota_evt *evt)
{
switch (evt->id) {
static void ota_evt_handler(const struct zigbee_fota_evt *evt) {
switch (evt->id) {
case ZIGBEE_FOTA_EVT_PROGRESS:
// dk_set_led(OTA_ACTIVITY_LED, evt->dl.progress % 2);
// dk_set_led(OTA_ACTIVITY_LED, evt->dl.progress % 2);
prst_led_flash(1);
break;
break;
case ZIGBEE_FOTA_EVT_FINISHED:
LOG_INF("Reboot application.");
/* Power on unused sections of RAM to allow MCUboot to use it. */
if (IS_ENABLED(CONFIG_RAM_POWER_DOWN_LIBRARY)) {
power_up_unused_ram();
}
sys_reboot(SYS_REBOOT_COLD);
break;
LOG_INF("Reboot application.");
/* Power on unused sections of RAM to allow MCUboot to use it. */
if (IS_ENABLED(CONFIG_RAM_POWER_DOWN_LIBRARY)) {
power_up_unused_ram();
}
sys_reboot(SYS_REBOOT_COLD);
break;
case ZIGBEE_FOTA_EVT_ERROR:
LOG_ERR("OTA image transfer failed.");
break;
}
LOG_ERR("OTA image transfer failed.");
break;
}
}
static void zcl_device_cb(zb_bufid_t bufid)
{
zb_zcl_device_callback_param_t *device_cb_param =
ZB_BUF_GET_PARAM(bufid, zb_zcl_device_callback_param_t);
static void zcl_device_cb(zb_bufid_t bufid) {
zb_zcl_device_callback_param_t *device_cb_param =
ZB_BUF_GET_PARAM(bufid, zb_zcl_device_callback_param_t);
if (device_cb_param->device_cb_id == ZB_ZCL_OTA_UPGRADE_VALUE_CB_ID) {
zigbee_fota_zcl_cb(bufid);
} else {
device_cb_param->status = RET_NOT_IMPLEMENTED;
}
if (device_cb_param->device_cb_id == ZB_ZCL_OTA_UPGRADE_VALUE_CB_ID) {
zigbee_fota_zcl_cb(bufid);
} else {
device_cb_param->status = RET_NOT_IMPLEMENTED;
}
}
#endif /* CONFIG_ZIGBEE_FOTA */
@ -250,8 +247,8 @@ void zboss_signal_handler(zb_bufid_t bufid) {
// See zigbee_default_signal_handler() for all available signals.
#ifdef CONFIG_ZIGBEE_FOTA
/* Pass signal to the OTA client implementation. */
zigbee_fota_signal_handler(bufid);
/* Pass signal to the OTA client implementation. */
zigbee_fota_signal_handler(bufid);
#endif /* CONFIG_ZIGBEE_FOTA */
zb_zdo_app_signal_hdr_t *sig_hndler = NULL;
@ -390,14 +387,14 @@ int main(void) {
power_down_unused_ram();
#ifdef CONFIG_ZIGBEE_FOTA
/* Initialize Zigbee FOTA download service. */
zigbee_fota_init(ota_evt_handler);
/* Initialize Zigbee FOTA download service. */
zigbee_fota_init(ota_evt_handler);
/* Mark the current firmware as valid. */
confirm_image();
/* Mark the current firmware as valid. */
confirm_image();
/* Register callback for handling ZCL commands. */
ZB_ZCL_REGISTER_DEVICE_CB(zcl_device_cb);
/* Register callback for handling ZCL commands. */
ZB_ZCL_REGISTER_DEVICE_CB(zcl_device_cb);
#endif /* CONFIG_ZIGBEE_FOTA */
ZB_AF_REGISTER_DEVICE_CTX(&app_template_ctx);