Skip to content

Commit 7b79157

Browse files
authored
Merge pull request #11580 from wajahat-ublox/ubx_modems_custom_boards
Remove target dependency in ublox cellular APIs
2 parents 7cfa6fa + 98f3baa commit 7b79157

File tree

8 files changed

+114
-37
lines changed

8 files changed

+114
-37
lines changed

features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,36 @@
2020
using namespace mbed;
2121
using namespace events;
2222

23-
#ifdef TARGET_UBLOX_C030_R41XM
23+
#ifdef UBX_MDM_SARA_R41XM
2424
static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
2525
AT_CellularNetwork::RegistrationModeDisable,// C_EREG
2626
AT_CellularNetwork::RegistrationModeLAC, // C_GREG
2727
AT_CellularNetwork::RegistrationModeLAC, // C_REG
2828
0, // AT_CGSN_WITH_TYPE
29-
1, // AT_CGDATA
30-
1, // AT_CGAUTH
29+
0, // AT_CGDATA
30+
0, // AT_CGAUTH
3131
1, // AT_CNMI
3232
1, // AT_CSMP
3333
1, // AT_CMGF
34-
1, // AT_CSDH
34+
0, // AT_CSDH
3535
1, // PROPERTY_IPV4_STACK
3636
0, // PROPERTY_IPV6_STACK
3737
0, // PROPERTY_IPV4V6_STACK
3838
0, // PROPERTY_NON_IP_PDP_TYPE
3939
1, // PROPERTY_AT_CGEREP
4040
};
41-
#else
41+
#elif defined(UBX_MDM_SARA_U2XX) || defined(UBX_MDM_SARA_G3XX)
4242
static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
4343
AT_CellularNetwork::RegistrationModeDisable,// C_EREG
4444
AT_CellularNetwork::RegistrationModeLAC, // C_GREG
4545
AT_CellularNetwork::RegistrationModeLAC, // C_REG
46+
#ifdef UBX_MDM_SARA_G3XX
47+
0, // AT_CGSN_WITH_TYPE
48+
#else
4649
1, // AT_CGSN_WITH_TYPE
50+
#endif
4751
1, // AT_CGDATA
48-
1, // AT_CGAUTH
52+
0, // AT_CGAUTH
4953
1, // AT_CNMI
5054
1, // AT_CSMP
5155
1, // AT_CMGF
@@ -56,6 +60,24 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
5660
0, // PROPERTY_NON_IP_PDP_TYPE
5761
1, // PROPERTY_AT_CGEREP
5862
};
63+
#else
64+
static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
65+
0, // C_EREG
66+
0, // C_GREG
67+
0, // C_REG
68+
0, // AT_CGSN_WITH_TYPE
69+
0, // AT_CGDATA
70+
0, // AT_CGAUTH
71+
0, // AT_CNMI
72+
0, // AT_CSMP
73+
0, // AT_CMGF
74+
0, // AT_CSDH
75+
0, // PROPERTY_IPV4_STACK
76+
0, // PROPERTY_IPV6_STACK
77+
0, // PROPERTY_IPV4V6_STACK
78+
0, // PROPERTY_NON_IP_PDP_TYPE
79+
0, // PROPERTY_AT_CGEREP
80+
};
5981
#endif
6082

6183
UBLOX_AT::UBLOX_AT(FileHandle *fh) : AT_CellularDevice(fh)
@@ -98,7 +120,7 @@ nsapi_error_t UBLOX_AT::init()
98120

99121
nsapi_error_t err = NSAPI_ERROR_OK;
100122

101-
#ifdef TARGET_UBLOX_C027
123+
#ifdef UBX_MDM_SARA_G3XX
102124
err = _at->at_cmd_discard("+CFUN", "=0");
103125

104126
if (err == NSAPI_ERROR_OK) {
@@ -107,14 +129,17 @@ nsapi_error_t UBLOX_AT::init()
107129
config_authentication_parameters();
108130
err = _at->at_cmd_discard("+CFUN", "=1"); // set full functionality
109131
}
110-
#else
132+
#elif defined(UBX_MDM_SARA_U2XX) || defined(UBX_MDM_SARA_R41XM)
111133
err = _at->at_cmd_discard("+CFUN", "=4");
112134
if (err == NSAPI_ERROR_OK) {
113135
_at->at_cmd_discard("E0", ""); // echo off
114136
_at->at_cmd_discard("+CMEE", "=1"); // verbose responses
115137
config_authentication_parameters();
116138
err = _at->at_cmd_discard("+CFUN", "=1"); // set full functionality
117139
}
140+
#else
141+
_at->unlock();
142+
return NSAPI_ERROR_UNSUPPORTED;
118143
#endif
119144

120145
return _at->unlock_return_error();
@@ -155,7 +180,7 @@ nsapi_error_t UBLOX_AT::set_authentication_parameters(const char *apn,
155180
nsapi_error_t err = _at->at_cmd_discard("+CGDCONT", "=", "%d%s%s", 1, "IP", apn);
156181

157182
if (err == NSAPI_ERROR_OK) {
158-
#ifdef TARGET_UBLOX_C030_R41XM
183+
#ifdef UBX_MDM_SARA_R41XM
159184
if (modem_security == CellularContext::CHAP) {
160185
err = _at->at_cmd_discard("+UAUTHREQ", "=", "%d%d%s%s", 1, modem_security, password, username);
161186
} else if (modem_security == CellularContext::NOAUTH) {

features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularContext.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "UBLOX_AT_CellularStack.h"
1919
#include "APN_db.h"
2020
#include "CellularLog.h"
21-
2221
#include "rtos/ThisThread.h"
2322

2423
namespace mbed {
@@ -53,9 +52,9 @@ void UBLOX_AT_CellularContext::do_connect()
5352
_cb_data.error = NSAPI_ERROR_NO_CONNECTION;
5453

5554
// Attempt to establish a connection
56-
#ifndef TARGET_UBLOX_C030_R41XM
55+
#ifndef UBX_MDM_SARA_R41XM
5756
_cb_data.error = define_context();
58-
#elif TARGET_UBLOX_C030_R410M
57+
#elif UBX_MDM_SARA_R410M
5958
_at.cmd_start_stop("+CGACT", "?");
6059
_at.resp_start("+CGACT:");
6160
_cid = _at.read_int();
@@ -66,7 +65,7 @@ void UBLOX_AT_CellularContext::do_connect()
6665
_is_context_active = true;
6766
_is_context_activated = true;
6867
_cb_data.error = NSAPI_ERROR_OK;
69-
#elif TARGET_UBLOX_C030_R412M
68+
#elif UBX_MDM_SARA_R412M
7069
CellularNetwork::RadioAccessTechnology rat = read_radio_technology();
7170
if (rat == CellularNetwork::RadioAccessTechnology::RAT_EGPRS) {
7271
if (!_is_context_active) {
@@ -115,7 +114,7 @@ void UBLOX_AT_CellularContext::do_connect()
115114
}
116115
}
117116

118-
#ifndef TARGET_UBLOX_C030_R41XM
117+
#ifndef UBX_MDM_SARA_R41XM
119118
nsapi_error_t UBLOX_AT_CellularContext::define_context()
120119
{
121120
bool success = false;
@@ -249,7 +248,7 @@ int UBLOX_AT_CellularContext::nsapi_security_to_modem_security(AuthenticationTyp
249248
case CHAP:
250249
modem_security = 2;
251250
break;
252-
#ifndef TARGET_UBLOX_C030_R41XM
251+
#ifndef UBX_MDM_SARA_R41XM
253252
case AUTOMATIC:
254253
modem_security = 3;
255254
break;
@@ -324,7 +323,7 @@ CellularContext::AuthenticationType UBLOX_AT_CellularContext::get_auth()
324323
return _authentication_type;
325324
}
326325

327-
#ifdef TARGET_UBLOX_C030_R412M
326+
#ifdef UBX_MDM_SARA_R412M
328327
CellularNetwork::RadioAccessTechnology UBLOX_AT_CellularContext::read_radio_technology()
329328
{
330329
int act;
@@ -358,6 +357,6 @@ CellularNetwork::RadioAccessTechnology UBLOX_AT_CellularContext::read_radio_tech
358357

359358
return rat;
360359
}
361-
#endif // #ifdef TARGET_UBLOX_C030_R412M
360+
#endif // #ifdef UBX_MDM_SARA_R412M
362361

363362
} /* namespace mbed */

features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularContext.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class UBLOX_AT_CellularContext: public AT_CellularContext {
4545
/** Get the next set of credentials from the database.
4646
*/
4747
void get_next_credentials(char **config);
48-
#ifdef TARGET_UBLOX_C030_R412M
48+
#ifdef UBX_MDM_SARA_R412M
4949
CellularNetwork::RadioAccessTechnology read_radio_technology(void);
5050
#endif
5151
protected:
@@ -55,7 +55,7 @@ class UBLOX_AT_CellularContext: public AT_CellularContext {
5555
*
5656
* @return True if successful, otherwise false.
5757
*/
58-
#ifndef TARGET_UBLOX_C030_R41XM
58+
#ifndef UBX_MDM_SARA_R41XM
5959
nsapi_error_t define_context();
6060
#endif
6161

@@ -79,7 +79,7 @@ class UBLOX_AT_CellularContext: public AT_CellularContext {
7979
* CHAP or AUTOMATIC).
8080
* @return True if successful, otherwise false.
8181
*/
82-
#ifndef TARGET_UBLOX_C030_R41XM
82+
#ifndef UBX_MDM_SARA_R41XM
8383
bool activate_profile(const char *apn, const char *username, const char *password, AuthenticationType auth);
8484
#endif
8585

features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularNetwork.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717

1818
#include "UBLOX_AT_CellularNetwork.h"
19-
2019
#include "rtos/ThisThread.h"
2120

2221
using namespace mbed;
@@ -47,11 +46,11 @@ nsapi_error_t UBLOX_AT_CellularNetwork::set_access_technology_impl(RadioAccessTe
4746
_at.lock();
4847
switch (opRat) {
4948
case RAT_EGPRS:
50-
#if defined (TARGET_UBLOX_C030_R412M)
49+
#if defined (UBX_MDM_SARA_R412M)
5150
_at.at_cmd_discard("+URAT", "=", "%d%d", 9, 8);
5251
break;
5352
#endif
54-
#if defined(TARGET_UBLOX_C030_U201)
53+
#if defined(UBX_MDM_SARA_U201)
5554
case RAT_GSM:
5655
_at.at_cmd_discard("+URAT", "=", "%d%d", 0, 0);
5756
break;
@@ -61,7 +60,7 @@ nsapi_error_t UBLOX_AT_CellularNetwork::set_access_technology_impl(RadioAccessTe
6160
case RAT_HSDPA_HSUPA:
6261
_at.at_cmd_discard("+URAT", "=", "%d%d", 2, 2);
6362
break;
64-
#elif defined(TARGET_UBLOX_C030_R41XM)
63+
#elif defined(UBX_MDM_SARA_R41XM)
6564
case RAT_CATM1:
6665
_at.at_cmd_discard("+URAT", "=", "%d%d", 7, 8);
6766
break;

features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularStack.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ nsapi_error_t UBLOX_AT_CellularStack::gethostbyname(const char *host, SocketAddr
447447
if (address->set_ip_address(host)) {
448448
err = NSAPI_ERROR_OK;
449449
} else {
450-
#ifdef TARGET_UBLOX_C030_R41XM
450+
#ifdef UBX_MDM_SARA_R41XM
451451
_at.set_at_timeout(70000);
452452
#else
453453
_at.set_at_timeout(120000);

features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,36 @@
2121
using namespace mbed;
2222
using namespace events;
2323

24-
#ifdef TARGET_UBLOX_C027
24+
#ifdef UBX_MDM_SARA_R41XM
2525
static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
2626
AT_CellularNetwork::RegistrationModeDisable,// C_EREG
2727
AT_CellularNetwork::RegistrationModeLAC, // C_GREG
2828
AT_CellularNetwork::RegistrationModeLAC, // C_REG
2929
0, // AT_CGSN_WITH_TYPE
30-
1, // AT_CGDATA
31-
1, // AT_CGAUTH
30+
0, // AT_CGDATA
31+
0, // AT_CGAUTH
3232
1, // AT_CNMI
3333
1, // AT_CSMP
3434
1, // AT_CMGF
35-
1, // AT_CSDH
35+
0, // AT_CSDH
3636
1, // PROPERTY_IPV4_STACK
3737
0, // PROPERTY_IPV6_STACK
3838
0, // PROPERTY_IPV4V6_STACK
3939
0, // PROPERTY_NON_IP_PDP_TYPE
4040
1, // PROPERTY_AT_CGEREP
4141
};
42-
#else
42+
#elif defined(UBX_MDM_SARA_U2XX) || defined(UBX_MDM_SARA_G3XX)
4343
static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
4444
AT_CellularNetwork::RegistrationModeDisable,// C_EREG
4545
AT_CellularNetwork::RegistrationModeLAC, // C_GREG
4646
AT_CellularNetwork::RegistrationModeLAC, // C_REG
47+
#ifdef UBX_MDM_SARA_G3XX
48+
0, // AT_CGSN_WITH_TYPE
49+
#else
4750
1, // AT_CGSN_WITH_TYPE
51+
#endif
4852
1, // AT_CGDATA
49-
1, // AT_CGAUTH
53+
0, // AT_CGAUTH
5054
1, // AT_CNMI
5155
1, // AT_CSMP
5256
1, // AT_CMGF
@@ -57,6 +61,24 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
5761
0, // PROPERTY_NON_IP_PDP_TYPE
5862
1, // PROPERTY_AT_CGEREP
5963
};
64+
#else
65+
static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
66+
0, // C_EREG
67+
0, // C_GREG
68+
0, // C_REG
69+
0, // AT_CGSN_WITH_TYPE
70+
0, // AT_CGDATA
71+
0, // AT_CGAUTH
72+
0, // AT_CNMI
73+
0, // AT_CSMP
74+
0, // AT_CMGF
75+
0, // AT_CSDH
76+
0, // PROPERTY_IPV4_STACK
77+
0, // PROPERTY_IPV6_STACK
78+
0, // PROPERTY_IPV4V6_STACK
79+
0, // PROPERTY_NON_IP_PDP_TYPE
80+
0, // PROPERTY_AT_CGEREP
81+
};
6082
#endif
6183

6284
UBLOX_PPP::UBLOX_PPP(FileHandle *fh) : AT_CellularDevice(fh)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## Configuring Ublox Cellular Modems for custom targets
2+
3+
In order to use cellular APIs with custom targets, user needs to define ublox modem macros in `mbed_app.json` configuration file:
4+
```
5+
"target_overrides": {
6+
"*": {
7+
"mbed-trace.enable": true,
8+
"platform.stdio-convert-newlines": true,
9+
"platform.stdio-baud-rate": 115200,
10+
"platform.default-serial-baud-rate": 115200
11+
},
12+
"K64F": {
13+
"target.macros_add": ["UBX_MDM_SARA_R41XM", "UBX_MDM_SARA_R412M"]
14+
}
15+
}
16+
```
17+
18+
19+
List of supported ublox modems and their respective macros are as follow:
20+
21+
| Ublox mbed board | Modem Name | Family Macro | Modem Macro |
22+
| ----------- | :-----------: | :-------------: | :-------------: |
23+
| UBLOX_C027 | SARA-G350 | `UBX_MDM_SARA_G3XX` | `UBX_MDM_SARA_G350` |
24+
| UBLOX_C030_N211 | SARA-N211 | `UBX_MDM_SARA_N2XX` | `UBX_MDM_SARA_N211` |
25+
| UBLOX_C030_U201 | SARA-U201 | `UBX_MDM_SARA_U2XX` | `UBX_MDM_SARA_U201` |
26+
| UBLOX_C030_R410M | SARA-R410M | `UBX_MDM_SARA_R41XM` | `UBX_MDM_SARA_R410M` |
27+
| UBLOX_C030_R412M | SARA-R412M | `UBX_MDM_SARA_R41XM` | `UBX_MDM_SARA_R412M` |

targets/targets.json

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@
666666
"macro_name": "MODEM_ON_BOARD_UART"
667667
}
668668
},
669-
"macros": ["TARGET_LPC1768"],
669+
"macros": ["TARGET_LPC1768", "UBX_MDM_SARA_G3XX", "UBX_MDM_SARA_G350"],
670670
"inherits": ["LPCTarget"],
671671
"device_has": [
672672
"USTICKER",
@@ -4983,23 +4983,28 @@
49834983
"UBLOX_C030_U201": {
49844984
"inherits": ["UBLOX_C030"],
49854985
"components_add": ["SD", "FLASHIAP"],
4986-
"release_versions": ["5"]
4986+
"release_versions": ["5"],
4987+
"macros_add": ["UBX_MDM_SARA_U2XX", "UBX_MDM_SARA_U201"]
49874988
},
49884989
"UBLOX_C030_N211": {
49894990
"inherits": ["UBLOX_C030"],
4990-
"release_versions": ["5"]
4991+
"release_versions": ["5"],
4992+
"macros_add": ["UBX_MDM_SARA_N2XX", "UBX_MDM_SARA_N211"]
49914993
},
49924994
"UBLOX_C030_R41XM": {
49934995
"inherits": ["UBLOX_C030"],
4994-
"release_versions": ["5"]
4996+
"release_versions": ["5"],
4997+
"public": false
49954998
},
49964999
"UBLOX_C030_R410M": {
49975000
"inherits": ["UBLOX_C030_R41XM"],
4998-
"release_versions": ["5"]
5001+
"release_versions": ["5"],
5002+
"macros_add": ["UBX_MDM_SARA_R41XM", "UBX_MDM_SARA_R410M"]
49995003
},
50005004
"UBLOX_C030_R412M": {
50015005
"inherits": ["UBLOX_C030_R41XM"],
5002-
"release_versions": ["5"]
5006+
"release_versions": ["5"],
5007+
"macros_add": ["UBX_MDM_SARA_R41XM", "UBX_MDM_SARA_R412M"]
50035008
},
50045009
"NZ32_SC151": {
50055010
"inherits": ["FAMILY_STM32"],

0 commit comments

Comments
 (0)