Skip to content

Commit 9be5c8e

Browse files
Add support for GSM and GPS libraries
1 parent 99f8ba8 commit 9be5c8e

16 files changed

+84
-25
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
[submodule "mbed-os"]
55
path = mbed-os
66
url = https://github.com/mbed-ce/mbed-os.git
7+
[submodule "libraries/GPS/MicroNMEA"]
8+
path = libraries/GPS/MicroNMEA
9+
url = https://github.com/stevemarple/MicroNMEA.git

.idea/vcs.xml

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ include(mbed-os/tools/cmake/mbed_toolchain_setup.cmake)
1111

1212
project(ArduinoCore-mbed-ce
1313
LANGUAGES C CXX ASM
14-
VERSION 1.2.1) # This is the version of the Mbed CE Arduino core, not of Mbed CE
14+
VERSION 1.3.0) # This is the version of the Mbed CE Arduino core, not of Mbed CE
1515

1616
include(mbed_project_setup)
1717

@@ -81,6 +81,9 @@ set(MBED_LIBS_TO_INSTALL
8181
mbed-storage-littlefs-v2
8282
mbed-storage-securestore
8383
mbed-storage-tdbstore
84+
85+
# Cellular
86+
mbed-cellular
8487
)
8588

8689
if("DEVICE_USBDEVICE=1" IN_LIST MBED_TARGET_DEFINITIONS)

libraries/Arduino_CAN/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
set(ARDUINO_CAN_SOURCES
2+
src/Arduino_CAN.cpp)
3+
4+
add_library(arduino-Arduino_CAN STATIC ${ARDUINO_CAN_SOURCES})
5+
target_link_libraries(arduino-Arduino_CAN PUBLIC arduino-core)
6+
target_include_directories(arduino-Arduino_CAN PUBLIC src)
7+
8+
build_arduino_examples(Arduino_CAN examples)
9+
10+
install(DIRECTORY . DESTINATION libraries/Arduino_CAN)

libraries/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,16 @@ if("ARDUINO_PORTENTA_H7" IN_LIST MBED_TARGET_LABELS)
6161
add_subdirectory(USBAudio)
6262
add_subdirectory(KernelDebug)
6363
add_subdirectory(Ethernet)
64+
add_subdirectory(Arduino_CAN)
65+
add_subdirectory(GSM)
66+
add_subdirectory(GPS)
6467
# TODO add missing libraries for Portenta
6568
# add_subdirectory(PDM)
6669
# add_subdirectory(Arduino_H7_Video)
6770
# add_subdirectory(Himax_HM01B0)
6871
# add_subdirectory(Himax_HM0360)
6972
# add_subdirectory(Portenta_Audio)
7073
# add_subdirectory(RPC)
71-
# add_subdirectory(GSM)
7274
# add_subdirectory(Portenta_lvgl)
7375
# add_subdirectory(Camera)
7476
# add_subdirectory(rpclib)
@@ -77,7 +79,7 @@ if("ARDUINO_PORTENTA_H7" IN_LIST MBED_TARGET_LABELS)
7779
# add_subdirectory(Portenta_SDCARD)
7880
# add_subdirectory(GPS)
7981
# add_subdirectory(MCUboot)
80-
# add_subdirectory(Arduino_CAN)
82+
#
8183
endif()
8284

8385
# Libraries for all targets

libraries/GPS/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
set(GPS_SOURCES
2+
src/GPS.cpp
3+
MicroNMEA/src/MicroNMEA.cpp)
4+
5+
add_library(arduino-GPS STATIC ${GPS_SOURCES})
6+
target_link_libraries(arduino-GPS PUBLIC arduino-core arduino-GSM)
7+
target_include_directories(arduino-GPS PUBLIC src MicroNMEA/src)
8+
9+
install(DIRECTORY . DESTINATION libraries/GPS)
10+
install(FILES MicroNMEA/src/MicroNMEA.cpp MicroNMEA/src/MicroNMEA.h DESTINATION libraries/GPS)

libraries/GSM/CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
set(GSM_SOURCES
2+
src/buffercmux.c
3+
src/CMUXClass.cpp
4+
src/GSM.cpp
5+
src/GSMClient.cpp
6+
src/GSMDebug.cpp
7+
src/GSMSSLClient.cpp
8+
src/GSMTrace.cpp
9+
src/PTYSerial.cpp)
10+
11+
add_library(arduino-GSM STATIC ${GSM_SOURCES})
12+
target_link_libraries(arduino-GSM PUBLIC arduino-core arduino-SocketWrapper mbed-cellular)
13+
target_include_directories(arduino-GSM PUBLIC src)
14+
15+
build_arduino_examples(GSM examples)
16+
target_link_libraries(GSM-example-GNSSClient arduino-GPS)
17+
target_link_libraries(GSM-example-MicroNMEA_integration arduino-GPS)
18+
19+
install(DIRECTORY . DESTINATION libraries/GSM)

libraries/GSM/examples/GSMClient/GSMClient.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void setup() {
2727
//GSM.setTraceLevel(4);
2828

2929
Serial.println("Starting Carrier Network registration");
30-
if(!GSM.begin(pin, apn, username, pass, CATNB, BAND_20 | BAND_19)){
30+
if(!GSM.begin(pin, apn, username, pass, CATNB)){
3131
Serial.println("The board was not able to register to the network...");
3232
// do nothing forevermore:
3333
while(1);

libraries/GSM/examples/GSMSSLClient/GSMSSLClient.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void setup() {
4242
//GSM.setTraceLevel(4);
4343

4444
Serial.println("Starting Carrier Network registration");
45-
if(!GSM.begin(pin, apn, username, pass, CATM1, BAND_3 | BAND_20 | BAND_19)){
45+
if(!GSM.begin(pin, apn, username, pass, CATM1)){
4646
Serial.println("The board was not able to register to the network...");
4747
// do nothing forevermore:
4848
while(1);

libraries/GSM/src/CMUXClass.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class CMUXClass {
5151
private:
5252
void api_lock();
5353
void api_unlock();
54-
PlatformMutex _mutex;
54+
rtos::Mutex _mutex;
5555
bool _cmuxFlag = false;
5656
int id;
5757
mbed::CircularBuffer<char, 1500> rx_buffer;

libraries/GSM/src/GSM.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
arduino::CMUXClass *arduino::CMUXClass::get_default_instance()
3131
{
3232
static mbed::UnbufferedSerial serial(MBED_CONF_GEMALTO_CINTERION_TX, MBED_CONF_GEMALTO_CINTERION_RX, 115200);
33-
serial.set_flow_control(mbed::SerialBase::RTSCTS_SW, MBED_CONF_GEMALTO_CINTERION_CTS, NC);
3433
static arduino::CMUXClass device(&serial);
3534
return &device;
3635
}
@@ -40,11 +39,10 @@ mbed::CellularDevice *mbed::CellularDevice::get_default_instance()
4039
static auto cmux = arduino::CMUXClass::get_default_instance();
4140
static mbed::GEMALTO_CINTERION device(cmux->get_serial(0));
4241
nextSerialPort++;
43-
device.enableCMUXChannel = mbed::callback(cmux, &arduino::CMUXClass::enableCMUXChannel);
4442
return &device;
4543
}
4644

47-
int arduino::GSMClass::begin(const char* pin, const char* apn, const char* username, const char* password, RadioAccessTechnologyType rat, uint32_t band, bool restart) {
45+
int arduino::GSMClass::begin(const char* pin, const char* apn, const char* username, const char* password, mbed::RadioAccessTechnologyType rat, bool restart) {
4846

4947
if (restart || isCmuxEnable()) {
5048
reset();
@@ -61,33 +59,35 @@ int arduino::GSMClass::begin(const char* pin, const char* apn, const char* usern
6159

6260
static mbed::DigitalOut rts(MBED_CONF_GEMALTO_CINTERION_RTS, 0);
6361

64-
_device = _context->get_device();
62+
_device = reinterpret_cast<mbed::GEMALTO_CINTERION *>(_context->get_device());
6563
_device->modem_debug_on(_at_debug);
6664

6765
if (!isReady()) {
6866
DEBUG_ERROR("Cellular device not ready");
6967
return 0;
7068
}
7169

72-
_device->set_cmux_status_flag(_cmuxGSMenable);
7370
_device->set_retry_timeout_array(_retry_timeout, sizeof(_retry_timeout) / sizeof(_retry_timeout[0]));
7471
#if GSM_DEBUG_ENABLE
7572
_device->attach(mbed::callback(this, &GSMClass::onStatusChange));
7673
#endif
74+
75+
if (_cmuxGSMenable) {
76+
_device->enable_cmux();
77+
CMUXClass::get_default_instance()->enableCMUXChannel();
78+
}
7779
_device->init();
7880

7981
_pin = pin;
8082
_apn = apn;
8183
_username = username;
8284
_password = password;
8385
_rat = rat;
84-
_band = (FrequencyBand) band;
8586

8687
_context->set_sim_pin(pin);
8788
_context->set_authentication_type(mbed::CellularContext::AuthenticationType::PAP);
8889
_context->set_credentials(_apn, _username, _password);
8990
_context->set_access_technology(_rat);
90-
_context->set_band(_band);
9191

9292
int connect_status = NSAPI_ERROR_AUTH_FAILURE;
9393

@@ -132,9 +132,9 @@ unsigned long arduino::GSMClass::getLocalTime()
132132
return _device->get_local_time();
133133
}
134134

135-
bool arduino::GSMClass::setTime(unsigned long const epoch, int const timezone)
135+
void arduino::GSMClass::setTime(unsigned long const epoch, int const timezone)
136136
{
137-
return _device->set_time(epoch, timezone);
137+
_device->set_time(epoch, timezone);
138138
}
139139

140140
bool arduino::GSMClass::isConnected()

libraries/GSM/src/GSM.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class GSMClass : public MbedSocketClass {
7171
public:
7272

7373
GSMClass()
74-
: _rat(CATNB) {
74+
: _rat(mbed::CATNB) {
7575
if(_CMUX_ENABLE){
7676
arduino::GSMClass::enableCmux();
7777
}
@@ -88,7 +88,7 @@ class GSMClass : public MbedSocketClass {
8888
*
8989
* return: 0 in case of success, negative number in case of failure
9090
*/
91-
int begin(const char* pin, const char* apn, const char* username, const char* password, RadioAccessTechnologyType rat = CATNB, uint32_t band = BAND_20, bool restart = true);
91+
int begin(const char* pin, const char* apn, const char* username, const char* password, mbed::RadioAccessTechnologyType rat = mbed::CATNB, bool restart = true);
9292

9393
/*
9494
* Disconnect from the network
@@ -103,7 +103,7 @@ class GSMClass : public MbedSocketClass {
103103

104104
unsigned long getLocalTime();
105105

106-
bool setTime(unsigned long const epoch, int const timezone = 0);
106+
void setTime(unsigned long const epoch, int const timezone = 0);
107107
void enableCmux();
108108
bool isCmuxEnable();
109109
#if MBED_CONF_MBED_TRACE_ENABLE
@@ -126,11 +126,10 @@ class GSMClass : public MbedSocketClass {
126126
const char* _username = nullptr;
127127
const char* _password = nullptr;
128128
bool _cmuxGSMenable = _CMUX_ENABLE;
129-
RadioAccessTechnologyType _rat;
130-
FrequencyBand _band;
129+
mbed::RadioAccessTechnologyType _rat;
131130
NetworkInterface* gsm_if = nullptr;
132131
mbed::CellularContext* _context = nullptr;
133-
mbed::CellularDevice* _device = nullptr;
132+
mbed::GEMALTO_CINTERION* _device = nullptr;
134133
bool _at_debug = false;
135134

136135
/* Internal cellular state machine retries. Values are in seconds.

libraries/GSM/src/GSMClient.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
#include "GSM.h"
2424
#include "MbedClient.h"
2525

26+
// Bring these into the global scope
27+
using mbed::RadioAccessTechnologyType::CATNB;
28+
using mbed::RadioAccessTechnologyType::CATM1;
29+
2630
namespace arduino {
2731

2832
class GSMClient : public MbedClient {

libraries/GSM/src/GSMTrace.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1818
*/
1919

20+
#include <Arduino.h>
2021
#include <mbed.h>
2122
#include <GSM.h>
2223

2324
#if MBED_CONF_MBED_TRACE_ENABLE
2425

2526
static Stream* trace_stream = nullptr;
26-
static PlatformMutex trace_mutex;
27+
static rtos::Mutex trace_mutex;
2728
static char trace_timestamp[8];
2829

2930
static void trace_wait() {

libraries/GSM/src/PTYSerial.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
#include "platform/FileHandle.h"
3131
#include "drivers/InterruptIn.h"
32-
#include "platform/PlatformMutex.h"
32+
#include "rtos/Mutex.h"
3333
#include "platform/CircularBuffer.h"
3434
#include "platform/NonCopyable.h"
3535

@@ -101,7 +101,7 @@ class PTYSerial : public mbed::FileHandle
101101
void api_lock(void);
102102
void api_unlock(void);
103103

104-
PlatformMutex _mutex;
104+
rtos::Mutex _mutex;
105105
bool _blocking = true;
106106
void wake(void);
107107

mbed_app.json5

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@
103103
"RPMSG_BUFFER_SIZE=512"
104104
],
105105

106+
// Enable cellular drivers, needed for GSM library to compile
107+
"target.components_add": [
108+
"GEMALTO_CINTERION",
109+
"GENERIC_AT3GPP"
110+
],
111+
106112
// Access the wifi driver from the QSPI flash instead of including it (400kB) in the
107113
// application image.
108114
"target.wifi_driver_in_qspi_flash": true

0 commit comments

Comments
 (0)