Skip to content

Commit f2a7408

Browse files
authored
Merge pull request #10866 from LMESTM/component_cellular_stmod
Adding stmod_cellular component
2 parents 13081a2 + 1e06ad0 commit f2a7408

File tree

4 files changed

+315
-0
lines changed

4 files changed

+315
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# STMOD CELLULAR library
2+
3+
This library allows enabling the cellular module that is connected to the STMOD+ connector of the board.
4+
5+
## Supported modems.
6+
7+
Currently supported cellular modules are Quectel UG96 and BG96 expansion boards that are included in [p-l496g-cell01] (https://www.st.com/en/evaluation-tools/p-l496g-cell01.html) and [p-l496g-cell02.] (https://www.st.com/en/evaluation-tools/p-l496g-cell02.html) packs.
8+
9+
## Specifications
10+
11+
The STMOD+ Connector specification can be found [here] (https://www.st.com/content/ccc/resource/technical/document/technical_note/group0/04/7f/90/c1/ad/54/46/1f/DM00323609/files/DM00323609.pdf/jcr:content/translations/en.DM00323609.pdf).
12+
13+
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "STModCellular.h"
19+
#include "mbed_wait_api.h"
20+
#include "mbed_trace.h"
21+
22+
#define TRACE_GROUP "CELL"
23+
24+
using namespace mbed;
25+
26+
STModCellular::STModCellular(FileHandle *fh) : STMOD_CELLULAR_MODEM(fh),
27+
m_powerkey(MBED_CONF_STMOD_CELLULAR_POWER),
28+
m_reset(MBED_CONF_STMOD_CELLULAR_RESET),
29+
m_simsel0(MBED_CONF_STMOD_CELLULAR_SIMSEL0),
30+
m_simsel1(MBED_CONF_STMOD_CELLULAR_SIMSEL1),
31+
m_mdmdtr(MBED_CONF_STMOD_CELLULAR_MDMDTR),
32+
m_sim_reset(MBED_CONF_STMOD_CELLULAR_SIM_RESET),
33+
m_sim_clk(MBED_CONF_STMOD_CELLULAR_SIM_CLK),
34+
m_sim_data(MBED_CONF_STMOD_CELLULAR_SIM_DATA)
35+
{
36+
tr_debug("STModCellular creation\r\n");
37+
38+
// start with modem disabled
39+
m_powerkey.write(0);
40+
m_reset.write(1);
41+
wait_ms(200);
42+
m_reset.write(0);
43+
wait_ms(150);
44+
45+
wait_ms(50);
46+
m_simsel0.write(MBED_CONF_STMOD_CELLULAR_SIM_SELECTION & 0x01);
47+
m_simsel1.write(MBED_CONF_STMOD_CELLULAR_SIM_SELECTION & 0x02);
48+
wait_ms(50);
49+
}
50+
51+
STModCellular::~STModCellular()
52+
{
53+
}
54+
55+
nsapi_error_t STModCellular::soft_power_on()
56+
{
57+
tr_debug("STMOD cellular modem power ON\r\n");
58+
59+
#if (MBED_CONF_STMOD_CELLULAR_TYPE == STMOD_UG96)
60+
tr_debug("Booting UG96\r\n");
61+
m_reset.write(1);
62+
wait_ms(200);
63+
m_reset.write(0);
64+
wait_ms(150);
65+
m_powerkey.write(1);
66+
wait_ms(150);
67+
m_powerkey.write(0);
68+
/* Because modem status is not available on STMOD+ connector,
69+
* let's wait for Modem complete boot */
70+
wait_ms(2300);
71+
#endif
72+
#if (MBED_CONF_STMOD_CELLULAR_TYPE == STMOD_BG96)
73+
tr_debug("Booting BG96\r\n");
74+
m_powerkey.write(1);
75+
m_reset.write(1);
76+
wait_ms(150);
77+
m_powerkey.write(0);
78+
m_reset.write(0);
79+
wait_ms(100);
80+
m_powerkey.write(1);
81+
wait_ms(200);
82+
m_powerkey.write(0);
83+
wait_ms(5000);
84+
#endif
85+
86+
nsapi_error_t err = STMOD_CELLULAR_MODEM::soft_power_on();
87+
if (err != 0) {
88+
return err;
89+
}
90+
91+
// wait for RDY
92+
_at->lock();
93+
_at->set_at_timeout(5000);
94+
_at->set_stop_tag("RDY");
95+
bool rdy = _at->consume_to_stop_tag();
96+
(void)rdy;
97+
98+
/* Modem may send more bytes are RDY flag */
99+
_at->flush();
100+
101+
/* Turn OFF ECHO before anything else */
102+
_at->set_stop_tag(mbed::OK);
103+
_at->cmd_start("ATE0");
104+
_at->cmd_stop();
105+
_at->consume_to_stop_tag();
106+
107+
_at->restore_at_timeout();
108+
_at->unlock();
109+
110+
tr_debug("Modem %sready to receive AT commands", rdy ? "" : "NOT ");
111+
112+
#if DEVICE_SERIAL_FC
113+
if ((MBED_CONF_STMOD_CELLULAR_CTS != NC) && (MBED_CONF_STMOD_CELLULAR_RTS != NC)) {
114+
tr_debug("Enable flow control\r\n");
115+
116+
_at->lock();
117+
// enable CTS/RTS flowcontrol
118+
_at->set_stop_tag(mbed::OK);
119+
_at->set_at_timeout(400);
120+
_at->cmd_start("AT+IFC=");
121+
_at->write_int(2);
122+
_at->write_int(2);
123+
_at->cmd_stop_read_resp();
124+
err = _at->get_last_error();
125+
_at->restore_at_timeout();
126+
_at->unlock();
127+
128+
if (err == NSAPI_ERROR_OK) {
129+
tr_debug("Flow control turned ON");
130+
} else {
131+
tr_error("Failed to enable hw flow control");
132+
}
133+
}
134+
#endif
135+
136+
wait_ms(500);
137+
138+
#if MBED_CONF_CELLULAR_DEBUG_AT
139+
_at->lock();
140+
/* Verify Flow Control settings */
141+
_at->cmd_start("AT+IFC?");
142+
_at->cmd_stop_read_resp();
143+
_at->unlock();
144+
#endif // MBED_CONF_CELLULAR_DEBUG_AT
145+
146+
return err;
147+
}
148+
149+
nsapi_error_t STModCellular::soft_power_off()
150+
{
151+
_at->cmd_start("AT+QPOWD");
152+
_at->cmd_stop();
153+
wait_ms(1000);
154+
// should wait for POWERED DOWN with a time out up to 65 second according to the manual.
155+
// we cannot afford such a long wait though.
156+
return STMOD_CELLULAR_MODEM::soft_power_off();
157+
}
158+
159+
#if MBED_CONF_STMOD_CELLULAR_PROVIDE_DEFAULT
160+
#include "UARTSerial.h"
161+
CellularDevice *CellularDevice::get_default_instance()
162+
{
163+
tr_debug("MODEM default instance\r\n");
164+
165+
static UARTSerial serial(MBED_CONF_STMOD_CELLULAR_TX, MBED_CONF_STMOD_CELLULAR_RX, MBED_CONF_STMOD_CELLULAR_BAUDRATE);
166+
#if defined (MBED_CONF_STMOD_CELLULAR_RTS) && defined(MBED_CONF_STMOD_CELLULAR_CTS)
167+
tr_debug("STMOD_CELLULAR flow control: RTS %d CTS %d", MBED_CONF_STMOD_CELLULAR_RTS, MBED_CONF_STMOD_CELLULAR_CTS);
168+
serial.set_flow_control(SerialBase::RTSCTS, MBED_CONF_STMOD_CELLULAR_RTS, MBED_CONF_STMOD_CELLULAR_CTS);
169+
#endif
170+
static STModCellular device(&serial);
171+
return &device;
172+
}
173+
#endif
174+
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef STMOD_CELLULAR_H_
19+
#define STMOD_CELLULAR_H_
20+
21+
#include "QUECTEL_UG96.h"
22+
#include "QUECTEL_BG96.h"
23+
#include "DigitalOut.h"
24+
#include "DigitalIn.h"
25+
26+
/* List of supported STMOD+ cellular expansion boards */
27+
#define STMOD_BG96 0
28+
#define STMOD_UG96 1
29+
30+
31+
#if (MBED_CONF_STMOD_CELLULAR_TYPE == STMOD_BG96)
32+
#define STMOD_CELLULAR_MODEM QUECTEL_BG96
33+
#endif
34+
35+
#if (MBED_CONF_STMOD_CELLULAR_TYPE == STMOD_UG96)
36+
#define STMOD_CELLULAR_MODEM QUECTEL_UG96
37+
#endif
38+
39+
namespace mbed {
40+
41+
class STModCellular : public STMOD_CELLULAR_MODEM {
42+
private:
43+
DigitalOut m_powerkey;
44+
DigitalOut m_reset;
45+
DigitalOut m_simsel0;
46+
DigitalOut m_simsel1;
47+
DigitalOut m_mdmdtr;
48+
DigitalIn m_sim_reset;
49+
DigitalIn m_sim_clk;
50+
DigitalIn m_sim_data;
51+
public:
52+
STModCellular(FileHandle *fh);
53+
virtual nsapi_error_t soft_power_on();
54+
virtual nsapi_error_t soft_power_off();
55+
virtual ~STModCellular();
56+
};
57+
58+
} // namespace mbed
59+
#endif // STMOD_CELLULAR_H_
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{
2+
"name": "stmod_cellular",
3+
"config": {
4+
"type": {
5+
"help": "STMOD+ connected modem can be either STMOD_UG96 or STMOD_BG96",
6+
"value": "STMOD_BG96"
7+
},
8+
"sim_selection": {
9+
"help": "Module sim selection. 0 for plastic sim, 1 for esim.",
10+
"value": 0
11+
},
12+
"mdmdtr": {
13+
"help": "Modem's Data Terminal Ready. Usually not connected to STMOD+ connector. It needs to be set/overwritten otherwise",
14+
"value": "NC"
15+
},
16+
"simsel0": {
17+
"help": "Module sim select pin 0. By default connected to STMOD+ pin 18. It needs to be set/overwritten otherwise",
18+
"value": "STMOD_18"
19+
},
20+
"simsel1": {
21+
"help": "Module sim select pin 1. By default connected to STMOD+ pin 8. It needs to be set/overwritten otherwise",
22+
"value": "STMOD_8"
23+
},
24+
"sim_reset": {
25+
"help": "Module sim reset pin. Used for sim selection sequence. By default connected to STMOD+ pin 17. It needs to be set/overwritten otherwise",
26+
"value": "STMOD_17"
27+
},
28+
"sim_clk": {
29+
"help": "Module sim clock pin. Used for sim selection sequence. By default connected to STMOD+ pin 13. It needs to be set/overwritten otherwise",
30+
"value": "STMOD_13"
31+
},
32+
"sim_data": {
33+
"help": "Module sim data pin. Used for sim selection sequence. By default connected to STMOD+ pin 19. It needs to be set/overwritten otherwise",
34+
"value": "STMOD_19"
35+
},
36+
"power": {
37+
"help": "Modem's power key. By default connected to STMOD+ pin 9. It needs to be set/overwritten otherwise",
38+
"value": "STMOD_9"
39+
},
40+
"reset": {
41+
"help": "Modem's reset. By default connected to STMOD+ pin 12. It needs to be set/overwritten otherwise",
42+
"value": "STMOD_12"
43+
},
44+
"tx": {
45+
"help": "TX pin for serial connection. STMOD pin 2 is the default STMOD+ UART TX. It needs to be set/overwritten otherwise",
46+
"value": "STMOD_2"
47+
},
48+
"rx": {
49+
"help": "RX pin for serial connection. STMOD pin 3 is the default STMOD+ UART TX. It needs to be set/overwritten otherwise.",
50+
"value": "STMOD_3"
51+
},
52+
"rts": {
53+
"help": "RTS pin for serial connection. STMOD pin 4 is the default STMOD+ UART RTS. It needs to be set/overwritten otherwise.",
54+
"value": "STMOD_4"
55+
},
56+
"cts": {
57+
"help": "CTS pin for serial connection. STMOD pin 1 is the default STMOD+ UART RTS. It needs to be set/overwritten otherwise.",
58+
"value": "STMOD_1"
59+
},
60+
"baudrate" : {
61+
"help": "Serial connection baud rate",
62+
"value": 115200
63+
},
64+
"provide-default": {
65+
"help": "Provide as default CellularDevice [true/false]",
66+
"value": false
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)