Skip to content

Commit 4933069

Browse files
tokangaslemrey
authored andcommitted
lib: modem_antenna: add new library for setting antenna configuration
Created a new library to set the antenna configuration on nRF9160 DK and Thingy:91. The library sets the modem MAGPIO and COEX0 configuration depending on the selected board and the used GNSS antenna type. Removed MAGPIO and COEX0 configuration from LTE LC and Thingy:91 board. CIA-385 Signed-off-by: Tommi Kangas <[email protected]> Co-authored-by: Emanuele Di Santo <[email protected]>
1 parent 556c8cc commit 4933069

File tree

10 files changed

+149
-35
lines changed

10 files changed

+149
-35
lines changed

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ Kconfig* @tejlmand
9191
/lib/flash_patch/ @hakonfam
9292
/lib/location/ @trantanen @hiltunent @jhirsi @tokangas
9393
/lib/lte_link_control/ @jtguggedal @tokangas @simensrostad
94+
/lib/modem_antenna/ @tokangas
9495
/lib/modem_info/ @rlubos
9596
/lib/modem_key_mgmt/ @rlubos
9697
/lib/multicell_location/ @jhirsi @tokangas

boards/arm/thingy91_nrf9160/board_nonsecure.c

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ LOG_MODULE_REGISTER(board_nonsecure, CONFIG_BOARD_LOG_LEVEL);
1313

1414
#define AT_CMD_MAX_READ_LENGTH 128
1515
#define AT_CMD_LEN(cmd) (sizeof (cmd) - 1)
16-
#define AT_CMD_MAGPIO "AT%%XMAGPIO=1,1,1,7,1,746,803,2,698,748," \
17-
"2,1710,2200,3,824,894,4,880,960,5,791,849," \
18-
"7,1565,1586"
19-
#define AT_CMD_COEX0 "AT%%XCOEX0=1,1,1565,1586"
2016
#define AT_CMD_TRACE "AT%%XMODEMTRACE=0"
2117

2218
static int thingy91_magpio_configure(void)
@@ -50,22 +46,6 @@ static int thingy91_magpio_configure(void)
5046
return -EIO;
5147
}
5248

53-
LOG_DBG("AT CMD: %s", log_strdup(AT_CMD_MAGPIO));
54-
err = nrf_modem_at_printf(AT_CMD_MAGPIO);
55-
if (err) {
56-
LOG_ERR("MAGPIO command failed");
57-
return -EIO;
58-
}
59-
60-
LOG_DBG("AT CMD: %s", log_strdup(AT_CMD_COEX0));
61-
err = nrf_modem_at_printf(AT_CMD_COEX0);
62-
if (err) {
63-
LOG_ERR("MAGPIO command failed");
64-
return -EIO;
65-
}
66-
67-
LOG_DBG("MAGPIO successfully configured");
68-
6949
#endif
7050
return 0;
7151
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
.. _lib_modem_antenna:
2+
3+
Modem antenna
4+
#############
5+
6+
.. contents::
7+
:local:
8+
:depth: 2
9+
10+
You can use this library to set the antenna configuration on an nRF9160 DK or a Thingy:91.
11+
12+
Overview
13+
********
14+
15+
The library writes the MAGPIO and COEX0 configuration to the modem after the :ref:`nrfxlib:nrf_modem` library has been initialized.
16+
The configuration depends on the selected board and the used GNSS antenna type, onboard or external.
17+
18+
For an nRF9160 DK, the library configures the Low Noise Amplifier (LNA) depending on the GNSS antenna type.
19+
20+
For a Thingy:91, it configures the antenna matching network used with both LTE and GNSS.
21+
22+
Configuration
23+
*************
24+
25+
Set the following Kconfig option to enable this library:
26+
27+
* :kconfig:option:`CONFIG_MODEM_ANTENNA` - Enables the Modem antenna library.
28+
29+
.. note::
30+
31+
The library is enabled by default when building for targets ``nrf9160dk_nrf9160_ns`` and ``thingy91_nrf9160_ns``.
32+
33+
Use one of the following options to select the used antenna type:
34+
35+
* :kconfig:option:`CONFIG_MODEM_ANTENNA_GNSS_ONBOARD` - Selects the onboard GNSS antenna (default).
36+
* :kconfig:option:`CONFIG_MODEM_ANTENNA_GNSS_EXTERNAL` - Selects an external GNSS antenna.
37+
38+
Use the following options to set custom AT commands for MAGPIO and COEX0 configuration:
39+
40+
* :kconfig:option:`CONFIG_MODEM_ANTENNA_AT_MAGPIO` - Sets custom MAGPIO configuration.
41+
* :kconfig:option:`CONFIG_MODEM_ANTENNA_AT_COEX0` - Sets custom COEX0 configuration.
42+
43+
Dependencies
44+
************
45+
46+
This library uses the following `sdk-nrfxlib`_ library:
47+
48+
* :ref:`nrfxlib:nrf_modem`

doc/nrf/releases/release-notes-changelog.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,12 @@ Bluetooth libraries and services
360360
Modem libraries
361361
---------------
362362

363+
* Added:
364+
365+
* :ref:`lib_modem_antenna` library:
366+
367+
* A new library for setting the antenna configuration on an nRF9160 DK or a Thingy:91.
368+
363369
* Updated:
364370

365371
* :ref:`sms_readme` library:

lib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ add_subdirectory_ifdef(CONFIG_MODEM_ATTEST_TOKEN modem_attest_token)
3434
add_subdirectory_ifdef(CONFIG_MULTICELL_LOCATION multicell_location)
3535
add_subdirectory_ifdef(CONFIG_LOCATION location)
3636
add_subdirectory_ifdef(CONFIG_AT_SHELL at_shell)
37+
add_subdirectory_ifdef(CONFIG_MODEM_ANTENNA modem_antenna)

lib/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@ rsource "modem_attest_token/Kconfig"
3535
rsource "multicell_location/Kconfig"
3636
rsource "location/Kconfig"
3737
rsource "at_shell/Kconfig"
38+
rsource "modem_antenna/Kconfig"
3839

3940
endmenu

lib/lte_link_control/lte_lc_modem_hooks.c

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,14 @@
1212
LOG_MODULE_DECLARE(lte_lc);
1313

1414
NRF_MODEM_LIB_ON_INIT(lte_lc_init_hook, on_modem_init, NULL);
15-
NRF_MODEM_LIB_ON_SHUTDOWN(lte_lc_shutdown_hook, on_shutdown, NULL);
15+
NRF_MODEM_LIB_ON_SHUTDOWN(lte_lc_shutdown_hook, on_modem_shutdown, NULL);
1616

1717
static void on_modem_init(int err, void *ctx)
1818
{
1919
if (err) {
2020
return;
2121
}
2222

23-
#if defined(CONFIG_BOARD_THINGY91_NRF9160_NS)
24-
/* Configuring MAGPIO, so that the correct antenna
25-
* matching network is used for each LTE band and GPS.
26-
*/
27-
err = nrf_modem_at_printf("AT%%XMAGPIO=1,1,1,7,1,746,803,2,698,748,"
28-
"2,1710,2200,3,824,894,4,880,960,5,791,849,"
29-
"7,1565,1586");
30-
if (err) {
31-
LOG_ERR("Failed to configure MAGPIO, err %d", err);
32-
return;
33-
}
34-
#endif
35-
3623
#if defined(CONFIG_LTE_EDRX_REQ)
3724
/* Request configured eDRX settings to save power */
3825
err = lte_lc_edrx_req(true);
@@ -81,7 +68,7 @@ static void on_modem_init(int err, void *ctx)
8168
#endif
8269
}
8370

84-
static void on_shutdown(void *ctx)
71+
static void on_modem_shutdown(void *ctx)
8572
{
8673
(void)lte_lc_deinit();
8774
}

lib/modem_antenna/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#
2+
# Copyright (c) 2022 Nordic Semiconductor
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
zephyr_library()
8+
zephyr_library_sources(modem_antenna.c)

lib/modem_antenna/Kconfig

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#
2+
# Copyright (c) 2022 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
menuconfig MODEM_ANTENNA
8+
bool "Modem antenna configuration"
9+
depends on NRF_MODEM_LIB
10+
default y if (BOARD_NRF9160DK_NRF9160_NS || BOARD_THINGY91_NRF9160_NS)
11+
12+
if MODEM_ANTENNA
13+
14+
choice
15+
default MODEM_ANTENNA_GNSS_ONBOARD
16+
prompt "Select which antenna to use for GNSS"
17+
18+
config MODEM_ANTENNA_GNSS_ONBOARD
19+
bool "Use onboard antenna"
20+
21+
config MODEM_ANTENNA_GNSS_EXTERNAL
22+
bool "Use external antenna"
23+
24+
endchoice
25+
26+
config MODEM_ANTENNA_AT_MAGPIO
27+
string "AT%XMAGPIO command"
28+
default "AT\%XMAGPIO=1,0,0,1,1,1574,1577" if BOARD_NRF9160DK_NRF9160_NS
29+
default "AT\%XMAGPIO=1,1,1,7,1,746,803,2,698,748,2,1710,2200,3,824,894,4,880,960,5,791,849,7,1565,1586" if BOARD_THINGY91_NRF9160_NS
30+
help
31+
Defines the AT%XMAGPIO command to be sent to the modem. Leave
32+
empty if this command should not be sent.
33+
34+
config MODEM_ANTENNA_AT_COEX0
35+
string "AT%XCOEX0 command"
36+
default "AT\%XCOEX0=1,1,1565,1586" if (BOARD_NRF9160DK_NRF9160_NS || BOARD_THINGY91_NRF9160_NS) && MODEM_ANTENNA_GNSS_ONBOARD
37+
default "AT\%XCOEX0" if (BOARD_NRF9160DK_NRF9160_NS || BOARD_THINGY91_NRF9160_NS) && MODEM_ANTENNA_GNSS_EXTERNAL
38+
help
39+
Defines the AT%XCOEX0 command to be sent to the modem. Leave
40+
empty if this command should not be sent.
41+
42+
module=MODEM_ANTENNA
43+
module-dep=LOG
44+
module-str=Modem antenna
45+
source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config"
46+
47+
endif # MODEM_ANTENNA

lib/modem_antenna/modem_antenna.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (c) 2022 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <string.h>
8+
#include <nrf_modem_at.h>
9+
#include <modem/nrf_modem_lib.h>
10+
#include <logging/log.h>
11+
12+
LOG_MODULE_REGISTER(modem_antenna, CONFIG_MODEM_ANTENNA_LOG_LEVEL);
13+
14+
NRF_MODEM_LIB_ON_INIT(gnss_cfg_init_hook, on_modem_lib_init, NULL);
15+
16+
static void on_modem_lib_init(int ret, void *ctx)
17+
{
18+
if (ret != 0) {
19+
return;
20+
}
21+
22+
if (strlen(CONFIG_MODEM_ANTENNA_AT_MAGPIO) > 0) {
23+
LOG_DBG("Setting MAGPIO configuration: %s", CONFIG_MODEM_ANTENNA_AT_MAGPIO);
24+
if (nrf_modem_at_printf("%s", CONFIG_MODEM_ANTENNA_AT_MAGPIO) != 0) {
25+
LOG_ERR("Failed to set MAGPIO configuration");
26+
}
27+
}
28+
29+
if (strlen(CONFIG_MODEM_ANTENNA_AT_COEX0) > 0) {
30+
LOG_DBG("Setting COEX0 configuration: %s", CONFIG_MODEM_ANTENNA_AT_COEX0);
31+
if (nrf_modem_at_printf("%s", CONFIG_MODEM_ANTENNA_AT_COEX0) != 0) {
32+
LOG_ERR("Failed to set COEX0 configuration");
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)