Skip to content

Commit ec50468

Browse files
added documentation on initialisation in ModemInterface
1 parent 4a418dc commit ec50468

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

Diff for: src/ModemInterface.cpp

+11-8
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,31 @@
55
#include <ModemInterface.h>
66

77
#if defined(ARDUINO_PORTENTA_C33)
8-
#define ON_PIN 32 // P708 (32) is the ON pin
9-
8+
// On the C33 the Serial1 object is already defined, but it does not have hardware flow control
9+
// mbed allows us to define a UART object with software flow control on given pins
1010
// P602/P110/P603/P604 -> Serial1
11-
UART Serial1_FC(UART1_TX_PIN, UART1_RX_PIN, 61, 62);
11+
UART Serial1_FC(UART1_TX_PIN, UART1_RX_PIN, PORTENTA_C33_CTS_PIN, PORTENTA_C33_RTS_PIN);
1212

1313
#ifdef DUMP_AT_COMMANDS
1414
StreamDebugger debugger(Serial1_FC, Serial);
15-
__attribute__ ((init_priority (101))) ModemInterface modem(debugger, ON_PIN);
15+
16+
// we need to make sure that the Modem object is initialised before anything else in the sketch to avoid issues with the TinyGSM library
17+
// the init_priority attribute is used to set the priority of the constructor, the lower the number the higher the priority (101 to 65535)
18+
// for more information see https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Attributes.html
19+
__attribute__ ((init_priority (101))) ModemInterface modem(debugger, PORTENTA_C33_MODEM_ON_PIN);
1620
#else
17-
__attribute__ ((init_priority (101))) ModemInterface modem(Serial1_FC, ON_PIN);
21+
__attribute__ ((init_priority (101))) ModemInterface modem(Serial1_FC, PORTENTA_C33_MODEM_ON_PIN);
1822
#endif
1923

2024
#elif defined(ARDUINO_PORTENTA_H7_M7) || defined(CORE_CM4)
2125
#include "pinDefinitions.h"
22-
#define ON_PIN PG_3 // PG3 is the ON pin
2326

2427
// P602/P110/P603/P604 -> Serial1
2528
#ifdef DUMP_AT_COMMANDS
2629
StreamDebugger debugger(Serial1, Serial);
27-
__attribute__ ((init_priority (101))) ModemInterface modem(debugger, PinNameToIndex(ON_PIN));
30+
__attribute__ ((init_priority (101))) ModemInterface modem(debugger, PinNameToIndex(PORTENTA_H7_MODEM_ON_PIN));
2831
#else
29-
__attribute__ ((init_priority (101))) ModemInterface modem(Serial1, PinNameToIndex(ON_PIN));
32+
__attribute__ ((init_priority (101))) ModemInterface modem(Serial1, PinNameToIndex(PORTENTA_H7_MODEM_ON_PIN));
3033
#endif
3134

3235
#endif

Diff for: src/ModemInterface.h

+14-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111
#define TINY_GSM_RX_BUFFER 1024
1212
#define TINY_GSM_MODEM_BG96
1313

14+
#if defined(ARDUINO_PORTENTA_H7_M7) || defined(CORE_CM4)
15+
#define PORTENTA_H7_MODEM_ON_PIN PG_3 // PG3 is the ON pin
16+
#elif defined(ARDUINO_PORTENTA_C33)
17+
#define PORTENTA_C33_CTS_PIN 61
18+
#define PORTENTA_C33_RTS_PIN 62
19+
#define PORTENTA_C33_MODEM_ON_PIN 32
20+
#endif
21+
1422

1523
#include <Arduino.h>
1624
#include <StreamDebugger.h>
@@ -19,7 +27,7 @@
1927

2028
/**
2129
* @class ModemInterface
22-
* @brief Represents the interface to the 4G modem module.
30+
* @brief Represents the interface to the 4G modem module which extends the TinyGsmBG96 class.
2331
*/
2432
class ModemInterface : public TinyGsmBG96 {
2533
public:
@@ -33,16 +41,20 @@ class ModemInterface : public TinyGsmBG96 {
3341
};
3442

3543
/**
36-
* @brief Initializes the modem interface.
44+
* @brief Initializes the modem interface. (Overrides the init method in TinyGsmBG96)
3745
* @param pin The PIN code for the SIM card (optional).
3846
* @return True if initialization is successful, false otherwise.
3947
*/
4048
bool init(const char* pin = NULL) {
49+
// Power on the modem
4150
pinMode(powerPin, OUTPUT);
4251
digitalWrite(powerPin, HIGH);
4352
delay(1000);
53+
4454
#ifdef DUMP_AT_COMMANDS
4555
#if defined(ARDUINO_PORTENTA_C33)
56+
// On the C33 we have defined a UART object with software flow control on given pins in the .cpp file, we'll use extern to access and begin communication
57+
4658
extern UART Serial1_FC;
4759
Serial1_FC.begin(115200);
4860
#endif

0 commit comments

Comments
 (0)