📜 ⬆️ ⬇️

Writing the first simple telit firmware

image
Good day, dear community!

It so happened that I had to deal with the task of writing firmware for a rather interesting modem Telit GL865-DUAL . And in this topic I would like at least in general terms to describe the process of developing firmware for it.

So, let's begin, perhaps, with a general idea of ​​where Telit's firmware “sticks out”. This is very clearly demonstrates the scheme of the official documentation :
')
image

As can be clearly seen from this scheme, the firmware works with the device, communicating with it through ready-made interfaces, while being in rather cramped conditions. By the way, I would immediately like to make a reservation - the amounts of memory indicated in the diagram are very abstract. In Telit GL865-DUAL , for example, only 1 megabyte of RAM is available and only 2 megabytes of flash memory.

A few words about the available interfaces. There are 9 of them in total, but the number of workers directly depends on the piece of iron on which the script runs.
MDM

The interface is the most important. It allows you to send send and receive AT commands, send and receive data from the network, and so on and so forth. The data sent through it is processed using the AT command handler. MDM module does not interact with the real serial port, so it does not matter what settings are on the port - data will still reach the module.

MDM2

This is the second interface between Python and the AT command handler. Through it, you can send and receive responses to AT commands when the MDM interface is busy.

SER

This interface allows the Python script to read and send data to the physical serial port ASC0 , usually used to send AT commands to the module (when we communicate with the module from the outside, for example, with a computer). When the Python script is running, this serial port comes at its full disposal and is not used by the AT command handler (that is, it will not work to send commands to this port at this time). At this port using Python scripts can not control the flow-control.

SER2

The interface allows the Python script to read and write data to the physical serial port ASC1 , which is usually used for debugging.

GPIO

The interface allows you to control I / O ports (or simply pull legs), bypassing the AT command handler, which is faster.

MOD

The interface is a set of user-defined functions.

Iic

The interface is an implementation of the IIC Bus Master in the Python core. It allows Python to create one or more IIC tires on existing GPIO pins.

SPI

The interface is an implementation of the SPI Master Bus in the Python core. It allows Python to create one or more SPI tires on existing GPIO pins.

GPS

The interface provides interaction between Python and the controller built into the GPS module. It allows you to work with him bypassing AT commands.

This set of interfaces allows performing, in principle, any machinations with iron at fairly acceptable speeds. But not without pitfalls. When porting Python, the guys from Telit for some reason removed the language support for such simple data types as:


So, unfortunately, we cannot produce any complicated calculations. Well, enough of the sad things - it's time to go directly to writing and testing the first simple firmware. We assume that the device is already prepared for operation. If not, welcome here and here .

I personally use the RSTerm terminal to communicate with the device. It is convenient, portable and even seems to be free.

So, let's start writing the firmware itself. I did not invent anything more stupid than sending an SMS with the text “Hello world” to my phone.

At the very beginning of the script connect the necessary interfaces
import MOD import MDM 


Further, according to the logic of things, we need to check whether the module is registered on the network. For this, I have sketched a simple function that sends the AT command AT + CREG? and processes the results.
 def checkNetwork(): MOD.sleep(20) REC_TIME = 200 for _ in range(10): MDM.send("AT+CREG?\r",0) res = MDM.receive(REC_TIME) if (res.find('0,1')!=-1): return 1 else: MOD.sleep(50) return 0 


Yes, I almost forgot. Python in Telit does not know this type of bool , so you have to work with 0 and 1.

Afterwards, of course, we will need a function that will help us send SMS. I got something like that.
 def sendSMS( number, smstext, csca): if number=="" or smstext=="" or csca == "" : return 0 MDM.send('AT+CSCA='+csca+'\r',2) MDM.receive(20) MDM.send('AT+CMGF=1\r',2) MDM.receive(20) a = MDM.send('AT+CMGS="' + number + '"\r', 2) res = MDM.receive(10) a = MDM.send(smstext, 2) a = MDM.sendbyte(0x1A, 2) a='' while a=='': a = MDM.receive(20) return ( a.find('OK')!=-1 ) 

Its parameters are respectively:
  1. Phone number;
  2. Message text;
  3. The message center number of the operator.


Well, now it remains only to wrap all this in logic and to provide at least a simple debug. Yes, for debugging, you can use the second port of the serial port of the device, but for me it was unnecessary chic, so for my own convenience I redefined the output of the print command to the first serial port.
 import SER2 SER.set_speed('115200','8N1') class SerWriter: def __init__(self): SER.set_speed('115200','8N1') def write(self,s): SER.send(s+'\r') sys.stdout = sys.stderr = SerWriter() 


Well, the whole source
 import MOD import MDM import SER SER.set_speed('115200','8N1') class SerWriter: def __init__(self): SER.set_speed('115200','8N1') def write(self,s): SER.send(s+'\r') sys.stdout = sys.stderr = SerWriter() def checkNetwork(): MOD.sleep(20) REC_TIME = 200 for _ in range(10): MDM.send("AT+CREG?\r",0) res = MDM.receive(REC_TIME) if (res.find('0,1')!=-1): return 1 else: MOD.sleep(50) return 0 def sendSMS( number, smstext, csca): if number=="" or smstext=="" or csca == "" : return 0 MDM.send('AT+CSCA='+csca+'\r',2) MDM.receive(20) MDM.send('AT+CMGF=1\r',2) MDM.receive(20) a = MDM.send('AT+CMGS="' + number + '"\r', 2) res = MDM.receive(10) a = MDM.send(smstext, 2) a = MDM.sendbyte(0x1A, 2) a='' while a=='': a = MDM.receive(20) return ( a.find('OK')!=-1 ) print "Start" while not checkNetwork(): print "No network" MOD.sleep(10) print "I find network" myNumber = "+7960*******" myText = "Hello world" smsGate = "+79037011111" print "Try to send SMS" if sendSMS(myNumber,myText,smsGate): print "SMS sended" else: print "SMS not sended" 


I saved this script as hello.py

Now it remains only to open RSTerm , select the Telit Python menu, upload the file using the Upload selected file (s) from PC to module button, activate it using the AT # ESCRIPT = “hello.py” button and launch it with the AT # EXECSCR button .

I hope this material at least someone will come in handy. Thanks for attention.

Source: https://habr.com/ru/post/153009/


All Articles