Skip to content

Commit 13cef68

Browse files
authored
Merge pull request #117 from facchinm/portenta_max_carrier
Portenta H7 + MAX Carrier support
2 parents 47f4bd1 + 02e444d commit 13cef68

File tree

5 files changed

+89
-24
lines changed

5 files changed

+89
-24
lines changed

src/GPRS.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ NB_NetworkStatus_t GPRS::attachGPRS(bool synchronous)
5151

5252
while (ready() == 0) {
5353
if (_timeout && !((millis() - start) < _timeout)) {
54-
_state = ERROR;
54+
_state = NB_ERROR;
5555
break;
5656
}
5757
delay(500);
@@ -106,7 +106,7 @@ int GPRS::ready()
106106
case GPRS_STATE_WAIT_ATTACH_RESPONSE: {
107107
if (ready > 1) {
108108
_state = GPRS_STATE_IDLE;
109-
_status = ERROR;
109+
_status = NB_ERROR;
110110
} else {
111111
_state = GPRS_STATE_CHECK_ATTACHED;
112112
ready = 0;
@@ -125,7 +125,7 @@ int GPRS::ready()
125125
case GPRS_STATE_WAIT_CHECK_ATTACHED_RESPONSE: {
126126
if (ready > 1) {
127127
_state = GPRS_STATE_IDLE;
128-
_status = ERROR;
128+
_status = NB_ERROR;
129129
} else {
130130
if (_response.indexOf("1,1") >= 0) {
131131
_state = GPRS_STATE_IDLE;
@@ -149,7 +149,7 @@ int GPRS::ready()
149149
case GPRS_STATE_WAIT_DEATTACH_RESPONSE: {
150150
if (ready > 1) {
151151
_state = GPRS_STATE_IDLE;
152-
_status = ERROR;
152+
_status = NB_ERROR;
153153
} else {
154154
_state = GPRS_STATE_IDLE;
155155
_status = IDLE;

src/Modem.cpp

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,63 @@ int ModemClass::isPowerOn()
5656
return digitalRead(_vIntPin);
5757
}
5858

59+
#ifdef ARDUINO_PORTENTA_H7_M7
60+
#include <mbed.h>
61+
#include <BQ24195.h>
62+
mbed::DigitalInOut pwr(PD_4);
63+
mbed::DigitalInOut rst(PE_3);
64+
#endif
65+
5966
int ModemClass::begin(bool restart)
6067
{
68+
#ifdef ARDUINO_PORTENTA_H7_M7
69+
pwr.input();
70+
rst.input();
71+
PMIC.begin();
72+
PMIC.disableWatchdog();
73+
// Set the input current limit to 2 A and the overload input voltage to 3.88 V
74+
PMIC.setInputCurrentLimit(3.0);
75+
PMIC.setInputVoltageLimit(3.88);
76+
// set the minimum voltage used to feeding the module embed on Board
77+
PMIC.setMinimumSystemVoltage(3.8);
78+
// Set the desired charge voltage to 4.11 V
79+
PMIC.setChargeVoltage(4.2);
80+
// Set the charge current to 375 mA
81+
// the charge current should be defined as maximum at (C for hour)/2h
82+
// to avoid battery explosion (for example for a 750 mAh battery set to 0.375 A)
83+
PMIC.setChargeCurrent(0.375);
84+
PMIC.enableBoostMode();
85+
PMIC.setInputCurrentLimit(3.0);
86+
87+
pwr.output();
88+
pwr = 0;
89+
delay(150);
90+
pwr = 1;
91+
delay(150);
92+
pwr.input();
93+
rst.output();
94+
rst = 0;
95+
delay(150);
96+
rst = 1;
97+
delay(150);
98+
rst.input();
99+
#endif
100+
101+
#ifndef ARDUINO_PORTENTA_H7_M7
61102
// datasheet warns not to use _resetPin, this may lead to an unrecoverable state
103+
pinMode(_powerOnPin, OUTPUT);
104+
pinMode(_resetPin, OUTPUT);
62105
digitalWrite(_resetPin, LOW);
63-
64106
if (restart) {
65107
shutdown();
66108
end();
67109
}
110+
#endif
68111

69112
_uart->begin(_baud > 115200 ? 115200 : _baud);
70113

71114
// power on module
115+
#ifndef ARDUINO_PORTENTA_H7_M7
72116
if (!isPowerOn()) {
73117
digitalWrite(_powerOnPin, HIGH);
74118
delay(150); // Datasheet says power-on pulse should be >=150ms, <=3200ms
@@ -79,6 +123,7 @@ int ModemClass::begin(bool restart)
79123
return 0;
80124
}
81125
}
126+
#endif
82127

83128
if (!autosense()) {
84129
return 0;
@@ -105,7 +150,11 @@ int ModemClass::begin(bool restart)
105150
int ModemClass::shutdown()
106151
{
107152
// AT command shutdown
153+
#ifdef ARDUINO_PORTENTA_H7_M7
154+
if (autosense(200)) {
155+
#else
108156
if (isPowerOn()) {
157+
#endif
109158
send("AT+CPWROFF");
110159
if (waitForResponse(40000) != 1) {
111160
return 0;
@@ -119,7 +168,11 @@ void ModemClass::end()
119168
{
120169
_uart->end();
121170
// Hardware pin power off
171+
#ifdef ARDUINO_PORTENTA_H7_M7
172+
if (1) {
173+
#else
122174
if (isPowerOn()) {
175+
#endif
123176
digitalWrite(_powerOnPin, HIGH);
124177
delay(1500); // Datasheet says power-off pulse should be >=1500ms
125178
digitalWrite(_powerOnPin, LOW);
@@ -389,4 +442,12 @@ void ModemClass::setBaudRate(unsigned long baud)
389442
_baud = baud;
390443
}
391444

445+
#ifdef ARDUINO_PORTENTA_H7_M7
446+
#include <mbed.h>
447+
UART SerialSARA(PA_9, PA_10, NC, NC);
448+
mbed::DigitalOut rts(PI_14, 0);
449+
#define SARA_PWR_ON PD_4
450+
#define SARA_RESETN PE_3
451+
#endif
452+
392453
ModemClass MODEM(SerialSARA, 115200, SARA_RESETN, SARA_PWR_ON, SARA_VINT);

src/Modem.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ class ModemUrcHandler {
4242
virtual void handleUrc(const String& urc) = 0;
4343
};
4444

45+
#ifdef ARDUINO_PORTENTA_H7_M7
46+
typedef UART Uart;
47+
#endif
48+
4549
class ModemClass {
4650
public:
4751
ModemClass(Uart& uart, unsigned long baud, int resetPin, int powerOnPin, int vIntPin=SARA_VINT);

src/NB.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ enum {
6060
};
6161

6262
NB::NB(bool debug) :
63-
_state(ERROR),
63+
_state(NB_ERROR),
6464
_readyState(0),
6565
_pin(NULL),
6666
_apn(""),
@@ -86,7 +86,7 @@ NB_NetworkStatus_t NB::begin(const char* pin, const char* apn, bool restart, boo
8686
NB_NetworkStatus_t NB::begin(const char* pin, const char* apn, const char* username, const char* password, bool restart, bool synchronous)
8787
{
8888
if (!MODEM.begin(restart)) {
89-
_state = ERROR;
89+
_state = NB_ERROR;
9090
} else {
9191
_pin = pin;
9292
_apn = apn;
@@ -100,7 +100,7 @@ NB_NetworkStatus_t NB::begin(const char* pin, const char* apn, const char* usern
100100

101101
while (ready() == 0) {
102102
if (_timeout && !((millis() - start) < _timeout)) {
103-
_state = ERROR;
103+
_state = NB_ERROR;
104104
break;
105105
}
106106

@@ -152,7 +152,7 @@ bool NB::secureShutdown()
152152

153153
int NB::ready()
154154
{
155-
if (_state == ERROR) {
155+
if (_state == NB_ERROR) {
156156
return 2;
157157
}
158158

@@ -172,7 +172,7 @@ int NB::ready()
172172

173173
case READY_STATE_WAIT_SET_ERROR_DISABLED: {
174174
if (ready > 1) {
175-
_state = ERROR;
175+
_state = NB_ERROR;
176176
ready = 2;
177177
} else {
178178
_readyState = READY_STATE_SET_MINIMUM_FUNCTIONALITY_MODE;
@@ -191,7 +191,7 @@ int NB::ready()
191191

192192
case READY_STATE_WAIT_SET_MINIMUM_FUNCTIONALITY_MODE:{
193193
if (ready > 1) {
194-
_state = ERROR;
194+
_state = NB_ERROR;
195195
ready = 2;
196196
} else {
197197
_readyState = READY_STATE_CHECK_SIM;
@@ -222,7 +222,7 @@ int NB::ready()
222222
_readyState = READY_STATE_UNLOCK_SIM;
223223
ready = 0;
224224
} else {
225-
_state = ERROR;
225+
_state = NB_ERROR;
226226
ready = 2;
227227
}
228228
}
@@ -238,15 +238,15 @@ int NB::ready()
238238
_readyState = READY_STATE_WAIT_UNLOCK_SIM_RESPONSE;
239239
ready = 0;
240240
} else {
241-
_state = ERROR;
241+
_state = NB_ERROR;
242242
ready = 2;
243243
}
244244
break;
245245
}
246246

247247
case READY_STATE_WAIT_UNLOCK_SIM_RESPONSE: {
248248
if (ready > 1) {
249-
_state = ERROR;
249+
_state = NB_ERROR;
250250
ready = 2;
251251
} else {
252252
_readyState = READY_STATE_DETACH_DATA;
@@ -265,7 +265,7 @@ int NB::ready()
265265

266266
case READY_STATE_WAIT_DETACH_DATA:{
267267
if (ready > 1) {
268-
_state = ERROR;
268+
_state = NB_ERROR;
269269
ready = 2;
270270
} else {
271271
_readyState = READY_STATE_SET_PREFERRED_MESSAGE_FORMAT;
@@ -284,7 +284,7 @@ int NB::ready()
284284

285285
case READY_STATE_WAIT_SET_PREFERRED_MESSAGE_FORMAT_RESPONSE: {
286286
if (ready > 1) {
287-
_state = ERROR;
287+
_state = NB_ERROR;
288288
ready = 2;
289289
} else {
290290
_readyState = READY_STATE_SET_HEX_MODE;
@@ -303,7 +303,7 @@ int NB::ready()
303303

304304
case READY_STATE_WAIT_SET_HEX_MODE_RESPONSE: {
305305
if (ready > 1) {
306-
_state = ERROR;
306+
_state = NB_ERROR;
307307
ready = 2;
308308
} else {
309309
_readyState = READY_STATE_SET_AUTOMATIC_TIME_ZONE;
@@ -322,7 +322,7 @@ int NB::ready()
322322

323323
case READY_STATE_WAIT_SET_AUTOMATIC_TIME_ZONE_RESPONSE: {
324324
if (ready > 1) {
325-
_state = ERROR;
325+
_state = NB_ERROR;
326326
ready = 2;
327327
} else {
328328
_readyState = READY_STATE_SET_APN;
@@ -340,7 +340,7 @@ int NB::ready()
340340

341341
case READY_STATE_WAIT_SET_APN: {
342342
if (ready > 1) {
343-
_state = ERROR;
343+
_state = NB_ERROR;
344344
ready = 2;
345345
} else {
346346
_readyState = READY_STATE_SET_APN_AUTH;
@@ -365,7 +365,7 @@ int NB::ready()
365365

366366
case READY_STATE_WAIT_SET_APN_AUTH: {
367367
if (ready > 1) {
368-
_state = ERROR;
368+
_state = NB_ERROR;
369369
ready = 2;
370370
} else {
371371
_readyState = READY_STATE_SET_FULL_FUNCTIONALITY_MODE;
@@ -383,7 +383,7 @@ int NB::ready()
383383

384384
case READY_STATE_WAIT_SET_FULL_FUNCTIONALITY_MODE:{
385385
if (ready > 1) {
386-
_state = ERROR;
386+
_state = NB_ERROR;
387387
ready = 2;
388388
} else {
389389
_readyState = READY_STATE_CHECK_REGISTRATION;
@@ -403,7 +403,7 @@ int NB::ready()
403403

404404
case READY_STATE_WAIT_CHECK_REGISTRATION_RESPONSE: {
405405
if (ready > 1) {
406-
_state = ERROR;
406+
_state = NB_ERROR;
407407
ready = 2;
408408
} else {
409409
int status = _response.charAt(_response.length() - 1) - '0';
@@ -420,7 +420,7 @@ int NB::ready()
420420
_state = CONNECTING;
421421
ready = 0;
422422
} else if (status == 3) {
423-
_state = ERROR;
423+
_state = NB_ERROR;
424424
ready = 2;
425425
}
426426
}

src/NB.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
#include <Arduino.h>
2424

25-
enum NB_NetworkStatus_t { ERROR, IDLE, CONNECTING, NB_READY, GPRS_READY, TRANSPARENT_CONNECTED, NB_OFF};
25+
enum NB_NetworkStatus_t { NB_ERROR, IDLE, CONNECTING, NB_READY, GPRS_READY, TRANSPARENT_CONNECTED, NB_OFF};
2626

2727
class NB {
2828

0 commit comments

Comments
 (0)