Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

samples: cellular: nrf_cloud_rest_fota: add smp fota for nrf9160dk #18145

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions samples/cellular/nrf_cloud_rest_fota/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ zephyr_compile_definitions(PROJECT_NAME=${PROJECT_NAME})

# NORDIC SDK APP START
target_sources(app PRIVATE src/main.c)

if(CONFIG_NRF_CLOUD_FOTA_SMP AND CONFIG_BOARD_NRF9160DK_NRF9160_NS)
jayteemo marked this conversation as resolved.
Show resolved Hide resolved
target_sources(app PRIVATE src/smp_reset.c)
endif()
# NORDIC SDK APP END
13 changes: 13 additions & 0 deletions samples/cellular/nrf_cloud_rest_fota/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,19 @@ To enable full modem FOTA, add the following parameter to your build command:
Also, if you are using an nRF9160 DK, specify your development kit version by appending it to the board name.
For example, if you are using version 1.0.1, use the board name ``[email protected]/nrf9160/ns`` in your build command.

To enable SMP FOTA (nRF9160 DK only), add the following parameters to your build command:

* ``-DEXTRA_CONF_FILE=overlay_smp_fota.conf``
* ``-DEXTRA_DTC_OVERLAY_FILE=nrf9160dk_mcumgr_client_uart2.overlay``

The nRF52840 device on your DK must be running an SMP compatible firmware, such as the :ref:`smp_svr` sample.
Build the :ref:`smp_svr` sample for the ``nrf9160dk/nrf52840`` board with the following parameters:

* ``-DEXTRA_CONF_FILE=overlay_smp_fota.conf``
* ``-DEXTRA_DTC_OVERLAY_FILE=nrf9160dk_mcumgr_client_uart2.overlay``

To change :ref:`smp_svr` sample's application version, set the :kconfig:option:`CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION` Kconfig option.

Dependencies
************

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

/* Generic PIN definition for UART2 or UART1 to nRF52840 */
&pinctrl {
mcumgr_uart_default: mcumgr_uart_default {
group1 {
psels = <NRF_PSEL(UART_TX, 0, 23)>,
<NRF_PSEL(UART_RTS, 0, 17)>;
};
group2 {
psels = <NRF_PSEL(UART_RX, 0, 21)>,
<NRF_PSEL(UART_CTS, 0, 22)>;
bias-pull-up;
};
};

mcumgr_uart_sleep: mcumgr_uart_sleep {
group1 {
psels = <NRF_PSEL(UART_TX, 0, 23)>,
<NRF_PSEL(UART_RX, 0, 21)>,
<NRF_PSEL(UART_RTS, 0, 17)>,
<NRF_PSEL(UART_CTS, 0, 22)>;
low-power-enable;
};
};
};

&uart2 {
compatible = "nordic,nrf-uarte";
current-speed = <1000000>;
status = "okay";
pinctrl-0 = <&mcumgr_uart_default>;
pinctrl-1 = <&mcumgr_uart_sleep>;
pinctrl-names = "default", "sleep";
hw-flow-control;
};

/ {
chosen {
zephyr,uart-mcumgr = &uart2;
};
};
12 changes: 12 additions & 0 deletions samples/cellular/nrf_cloud_rest_fota/overlay_smp_fota.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
CONFIG_NRF_CLOUD_FOTA_SMP=y
CONFIG_NRF_MCUMGR_SMP_CLIENT=y
CONFIG_MCUMGR_GRP_IMG=y
CONFIG_MCUMGR_GRP_OS=y
CONFIG_MCUMGR_TRANSPORT_UART=y
CONFIG_UART_MCUMGR_RX_BUF_COUNT=4
CONFIG_BOOT_IMAGE_ACCESS_HOOKS=y
9 changes: 7 additions & 2 deletions samples/cellular/nrf_cloud_rest_fota/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <net/nrf_cloud_defs.h>
#include <net/fota_download.h>
#include <dk_buttons_and_leds.h>
#include "smp_reset.h"

LOG_MODULE_REGISTER(nrf_cloud_rest_fota, CONFIG_NRF_CLOUD_REST_FOTA_SAMPLE_LOG_LEVEL);

Expand Down Expand Up @@ -81,7 +82,10 @@ static void sample_reboot(enum nrf_cloud_fota_reboot_status status);
static struct nrf_cloud_fota_poll_ctx fota_ctx = {
.rest_ctx = &rest_ctx,
.device_id = device_id,
.reboot_fn = sample_reboot
.reboot_fn = sample_reboot,
#if SMP_FOTA_ENABLED
.smp_reset_cb = nrf52840_reset_api
#endif
};

#if defined(CONFIG_REST_FOTA_DO_JITP)
Expand Down Expand Up @@ -219,7 +223,8 @@ static void send_device_status(void)
.bootloader = 1,
.modem = 1,
.application = 1,
.modem_full = fota_ctx.full_modem_fota_supported
.modem_full = fota_ctx.full_modem_fota_supported,
.smp = SMP_FOTA_ENABLED
};

struct nrf_cloud_svc_info svc_inf = {
Expand Down
62 changes: 62 additions & 0 deletions samples/cellular/nrf_cloud_rest_fota/src/smp_reset.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/
#include <zephyr/kernel.h>
#include <zephyr/settings/settings.h>
#include <zephyr/logging/log.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/device.h>
#include <zephyr/devicetree.h>

LOG_MODULE_REGISTER(nrf_cloud_rest_fota_smp, CONFIG_NRF_CLOUD_REST_FOTA_SAMPLE_LOG_LEVEL);

#define RESET_NODE DT_NODELABEL(nrf52840_reset)
#define HAS_RECOVERY_MODE (DT_NODE_HAS_STATUS(RESET_NODE, okay))

int nrf52840_reset_api(void)
{
int err;
const struct gpio_dt_spec reset_pin_spec = GPIO_DT_SPEC_GET(RESET_NODE, gpios);

if (!device_is_ready(reset_pin_spec.port)) {
LOG_ERR("Reset device not ready");
return -EIO;
}

/* Configure pin as output and initialize it to inactive state. */
err = gpio_pin_configure_dt(&reset_pin_spec, GPIO_OUTPUT_INACTIVE);
if (err) {
LOG_ERR("Pin configure err: %d", err);
return err;
}

/* Reset the nRF52840 and let it wait until the pin is inactive again
* before running to main to ensure that it won't send any data until
* the H4 device is setup and ready to receive.
*/
err = gpio_pin_set_dt(&reset_pin_spec, 1);
if (err) {
LOG_ERR("GPIO Pin set to 1 err: %d", err);
return err;
}

/* Wait for the nRF52840 peripheral to stop sending data.
*
* It is critical (!) to wait here, so that all bytes
* on the lines are received and drained correctly.
*/
k_sleep(K_MSEC(10));

/* We are ready, let the nRF52840 run to main */
err = gpio_pin_set_dt(&reset_pin_spec, 0);
if (err) {
LOG_ERR("GPIO Pin set to 0 err: %d", err);
return err;
}

LOG_DBG("Reset Pin %d", reset_pin_spec.pin);

return 0;
}
20 changes: 20 additions & 0 deletions samples/cellular/nrf_cloud_rest_fota/src/smp_reset.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#ifndef _SMP_RESET_H_
#define _SMP_RESET_H_

#if defined(CONFIG_NRF_CLOUD_FOTA_SMP) && defined(CONFIG_BOARD_NRF9160DK_NRF9160_NS)
jayteemo marked this conversation as resolved.
Show resolved Hide resolved
#define SMP_FOTA_ENABLED 1
#else
#define SMP_FOTA_ENABLED 0
#endif

/**
* @brief Reset the nRF52840 for SMP FOTA.
*/
int nrf52840_reset_api(void);

#endif /* _SMP_RESET_H_ */
Loading