You are on page 1of 43

M65&M08-R&MC65

QuecOpen
Quick Start Guide

GSM/GPRS/GNSS Module Series

Version: 1.0

Date: 2021-04-07

Status: Released
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

Our aim is to provide customers with timely and comprehensive service. For any assistance,
please contact our company headquarters:

Quectel Wireless Solutions Co., Ltd.


Building 5, Shanghai Business Park Phase III (Area B), No.1016 Tianlin Road, Minhang District, Shanghai
200233, China
Tel: +86 21 5108 6236
Email: info@quectel.com

Or our local office. For more information, please visit:


http://www.quectel.com/support/sales.htm.

For technical support, or to report documentation errors, please visit:


http://www.quectel.com/support/technical.htm
Or email to support@quectel.com.

General Notes
Quectel offers the information as a service to its customers. The information provided is based upon
customers’ requirements. Quectel makes every effort to ensure the quality of the information it makes
available. Quectel does not make any warranty as to the information contained herein, and does not
accept any liability for any injury, loss or damage of any kind incurred by use of or reliance upon the
information. All information supplied herein is subject to change without prior notice.

Disclaimer
While Quectel has made efforts to ensure that the functions and features under development are free
from errors, it is possible that these functions and features could contain errors, inaccuracies and
omissions. Unless otherwise provided by valid agreement, Quectel makes no warranties of any kind,
implied or express, with respect to the use of features and functions under development. To the maximum
extent permitted by law, Quectel excludes all liability for any loss or damage suffered in connection with
the use of the functions and features under development, regardless of whether such loss or damage
may have been foreseeable.

Duty of Confidentiality
The Receiving Party shall keep confidential all documentation and information provided by Quectel,
except when the specific permission has been granted by Quectel. The Receiving Party shall not access
or use Quectel’s documentation and information for any purpose except as expressly provided herein.
Furthermore, the Receiving Party shall not disclose any of the Quectel's documentation and information
to any third party without the prior written consent by Quectel. For any noncompliance to the above
requirements, unauthorized use, or other illegal or malicious use of the documentation and information,
Quectel will reserve the right to take legal action.

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 1 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

Copyright
The information contained here is proprietary technical information of Quectel. Transmitting, reproducing,
disseminating and editing this document as well as using the content without permission are forbidden.
Offenders will be held liable for payment of damages. All rights are reserved in the event of a patent grant
or registration of a utility model or design.

Copyright © Quectel Wireless Solutions Co., Ltd. 2021. All rights reserved.

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 2 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

About the Document

Revision History

Version Date Author Description

- 2021-02-07 Waner PAN Creation of the document

1.0 2021-04-07 Waner PAN First official release

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 3 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

Contents

About the Document .................................................................................................................................. 3


Contents ...................................................................................................................................................... 4
Table Index .................................................................................................................................................. 6
Figure Index ................................................................................................................................................ 7

1 Introduction ......................................................................................................................................... 8

2 Preparations ........................................................................................................................................ 9
2.1. Host System ............................................................................................................................... 9
2.2. Compiler and Debugging Tool.................................................................................................... 9
2.3. Developer Experience................................................................................................................ 9
2.4. Hardware .................................................................................................................................... 9
2.5. QuecOpen SDK ....................................................................................................................... 10

3 QuecOpen® SDK................................................................................................................................ 11

4 Development Environment Construction....................................................................................... 13


4.1. Compilation Environment ......................................................................................................... 13
4.1.1. Installation of CSDTK Compiler .................................................................................... 13
4.2. Debugging Environment .......................................................................................................... 14
4.2.1. Installation of CoolWatcher ........................................................................................... 14
4.2.2. Configuration of CoolWatcher ....................................................................................... 15

5 Compilation ....................................................................................................................................... 17
5.1. Compilation Process ................................................................................................................ 17
5.2. Compilation Output .................................................................................................................. 17

6 Download ........................................................................................................................................... 18
6.1. Download through TE-A ........................................................................................................... 18
6.2. Download through Debug Port of QuecOpen Modules ........................................................... 18

7 Debugging ......................................................................................................................................... 20
7.1. Serial Port Printing Debugging ................................................................................................ 20
7.2. Debug and Download with CoolWatcher ................................................................................. 20
7.2.1. Debug Application Program with CoolWatcher ............................................................. 20
7.2.2. Download Application Program with CoolWatcher ....................................................... 24

8 Custom Project Creation .................................................................................................................. 25

9 Quick Programming.......................................................................................................................... 26
9.1. GPIO Programming.................................................................................................................. 26
9.1.1. Confirm the Header Files to be Included ...................................................................... 26
9.1.2. GPIO Programming....................................................................................................... 26
9.1.3. Control Timer and LED Light......................................................................................... 27
9.1.4. Run the Application ....................................................................................................... 31
9.2. GPRS Programming ................................................................................................................ 31

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 4 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

9.2.1. Confirm Header Files to be Included ............................................................................ 31


9.2.2. Define PDP Context and GPRS Configuration ............................................................. 32
9.2.3. Define IP Address and Port of Server ........................................................................... 32
9.2.4. Define Receiving Buffer ................................................................................................ 32
9.2.5. Define Callback Function for GPRS and Socket .......................................................... 32
9.2.6. QuecOpen RIL Programming........................................................................................ 33
9.2.7. URC Message Programming ........................................................................................ 33
9.2.8. GPRS Programming ..................................................................................................... 35
9.2.9. Socket Programming..................................................................................................... 36

10 Precautions........................................................................................................................................ 38
10.1. External WatchDog .................................................................................................................. 38
10.2. Reboot Solution........................................................................................................................ 38
10.3. Add User Task .......................................................................................................................... 38
10.4. Timer ........................................................................................................................................ 38
10.5. UART........................................................................................................................................ 39
10.6. GPRS and TCP ........................................................................................................................ 39
10.7. Dynamic Memory Allocation..................................................................................................... 40
10.8. Application Debugging ............................................................................................................. 40

11 Appendix A References.................................................................................................................... 41

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 5 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

Table Index

Table 1: Directory of QuecOpen_GS5_SDK_V1.0 .....................................................................................11


Table 2: Debug Port Pins of QuecOpen Modules ...................................................................................... 19
Table 3: Operation Interface of the Trace Tool ........................................................................................... 21
Table 4: Trace Levels ................................................................................................................................. 23
Table 5: Related Documents ...................................................................................................................... 41
Table 6: Terms and Abbreviations .............................................................................................................. 41

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 6 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

Figure Index

Figure 1: Directory Structure of QuecOpen_GS5_SDK_V1.0 ....................................................................11


Figure 2: Installation of CSDTK Compiler .................................................................................................. 13
Figure 3: Installation of CoolWatcher ......................................................................................................... 14
Figure 4: Configuration of CoolWatcher ..................................................................................................... 15
Figure 5: Operation Interface of CoolWatcher ........................................................................................... 16
Figure 6: Compilation Result of MC65 QuecOpen .................................................................................... 17
Figure 7: TE-A ............................................................................................................................................ 18
Figure 8: QFlash......................................................................................................................................... 19
Figure 9: Activate Trace Tool ...................................................................................................................... 21
Figure 10: Operation Interface of Trace Tool ............................................................................................. 21
Figure 11: Trace Level Settings.................................................................................................................. 22
Figure 12: Trace Tool Information Table ..................................................................................................... 23
Figure 13: Download Progress Bar ............................................................................................................ 24
Figure 14: Custom Directory (taking QuecOpen_GS5_SDK_V1.0 as an example) ................................. 25
Figure 15: NETLIGHT on GSM EVB .......................................................................................................... 26

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 7 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

1 Introduction
Quectel M65, M08-R and MC65 modules support QuecOpen® solution. QuecOpen® is an open-source
embedded development platform based on Linux system. It is intended to simplify the design and
development of IoT applications.

This document introduces how to use the QuecOpen® SDK package to quickly start the development of
QuecOpen® modules, and describes the structure of SDK directory, development environment
construction, compilation, download, debugging, demonstration and quick programming of the application
as well as relevant precautions.

NOTE

"OpenCPU" has already been changed to "QuecOpen". However, "OpenCPU" in some examples or
diagrams remains unchanged to avoid confusion.

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 8 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

2 Preparations
Before design and programming of the QuecOpen application, it is necessary to confirm whether the
following software and hardware components listed in this chapter are ready.

2.1. Host System

The host operating system must be one of the following systems:

⚫ Windows 7 32-bit or 64-bit


⚫ Windows 10 32-bit or 64-bit

2.2. Compiler and Debugging Tool

⚫ CSDTK compiler environment


⚫ CoolWathcer debugging tool

When you need related software package, please contact the Quectel technical support team
(support@quectel.com).

2.3. Developer Experience

It is essential to master basic C-language programming and experience in development of a multitasking


operating system is helpful.

2.4. Hardware

⚫ Quectel M65, M08-R and MC65 QuecOpen modules


⚫ Quectel GSM EVB
⚫ Other accessories such as power adapters and RS232 serial ports

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 9 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

For hardware components, please contact the Quectel technical support team (support@quectel.com).

2.5. QuecOpen SDK

⚫ QuecOpen SDK package

Please contact the Quectel technical support team (support@quectel.com) to obtain the QuecOpen
SDK package.

⚫ Download tool

The related download tool may be fetched from the folder tools in the SDK package.

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 10 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

3 QuecOpen® SDK
The folder structure of QuecOpen SDK can be found after the software package is decompressed. For
example, a typical directory structure of QuecOpen_GS5_SDK_V1.0 is as follows:

Figure 1: Directory Structure of QuecOpen_GS5_SDK_V1.0

Table 1: Directory of QuecOpen_GS5_SDK_V1.0

Directory Name Description

QuecOpen_GS5_SDK_V1.0 Root directory of QuecOpen SDK package.

build Compilation information storage folder.

Folder of custom configuration-related files.


In the related files under subdirectory custom\config\, users
can disable the QuecOpen function, add new tasks, configure
custom the volume of task stack space and set the initial status of
GPIO.
All configuration files for users are named with the prefix of
"custom_".
docs Storage folder of QuecOpen development files.
The folder to store the examples of supported function.
example Each example file can be used to implement an independent
and complete function; after the file makefile is revised, all

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 11 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

example files can be compiled as executable binary files.

include Storage folder of API header files.

libs Storage folder of Library files.

make Storage folders of compilation script files and file makefile.


Storage folder of QuecOpen RIL source code.
ril With this source code, you can develop RIL interfaces for
other AT commands.
Storage folder of related development tools, including the
tools
download tool and the DFOTA packet generator.

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 12 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

4 Development Environment
Construction

4.1. Compilation Environment

4.1.1. Installation of CSDTK Compiler

The steps include: create a folder CSDTK4 under root directory of the disk C and decompress the latest
CSDTK tool kit to CSDTK4. When you need the tool kit, please contact the Quectel technical support
team (support@quectel.com).

Figure 2: Installation of CSDTK Compiler

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 13 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

4.2. Debugging Environment

4.2.1. Installation of CoolWatcher

CoolWatcher is the main tool for debugging.

The steps include: create a folder cooltools under the root directory of the disk C, and decompress the
latest tool kit cooltools which includes CoolWatcher by default to the folder cooltools. When you need the
tool kit, please contact the Quectel technical support team (support@quectel.com).

Figure 3: Installation of CoolWatcher

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 14 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

4.2.2. Configuration of CoolWatcher

The configuration steps of the tool CoolWatcher are as follows:

⚫ Run coolwatcher.exe, then select the corresponding platform “8955” in the “Profiles” and enter a
corresponding serial port number (debug port) at “lastcomport”. The previous configuration will be
used by default when CoolWatcher runs. Please reconfigure the platform or serial port if it changes.

Figure 4: Configuration of CoolWatcher

⚫ After completing the foregoing settings, click "OK" to enter into CoolWatcher.

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 15 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

Figure 5: Operation Interface of CoolWatcher

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 16 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

5 Compilation
This chapter introduces how to compile QuecOpen application program in the form of command lines.

5.1. Compilation Process

Shortcut MS-DOS of command lines is included in QuecOpen SDK. SDK codes can be compiled by
executing the following commands. The commands for cleaning compilation files and compiling new
programs are respectively defined as below:

make clean
make new

The following result is output (taking MC65 QuecOpen as an example) if the compilation succeeds. And
the generated files are stored in SDK\build\gcc.

Figure 6: Compilation Result of MC65 QuecOpen

5.2. Compilation Output

Compilation information is output during compilation in the form of command lines. All warnings and
errors are saved in SDK\build\gcc\build.log. Code errors can be investigated by reviewing error lines and
error tips of file build.log.

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 17 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

6 Download

6.1. Download through TE-A

If Quectel TE-A (demonstration board, as shown below) is used, please connect the GSM EVB first, and
then download the program via the Mini USB interface of the TE-A. Before transmitting data through the
Mini USB interface, please ensure that a driver program of the serial port chip (XR21B1411) is correctly
installed.

Figure 7: TE-A

6.2. Download through Debug Port of QuecOpen Modules

If the module is soldered onto a motherboard of a customer device, please download the program through
the debug port of the module.

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 18 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

Before downloading the program, please ensure that the serial port has been connected normally
(DBG_TXD and DBG_RXD are respectively connected to the RXD and TXD of the customer device) and
corresponding serial port driver has been installed correctly.

The debug port pins of QuecOpen Modules are as follows:

Table 2: Debug Port Pins of QuecOpen Modules

Module DBG_TXD Pin DBG_RXD Pin

M65 QuecOpen 39 38

M08-R QuecOpen 25 26

MC65 QuecOpen 29 30

It is recommended that QFlash provided by Quectel is used to download the application program. This
tool can be found in tools of SDK. For detailed usages, please refer to document [1].

Figure 8: QFlash

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 19 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

7 Debugging
There are two ways to debug application program of M65, M08-R and MC65 QuecOpen modules:

⚫ Serial port printing debugging


⚫ CoolWatcher debugging

7.1. Serial Port Printing Debugging

The steps are as follows: Call Ql_UART_Open() to open UART 1 (main serial port) or UART 2 (auxiliary
serial port), call Ql_UART_Write() to output debugging information, and then receive debugging
information with QCOM tool (other serial debugging tool is accepted).

7.2. Debug and Download with CoolWatcher

Generally, if abnormal rebooting or a network error occurs, it is recommended that the CoolWatcher be
used to capture a log and then to send the log to Quectel for analysis. The log can also be output to the
CoolWatcher through the debug port by calling Ql_Debug_Trace().

7.2.1. Debug Application Program with CoolWatcher

The steps are as follows: Select "Plugins" from the menu column in the navigation page of CoolWathcer,
click on "Activate Tracer" to activate the trace tool.

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 20 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

Figure 9: Activate Trace Tool

The operation interface of the trace tool is shown below.

Figure 10: Operation Interface of Trace Tool

Table 3: Operation Interface of the Trace Tool

Icons and Titles Description

Start the trace tool

Stop the trace tool

Clean up

Configure the trace level

Multiplex the trace level

Save

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 21 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

Open/Close received column

Open/Close comment column

Index Index number

Received Trace receiving time of PC

Level Trace level

Description Brief introduction

The steps for using the trace tool are as follows:

⚫ Enter the operation interface of the trace tool, click to set the trace levels. Please check the
relevant level in the table on the left side of the picture below.

Figure 11: Trace Level Settings

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 22 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

Table 4: Trace Levels

Options Description
Whether to save Trace automatically. Trace is saved automatically if
Auto Save Trace
checking this option.
Bin/Trc Type of Trace file. Bin means binary file and trc means test file.

Size of Trace file. The file will be segmented automatically if the total size
Split Size
is larger than this value.
Directory The saved path.

Row Limit The maximum line number of Trace information table.

DB File Name DB file.


Auto Reapply Trace Levels Whether to use Trace level configuration saved automatically after
on Reset rebooting.
Save Timestamp in Trc Whether to save timestamp.

Save ReceivedTime in Trc Whether to save the time when the tool resolves Trace.

This option needs to stay pace with .lod file. Please check this option If
Tick in Flow ID 0x80
the .lod file has timestamp, otherwise, please uncheck.
Receive Event Whether to receive event.

Save Click this button to save level configurations.

Load Click this button to load level configurations.

⚫ Go back to the operation interface of Trace tool, click to enable the Trace function. Trace
information will be displayed in the table as below:

Figure 12: Trace Tool Information Table

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 23 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

⚫ The printed log can be searched and filtered by entering key information into the textbox in the upper
right corner.

⚫ Click to save the log as .trc file.

⚫ Click to end Trace tool.

NOTES

1. The .trc file can be opened by using text editor, such as Notepad++.
2. The default configuration of trace tool can be obtained from files under directory rbbase\comm
on\plugins\tracer\.

7.2.2. Download Application Program with CoolWatcher

⚫ Click of CoolWatcher bar, then select .lod file of kernel firmware package or of application
program from the corresponding file loading path.

⚫ Click and select corresponding Flash programmer (host_8955_flsh_spi32m_ramrun.lod).

⚫ Click to begin downloading the firmware package or application program. Meantime, a


downloading progress bar shown below will be displayed in the lower right corner. After the
downloading is completed, the progress bar will show 100% and the completion information will be
displayed in the Ruby Script area of the operation interface.

Figure 13: Download Progress Bar

NOTES

1. It is not neceesary to reboot the module before downloading, and the module reboots automatically
after successful downloading.
2. This method is applicable to code debugging only. QFlash tool should be used for downloading during
mass production.

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 24 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

8 Custom Project Creation


By default, the directory SDK\custom\ is designed as the root directory for custom projects. In this
directory, a program file main.c is available, which demonstrates the primary program framework of
QuecOpen application.

Figure 14: Custom Directory (taking QuecOpen_GS5_SDK_V1.0 as an example)

In the SDK\custom\ directory, it is allowed to add new custom folders or sub-directories. the directory
SDK\custom\main.c is designed for custom projects. You only need to add or change codes in main.c or
simply replace this file. Additionally, newly created source files can be added into this directory, and these
newly-added .c files in SDK\custom\ is compiled automatically.

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 25 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

9 Quick Programming
This chapter use two examples to demonstrate how to write application program based on QuecOpen
SDK.

9.1. GPIO Programming

This chapter shows how to control the pin level of a GPIO to drive the LED light, that is, to turn on/off the
LED as programmed.

9.1.1. Confirm the Header Files to be Included

To confirm the header files to be included, basic requirements of the application need to be confirmed first.
For instance, in this demonstration application, the requirement is to implement the on-off control of the
LED light by changing the level of the GPIO periodically. Therefore, the header files to be included are:

#include "ql_stdlib.h"
#include "ql_trace.h" //Related to log printing.
#include "ql_error.h" //Define all return values of APIs in ql_error.h.
#include "ql_system.h" //QuecOpen application has a message loop process.
#include “ql_uart.h” //Related to serial port.
#include "ql_gpio.h" //Related to GPIO.
#include "ql_timer.h" //Related to timer.

9.1.2. GPIO Programming

The NETLIGHT pin is already connected to an LED light on Quectel GSM EVB. Therefore, you can
implement on-off control of the LED light by controlling NETLIGHT directly.

Figure 15: NETLIGHT on GSM EVB

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 26 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

Step 1: Configure GPIO pin in the program.

//Define GPIO pin


static Enum_PinName m_gpioPin = PINNAME_NETLIGHT;

Step 2: Initialize GPIO in the following way:

⚫ Initialize GPIO until "input/output" status is changed to "PINDIRECTION_OUT".


⚫ Initialize GPIO until "initial level" status is changed to "PINLEVEL_LOW".
⚫ Initialize GPIO until "pull up and down" status is changed to "PINPULLSEL_PULLUP".

//Initialize GPIO
ret = Ql_GPIO_Init(m_gpioPin, PINDIRECTION_OUT, PINLEVEL_LOW, PINPULLSEL_PULLUP);
if (QL_RET_OK == ret)
{
APP_DEBUG ("<-- Initialize GPIO successfully -->\r\n");
}
else
{
APP_DEBUG ("<-- Fail to initialize GPIO pin, cause=%d -->\r\n", ret);
}

Step 3: Start a timer and periodically change the level of the GPIO to implement LED blinking.

9.1.3. Control Timer and LED Light

In this demonstration, the program defines a timer with the timeout of 500 ms, making the LED be on for
500 ms and off for 500 ms.

Step 1: Define a timer and a corresponding timer interrupt handler.

//Define a timer and a handler


static u32 m_myTimerId = 2019;
static u32 m_nInterval = 500; //500ms
static void Callback_OnTimer(u32 timerId, void* param);

Step 2: Register and start a timer.

//Register and start the timer


Ql_Timer_Register(m_myTimerId, Callback_OnTimer, NULL);
Ql_Timer_Start(m_myTimerId, m_nInterval, TRUE);

Step 3: Implement interrupt handler of the defined timer.

static void Callback_OnTimer(u32 timerId, void* param)


{

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 27 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

s32 gpioLvl = Ql_GPIO_GetLevel(m_gpioPin);


if (PINLEVEL_LOW == gpioLvl)
{
//Set GPIO to high level, then LED is light
Ql_GPIO_SetLevel(m_gpioPin, PINLEVEL_HIGH);
Ql_Debug_Trace("<-- Set GPIO to high level -->\r\n");
}else{
//Set GPIO to low level, then LED is dark
Ql_GPIO_SetLevel(m_gpioPin, PINLEVEL_LOW);
Ql_Debug_Trace("<-- Set GPIO to low level -->\r\n");
}
}

In this case, all programming has been completed, and the complete code is shown below.

#include "ql_stdlib.h"
#include "ql_trace.h"
#include "ql_error.h"
#include "ql_system.h"
#include "ql_gpio.h"
#include "ql_timer.h"
#include "ql_uart.h"

//Define APP_DEBUG

#define DEBUG_ENABLE 1

#if DEBUG_ENABLE > 0

#define DEBUG_PORT UART_PORT1

#define DBG_BUF_LEN 512

static char DBG_BUFFER[DBG_BUF_LEN];

#define APP_DEBUG(FORMAT,...) {\

Ql_memset(DBG_BUFFER, 0, DBG_BUF_LEN);\

Ql_sprintf(DBG_BUFFER,FORMAT,##__VA_ARGS__); \

if (UART_PORT2 == (DEBUG_PORT)) \

{\

Ql_Debug_Trace(DBG_BUFFER);\

} else {\

Ql_UART_Write((Enum_SerialPort)(DEBUG_PORT), (u8*)(DBG_BUFFER), Ql_strlen((const


char *)(DBG_BUFFER)));\

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 28 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

}\

#else

#define APP_DEBUG(FORMAT,...)

#endif

static Enum_SerialPort m_myUartPort = UART_PORT1;

//Define GPIO pin


static Enum_PinName m_gpioPin = PINNAME_NETLIGHT;

//Define a timer and the handler


static u32 m_myTimerId = 2019;
static u32 m_nInterval = 500; //500ms
static void Callback_OnTimer(u32 timerId, void* param);
static void CallBack_UART_Hdlr(Enum_SerialPort port, Enum_UARTEventType msg, bool level, void*
customizedPara);
/************************************************************************/
/* The entrance procedure for this example application */
/************************************************************************/
void proc_main_task(s32 taskId)
{
s32 ret;
ST_MSG msg;

//Register & open UART port

ret = Ql_UART_Register(m_myUartPort, CallBack_UART_Hdlr, NULL);

if (ret < QL_RET_OK)

Ql_Debug_Trace("Fail to register serial port[%d], ret=%d\r\n", m_myUartPort, ret);

ret = Ql_UART_Open(m_myUartPort, 115200, FC_NONE);

if (ret < QL_RET_OK)

Ql_Debug_Trace("Fail to open serial port[%d], ret=%d\r\n", m_myUartPort, ret);

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 29 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

APP_DEBUG("QuecOpen: LED Blinking by NETLIGH\r\n");

//Initialize GPIO
ret = Ql_GPIO_Init(m_gpioPin, PINDIRECTION_OUT, PINLEVEL_LOW, PINPULLSEL_PULLUP);
if (QL_RET_OK == ret)
{
APP_DEBUG ("<-- Initialize GPIO successfully -->\r\n");
}else{
APP_DEBUG ("<-- Fail to initialize GPIO pin, cause=%d -->\r\n", ret);
}

//Register and start timer


Ql_Timer_Register(m_myTimerId, Callback_OnTimer, NULL);
Ql_Timer_Start(m_myTimerId, m_nInterval, TRUE);

//Start message loop of this task


while(TRUE)
{
Ql_OS_GetMessage(&msg);
switch(msg.message)
{
default:
break;
}
}
}

static void Callback_OnTimer(u32 timerId, void* param)


{
s32 gpioLvl = Ql_GPIO_GetLevel(m_gpioPin);
if (PINLEVEL_LOW == gpioLvl)
{
//Set GPIO to high level, then LED is light
Ql_GPIO_SetLevel(m_gpioPin, PINLEVEL_HIGH);
APP_DEBUG ("<-- Set GPIO to high level -->\r\n");
}else{
//Set GPIO to low level, then LED is dark
Ql_GPIO_SetLevel(m_gpioPin, PINLEVEL_LOW);
APP_DEBUG ("<-- Set GPIO to low level -->\r\n");
}
}

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 30 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

static void CallBack_UART_Hdlr(Enum_SerialPort port, Enum_UARTEventType msg, bool level, void*


customizedPara)

{
}

9.1.4. Run the Application

Copy the complete code to SDK\custom\main.c to overwrite the existing code, and compile the code.
Then download the generated executable file (.lod) into the module.

When the application runs, D502 LED on GSM EVB will blink at intervals of 500 ms and the main UART
will output the following log information:

[2019-02-13_13:14:08:624]QuecOpen: LED Blinking by NETLIGH


[2019-02-13_13:14:08:624]<-- Initialize GPIO successfully -->
[2019-02-13_13:14:09:120]<-- Set GPIO to high level -->
[2019-02-13_13:14:09:620]<-- Set GPIO to low level -->
[2019-02-13_13:14:10:120]<-- Set GPIO to high level -->
[2019-02-13_13:14:10:620]<-- Set GPIO to low level -->
[2019-02-13_13:14:11:120]<-- Set GPIO to high level -->
[2019-02-13_13:14:11:621]<-- Set GPIO to low level -->
[2019-02-13_13:14:12:120]<-- Set GPIO to high level -->
[2019-02-13_13:14:12:621]<-- Set GPIO to low level -->
[2019-02-13_13:14:13:121]<-- Set GPIO to high level -->

9.2. GPRS Programming

This chapter describes how to start a TCP connection with a GPRS network to send data to a TCP server.

9.2.1. Confirm Header Files to be Included

To confirm the header files to be included, requirements of the application need to be confirmed first. For
instance, in this demonstration application, the requirement is to connect the TCP server via socket and
send data to the TCP server.

Therefore, the header files to be included are as follows:

#include "custom_feature_def.h" //Definition of micro related to QuecOpen RIL function.


#include "ril.h" //QuecOpen RIL function.
#include "ql_stdlib.h" //Standard library.
#include "ql_trace.h" //Output printed information.
#include "ql_error.h" //Define all return values of APIs in ql_error.h.

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 31 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

#include "ql_system.h" //Related to QuecOpen system.


#include "ql_gprs.h" //Related to GPRS.
#include "ql_socket.h" //Related to socket connection.

9.2.2. Define PDP Context and GPRS Configuration

#define PDP_CONTEXT_ID 0
static ST_GprsConfig m_GprsConfig = {
"CMNET", //APN name
"", //User name for APN
"", //Password for APN
0,
NULL,
NULL,
};

The APN is configured as China Mobile "CMNET" in this demonstration and may change depending on
actual situation.

9.2.3. Define IP Address and Port of Server

static u8 m_SrvADDR[20] = "116.247.104.27";


static u32 m_SrvPort = 6003;

The IP address and port are configured as Quectel public server and socket port and may change
depending on actual situation.

9.2.4. Define Receiving Buffer

When a socket connection is established, a buffer is needed to receive data from the server.

#define SOC_RECV_BUFFER_LEN 1460


static u8 m_SocketRcvBuf[SOC_RECV_BUFFER_LEN];

9.2.5. Define Callback Function for GPRS and Socket

static void Callback_GPRS_Deactivated(u8 contextId, s32 errCode, void* customParam);


static void Callback_Socket_Close(s32 socketId, s32 errCode, void* customParam );
static void Callback_Socket_Read(s32 socketId, s32 errCode, void* customParam );
static void Callback_Socket_Write(s32 socketId, s32 errCode, void* customParam );

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 32 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

⚫ Callback_GPRS_Deactivated: This function is called when GPRS network is disconnected.


⚫ Callback_Socket_Close: This function is called when the socket connection is disabled.
⚫ Callback_Socket_Read: This function is called when socket connection receives data.
⚫ Callback_Socket_Write: If the socket is busy when calling Ql_SOC_Write() to send data to the
socket, this callback function will be called when socket is idle to
inform the application that the socket is available.

9.2.6. QuecOpen RIL Programming

Before using QuecOpen RIL function, the application needs to call Ql_RIL_Initialize() to initialize the
features related to RIL when the main task receives MSG_ID_RIL_READY.

//Start message loop of this task


while(TRUE)
{
Ql_OS_GetMessage(&msg);
switch(msg.message)
{
case MSG_ID_RIL_READY:
Ql_Debug_Trace("<-- RIL is ready -->\r\n");
Ql_RIL_Initialize();
break;

9.2.7. URC Message Programming

Before accessing GPRS network, it is required to wait for the module to register on GPRS network.
Application receives URC message URC_GPRS_NW_STATE_IND if the module network registration is
completed successfully. Before receiving this URC message, application will receive other URC
messages that indicate module initialization status, such as the status of AT+CFUN, (U)SIM card and
GSM network change, during the system initialization process. Please control these URC messages
depending upon specific requests.

The following code shows the entire URC message guide.

/************************************************************************/
/* The entrance procedure for this example application */
/************************************************************************/
void proc_main_task(s32 taskId)
{
ST_MSG msg;

Ql_Debug_Trace("QuecOpen: Simple GPRS-TCP Example\r\n");

//Start message loop of this task

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 33 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

while(TRUE)
{
Ql_OS_GetMessage(&msg);
switch(msg.message)
{
case MSG_ID_RIL_READY:
Ql_Debug_Trace("<-- RIL is ready -->\r\n");
Ql_RIL_Initialize();
break;
case MSG_ID_URC_INDICATION:
//Ql_Debug_Trace("<-- Received URC: type: %d, -->\r\n", msg.param1);
switch (msg.param1)
{
case URC_SYS_INIT_STATE_IND:
Ql_Debug_Trace("<-- Sys Init Status %d -->\r\n", msg.param2);
break;
case URC_SIM_CARD_STATE_IND:
Ql_Debug_Trace("<-- SIM Card Status:%d -->\r\n", msg.param2);
break;
case URC_GSM_NW_STATE_IND:
Ql_Debug_Trace("<-- GSM Network Status:%d -->\r\n", msg.param2);
break;
case URC_GPRS_NW_STATE_IND:
Ql_Debug_Trace("<-- GPRS Network Status:%d -->\r\n", msg.param2);
if (NW_STAT_REGISTERED == msg.param2)
{
GPRS_Surf();
}
break;
case URC_CFUN_STATE_IND:
Ql_Debug_Trace("<-- CFUN Status:%d -->\r\n", msg.param2);
break;
default:
Ql_Debug_Trace("<-- Other URC: type=%d\r\n", msg.param1);
break;
}
break;
default:
break;
}
}

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 34 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

9.2.8. GPRS Programming

GPRS programming can be performed after the module registers on GPRS network successfully. The
main steps of GPRS programming are as follows. For detailed GPRS API usage, please refer to the
following steps:

Step 1: Register callback function related to GPRS.

ST_PDPContxt_Callback callback_gprs_func = {
//Callback_GPRS_Actived,
NULL,
Callback_GPRS_Deactived
};
ST_SOC_Callback callback_soc_func = {
//Callback_socket_connect,
NULL,
Callback_Socket_Close,
//Callback_socket_accept,
NULL,
Callback_Socket_Read,
Callback_Socket_Write
};

//Register GPRS callback


ret=Ql_GPRS_Register(PDP_CONTEXT_ID, &callback_gprs_func, NULL);
if (GPRS_PDP_SUCCESS == ret)
{
Ql_Debug_Trace("<-- Register GPRS callback function -->\r\n");
}else{
Ql_Debug_Trace("<-- Fail to register GPRS, ret=%d. -->\r\n", ret);
return;
}

Step 2: Configure PDP context.

ret=Ql_GPRS_Config(PDP_CONTEXT_ID, &m_GprsConfig);
if (GPRS_PDP_SUCCESS == ret)
{
Ql_Debug_Trace("<-- Configure GPRS PDP -->\r\n");
}else{
Ql_Debug_Trace("<-- Fail to configure GPRS PDP, ret=%d. -->\r\n", ret);
return;
}

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 35 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

Step 3: Activate PDP context.

ret=Ql_GPRS_Activate(PDP_CONTEXT_ID);
if (ret == GPRS_PDP_SUCCESS)
{
m_GprsActState = 1;
Ql_Debug_Trace("<-- Activate GPRS successfully. -->\r\n\r\n");
}else{
Ql_Debug_Trace("<-- Fail to activate GPRS, ret=%d. -->\r\n\r\n", ret);
return;
}

Step 4: Deactivate PDP context.

ret=Ql_GPRS_Deactivate(PDP_CONTEXT_ID);
Ql_Debug_Trace("<-- Deactivate GPRS, ret=%d -->\r\n\r\n", ret);

9.2.9. Socket Programming

After the GPRS PDP context is activated, TCP/UDP socket programming can continue to be performed.
The main steps of socket programming are as follows. For detailed socket API usage, please refer to the
following steps:

Step 1: Register callback function related to socket.

ret=Ql_SOC_Register(callback_soc_func, NULL);
if (SOC_SUCCESS == ret)
{
Ql_Debug_Trace("<-- Register socket callback function -->\r\n");
}else{
Ql_Debug_Trace("<-- Fail to register socket callback, ret=%d. -->\r\n", ret);
return;
}

Step 2: Establish a socket.

m_SocketId=Ql_SOC_Create(PDP_CONTEXT_ID, SOC_TYPE_TCP);
if (m_SocketId >= 0)
{
Ql_Debug_Trace("<-- Create socket successfully, socket id=%d. -->\r\n", m_SocketId);
}else{
Ql_Debug_Trace("<-- Fail to create socket, ret=%d. -->\r\n", m_SocketId);
return;
}

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 36 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

Step 3: Connect to socket server.

ret=Ql_SOC_Connect (m_SocketId,(u32)m_ipAddress, m_SrvPort);


if (SOC_SUCCESS == ret)
{
m_SocketConnState=1;
Ql_Debug_Trace("<-- Connect to server successfully -->\r\n");
}else{
Ql_Debug_Trace("<-- Fail to connect to server, ret=%d -->\r\n", ret);
Ql_Debug_Trace("<-- Close socket.-->\r\n");
Ql_SOC_Close(m_SocketId);
m_SocketId=-1;
return;
}

Data can be transmitted to or received from the server after the socket is connected to the server
successfully.

Step 4: Send socket data.

char pchData[200];
s32 dataLen=0;
u64 ackNum=0;
Ql_memset(pchData, 0x0, sizeof(pchData));
dataLen += Ql_sprintf(pchData + dataLen, "%s", "Q u e c t e l");
ret=Ql_SOC_Send(m_SocketId, (u8*)pchData, dataLen);
if (ret ==dataLen)
{
Ql_Debug_Trace("<-- Send socket data successfully. --> \r\n");
}else{
Ql_Debug_Trace("<-- Fail to send socket data. --> \r\n");
}

The codes above demonstrate how to send data "Q u e c t e l" to the server.

After the data is sent, Ql_SOC_GetAckNumber() can be called to check whether the server has received
the data. Additionally, the socket connection can be disabled by calling Ql_SOC_Close(), and GPRS PDP
can be deactivated by calling Ql_GPRS_DeactivateEx().

The complete code of this example can be found in the file example_tcp_demo.c of SDK, which supports
compilation and running. For detailed usage, please refer to above description.

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 37 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

10 Precautions
10.1. External WatchDog

In order to protect the application from logic exceptions from which the application has difficulty in
recovering, it is recommended to add external WatchDog chip during product designing. For related
designs, please refer to document [2] and document [3]. When the external WatchDog overflows, VBAT
pin of the module will be reset, implementing power-off and rebooting to reset the module.

10.2. Reboot Solution

To ensure the continuous stable operation of the module, it is recommended to add reboot solution during
the software design. In case of network errors, the reboot solution can be adopted to expect automatic
recovery of the module.

10.3. Add User Task

Users can define tasks in file custom_task_cfg.h. An example is as follows:

TASK_ITEM (proc_name, subtask1_id, 5*1024, DEFAULT_VALUE1, DEFAULT_VALUE2)

proc_name is the entry function name of the new task, and subtask1_id is task ID of the new task.

If messages need to be processed in the task, please add a Ql_OS_GetMessage() interface (Callbacks of
interfaces such as timers and TCP are triggered by messages. Without such interface, these functions
would be unavailable) into the task. After calling this interface, if no message needs to be processed, the
task will be blocked here and CPU access stops.

10.4. Timer

Common timer and fast timer are provided in QuecOpen solution. A maximum of 10 common timers are
available for each task, and also 10 fast timers at most are available for the whole application.

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 38 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

When registering a common timer, a current task ID needs to be bound. Timer is not supported in ISR.
The task using Ql_Timer_Start() and Ql_Timer_Stop() should be the same as the task during timer
registration. Otherwise, a calling failure occurs.

When the common timer runs, if the Ql_OS_GetMessage() interface cannot be called in the task in a
timely manner to process a timeout message of the timer, the callback function of the timer will not be
processed in a timely manner.

The interrupt of fast timer is triggered by hardware directly, enjoying high real-time performance. However,
please avoid excessive workloads for the interrupt function, otherwise, a system exception may be
caused.

10.5. UART

M65, M08-R and MC65 QuecOpen modules provide three UART ports: a main serial port (UART 1), an
auxiliary serial port (UART 2) and a debug port. UART 1 and UART 2 both can implement the baud rate of
115200 bps by default, and therefore, can be used for application development. The serial data format is
8N1 (8 data bits, no parity and 1 stop bit). The data buffer sizes of the UART ports are 4096 bytes. The
debug port can only be used to download and cooperate with the tool CoolWatcher for debugging
application.

When the message of EVENT_UART_READY_TO_READ in the UART callback interface is received, it


means there is data to be read. It is recommended to read UART data circularly until all received data has
been read. Otherwise, no message will be reported to application layer when new data is received, and it
may cause blocking.

10.6. GPRS and TCP

Executing tasks of GPRS and TCP callback functions is registering these callback functions. If received
messages cannot be processed in a timely manner in the current task, execution of these callback
functions will be delayed.

API synchronization of GPRS and TCP in the module will block task execution. In order to avoid long-time
blocking, it is recommended to use asynchronous APIs as interfaces related to general network services.

Main synchronous APIs of GPRS are as follows:

⚫ Ql_GPRS_ActivateEx (u8 contextId)


The maximum timeout value is 180 s.

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 39 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

⚫ Ql_GPRS_DeactivateEx (u8 contextId)


The maximum timeout value is 90 s.

Synchronous APIs of TCP:

⚫ Ql_SOC_ConnectEx (s32 socketId, u32 remoteIP, u16 remotePort)


The maximum timeout value is 75 s.

⚫ Ql_IpHelper_GetIPByHostNameEx (u8 contextId, u8 requestId, u8 *hostname, u32* ipCount, u32*


ipAddress)
The maximum timeout value is 60 s.

10.7. Dynamic Memory Allocation

You can call Ql_MEM_Alloc() to specify the volume of dynamic memory or call Ql_MEM_Free() to release
the memory. The maximum volume of the dynamic memory for an application is 500 KB.

10.8. Application Debugging

In a QuecOpen application, printing a Trace log via a serial port is the main debugging way. Generally,
users can print information into serial port debugging tool via the APP_DEBUG interface and check, by
using the log information, whether the service process is normal. If the module has faults such as
abnormal rebooting, dump, abnormal network registration or data service, it is appreciated that a kernel
log obtained via the tool CoolWatcher can be provided to Quectel for analysis.

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 40 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

11 Appendix A References
Table 5: Related Documents

SN Document Name Description

Introduces how to download program with


[1] Quectel_QFlash_QuecOpen_User_Guide
QFlash tool in QuecOpen solution.

[2] Quectel_MC65_QuecOpen_Reference_Design Reference design of MC65 QuecOpen.

Introduces the QuecOpen watchdog


[3] Quectel_QuecOpen_Watchdog_Application_Note
application note.

Table 6: Terms and Abbreviations

Abbreviation Description

API Application Program Interface

APN Access Point Name

APP Application

DB Database

DFOTA Delta Firmware Upgrade Over-the-Air

DOS Disk Operating System

GCC GNU Compiler Collection

GPIO General Purpose Input/Output

GPRS General Packet Radio Service

GSM Global System for Mobile Communications

ID Identifier

ISR Interrupt Service Routine

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 41 / 42
GSM/GPRS/GNSS Module Series
M65&M08-R&MC65 QuecOpen Quick Start Guide

LED Light Emitting Diode

PDP Packet Data Protocol

RIL Radio Interface Layer

RTC Real Time Clock

RXD Receive Data

SDK Software Development Kit

TCP Transmission Control Protocol

TXD Transmit Data

UART Universal Asynchronous Receiver & Transmitter

UDP User Datagram Protocol

URC Unsolicited Result Code

USB Universal Serial Bus

(U)SIM (Universal) Subscriber Identity Module

M65&M08-R&MC65_QuecOpen_Quick_Start_Guide 42 / 42

You might also like