Skip to content

Commit 8454f71

Browse files
Unify cellular example (#210)
* update mbed-os lib to master * add git ignore * example unification * unify readme * constexpr * clarify drivers in readme
1 parent d7acbe5 commit 8454f71

File tree

7 files changed

+479
-361
lines changed

7 files changed

+479
-361
lines changed

.gitignore

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Compiled Object files
2+
*.slo
3+
*.lo
4+
*.o
5+
*.obj
6+
7+
# Precompiled Headers
8+
*.gch
9+
*.pch
10+
11+
# Compiled Dynamic libraries
12+
*.so
13+
*.dylib
14+
*.dll
15+
16+
# Fortran module files
17+
*.mod
18+
19+
# Compiled Static libraries
20+
*.lai
21+
*.la
22+
*.a
23+
24+
# Executables
25+
*.exe
26+
*.out
27+
*.app
28+
29+
.yotta.json
30+
BUILD
31+
yotta_modules/
32+
yotta_targets/
33+
.DS_Store
34+
35+
# clion
36+
.idea/
37+
cmake-build-*/
38+
39+
# exporters
40+
GettingStarted.html
41+
42+
# mbed build system
43+
mbed-os/
44+
mbed_settings.py
45+
mbed_config.h
46+
*.pyc
47+
TARGET_CORDIO_BLUENRG/
48+

CMakeLists.txt

+7-1
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,20 @@ mbed_set_mbed_target_linker_script(${APP_TARGET})
1919

2020
project(${APP_TARGET})
2121

22+
target_include_directories(${APP_TARGET}
23+
PUBLIC
24+
${CMAKE_CURRENT_SOURCE_DIR}/include
25+
)
26+
2227
target_sources(${APP_TARGET}
2328
PRIVATE
24-
main.cpp
29+
source/main.cpp
2530
)
2631

2732
target_link_libraries(${APP_TARGET}
2833
PRIVATE
2934
mbed-os
35+
mbed-netsocket
3036
mbed-cellular
3137
)
3238

README.md

+98-70
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,86 @@
11
![](./resources/official_armmbed_example_badge.png)
2-
# Example cellular application for Mbed OS
2+
# Cellular Example
33

44
This is an example based on `mbed-os` cellular APIs that demonstrates a TCP or UDP echo transaction with a public echo server.
55

6-
(Note: To see this example in a rendered form you can import into the Arm Mbed Online Compiler, please see [the documentation](https://os.mbed.com/docs/mbed-os/latest/apis/cellular-api.html#cellular-example-connection-establishment).)
6+
(Note: To see this example in a rendered form you can import into the Arm Mbed Online Compiler, please see
7+
[the documentation](https://os.mbed.com/docs/mbed-os/latest/apis/cellular-api.html#cellular-example-connection-establishment).)
78

89
## Getting started
910

1011
This particular cellular application uses a cellular network and network-socket APIs that are part of [`mbed-os`](https://github.com/ARMmbed/mbed-os).
1112

12-
The program uses a [cellular modem driver](https://github.com/ARMmbed/mbed-os/tree/master/features/cellular/framework/API) using an external IP stack (LWIP) standard 3GPP AT 27.007 AT commands to setup the cellular modem and registers to the network.
13+
The program uses a [cellular modem driver](https://github.com/ARMmbed/mbed-os/tree/master/connectivity/cellular/include/cellular/framework/API)
14+
using an external IP stack standard 3GPP AT 27.007 AT commands to setup the cellular modem and registers to the network.
1315

14-
After registration, the driver opens a point-to-point protocol (PPP) pipe using LWIP with the cellular modem and connects to internet. This driver currently supports UART data connection type only between your cellular modem and MCU.
16+
After registration, the driver opens a point-to-point protocol (PPP) pipe with the cellular modem and connects
17+
to internet. This driver currently supports UART data connection type only between your cellular modem and MCU.
1518

16-
For more information on Arm Mbed OS cellular APIs and porting guide, please visit the [Mbed OS cellular API](https://os.mbed.com/docs/latest/reference/cellular.html) and [contributing documentation](https://os.mbed.com/docs/mbed-os/latest/contributing/index.html).
19+
For more information on Arm Mbed OS cellular APIs and porting guide, please visit the
20+
[Mbed OS cellular API](https://os.mbed.com/docs/mbed-os/latest/apis/cellular-networking.html) and
21+
[Mbed OS cellular porting guide](https://os.mbed.com/docs/mbed-os/latest/porting/cellular-device-porting.html).
1722

18-
### Download the application
23+
### Board support
24+
25+
Currently supported boards with onboard modem chips can be found under Mbed OS
26+
[/targets folder](https://github.com/ARMmbed/mbed-os/tree/master/targets).
27+
You can find all cellular specific onboard modems by searching an overridden function
28+
`CellularDevice::get_target_default_instance()`.
29+
30+
Currently supported modem drivers can be found under cellular
31+
[/drivers folder](https://github.com/ARMmbed/mbed-os/tree/master/connectivity/drivers/cellular).
32+
33+
For a cellular shield, you need to define which shield to use with `provide-default`, and also how the shield is connected
34+
to the Mbed OS board. For example, a generic AT/PPP modem would add from the `GENERIC_AT3GPP/mbed_lib.json` file to your
35+
`mbed_app.json`:
36+
37+
```
38+
"target_overrides": {
39+
"GENERIC_AT3GPP.provide-default": true,
40+
"GENERIC_AT3GPP.tx": "<tx-pinmap>",
41+
"GENERIC_AT3GPP.rx": "<rx-pinmap>"
42+
}
43+
```
44+
45+
## Building and flashing the example
1946

20-
```sh
21-
$ mbed import mbed-os-example-cellular
22-
$ cd mbed-os-example-cellular
47+
### To build the example
2348

24-
#OR
49+
Clone the repository containing example:
2550

26-
$ git clone [email protected]:ARMmbed/mbed-os-example-cellular.git
27-
$ cd mbed-os-example-cellular
2851
```
52+
git clone https://github.com/ARMmbed/mbed-os-example-cellular.git
53+
```
54+
55+
**Tip:** If you don't have git installed, you can
56+
[download a zip file](https://github.com/ARMmbed/mbed-os-example-cellular/archive/master.zip) of the repository.
57+
58+
Update the source tree:
59+
60+
```
61+
cd mbed-os-example-cellular
62+
mbed deploy
63+
```
64+
65+
Run the build:
66+
67+
```mbed compile -t <ARM | GCC_ARM> -m <YOUR_TARGET>```
68+
69+
### To flash the example onto your board
70+
71+
Connect your mbed board to your computer over USB. It appears as removable storage.
72+
73+
When you run the `mbed compile` command above, mbed cli creates a .bin or a .hex file (depending on your target) in
74+
```BUILD/<target-name>/<toolchain>``` under the example's directory. Drag and drop the file to the removable storage.
75+
76+
Alternatively you may launch compilation with `-f` flag to have mbed tools attempt to flash your board.
77+
The tools will flash the binary to all targets that match the board specified by '-m' parameter.
2978

3079
### Change the network and SIM credentials
3180

32-
See the file `mbed_app.json` in the root directory of your application. This file contains all the user specific configurations your application needs. Provide the pin code for your SIM card, as well as any other cellular settings, or `null` if not used. For example:
81+
See the file `mbed_app.json` in the root directory of your application. This file contains all the user specific
82+
configurations your application needs. Provide the pin code for your SIM card, as well as any other cellular settings,
83+
or `null` if not used. For example:
3384

3485
```json
3586
"target_overrides": {
@@ -39,9 +90,8 @@ See the file `mbed_app.json` in the root directory of your application. This fil
3990

4091
### Selecting socket type (TCP, UDP or NONIP)
4192

42-
43-
You can choose which socket type the application should use; however, please note that TCP is a more reliable transmission protocol. For example:
44-
93+
You can choose which socket type the application should use; however, please note that TCP is a more reliable
94+
transmission protocol. For example:
4595

4696
```json
4797

@@ -51,22 +101,24 @@ You can choose which socket type the application should use; however, please not
51101

52102
### Turning modem AT echo trace on
53103

54-
If you like details and wish to know about all the AT interactions between the modem and your driver, turn on the modem AT echo trace.
104+
If you like details and wish to know about all the AT interactions between the modem and your driver, turn on the modem
105+
AT echo trace:
55106

56107
```json
57108
"cellular.debug-at": true
58109
```
59110

60111
### Turning on the tracing and trace level
61112

62-
If you like to add more traces or follow the current ones you can turn traces on by changing `mbed-trace.enable` in mbed_app.json
113+
If you like to add more traces or follow the current ones you can turn traces on by changing `mbed-trace.enable` in
114+
mbed_app.json:
63115

64116
```"target_overrides": {
65117
"*": {
66118
"mbed-trace.enable": true,
67119
```
68120

69-
After you have defined `mbed-trace.enable: true`, you can set trace levels by changing value in `trace-level`
121+
After you have defined `mbed-trace.enable: true`, you can set trace levels by changing value in `trace-level`:
70122

71123
```"trace-level": {
72124
"help": "Options are TRACE_LEVEL_ERROR,TRACE_LEVEL_WARN,TRACE_LEVEL_INFO,TRACE_LEVEL_DEBUG",
@@ -75,85 +127,61 @@ After you have defined `mbed-trace.enable: true`, you can set trace levels by ch
75127
}
76128
```
77129

78-
### Board support
130+
## Running the example
79131

80-
The [cellular modem driver](https://github.com/ARMmbed/mbed-os/tree/master/features/cellular/framework/API) in this example uses PPP with an Mbed-supported external LwIP stack. It supports targets when modem exists on the Mbed Enabled target as opposed to plug-in modules (shields). For more details, please see our [Mbed OS cellular documentation](https://os.mbed.com/docs/mbed-os/latest/apis/cellular-api.html).
132+
When example application is running information about activity is printed over the serial connection.
81133

82-
Currently supported boards with onboard modem chips can be found under Mbed OS [/targets folder](https://github.com/ARMmbed/mbed-os/tree/master/targets). You can find all cellular specific onboard modems by searching an overridden function ```CellularDevice::get_target_default_instance()```.
134+
**Note:** The default serial baudrate has been set to 115200.
83135

84-
Currently supported modem drivers (for plug-in shields) can be found under cellular [/targets folder](https://github.com/ARMmbed/mbed-os/tree/master/features/cellular/framework/targets).
136+
Please have a client open and connected to the board. You may use:
85137

138+
- [Tera Term](https://ttssh2.osdn.jp/index.html.en) for windows
86139

87-
For a cellular shield, you need to define which shield to use with `provide-default`, and also how the shield is connected to the Mbed OS board. For example, a generic AT/PPP modem would add from the `GENERIC_AT3GPP/mbed_lib.json` file to your `mbed_app.json`:
88-
```
89-
"target_overrides": {
90-
"GENERIC_AT3GPP.provide-default": true,
91-
"GENERIC_AT3GPP.tx": "<tx-pinmap>",
92-
"GENERIC_AT3GPP.rx": "<rx-pinmap>"
93-
}
94-
```
140+
- screen or minicom for Linux (example usage: `screen /dev/serial/<your board> 115200`)
95141

96-
## Compiling the application
142+
- mbed tools has a terminal command `mbed term -b 115200`
97143

98-
The master branch is for daily development and it uses the latest mbed-os/master release.
99-
100-
To use older versions update Mbed OS release tag, for example:
101-
102-
```
103-
mbed releases
104-
* mbed-os-5.10.4
105-
...
106-
mbed update mbed-os-5.10.4
107-
```
108-
109-
You may need to use `--clean` option to discard your local changes (use with caution).
110-
111-
Use Mbed CLI commands to generate a binary for the application. For example, in the case of GCC, use the following command:
112-
113-
```sh
114-
$ mbed compile -m YOUR_TARGET_WITH_MODEM -t GCC_ARM
115-
```
116-
117-
## Running the application
118-
119-
Drag and drop the application binary from `BUILD/YOUR_TARGET_WITH_MODEM/GCC_ARM/mbed-os-example-cellular.bin` to your Mbed Enabled target hardware, which appears as a USB device on your host machine.
120-
121-
Attach a serial console emulator of your choice (for example, PuTTY, Minicom or screen) to your USB device. Set the baudrate to 115200 bit/s, and reset your board by pressing the reset button.
144+
### Expected output
122145

123146
You should see an output similar to this:
124147

125148
```
126149
mbed-os-example-cellular
127-
Establishing connection ......
128-
150+
Establishing connection
129151
Connection Established.
130152
TCP: connected with echo.mbedcloudtesting.com server
131153
TCP: Sent 4 Bytes to echo.mbedcloudtesting.com
132154
Received from echo server 4 Bytes
133-
134-
135155
Success. Exiting
136156
```
137157

138-
## Troubleshooting
158+
### Troubleshooting
139159

140-
* Make sure the fields `nsapi.default-cellular-sim-pin`, `nsapi.default-cellular-plmn`, `nsapi.default-cellular-apn`, `nsapi.default-cellular-username` and `nsapi.default-cellular-password` from the `mbed_app.json` file are filled in correctly. The correct values should appear in the user manual of the board if using eSIM or in the details of the SIM card if using normal SIM.
160+
* Make sure the fields `nsapi.default-cellular-sim-pin`, `nsapi.default-cellular-plmn`, `nsapi.default-cellular-apn`,
161+
`nsapi.default-cellular-username` and `nsapi.default-cellular-password` from the `mbed_app.json` file are filled in
162+
correctly. The correct values should appear in the user manual of the board if using eSIM or in the details of the
163+
SIM card if using normal SIM.
141164
* Enable trace flag to have access to debug information `"mbed-trace.enable": true` and `"cellular.debug-at": true`.
142-
* Error Message: Assertion failed: iface usually means that a default modem is not defined, e.g. `"GENERIC_AT3GPP.provide-default": true`
143-
* If the modem does not respond to (AT) queries, check that UART pins (tx, rx, rts, cts) are connected and defined, e.g. `"GENERIC_AT3GPP.tx": "<tx-pinmap>"`, ...
144-
* It is a common case that a modem seems to connect fine with just USB power, but actually it needs to have an external power supply for a data connection.
165+
* Error Message: Assertion failed: iface usually means that a default modem is not defined, e.g.
166+
`"GENERIC_AT3GPP.provide-default": true`
167+
* If the modem does not respond to (AT) queries, check that UART pins (tx, rx, rts, cts) are connected and defined,
168+
e.g. `"GENERIC_AT3GPP.tx": "<tx-pinmap>"`, ...
169+
* It is a common case that a modem seems to connect fine with just USB power, but actually it needs to have an external
170+
power supply for a data connection.
145171
* Try both `TCP` and `UDP` socket types.
146172
* Try both `"lwip.ppp-enabled": true` and `"lwip.ppp-enabled": false`.
147173
* The modem may support only a fixed baud-rate, such as `"platform.default-serial-baud-rate": 9600`.
148174
* The modem and network may only support IPv6 in which case `"lwip.ipv6-enabled": true` shall be defined.
149175
* The SIM and modem must have compatible cellular technology (3G, 4G, NB-IoT, ...) supported and cellular network available.
150176
* Enable CIoT optimization for NONIP socket `control-plane-opt: true`.
151177

152-
If you have problems to get started with debugging, you can review the [documentation](https://os.mbed.com/docs/latest/tutorials/debugging.html) for suggestions on what could be wrong and how to fix it.
153-
154-
### License and contributions
178+
If you have problems to get started with debugging, you can review the
179+
[documentation](https://os.mbed.com/docs/latest/tutorials/debugging.html) for suggestions on what could be wrong and how to fix it.
155180

156-
The software is provided under Apache-2.0 license. Contributions to this project are accepted under the same license. Please see [contributing.md](CONTRIBUTING.md) for more info.
181+
## License and contributions
157182

158-
This project contains code from other projects. The original license text is included in those source files. They must comply with our license guide.
183+
The software is provided under Apache-2.0 license. Contributions to this project are accepted under the same license.
184+
Please see [contributing.md](CONTRIBUTING.md) for more info.
159185

186+
This project contains code from other projects. The original license text is included in those source files.
187+
They must comply with our license guide

0 commit comments

Comments
 (0)