You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This document provides guidelines and details for setting up a cellular device driver with Mbed OS. Please see the [working principles when working with a cellular C++ API](https://os.mbed.com/docs/latest/reference/network-socket.html) for more information.
3
+
This document provides guidelines how to make a cellular modem adaptation for Mbed OS. Please see [Cellular API usage](cellular-api.html) about how to use cellular modules from an application point of view.
4
4
5
-
### Implementing CellularInterface
5
+
### Adding modem target support
6
6
7
-
You can implement a cellular network interface in different ways depending on your requirements and physical setup. For example:
**Case 2: An implementation using Mbed OS provided network stacks (PPP mode, refer to figure 2)**
24
-
25
-
- Pros
26
-
- A well-established network stack with full Mbed OS support.
27
-
- The inherent network stack provides all socket APIs.
28
-
29
-
- Cons
30
-
- Heavier RAM memory consumption and bigger flash footprint.
31
-
- All modems do not support PPP mode making AT only mode the only available choice.
32
-
- Multiplexing command mode and data mode are not yet available.
33
-
34
-
#### Adding modem target support
35
-
36
-
For new targets, you may need to modify [targets.json](https://os.mbed.com/docs/v5.7/tools/adding-and-configuring-targets.html). `targets.json` defines all the target platforms that Mbed OS supports. If Mbed OS supports your specific target, an entry for your target is in this file. Define a global macro in your target description that tells the build system that your target has a modem, and the data connection type is attached with MCU.
7
+
For new targets, you may need to modify [targets.json](/docs/development/tools/adding-and-configuring-targets.html), which defines all the target platforms that Mbed OS supports. If Mbed OS supports your specific target, an entry for your target is in this file. To tell the Mbed OS build configuration that your target board has an onboard cellular module, you need to define `modem_is_on_board` and `modem_data_connection_type`.
37
8
38
9
For example,
39
10
@@ -62,7 +33,7 @@ For example,
62
33
},
63
34
```
64
35
65
-
Use standard pin names. A standard naming convention for pin names is required for standard modem pins in your target's **_'targets/TARGET_FAMILY/YOUR_TARGET/PinNames.h'_**. The example below shows the full UART capable modem. If any of these pins is not connected physically, mark it **_'NC'_**. Also indicate pin polarity.
36
+
In addition you need to map onboard modem pin aliases to your target board pin names and polarity in `targets/TARGET_FAMILY/YOUR_TARGET/PinNames.h`. If any of the pins are not connected, mark it 'NC'. An example UART configuration:
66
37
67
38
```C
68
39
typedefenum {
@@ -74,7 +45,7 @@ typedef enum {
74
45
MDMDSR = P0_19, // Data Set Ready
75
46
MDMDTR = P0_20, // Data Terminal Ready
76
47
MDMRI = P0_21, // Ring Indicator
77
-
MDMRTS = P0_22, // Request to Send
48
+
MDMRTS = P0_22, // Ready to Receive
78
49
79
50
} PinName;
80
51
@@ -85,71 +56,55 @@ typedef enum {
85
56
86
57
```
87
58
88
-
You must define all pins. Implement `onboard_modem_api.h`. The target board must provide an implementation of the [onboard_modem_API](https://os-doc-builder.test.mbed.com/docs/development/mbed-os-api-doxy/onboard__modem__api_8h_source.html).
59
+
### Adding a new cellular target
89
60
90
-
#### Modifying cellular targets
61
+
You need to specify in [CellularTargets.h](https://os-doc-builder.test.mbed.com/docs/development/mbed-os-api-doxy/_cellular_targets_8h_source.html), which `<manufacturer-module>` is mounted on your board.
91
62
92
-
Setup for some predefined targets is available in [CellularTargets.h](https://os-doc-builder.test.mbed.com/docs/development/mbed-os-api-doxy/_cellular_targets_8h_source.html). For a new target, you need to modify `CellularTargets.h`. In `CellularTargets.h`, you need to specify a cellular device in addition to UART pins connecting the Mbed OS CPU to the modem. For example, if the new device MY_NEW_TARGET defined above in the "Adding modem target support" chapter is connected with QUECTEL BG96, you would need the following changes marked in between `// !!!!` in `CellularTargets.h`:
63
+
```target
64
+
65
+
#elif <your target>
66
+
#define CELLULAR_DEVICE <manufacturer-module>
93
67
94
-
```C
95
-
...
96
-
#elif TARGET_UBLOX_C027
97
-
#defineCELLULAR_DEVICE UBLOX_C027
98
-
// !!!!
99
-
// cellular device to be connected with MY_NEW_TARGET is specified below:
100
-
#elif TARGET_MY_NEW_TARGET
101
-
#defineCELLULAR_DEVICE QUECTEL_BG96
102
-
// !!!!
103
-
#else
104
-
#error Cellular target not defined, see cellular/targets.h
105
-
//#define CELLULAR_TARGET <target-modem>
106
-
//#define MDMTXD <pin-name>
107
-
//#define MDMRXD <pin-name>
108
-
#endif
109
-
#endif
110
-
// !!!!
111
-
// cellular target and UART pins connecting MY_NEW_TARGET with the modem are specified below:
112
-
#defineCELLULAR_TARGET TARGET_MY_NEW_TARGET
113
-
#define MDMTXD PTC17
114
-
#define MDMRXD PTC16
115
-
// !!!!
116
-
...
117
68
```
118
69
119
-
If none of the existing modems is compatible with the new modem, then create new modem implementation under [features/cellular/framework/targets](https://github.com/ARMmbed/mbed-os/blob/master/features/cellular/framework/targets). A device class inheriting [AT_CellularDevice](https://os-doc-builder.test.mbed.com/docs/development/mbed-os-api-doxy/_a_t___cellular_device_8h_source.html) is a minimum. [QUECTEL_BG96](https://github.com/ARMmbed/mbed-os/blob/master/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h) is an example of the device class. You can create additional overlapping functionality for everything that is available in [features/cellular/framework/targets](https://github.com/ARMmbed/mbed-os/blob/master/features/cellular/framework/targets).
70
+
You can browse the existing `manufacturer-modules`under `features/cellular/framework/targets`. If none of those are compatible with your module then you need to make a new cellular module adaptation.
120
71
121
-
#### Providing an implementation using on-chip network stacks (AT only mode)
72
+
###Adding a new cellular module
122
73
123
-
[QUECTEL_BG96_CellularStack](https://github.com/ARMmbed/mbed-os/blob/master/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularStack.h) is an example of a modem specific AT command cellular stack implementation. For example, [mbed-os-example-cellular](https://os.mbed.com/teams/mbed-os-examples/code/mbed-os-example-cellular/) instantiates the [EasyCellularConnection class](https://os-doc-builder.test.mbed.com/docs/development/mbed-os-api-doxy/_easy_cellular_connection_8h_source.html), which in turn instantiates the [CellularConnectionFSM class](https://os-doc-builder.test.mbed.com/docs/development/mbed-os-api-doxy/_cellular_connection_f_s_m_8h_source.html). CellularConnectionFSM instantiates classes implementing [the AT command layer](https://os-doc-builder.test.mbed.com/docs/development/mbed-os-api-doxy/_a_t___cellular_device_8h_source.html) between the modem and the Mbed OS CPU. For the [QUECTEL BG96](https://github.com/ARMmbed/mbed-os/tree/master/features/cellular/framework/targets/QUECTEL/BG96) classes [QUECTEL_BG96](https://github.com/ARMmbed/mbed-os/blob/master/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h), [QUECTEL_BG96_CellularStack](https://github.com/ARMmbed/mbed-os/blob/master/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularStack.h) and [QUECTEL_BG96_CellularNetwork](https://github.com/ARMmbed/mbed-os/blob/master/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularNetwork.h) have been implemented for a modem specific functionality. QUECTEL_BG96_CellularStack implements QUECTEL BG96 specific AT command stack for socket data handling.
74
+
Cellular module adaptations are very similar to each other and due to they only need to implement deviation from the default implementation, you can most probably reuse some existing adaptation.
124
75
125
-
#### Providing an implementation using Mbed OS provided network stacks (PPP mode)
76
+
You need to create a new folder as _MANUFACTURER/MODULE/_ for your new cellular module in `features/cellular/framework/targets/`. A device class inheriting [AT_CellularDevice](https://os-doc-builder.test.mbed.com/docs/development/mbed-os-api-doxy/_a_t___cellular_device_8h_source.html) is a minimum, and you may need to extend other cellular APIs as well if the default implementation is not sufficient for your cellular module.
126
77
127
-
If the new modem supports PPP mode, then you can use the existing Mbed OS LWIP stack to control the modem when connecting to a network. To use the LWIP stack, set `lwip.ppp-enabled` to true in an application `mbed_app.json`. [UBLOX LISA](https://github.com/ARMmbed/mbed-os/tree/master/features/cellular/framework/targets/UBLOX/LISA_U) is an example of a modem implementation using PPP mode to connect to a network. For example, [mbed-os-example-cellular](https://os.mbed.com/teams/mbed-os-examples/code/mbed-os-example-cellular/) instantiates [EasyCellularConnection class](https://os-doc-builder.test.mbed.com/docs/development/mbed-os-api-doxy/_easy_cellular_connection_8h_source.html), which in turn instantiates [CellularConnectionFSM class](https://os-doc-builder.test.mbed.com/docs/development/mbed-os-api-doxy/_cellular_connection_f_s_m_8h_source.html). CellularConnectionFSM instantiates classes implementing [the AT command layer](https://os-doc-builder.test.mbed.com/docs/development/mbed-os-api-doxy/_a_t___cellular_device_8h_source.html) between the modem and the Mbed OS CPU. For LISA classes [UBLOX_LISA_U](https://github.com/ARMmbed/mbed-os/blob/master/features/cellular/framework/targets/UBLOX/LISA_U/UBLOX_LISA_U.h), [UBLOX_LISA_U_CellularNetwork](https://github.com/ARMmbed/mbed-os/blob/master/features/cellular/framework/targets/UBLOX/LISA_U/UBLOX_LISA_U_CellularNetwork.h) and [UBLOX_LISA_U_CellularPower](https://github.com/ARMmbed/mbed-os/blob/master/features/cellular/framework/targets/UBLOX/LISA_U/UBLOX_LISA_U_CellularPower.h) have been implemented for a modem specific functionality. In the AT command layer, [AT_CellularNetwork](https://os-doc-builder.test.mbed.com/docs/development/mbed-os-api-doxy/_a_t___cellular_network_8h_source.html) includes functionality calling [nsapi_ppp_connect()](https://os-doc-builder.test.mbed.com/docs/development/mbed-os-api-doxy/netsocket_2nsapi__ppp_8h_source.html) to start the data call through the PPP pipe.
78
+
### Socket adaptation
128
79
129
-
### Testing
80
+
You can implement socket API in two ways:
130
81
131
-
Once you have your target and driver port ready, you can verify your implementation by running port verification tests on your system. You must have `mbed-greentea` installed for this.
82
+
- Use the IP stack on the cellular module (AT mode).
83
+
- Use the LWIP stack on Mbed OS (PPP mode).
132
84
133
-
- To run the tests:
134
-
1. From the root of your application, enter this command:
85
+
If your cellular module has an IP stack, you need to implement AT commands to connect to a network and to control network sockets. If the modem supports PPP mode, you can use LWIP stack to handle sockets and IP connectivity for your modem after connected to a network. A modem can support the both AT and PPP modes, but an application developer need to select at compile time whether to use AT mode or PPP mode in the application's `mbed_app.json` configuration file using `lwip.ppp-enabled` flag.
135
86
136
-
```
137
-
mbed test --compile-list
138
-
```
87
+
For example implementations of socket adaptation, look for `features/cellular/framework/targets`.
139
88
140
-
1. Look for the name of a test suite matching `mbed-os-features-cellular-tests-cellular-cellular_all`.
141
-
1. Run tests with the command:
89
+
When the modem has AT and/or PPP mode support in place and the application developer has selected which mode to use, it's up to the cellular framework to instantiate the correct classes. For example, [mbed-os-example-cellular](https://os.mbed.com/teams/mbed-os-examples/code/mbed-os-example-cellular/) instantiates [EasyCellularConnection class](https://os-doc-builder.test.mbed.com/docs/development/mbed-os-api-doxy/_easy_cellular_connection_8h_source.html), which in turn instantiates [CellularConnectionFSM class](https://os-doc-builder.test.mbed.com/docs/development/mbed-os-api-doxy/_cellular_connection_f_s_m_8h_source.html). CellularConnectionFSM instantiates classes implementing [the AT command layer](https://os-doc-builder.test.mbed.com/docs/development/mbed-os-api-doxy/_a_t___cellular_device_8h_source.html) between the modem and the Mbed OS CPU. If an application developer has configured PPP mode in `mbed_app.json` then [AT_CellularNetwork](https://os-doc-builder.test.mbed.com/docs/development/mbed-os-api-doxy/_a_t___cellular_network_8h_source.html) connects to a cellular network and calls [nsapi_ppp_connect()](https://os-doc-builder.test.mbed.com/docs/development/mbed-os-api-doxy/netsocket_2nsapi__ppp_8h_source.html) to start the data call through the PPP pipe using LWIP sockets.
90
+
91
+
### Testing
92
+
93
+
Once you have your target and driver port ready, you can verify your implementation by running port verification tests on your system. You must have `mbed-greentea` installed for this.
142
94
143
-
```
144
-
mbed test -n "mbed-os-features-cellular-tests-cellular-cellular_all" -m YOURMACHINE -t YOURCOMPILER --app-config YOURCONFIG.json
145
-
```
95
+
To run the tests:
146
96
147
-
For more information on the `mbed-greentea` test suite, please visit [its documentation](https://os.mbed.com/docs/v5.7/tools/greentea.html).
97
+
1. From the root of your application, enter this command:
148
98
149
-
You can also run stand-alone tests. The [`UNITTESTS` folder](https://github.com/ARMmbed/mbed-os/tree/master/features/cellular/UNITTESTS) contains unit tests for cellular specific classes. Unit tests are based on the stubbing method.
99
+
```
100
+
mbed test --compile-list
101
+
```
150
102
151
-
You can run those tests locally by running `./run_tests` script under the [`UNITTESTS` folder](https://github.com/ARMmbed/mbed-os/tree/master/features/cellular/UNITTESTS).
103
+
1. Look for the name of a test suite matching `features-cellular-tests-*`.
104
+
1. Run tests with the command:
152
105
153
-
You need the following applications: `cpputest`, `gcov` and `lcov` (`genhtml`) for running the tests by themselves.
106
+
```
107
+
mbed test -n "mbed-os-features-cellular-tests-*" -m TARGET -t TOOLCHAIN --app-config YOURCONFIG.json
108
+
```
154
109
155
-
After you have run the `run_tests` script, you can find test results in the [`UNITTESTS/results` folder](https://github.com/ARMmbed/mbed-os/tree/master/features/cellular/UNITTESTS) and line and function coverages in the [`UNITTESTS/coverages` folder](https://github.com/ARMmbed/mbed-os/tree/master/features/cellular/UNITTESTS).
110
+
For more information on the `mbed-greentea` test suite, please visit [its documentation](/docs/development/tools/greentea.html).
0 commit comments