From 6c63aa4e5786a9f0dd54bd4bdb3cb47736f1a65b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 25 May 2023 00:37:19 +0000 Subject: [PATCH] fix: update from upstream See https://github.com/nrfconnect/sdk-nrf/tree/8c420a58e74c1b5f138d87d5435b213ee8dea95f/applications/asset_tracker_v2 --- doc/app_behavior.rst | 1 - doc/asset_tracker_v2_description.rst | 2 +- doc/location_module.rst | 21 +++--- doc/modem_module.rst | 3 - doc/sensor_module.rst | 7 +- nrf9160dk_with_ext_flash.overlay | 45 +++++++++++++ overlay-carrier.conf | 4 -- sample.yaml | 1 + src/events/modem_module_event.c | 2 - src/events/modem_module_event.h | 7 -- src/main.c | 7 +- src/modules/modem_module.c | 99 ++++++++-------------------- 12 files changed, 90 insertions(+), 109 deletions(-) create mode 100644 nrf9160dk_with_ext_flash.overlay diff --git a/doc/app_behavior.rst b/doc/app_behavior.rst index e01fd16e..2f4336c3 100644 --- a/doc/app_behavior.rst +++ b/doc/app_behavior.rst @@ -136,5 +136,4 @@ To enable support for P-GPS, add the parameter ``-DOVERLAY_CONFIG=overlay-pgps.c To ensure that the resulting binary can be deployed using FOTA, you must make sure that the new partition layout is compatible with layout of the old image. See :ref:`static partitioning ` for more details. -.. note:: |gps_tradeoffs| diff --git a/doc/asset_tracker_v2_description.rst b/doc/asset_tracker_v2_description.rst index 0315d6db..33e63644 100644 --- a/doc/asset_tracker_v2_description.rst +++ b/doc/asset_tracker_v2_description.rst @@ -80,7 +80,7 @@ See the :ref:`nRF_asset_tracker` section for more details. Carrier library support *********************** -See the section :ref:`using_the_lwm2m_carrier_library` for steps on how to connect to a operator's device management platform, necessary in some LTE networks. +See the section :ref:`using_the_lwm2m_carrier_library` for steps on how to connect to an operator's device management platform, necessary in some LTE networks. .. _atv2_application_configuration: diff --git a/doc/location_module.rst b/doc/location_module.rst index 221e37e2..18d689aa 100644 --- a/doc/location_module.rst +++ b/doc/location_module.rst @@ -35,17 +35,18 @@ The default configuration for the location request is set as follows: The location module receives configuration updates as payload in the following two events: -* ``DATA_EVT_CONFIG_INIT`` - The event contains the value configured at build time or received from cloud and stored to flash. +* :c:enum:`DATA_EVT_CONFIG_INIT` - The event contains the value configured at build time or received from cloud and stored to flash. The event is distributed from the data module as part of the application initialization. -* ``DATA_EVT_CONFIG_READY`` - The event is received when the data module has processed an incoming message from cloud with a configuration update. +* :c:enum:`DATA_EVT_CONFIG_READY` - The event is received when the data module has processed an incoming message from cloud with a configuration update. The module sends the following events based on the outcome of the location request: -* ``LOCATION_MODULE_EVT_GNSS_DATA_READY``: GNSS position has been acquired -* ``LOCATION_MODULE_EVT_CLOUD_LOCATION_DATA_READY``: neighbor cell measurements or Wi-Fi access points (or both) have been obtained -* ``LOCATION_MODULE_EVT_DATA_NOT_READY``: Location request failed -* ``LOCATION_MODULE_EVT_TIMEOUT``: Timeout occurred -* ``LOCATION_MODULE_EVT_AGPS_NEEDED``: A-GPS request should be sent to cloud -* ``LOCATION_MODULE_EVT_PGPS_NEEDED``: P-GPS request should be sent to cloud + +* :c:enum:`LOCATION_MODULE_EVT_GNSS_DATA_READY`: GNSS position has been acquired +* :c:enum:`LOCATION_MODULE_EVT_CLOUD_LOCATION_DATA_READY`: Neighbor cell measurements or Wi-Fi access points (or both) have been obtained +* :c:enum:`LOCATION_MODULE_EVT_DATA_NOT_READY`: Location request failed +* :c:enum:`LOCATION_MODULE_EVT_TIMEOUT`: Timeout occurred +* :c:enum:`LOCATION_MODULE_EVT_AGPS_NEEDED`: A-GPS request should be sent to cloud +* :c:enum:`LOCATION_MODULE_EVT_PGPS_NEEDED`: P-GPS request should be sent to cloud GNSS LNA configuration ====================== @@ -59,7 +60,7 @@ GPS assistance data =================== The location module receives requests for GPS assistance data from the :ref:`lib_location` library. -When the module receives an A-GPS request, it distributes it to the other modules as a ``LOCATION_MODULE_EVT_AGPS_NEEDED`` event that contains information about the type of assistance data needed. +When the module receives an A-GPS request, it distributes it to the other modules as a :c:enum:`LOCATION_MODULE_EVT_AGPS_NEEDED` event that contains information about the type of assistance data needed. Providing the requested A-GPS data typically reduces significantly the time it takes to acquire a GNSS fix. Wi-Fi positioning @@ -98,7 +99,7 @@ In this sense, it differs from many other modules. All incoming events from other modules are handled in the context of the Application Event Manager callback, because they all complete fast enough to not require a separate thread. The :ref:`lib_location` library handles cellular and Wi-Fi positioning together when the location request method list has them next to each other. -This means that LTE neighbor cell measurements and Wi-Fi scanning results are combined into the same ``LOCATION_EVT_CLOUD_LOCATION_EXT_REQUEST`` event. +This means that LTE neighbor cell measurements and Wi-Fi scanning results are combined into the same :c:enum:`LOCATION_EVT_CLOUD_LOCATION_EXT_REQUEST` event. The location module responds to the :ref:`lib_location` library with unknown location resolution, because it does not request the location back from cloud service. Configuration options diff --git a/doc/modem_module.rst b/doc/modem_module.rst index 3bd54f84..336da3bc 100644 --- a/doc/modem_module.rst +++ b/doc/modem_module.rst @@ -86,10 +86,7 @@ Module states The modem module has an internal state machine with the following states: - * ``STATE_INIT`` - The initial state of the module in which it awaits the modem to be initialized. - The module enters this state only if the :ref:`liblwm2m_carrier_readme` library is enabled because the modem is automatically initialized otherwise. * ``STATE_DISCONNECTED`` - The module has performed all required initializations and is ready to establish an LTE connection. - This is the initial state for applications that do not use the :ref:`liblwm2m_carrier_readme` library. * ``STATE_CONNECTING`` - The modem is currently searching for a suitable LTE network and attempting to establish a connection. * ``STATE_CONNECTED`` - The device is connected to an LTE network. * ``STATE_SHUTDOWN`` - The module has been shut down after receiving a request from the utility module. diff --git a/doc/sensor_module.rst b/doc/sensor_module.rst index 9357f013..b3165f57 100644 --- a/doc/sensor_module.rst +++ b/doc/sensor_module.rst @@ -87,7 +87,7 @@ Motion impact detection ======================= Motion impact is detected when the magnitude (root sum squared) of acceleration exceeds the configured threshold value. -To enable motion impact detection, you must include :kconfig:option:`CONFIG_EXTERNAL_SENSORS_IMPACT_DETECTION` when building the application. +To enable motion impact detection, you must include :ref:`CONFIG_EXTERNAL_SENSORS_IMPACT_DETECTION ` when building the application. The threshold is configured using the :kconfig:option:`CONFIG_ADXL372_ACTIVITY_THRESHOLD` option. The accelerometer records acceleration magnitude when it is in the active mode and reports the peak magnitude once it reverts to the inactive mode. @@ -114,7 +114,7 @@ Perform the following steps to enable BSEC: #. Disable the Zephyr BME680 driver by setting :kconfig:option:`CONFIG_BME680` to false. #. Enable the external sensors API BSEC integration layer by enabling :ref:`CONFIG_EXTERNAL_SENSORS_BME680_BSEC ` option. -Air quality readings are provided with the :c:enumerator:`SENSOR_EVT_ENVIRONMENTAL_DATA_READY` event. +Air quality readings are provided with the :c:enum:`SENSOR_EVT_ENVIRONMENTAL_DATA_READY` event. To check and configure the BSEC configuration options, see :ref:`external_sensor_API_BSEC_configurations` section. @@ -172,7 +172,8 @@ Module states The sensor module has an internal state machine with the following states: * ``STATE_INIT`` - The initial state of the module in which it awaits its initial configuration from the data module. -* ``STATE_RUNNING`` - The module is initialized and can be queried for sensor data. It will also send :c:enum:`SENSOR_EVT_MOVEMENT_DATA_READY` on movement. +* ``STATE_RUNNING`` - The module is initialized and can be queried for sensor data. + It will also send :c:enum:`SENSOR_EVT_MOVEMENT_DATA_READY` on movement. * ``STATE_SHUTDOWN`` - The module has been shut down after receiving a request from the utility module. State transitions take place based on events from other modules, such as the app module, data module, and utility module. diff --git a/nrf9160dk_with_ext_flash.overlay b/nrf9160dk_with_ext_flash.overlay new file mode 100644 index 00000000..a5e60f44 --- /dev/null +++ b/nrf9160dk_with_ext_flash.overlay @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ + + /* The mx25r64 definition would normally be included when specifying a nrf9160dk_nrf9160_ns + * board revision >= 0.14.0, but unfortunately twister has a bug that prevents the revision + * overlay to get loaded when testing the sample. */ + &spi3 { + cs-gpios = <&arduino_header 16 GPIO_ACTIVE_LOW>, /* D10 */ + <&gpio0 25 GPIO_ACTIVE_LOW>; + mx25r64: mx25r6435f@1 { + compatible = "jedec,spi-nor"; + reg = <1>; + spi-max-frequency = <8000000>; + jedec-id = [c2 28 17]; + sfdp-bfp = [ + e5 20 f1 ff ff ff ff 03 44 eb 08 6b 08 3b 04 bb + ee ff ff ff ff ff 00 ff ff ff 00 ff 0c 20 0f 52 + 10 d8 00 ff 23 72 f5 00 82 ed 04 cc 44 83 68 44 + 30 b0 30 b0 f7 c4 d5 5c 00 be 29 ff f0 d0 ff ff + ]; + size = <67108864>; + mxicy,mx25r-power-mode = "high-performance"; + }; +}; + +/* Enable high drive mode for the SPI3 pins to get a square signal at 8 MHz */ +&spi3_default { + group1 { + nordic,drive-mode = ; + }; +}; + +/ { + aliases { + ext-flash = &mx25r64; + }; + + /* Configure partition manager to use mx25r64 as the external flash */ + chosen { + nordic,pm-ext-flash = &mx25r64; + }; +}; diff --git a/overlay-carrier.conf b/overlay-carrier.conf index 4b0b527d..84ea7376 100644 --- a/overlay-carrier.conf +++ b/overlay-carrier.conf @@ -28,10 +28,6 @@ CONFIG_DOWNLOAD_CLIENT_MAX_FILENAME_SIZE=230 # Modem info CONFIG_MODEM_INFO_BUFFER_SIZE=512 -# Disable AT host library as it's incompatible with the carrier library's -# requirement to initialize the modem library -CONFIG_AT_HOST_LIBRARY=n - # Credential management CONFIG_MODEM_KEY_MGMT=y diff --git a/sample.yaml b/sample.yaml index 7bf19a13..7a01506f 100644 --- a/sample.yaml +++ b/sample.yaml @@ -125,6 +125,7 @@ tests: integration_platforms: - nrf9160dk_nrf9160_ns extra_args: OVERLAY_CONFIG=overlay-carrier.conf + DTC_OVERLAY_FILE=nrf9160dk_with_ext_flash.overlay tags: ci_build applications.asset_tracker_v2.lwm2m.low-power: build_only: true diff --git a/src/events/modem_module_event.c b/src/events/modem_module_event.c index 4e297100..d9496274 100644 --- a/src/events/modem_module_event.c +++ b/src/events/modem_module_event.c @@ -40,8 +40,6 @@ static char *get_evt_type_str(enum modem_module_event_type type) return "MODEM_EVT_SHUTDOWN_READY"; case MODEM_EVT_ERROR: return "MODEM_EVT_ERROR"; - case MODEM_EVT_CARRIER_INITIALIZED: - return "MODEM_EVT_CARRIER_INITIALIZED"; case MODEM_EVT_CARRIER_EVENT_LTE_LINK_UP_REQUEST: return "MODEM_EVT_CARRIER_EVENT_LTE_LINK_UP_REQUEST"; case MODEM_EVT_CARRIER_EVENT_LTE_LINK_DOWN_REQUEST: diff --git a/src/events/modem_module_event.h b/src/events/modem_module_event.h index 0397762f..7ca184f1 100644 --- a/src/events/modem_module_event.h +++ b/src/events/modem_module_event.h @@ -103,13 +103,6 @@ enum modem_module_event_type { */ MODEM_EVT_ERROR, - /** The carrier library has initialized the modem library and it is - * now ready to be used. When the carrier library is enabled, this - * event must be received before the modem module can proceed to initialize - * other dependencies and subsequently send MODEM_EVT_INITIALIZED. - * The event has no associated payload. - */ - MODEM_EVT_CARRIER_INITIALIZED, /** Due to modem limitations for active TLS connections, the carrier * library requires all other TLS connections in the system to * be terminated while FOTA update is ongoing. diff --git a/src/main.c b/src/main.c index 3c5638d3..424257b8 100644 --- a/src/main.c +++ b/src/main.c @@ -517,12 +517,7 @@ int main(void) SEND_EVENT(app, APP_EVT_START); #if defined(CONFIG_NRF_MODEM_LIB) - /* The carrier library will initialize the modem if enabled, if not, - * we initialize the modem in here, before the rest of the application is started. - */ - if (!IS_ENABLED(CONFIG_LWM2M_CARRIER)) { - modem_init(); - } + modem_init(); #endif } diff --git a/src/modules/modem_module.c b/src/modules/modem_module.c index 434d4a87..572a7b8e 100644 --- a/src/modules/modem_module.c +++ b/src/modules/modem_module.c @@ -50,10 +50,6 @@ struct modem_msg_data { /* Modem module super states. */ static enum state_type { - /* Initialization state where all libraries that the module depends - * on need to be initialized before you can enter any other state. - */ - STATE_INIT, STATE_DISCONNECTED, STATE_CONNECTING, STATE_CONNECTED, @@ -90,6 +86,16 @@ NRF_MODEM_LIB_ON_INIT(asset_tracker_init_hook, on_modem_lib_init, NULL); static void on_modem_lib_init(int ret, void *ctx) { + int err; + + if (ret == 0) { + /* LTE LC is uninitialized on every modem shutdown. */ + err = lte_lc_init(); + if (err) { + LOG_ERR("lte_lc_init, error: %d", err); + } + } + k_sem_give(&nrf_modem_initialized); } @@ -109,8 +115,6 @@ static inline int adjust_rsrp(int input); static char *state2str(enum state_type state) { switch (state) { - case STATE_INIT: - return "STATE_INIT"; case STATE_DISCONNECTED: return "STATE_DISCONNECTED"; case STATE_CONNECTING: @@ -338,22 +342,12 @@ static void print_carrier_error(const lwm2m_carrier_event_t *evt) "Failed to connect to the LTE network", [LWM2M_CARRIER_ERROR_LTE_LINK_DOWN_FAIL] = "Failed to disconnect from the LTE network", - [LWM2M_CARRIER_ERROR_FOTA_PKG] = - "Package refused from modem", - [LWM2M_CARRIER_ERROR_FOTA_PROTO] = - "Protocol error", - [LWM2M_CARRIER_ERROR_FOTA_CONN] = - "Connection to remote server failed", - [LWM2M_CARRIER_ERROR_FOTA_CONN_LOST] = - "Connection to remote server lost", [LWM2M_CARRIER_ERROR_FOTA_FAIL] = "Modem firmware update failed", [LWM2M_CARRIER_ERROR_CONFIGURATION] = "Illegal object configuration detected", [LWM2M_CARRIER_ERROR_INIT] = "Initialization failure", - [LWM2M_CARRIER_ERROR_INTERNAL] = - "Internal failure", [LWM2M_CARRIER_ERROR_RUN] = "Configuration failure", }; @@ -400,11 +394,6 @@ int lwm2m_carrier_event_handler(const lwm2m_carrier_event_t *evt) int err = 0; switch (evt->type) { - case LWM2M_CARRIER_EVENT_INIT: { - LOG_INF("LWM2M_CARRIER_EVENT_INIT"); - SEND_EVENT(modem, MODEM_EVT_CARRIER_INITIALIZED); - break; - } case LWM2M_CARRIER_EVENT_LTE_LINK_UP: { LOG_INF("LWM2M_CARRIER_EVENT_LTE_LINK_UP"); SEND_EVENT(modem, MODEM_EVT_CARRIER_EVENT_LTE_LINK_UP_REQUEST); @@ -433,6 +422,9 @@ int lwm2m_carrier_event_handler(const lwm2m_carrier_event_t *evt) SEND_EVENT(modem, MODEM_EVT_CARRIER_FOTA_PENDING); break; } + case LWM2M_CARRIER_EVENT_FOTA_SUCCESS: + LOG_INF("LWM2M_CARRIER_EVENT_FOTA_SUCCESS"); + break; case LWM2M_CARRIER_EVENT_REBOOT: { LOG_INF("LWM2M_CARRIER_EVENT_REBOOT"); SEND_EVENT(modem, MODEM_EVT_CARRIER_REBOOT_REQUEST); @@ -444,20 +436,17 @@ int lwm2m_carrier_event_handler(const lwm2m_carrier_event_t *evt) */ return 1; } + case LWM2M_CARRIER_EVENT_MODEM_INIT: + LOG_INF("LWM2M_CARRIER_EVENT_MODEM_INIT"); + err = nrf_modem_lib_init(); + break; + case LWM2M_CARRIER_EVENT_MODEM_SHUTDOWN: + LOG_INF("LWM2M_CARRIER_EVENT_MODEM_SHUTDOWN"); + err = nrf_modem_lib_shutdown(); + break; case LWM2M_CARRIER_EVENT_ERROR: { - const lwm2m_carrier_event_error_t *err = evt->data.error; - LOG_ERR("LWM2M_CARRIER_EVENT_ERROR"); print_carrier_error(evt); - - bool fota_error = err->type == LWM2M_CARRIER_ERROR_FOTA_PKG || - err->type == LWM2M_CARRIER_ERROR_FOTA_PROTO || - err->type == LWM2M_CARRIER_ERROR_FOTA_CONN || - err->type == LWM2M_CARRIER_ERROR_FOTA_CONN_LOST || - err->type == LWM2M_CARRIER_ERROR_FOTA_FAIL; - if (fota_error) { - SEND_EVENT(modem, MODEM_EVT_CARRIER_FOTA_STOPPED); - } break; } } @@ -713,12 +702,6 @@ static int setup(void) } #endif - err = lte_lc_init(); - if (err) { - LOG_ERR("lte_lc_init, error: %d", err); - return err; - } - /* Setup a callback for the default PDP context. */ err = pdn_default_ctx_cb_reg(pdn_event_handler); if (err) { @@ -748,20 +731,6 @@ static int setup(void) return 0; } -/* Message handler for STATE_INIT */ -static void on_state_init(struct modem_msg_data *msg) -{ - if (IS_EVENT(msg, modem, MODEM_EVT_CARRIER_INITIALIZED)) { - int err; - - state_set(STATE_DISCONNECTED); - - err = setup(); - __ASSERT(err == 0, "Failed running setup()"); - SEND_EVENT(modem, MODEM_EVT_INITIALIZED); - } -} - /* Message handler for STATE_DISCONNECTED. */ static void on_state_disconnected(struct modem_msg_data *msg) { @@ -857,13 +826,6 @@ static void on_all_states(struct modem_msg_data *msg) if (IS_EVENT(msg, app, APP_EVT_START)) { int err; - if (IS_ENABLED(CONFIG_LWM2M_CARRIER)) { - /* The carrier library handles the LTE connection - * establishment. - */ - return; - } - err = lte_connect(); if (err) { LOG_ERR("Failed connecting to LTE, error: %d", err); @@ -922,26 +884,19 @@ static void module_thread_fn(void) k_sem_take(&nrf_modem_initialized, K_FOREVER); - if (IS_ENABLED(CONFIG_LWM2M_CARRIER)) { - state_set(STATE_INIT); - } else { - state_set(STATE_DISCONNECTED); - SEND_EVENT(modem, MODEM_EVT_INITIALIZED); + state_set(STATE_DISCONNECTED); + SEND_EVENT(modem, MODEM_EVT_INITIALIZED); - err = setup(); - if (err) { - LOG_ERR("Failed setting up the modem, error: %d", err); - SEND_ERROR(modem, MODEM_EVT_ERROR, err); - } + err = setup(); + if (err) { + LOG_ERR("Failed setting up the modem, error: %d", err); + SEND_ERROR(modem, MODEM_EVT_ERROR, err); } while (true) { module_get_next_msg(&self, &msg); switch (state) { - case STATE_INIT: - on_state_init(&msg); - break; case STATE_DISCONNECTED: on_state_disconnected(&msg); break;