We write the first simple firmware for Telit
Good day, dear community!
It just so happened that I had to deal with the task of writing firmware for a rather interesting Telit GL865-DUAL modem . And in this topic, I would like, at least in general terms, to describe the process of developing firmware for it.
So, let's start, perhaps, with a general idea of where Telit’s firmware “sticks out”. This is clearly demonstrated by the diagram from the official documentation :
As you can clearly see from this diagram, the firmware works with the device, communicating with it through ready-made interfaces, while being in fairly cramped conditions. By the way, I would like to make a reservation right away - the memory volumes indicated on the diagram are very abstract. At Telit GL865-DUALFor 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, but the number of workers directly depends on the piece of iron on which the script is run.
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. The MDM module does not interact with the real serial port, so it doesn’t matter what settings are on the port - the data will still reach the module.
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.
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, from a computer for example). When the Python script is running, this serial port is at its complete disposal and is not used by the AT command handler (that is, at this time, sending commands to this port will not work). You cannot control flow-control on this port using Python scripts.
The interface allows the Python script to read and write data to the physical serial port ASC1 , which is commonly used for debugging.
The interface allows you to control the input / output ports (or simply kick your legs) bypassing the AT command processor, which is faster.
An interface is a set of user-defined functions.
The interface is an implementation of the IIC Bus Master in the Python core. It allows Python to create one or more IIC buses on existing GPIO pins.
The interface is an implementation of the SPI Master Bus in the Python core. It allows Python to create one or more SPI buses on existing GPIO pins.
The interface provides the interaction between Python and the controller integrated in the GPS module. It allows you to work with him bypassing AT commands.
This set of interfaces allows, in principle, to perform any fraud with iron at fairly reasonable 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, you cannot perform some complicated calculations on a piece of iron. Well enough about the sad - it's time to go directly to writing and testing the first simple firmware. We assume that the device is already ready for use. If not, then welcome here and here .
To ensure communication with the device, I personally use the RSTerm terminal . It is convenient, portable and even seems to be free.
So, let's start writing the firmware itself. I didn’t come up with 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. To do this, I 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 such a type as bool , so we have to work with 0 and 1.
Next, 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:
- Phone number;
- Message text;
- Operator Message Center Number.
Well, now it remains only to turn all this into logic and provide at least a simple debug. Yes, you can use the second port the serial port of the device for debugging, 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 code
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"
Я сохранил этот скрипт под именем hello.py
Теперь остается только открыть RSTerm, выбрать меню Telit Python, залить файл при помощи кнопки Upload selected file(s) from PC to module, активировать его при помощи кнопки AT#ESCRIPT=«hello.py» и запустить кнопкой AT#EXECSCR.
Надеюсь данный материал хоть кому-нибудь пригодится. Спасибо за внимание.