GSM/GPRS
This page will summarize informations to use the GSM/GPRS/3G module of the APF27Wireless board, APF51Dev (optional) and the APF6Dev (optional).
Contents
Introduction
GSM/GPRS are generally driven through the RS-232 bus. AT commands are used to dialog with the module.
- GSM MODEM of the APF27Wireless extension board (APW) is connected to the UART2 (/dev/ttySMX1) of the APF27.
- GSM/3G MODEM of the APF51Dev is connected to the i.MX processor through an UART implemented in the FPGA. So the corresponding bitfile has to loaded before trying to access the MODEM.
- GSM/3G MODEM of the APF51Dev is connected to the UART3 of the i.MX6 processor.
They are all using a Sagem's Hilo module. Hilo AT commands can be found here
Linux configuration (APF27Dev only)
- Linux will have to be configured in order to tell that an APW is connected to your APF27Dev:
$ make linux-menuconfig
System Type ---> Freescale MXC Implementations ---> ... Extension board (Wireless (APW)) ---> [*] GSM/GPRS Modem (NEW) [ ] Bluetooth & WiFi module (NEW) [ ] CSI (Camera) pass-through (NEW) [ ] GPS module (NEW)
$ make linux
- reflash you Linux kernel
Configure serial port
APF27
# export GSM_DEVICE=/dev/ttySMX1 (or /dev/ttymxc1 on recent kernels) # stty -F $GSM_DEVICE raw -echo -echoe -echok 115200
APF51Dev
Note: Don't forget to put "Wireless" J42 jumper (near microSD connector) AND power on FPGA Bank 3 (with corresponding J39 jumper). |
- On APF51Dev, GSM/3G module is accessed through serial ports synthetized in APF51's FPGA. So we have to load it first. (Needed dual UARTs FPGA firmware can be found under armadeus-4.0 distribution in firmware/pod_scripts directory, with the POD script needed to regenerate it, and is by default installed in rootfs).
# load_fpga /lib/firmware/fpga/apf51_gsm_gps_firmware.bin
- Once firmware loaded, drivers related to FPGA can be used :
# modprobe irq_ocore # modprobe 8250 Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled # modprobe twin_uarts_irq_mng # modprobe twin_uarts_16750 serial8250.0: ttyS0 at MMIO 0xb8000020 (irq = 320) is a TI16750 serial8250.0: ttyS1 at MMIO 0xb8000040 (irq = 321) is a TI16750
- Bring MODEM out of reset state (POK_IN/PWON pin, connected to PMIC GPIO6):
# modprobe wm831x-gpio # echo 245 > /sys/class/gpio/export # echo out > /sys/class/gpio/gpio245/direction # echo 1 > /sys/class/gpio/gpio245/value
- Configure serial port:
# ls /dev/ttyS* /dev/ttyS0 /dev/ttyS1 /dev/ttyS2 /dev/ttyS3
- If the /dev/ttyS[0-1] files don't exist, create it/them with mknod :
# mknod /dev/ttyS0 c 4 64 # mknod /dev/ttyS1 c 4 65
Then :
# export GSM_DEVICE=/dev/ttyS0 # stty -F $GSM_DEVICE -echo -echoe -echok 115200 crtscts
APF6Dev
- Power up the chip. (GSM_PWR_EN is connected to the GPIO7_13)
# echo 205 > /sys/class/gpio/export # echo out > /sys/class/gpio/gpio205/direction # echo 1 > /sys/class/gpio/gpio205/value
- Start it by setting a low level pulse during about 2 seconds on the POKIN line (POKIN is connected to the GPIO1_4).
# echo 4 > /sys/class/gpio/export # echo out > /sys/class/gpio/gpio4/direction # echo 1 > /sys/class/gpio/gpio4/value # sleep 2 # echo 0 > /sys/class/gpio/gpio4/value
- Configure the serial port
# export GSM_DEVICE=/dev/ttymxc2 # stty -F $GSM_DEVICE -echo -echoe -echok 115200
Basic Usage
Sending AT commands "manually"
- Sending AT commands with minicom utility (one of the command coming with busybox):
# minicom $GSM_DEVICE
( To exit minocom you will have to type <CTRL-x> )
- Check module presence:
ATI3 SAGEM HiC,A.005.00 OK
Note: If no echo are printed on serial console: you can't see what you're typing. In that case, to reactivate the echo, use:
ATE1 |
- Get constructor name:
AT+CGMI SAGEM OK
- Get model name:
AT+CGMM HILO GPRS OK
- Enter PIN code (here 0000). !! Use your own and beware that you will only get 3 tries !!:
AT+CPIN="0000" OK
- Check PIN code status:
AT+CPIN? +CPIN: READY OK
- Check module status (0 Ready, 1 Unavailable, 2 Status unknown, 3 Ringing, 4 Call in progress, 5 Asleep):
AT+CPAS +CPAS: 0 OK
- Get Indicator control (<battchg>[0-4],<signal>[0-4],<service>0/1,<message>0/1,<call>0/1,<smsfull>0/1):
AT+CIND? +CIND: 0,4,1,0,0,0,1 OK
- Get signal quality (should be better than 12/99):
AT+CSQ +CSQ: 24,99 OK
- Voice call "123456789" (; is important here to signify a voice call, otherwise a data call is tried and may fail if you don't have the right subscribe)
ATD"123456789"; OK
- Terminate current call:
ATH OK
Sending AT commands in shell scripts
GSM_DEVICE=/dev/ttyXXX
send_at_cmd()
{
echo -e -n "$1\015" > $GSM_DEVICE
sleep 1 # Adjustable ! (usleep)
}
send_at_cmd AT
- See target/test/test_gsm.sh for more details
Sending SMS
- Supposing you are already connected to the modem with cu
- Check if you can send SMS with your SIM card (you should get +CMGF: (0,1))
AT+CMGF=?
- If OK, switch to SMS sending mode:
AT+CMGF=1
- Write a message for 0661234567 phone number:
AT+CMGW="0661326109" > Hey ! How are you doing ?? > <-- Ctrl+z to end SMS here +CMGW: 8
- +CMGW give you the number of your SMS saved in SIM card or phone memory
- Then, at anytime, you can send your SMS with (pass previous number as parameter):
AT+CMSS=8
Tools to look at
- http://www.developershome.com/sms/freeLibForSMS.asp
- http://www.gnokii.org/
- http://www.alamin.org/en/index.html
- http://www.gammu.org/wiki/index.php?title=Gammu:Main_Page
- http://gatling.ikk.sztaki.hu/~kissg/gsm/index.html
Data tranfers (EDGE/3G)
PPP installation (done by default on APF51)
$ make linux-menuconfig
Device Drivers ---> [*] Network device support ---> <M> PPP (point-to-point protocol) support [ ] PPP multilink support (EXPERIMENTAL) [ ] PPP filtering <M> PPP support for async serial ports < > PPP support for sync tty ports < > PPP Deflate compression < > PPP BSD-Compress compression < > PPP MPPE compression (encryption) (EXPERIMENTAL) < > PPP over Ethernet (EXPERIMENTAL)
$ make menuconfig
Package Selection for the target ---> Networking applications ---> [*] pppd [ ] filtering [ ] radius
$ make linux && make
- reflash kernel & rootfs
PPP configuration
Note: Following instructions are given for the French operator "Bouygtel" and may need to be ajusted accordingly, depending on your operator/country |
- Create a "chat" script that will be used to initiate MODEM dialup (here we use the "cat > xxxx << EOF trick" to automatically create the file, but you can also manually edit it with vi or nano):
# mkdir -p /etc/chatscripts/ # cat > /etc/chatscripts/bouygtel <<EOF ABORT BUSY ABORT 'NO CARRIER' ABORT VOICE ABORT 'NO DIALTONE' ABORT 'NO ANSWER' ABORT DELAYED ABORT ERROR '' AT OK AT+IPR=115200 OK AT+CPIN="0000" OK AT+CFUN=1 OK AT+COPS? OK AT+CSQ OK 'AT+CGDCONT=1,"IP","ebouygtel.com","",0,0' OK 'AT&FE0Q0V1' OK 'ATD*99#' CONNECT "" EOF
- Don't forget to set the baudrate (default: 115200) to have a stable communication between the modem and the processor
- Don't forget to update "AT+CPIN=" with your real PIN code and "AT+CGDCONT" and "ATD*99#" with your operator parameters.
- If you want to test your chat script (verbose mode -v, on console -s, with 5 second timeout by default for commands -t 5), then launch:
# /usr/sbin/chat -v -s -t 5 -f /etc/chatscripts/bouygtel > $GSM_DEVICE < $GSM_DEVICE
- If this test was OK, you may have to poweroff/poweron the MODEM to bring it to its initial state and go further.
For APF51
- create the PPPd config files (/etc/ppp/peers/bouygtel and /etc/ppp/options.ttyS0):
# mkdir -p /etc/ppp/peers/ # cat > /etc/ppp/peers/bouygtel <<EOF noauth connect "/usr/sbin/chat -v -t 5 -f /etc/chatscripts/bouygtel" debug ttyS0 defaultroute noipdefault usepeerdns EOF # cat > /etc/ppp/options.ttyS0 <<EOF 115200 EOF
For APF27
- create the PPPd config files (/etc/ppp/peers/bouygtel and /etc/ppp/options.ttySMX1):
# mkdir -p /etc/ppp/peers/ # cat > /etc/ppp/peers/bouygtel <<EOF noauth connect "/usr/sbin/chat -v -t 5 -f /etc/chatscripts/bouygtel" debug ttySMX1 defaultroute noipdefault usepeerdns EOF # cat > /etc/ppp/options.ttySMX1 <<EOF 115200 EOF
PPP Usage
- Load PPP module:
# modprobe ppp (APF27) or # modprobe ppp_async (APF51)
- Setup serial port name depending on your platform (/dev/ttyS0 on APF51, /dev/ttySMX1 on APF27)
# export GSM_DEVICE=/dev/ttyS0 or # export GSM_DEVICE=/dev/ttySMX1
- Launch the beast:
# pppd $GSM_DEVICE 115200 call bouygtel
Test
# ping www.google.fr
Troubleshots
- Might be needed after a successful IP setup:
# cp /etc/ppp/resolv.conf /etc/resolv.conf # route add default ppp0 (due to defaultroute option in ppp ?)
- To see what happened after having launched pppd or chat:
# tail -f /var/log/messages
GSM Muxing
Why ?
- By default AT commands usage is single threaded, ie only one program can open MODEM serial port and send AT commands at a given time. However it could be interesting to be able to send multiple AT commands from multiple programs at the same time, for example in order to: have a PPP link, send SMS and monitor network signal quality.
- This can be done by a "GSM mux", if your MODEM support the GSM 07.10 muxing norm (which is the case with our HiLo modules).
Build gsmmux
- To build GSM mux (if not already done):
$ make menuconfig
Package Selection for the target ---> Hardware handling ---> [*] gsmmux Version to use (sagem) --->
$ make
Use it
- If you have access to Sagem's version (you will get as much as virtual serial port as times you pass /dev/ptmx to the daemon):
# gsmMuxd -p $GSM_DEVICE -b 115200 -x /dev/ptmx /dev/ptmx /dev/ptmx
- Virtual serial ports will be created in /dev/pts/:
/dev/pts/0 /dev/pts/1 /dev/pts/2
- to know how /dev/ptmx & /dev/pts/x is working: [1]
- If you have telnet or SSH sessions running /dev/pts/0 may already be used ans so virtual serial ports will be allocated from /dev/pts/1, etc...
Going further
- In recent Linux kernels, there is also a driver to hanlde GSM muxing: n_gsm
- People wanting to do a "real" phone can take a look at ofono
SMS using SMS server tools 3
Simple AT commands can be used to send SMS. If you need more flexibility or advanced management of your SMS, you can use SMS Server Tools 3. SMS Server Tools 3 is a SMS Gateway software which can send and receive short messages through GSM modems and mobile phones.
Build SMS Server Tools3
- To build SMS Server Tools 3:
$ make menuconfig
Package Selection for the target ---> Networking applications ---> [*] smstools3 (1) Number of modems to support [*] Start SMS Server Tools at system boot
$ make
Configuration
The SMS server can be configured by using a configuration file /etc/smsd.conf. The following parameters have to be verified:
- device: UART port used to communicate with the modem. If GSMUX is used, then this parameter is of form /dev/pts/x where is x is the number of the virtual port
- baudrate: baudrate of the UART port
- rtscts: must be yes if your modem needs CTS/RTS controls
- incoming: say yes if you want to receive SMS
Usage
Start the smsd deamon (if not already done at boot):
# /etc/init.d/S50smsd start
Then put a SMS file in the /var/spool/sms/outgoing/ directory. Once placed a SMS will be sent. SMS file should be of the format defined here.
Incoming SMS can be read in the /var/spool/sms/incoming/ directory.
Reports and logs are also generated (/var/log/smsd.log).