Difference between revisions of "GSM/GPRS"

From ArmadeusWiki
Jump to: navigation, search
(Sending AT commands "manually")
(APF51Dev)
Line 37: Line 37:
 
====APF51Dev====
 
====APF51Dev====
 
 
 
+
{{Note|Don't forget to put "Wireless" J42 jumper (near microSD connector) '''AND''' power on FPGA Bank 3 (with corresponding J39 jumper).}}
<span style="color:red">* Don't forget to put "Wireless" jumper J42 on your [[APF51Dev]] (near microSD connector) '''AND''' power on FPGA Bank 3 (with corresponding jumper J39).</span>
+
 
* 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).
 
* 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).
 
<pre class="apf">
 
<pre class="apf">

Revision as of 10:59, 7 July 2012

This page will summarize informations to use the GSM/GPRS/3G module of the APF27Wireless board and the APF51Dev (optional).

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.

Both are 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 linux26-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 linux26
  • 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 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 raw -echo -echoe -echok 115200

Basic Usage

Sending AT commands "manually"

# cu -l $GSM_DEVICE

( To exit cu you will have to type ~. )

  • Check module presence:
ATI3
SAGEM HiC,A.005.00

OK
Note 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


Note Note: By default, the module starts in auto baudrate. This mays result in loss of communication with baud rate higher than 19200 bauds. To avoid problems, the baud rate has to be fixed (here to 115200 bauds):
AT+IPR=115200


  • 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
Note Note: Don't launch further AT commands if PIN code wasn't entered successfully


  • 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

Data tranfers (EDGE/3G)

PPP installation (done by default on APF51)

$ make linux26-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 linux26 && make
  • reflash kernel & rootfs

PPP configuration

Note 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

Note Note: Check if /dev/ttySMX1 exists, if not create it with :
mknod /dev/ttySMX1 c 204 42
  • 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

Links