Skip to content

Commit ee92cf4

Browse files
mike-scottioannisg
authored andcommitted
drivers: modem: ublox-sara-r4: Support SARA-U2 modems, sense VINT
This adds support for SARA-U2 modems. They have different timings on the PWR_ON pin, don't support AT+CESQ and require a manual GPRS connection setup. The VINT pin is used as a more reliable and faster way to power on the modem. Based on work by Göran Weinholt <[email protected]> Signed-off-by: Michael Scott <[email protected]>
1 parent ebf6520 commit ee92cf4

File tree

8 files changed

+136
-12
lines changed

8 files changed

+136
-12
lines changed

boards/arm/particle_boron/Kconfig.defconfig

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,13 @@ config UART_1_NRF_UARTE
5858
config UART_1_NRF_FLOW_CONTROL
5959
default y
6060

61-
config MODEM_UBLOX_SARA_R4
61+
config MODEM_UBLOX_SARA
6262
default y
6363

64+
choice MODEM_UBLOX_SARA_VARIANT
65+
default MODEM_UBLOX_SARA_R4
66+
endchoice
67+
6468
config UART_INTERRUPT_DRIVEN
6569
default y
6670

boards/arm/particle_boron/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static int board_particle_boron_init(struct device *dev)
3939

4040
external_antenna(false);
4141

42-
#if defined(CONFIG_MODEM_UBLOX_SARA_R4)
42+
#if defined(CONFIG_MODEM_UBLOX_SARA)
4343
struct device *gpio_dev;
4444

4545
/* Enable the serial buffer for SARA-R4 modem */
@@ -52,6 +52,7 @@ static int board_particle_boron_init(struct device *dev)
5252

5353
gpio_pin_configure(gpio_dev, SERIAL_BUFFER_ENABLE_GPIO_PIN,
5454
GPIO_DIR_OUT);
55+
gpio_pin_write(gpio_dev, SERIAL_BUFFER_ENABLE_GPIO_PIN, 0);
5556
#endif
5657

5758
return 0;

boards/arm/particle_boron/particle_boron.dts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,6 @@
4848

4949
mdm-power-gpios = <&gpio0 16 0>;
5050
mdm-reset-gpios = <&gpio0 12 0>;
51+
mdm-vint-gpios = <&gpio0 2 0>;
5152
};
5253
};

boards/shields/sparkfun_sara_r4/sparkfun_sara_r4.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Enable u-blox SARA-R4 modem
22
CONFIG_MODEM=y
33
CONFIG_MODEM_SHELL=y
4+
CONFIG_MODEM_UBLOX_SARA=y
45
CONFIG_MODEM_UBLOX_SARA_R4=y
56
CONFIG_UART_INTERRUPT_DRIVEN=y
67

drivers/modem/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ zephyr_sources_ifdef(CONFIG_MODEM_IFACE_UART modem_iface_uart.c)
1212
zephyr_sources_ifdef(CONFIG_MODEM_CMD_HANDLER modem_cmd_handler.c)
1313
zephyr_sources_ifdef(CONFIG_MODEM_SOCKET modem_socket.c)
1414

15-
if(CONFIG_MODEM_UBLOX_SARA_R4)
15+
if(CONFIG_MODEM_UBLOX_SARA)
1616
zephyr_library_include_directories(${ZEPHYR_BASE}/subsys/net/ip)
1717
zephyr_library_sources(ublox-sara-r4.c)
1818
endif()

drivers/modem/Kconfig.ublox-sara-r4

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
# SPDX-License-Identifier: Apache-2.0
77
#
88

9-
config MODEM_UBLOX_SARA_R4
10-
bool "Enable u-blox SARA-R4 LTE-CatM1/NB-IoT modem driver"
9+
config MODEM_UBLOX_SARA
10+
bool "Enable u-blox SARA modem driver"
1111
select MODEM_CONTEXT
1212
select MODEM_CMD_HANDLER
1313
select MODEM_IFACE_UART
@@ -19,7 +19,23 @@ config MODEM_UBLOX_SARA_R4
1919
Choose this setting to enable u-blox SARA-R4 LTE-CatM1/NB-IoT modem
2020
driver.
2121

22-
if MODEM_UBLOX_SARA_R4
22+
if MODEM_UBLOX_SARA
23+
24+
choice MODEM_UBLOX_SARA_VARIANT
25+
bool "u-blox SARA variant selection"
26+
default MODEM_UBLOX_SARA_R4
27+
28+
config MODEM_UBLOX_SARA_R4
29+
bool "u-blox SARA-R4"
30+
help
31+
Enable support for SARA-R4 modem
32+
33+
config MODEM_UBLOX_SARA_U2
34+
bool "u-blox SARA-U2"
35+
help
36+
Enable support for SARA-U2 modem
37+
38+
endchoice
2339

2440
config MODEM_UBLOX_SARA_R4_NAME
2541
string "Driver name"
@@ -64,4 +80,4 @@ config MODEM_UBLOX_SARA_R4_INIT_PRIORITY
6480
Note that the priority needs to be lower than the net stack
6581
so that it can start before the networking sub-system.
6682

67-
endif # MODEM_UBLOX_SARA_R4
83+
endif # MODEM_UBLOX_SARA

drivers/modem/ublox-sara-r4.c

Lines changed: 102 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ LOG_MODULE_REGISTER(modem_ublox_sara_r4, CONFIG_MODEM_LOG_LEVEL);
3333
enum mdm_control_pins {
3434
MDM_POWER = 0,
3535
MDM_RESET,
36+
#if defined(DT_UBLOX_SARA_R4_0_MDM_VINT_GPIOS_CONTROLLER)
37+
MDM_VINT,
38+
#endif
3639
};
3740

3841
static struct modem_pin modem_pins[] = {
@@ -44,6 +47,11 @@ static struct modem_pin modem_pins[] = {
4447
MODEM_PIN(DT_INST_0_UBLOX_SARA_R4_MDM_RESET_GPIOS_CONTROLLER,
4548
DT_INST_0_UBLOX_SARA_R4_MDM_RESET_GPIOS_PIN, GPIO_DIR_OUT),
4649

50+
#if defined(DT_UBLOX_SARA_R4_0_MDM_VINT_GPIOS_CONTROLLER)
51+
/* MDM_VINT */
52+
MODEM_PIN(DT_INST_0_UBLOX_SARA_R4_MDM_VINT_GPIOS_CONTROLLER,
53+
DT_INST_0_UBLOX_SARA_R4_MDM_VINT_GPIOS_PIN, GPIO_DIR_IN),
54+
#endif
4755
};
4856

4957
#define MDM_UART_DEV_NAME DT_INST_0_UBLOX_SARA_R4_BUS_NAME
@@ -52,10 +60,14 @@ static struct modem_pin modem_pins[] = {
5260
#define MDM_POWER_DISABLE 0
5361
#define MDM_RESET_NOT_ASSERTED 1
5462
#define MDM_RESET_ASSERTED 0
63+
#if defined(DT_UBLOX_SARA_R4_0_MDM_VINT_GPIOS_CONTROLLER)
64+
#define MDM_VINT_ENABLE 1
65+
#define MDM_VINT_DISABLE 0
66+
#endif
5567

5668
#define MDM_CMD_TIMEOUT K_SECONDS(10)
5769
#define MDM_REGISTRATION_TIMEOUT K_SECONDS(180)
58-
#define MDM_PROMPT_CMD_DELAY K_MSEC(10)
70+
#define MDM_PROMPT_CMD_DELAY K_MSEC(75)
5971

6072
#define MDM_MAX_DATA_LENGTH 1024
6173
#define MDM_RECV_MAX_BUF 30
@@ -255,7 +267,7 @@ static int send_socket_data(struct modem_socket *sock,
255267

256268
/* slight pause per spec so that @ prompt is received */
257269
k_sleep(MDM_PROMPT_CMD_DELAY);
258-
270+
#if defined(CONFIG_MODEM_UBLOX_SARA_R4)
259271
/*
260272
* HACK: Apparently, enabling HEX transmit mode also
261273
* affects the BINARY send method. We need to encode
@@ -266,6 +278,9 @@ static int send_socket_data(struct modem_socket *sock,
266278
snprintk(send_buf, sizeof(send_buf), "%02x", buf[i]);
267279
mctx.iface.write(&mctx.iface, send_buf, 2U);
268280
}
281+
#else
282+
mctx.iface.write(&mctx.iface, buf, buf_len);
283+
#endif
269284

270285
if (timeout == K_NO_WAIT) {
271286
ret = 0;
@@ -367,6 +382,7 @@ MODEM_CMD_DEFINE(on_cmd_atcmdinfo_imei)
367382
LOG_INF("IMEI: %s", log_strdup(mdata.mdm_imei));
368383
}
369384

385+
#if !defined(CONFIG_MODEM_UBLOX_SARA_U2)
370386
/*
371387
* Handler: +CESQ: <rxlev>[0],<ber>[1],<rscp>[2],<ecn0>[3],<rsrq>[4],<rsrp>[5]
372388
*/
@@ -383,6 +399,27 @@ MODEM_CMD_DEFINE(on_cmd_atcmdinfo_rssi_cesq)
383399

384400
LOG_INF("RSRP: %d", mctx.data_rssi);
385401
}
402+
#endif
403+
404+
#if defined(CONFIG_MODEM_UBLOX_SARA_U2)
405+
/* Handler: +CSQ: <signal_power>[0],<qual>[1] */
406+
MODEM_CMD_DEFINE(on_cmd_atcmdinfo_rssi_csq)
407+
{
408+
int rssi;
409+
410+
rssi = ATOI(argv[1], 0, "qual");
411+
if (rssi == 31) {
412+
mctx.data_rssi = -46;
413+
} else if (rssi >= 0 && rssi <= 31) {
414+
/* FIXME: This value depends on the RAT */
415+
mctx.data_rssi = -110 + ((rssi * 2) + 1);
416+
} else {
417+
mctx.data_rssi = -1000;
418+
}
419+
420+
LOG_INF("QUAL: %d", mctx.data_rssi);
421+
}
422+
#endif
386423

387424
/*
388425
* Modem Socket Command Handlers
@@ -595,31 +632,68 @@ static int pin_init(void)
595632

596633
LOG_DBG("MDM_POWER_PIN -> DISABLE");
597634
modem_pin_write(&mctx, MDM_POWER, MDM_POWER_DISABLE);
635+
#if defined(CONFIG_MODEM_UBLOX_SARA_U2)
636+
k_sleep(K_SECONDS(1));
637+
#else
598638
k_sleep(K_SECONDS(4));
639+
#endif
599640
LOG_DBG("MDM_POWER_PIN -> ENABLE");
600641
modem_pin_write(&mctx, MDM_POWER, MDM_POWER_ENABLE);
601642
k_sleep(K_SECONDS(1));
602643

603644
/* make sure module is powered off */
645+
#if defined(DT_UBLOX_SARA_R4_0_MDM_VINT_GPIOS_CONTROLLER)
646+
LOG_DBG("Waiting for MDM_VINT_PIN = 0");
647+
648+
do {
649+
k_sleep(K_MSEC(100));
650+
} while (modem_pin_read(&mctx, MDM_VINT) != MDM_VINT_DISABLE);
651+
#else
604652
k_sleep(K_SECONDS(8));
653+
#endif
654+
605655
LOG_DBG("MDM_POWER_PIN -> DISABLE");
656+
657+
unsigned int irq_lock_key = irq_lock();
658+
606659
modem_pin_write(&mctx, MDM_POWER, MDM_POWER_DISABLE);
660+
#if defined(CONFIG_MODEM_UBLOX_SARA_U2)
661+
k_usleep(50); /* 50-80 microseconds */
662+
#else
607663
k_sleep(K_SECONDS(1));
608-
LOG_DBG("MDM_POWER_PIN -> ENABLE");
664+
#endif
609665
modem_pin_write(&mctx, MDM_POWER, MDM_POWER_ENABLE);
666+
667+
irq_unlock(irq_lock_key);
668+
669+
LOG_DBG("MDM_POWER_PIN -> ENABLE");
670+
671+
#if defined(DT_UBLOX_SARA_R4_0_MDM_VINT_GPIOS_CONTROLLER)
672+
LOG_DBG("Waiting for MDM_VINT_PIN = 1");
673+
do {
674+
k_sleep(K_MSEC(100));
675+
} while (modem_pin_read(&mctx, MDM_VINT) != MDM_VINT_ENABLE);
676+
#else
610677
k_sleep(K_SECONDS(10));
678+
#endif
611679

612680
modem_pin_config(&mctx, MDM_POWER, GPIO_DIR_IN);
681+
613682
LOG_INF("... Done!");
614683

615684
return 0;
616685
}
617686

618687
static void modem_rssi_query_work(struct k_work *work)
619688
{
620-
struct modem_cmd cmd = MODEM_CMD("+CESQ: ", on_cmd_atcmdinfo_rssi_cesq,
621-
6U, ",");
689+
struct modem_cmd cmd =
690+
#if defined(CONFIG_MODEM_UBLOX_SARA_U2)
691+
MODEM_CMD("+CSQ: ", on_cmd_atcmdinfo_rssi_csq, 2U, ",");
692+
static char *send_cmd = "AT+CSQ";
693+
#else
694+
MODEM_CMD("+CESQ: ", on_cmd_atcmdinfo_rssi_cesq, 6U, ",");
622695
static char *send_cmd = "AT+CESQ";
696+
#endif
623697
int ret;
624698

625699
/* query modem RSSI */
@@ -668,6 +742,18 @@ static void modem_reset(void)
668742
SETUP_CMD_NOHANDLE("AT+CFUN=1"),
669743
};
670744

745+
#if defined(CONFIG_MODEM_UBLOX_SARA_U2)
746+
static struct setup_cmd u2_setup_cmds[] = {
747+
/* set the APN */
748+
SETUP_CMD_NOHANDLE("AT+UPSD=0,1,\""
749+
CONFIG_MODEM_UBLOX_SARA_R4_MANUAL_MCCMNO "\""),
750+
/* set dynamic IP */
751+
SETUP_CMD_NOHANDLE("AT+UPSD=0,7,\"0.0.0.0\""),
752+
/* activate the GPRS connection */
753+
SETUP_CMD_NOHANDLE("AT+UPSDA=0,3"),
754+
};
755+
#endif
756+
671757
/* bring down network interface */
672758
atomic_clear_bit(mdata.net_iface->if_dev->flags, NET_IF_UP);
673759

@@ -767,6 +853,17 @@ static void modem_reset(void)
767853
goto restart;
768854
}
769855

856+
#if defined(CONFIG_MODEM_UBLOX_SARA_U2)
857+
ret = modem_cmd_handler_setup_cmds(&mctx.iface, &mctx.cmd_handler,
858+
u2_setup_cmds,
859+
ARRAY_SIZE(u2_setup_cmds),
860+
&mdata.sem_response,
861+
MDM_REGISTRATION_TIMEOUT);
862+
if (ret < 0) {
863+
goto error;
864+
}
865+
#endif
866+
770867
LOG_INF("Network is ready.");
771868

772869
/* Set iface up */

dts/bindings/modem/ublox,sara-r4.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,7 @@ properties:
2626
mdm-reset-gpios:
2727
type: compound
2828
category: required
29+
30+
mdm-vint-gpios:
31+
type: compound
32+
category: optional

0 commit comments

Comments
 (0)