Skip to content

Commit 02e444d

Browse files
committed
Portenta H7 + MAX Carrier support
1 parent 3ac1a71 commit 02e444d

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.endsWith("1,1")) {
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
@@ -52,7 +52,7 @@ enum {
5252
};
5353

5454
NB::NB(bool debug) :
55-
_state(ERROR),
55+
_state(NB_ERROR),
5656
_readyState(0),
5757
_pin(NULL),
5858
_apn(""),
@@ -78,7 +78,7 @@ NB_NetworkStatus_t NB::begin(const char* pin, const char* apn, bool restart, boo
7878
NB_NetworkStatus_t NB::begin(const char* pin, const char* apn, const char* username, const char* password, bool restart, bool synchronous)
7979
{
8080
if (!MODEM.begin(restart)) {
81-
_state = ERROR;
81+
_state = NB_ERROR;
8282
} else {
8383
_pin = pin;
8484
_apn = apn;
@@ -92,7 +92,7 @@ NB_NetworkStatus_t NB::begin(const char* pin, const char* apn, const char* usern
9292

9393
while (ready() == 0) {
9494
if (_timeout && !((millis() - start) < _timeout)) {
95-
_state = ERROR;
95+
_state = NB_ERROR;
9696
break;
9797
}
9898

@@ -142,7 +142,7 @@ bool NB::secureShutdown()
142142

143143
int NB::ready()
144144
{
145-
if (_state == ERROR) {
145+
if (_state == NB_ERROR) {
146146
return 2;
147147
}
148148

@@ -162,7 +162,7 @@ int NB::ready()
162162

163163
case READY_STATE_WAIT_SET_ERROR_DISABLED: {
164164
if (ready > 1) {
165-
_state = ERROR;
165+
_state = NB_ERROR;
166166
ready = 2;
167167
} else {
168168
_readyState = READY_STATE_SET_MINIMUM_FUNCTIONALITY_MODE;
@@ -181,7 +181,7 @@ int NB::ready()
181181

182182
case READY_STATE_WAIT_SET_MINIMUM_FUNCTIONALITY_MODE:{
183183
if (ready > 1) {
184-
_state = ERROR;
184+
_state = NB_ERROR;
185185
ready = 2;
186186
} else {
187187
_readyState = READY_STATE_CHECK_SIM;
@@ -212,7 +212,7 @@ int NB::ready()
212212
_readyState = READY_STATE_UNLOCK_SIM;
213213
ready = 0;
214214
} else {
215-
_state = ERROR;
215+
_state = NB_ERROR;
216216
ready = 2;
217217
}
218218
}
@@ -228,15 +228,15 @@ int NB::ready()
228228
_readyState = READY_STATE_WAIT_UNLOCK_SIM_RESPONSE;
229229
ready = 0;
230230
} else {
231-
_state = ERROR;
231+
_state = NB_ERROR;
232232
ready = 2;
233233
}
234234
break;
235235
}
236236

237237
case READY_STATE_WAIT_UNLOCK_SIM_RESPONSE: {
238238
if (ready > 1) {
239-
_state = ERROR;
239+
_state = NB_ERROR;
240240
ready = 2;
241241
} else {
242242
_readyState = READY_STATE_DETACH_DATA;
@@ -255,7 +255,7 @@ int NB::ready()
255255

256256
case READY_STATE_WAIT_DETACH_DATA:{
257257
if (ready > 1) {
258-
_state = ERROR;
258+
_state = NB_ERROR;
259259
ready = 2;
260260
} else {
261261
_readyState = READY_STATE_SET_PREFERRED_MESSAGE_FORMAT;
@@ -274,7 +274,7 @@ int NB::ready()
274274

275275
case READY_STATE_WAIT_SET_PREFERRED_MESSAGE_FORMAT_RESPONSE: {
276276
if (ready > 1) {
277-
_state = ERROR;
277+
_state = NB_ERROR;
278278
ready = 2;
279279
} else {
280280
_readyState = READY_STATE_SET_HEX_MODE;
@@ -293,7 +293,7 @@ int NB::ready()
293293

294294
case READY_STATE_WAIT_SET_HEX_MODE_RESPONSE: {
295295
if (ready > 1) {
296-
_state = ERROR;
296+
_state = NB_ERROR;
297297
ready = 2;
298298
} else {
299299
_readyState = READY_STATE_SET_AUTOMATIC_TIME_ZONE;
@@ -312,7 +312,7 @@ int NB::ready()
312312

313313
case READY_STATE_WAIT_SET_AUTOMATIC_TIME_ZONE_RESPONSE: {
314314
if (ready > 1) {
315-
_state = ERROR;
315+
_state = NB_ERROR;
316316
ready = 2;
317317
} else {
318318
_readyState = READY_STATE_SET_APN;
@@ -330,7 +330,7 @@ int NB::ready()
330330

331331
case READY_STATE_WAIT_SET_APN: {
332332
if (ready > 1) {
333-
_state = ERROR;
333+
_state = NB_ERROR;
334334
ready = 2;
335335
} else {
336336
_readyState = READY_STATE_SET_APN_AUTH;
@@ -355,7 +355,7 @@ int NB::ready()
355355

356356
case READY_STATE_WAIT_SET_APN_AUTH: {
357357
if (ready > 1) {
358-
_state = ERROR;
358+
_state = NB_ERROR;
359359
ready = 2;
360360
} else {
361361
_readyState = READY_STATE_SET_FULL_FUNCTIONALITY_MODE;
@@ -373,7 +373,7 @@ int NB::ready()
373373

374374
case READY_STATE_WAIT_SET_FULL_FUNCTIONALITY_MODE:{
375375
if (ready > 1) {
376-
_state = ERROR;
376+
_state = NB_ERROR;
377377
ready = 2;
378378
} else {
379379
_readyState = READY_STATE_CHECK_REGISTRATION;
@@ -393,7 +393,7 @@ int NB::ready()
393393

394394
case READY_STATE_WAIT_CHECK_REGISTRATION_RESPONSE: {
395395
if (ready > 1) {
396-
_state = ERROR;
396+
_state = NB_ERROR;
397397
ready = 2;
398398
} else {
399399
int status = _response.charAt(_response.length() - 1) - '0';
@@ -410,7 +410,7 @@ int NB::ready()
410410
_state = CONNECTING;
411411
ready = 0;
412412
} else if (status == 3) {
413-
_state = ERROR;
413+
_state = NB_ERROR;
414414
ready = 2;
415415
}
416416
}

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)