sama5d2 4g 模块 记录

sama5d2 4g 模块 记录

会解压出一个目录:
/home/sama5d2/multi-serial/
进入目录:
/home/sama5d2/multi-serial/kernel/SAMA_XIN2/
执行如下命令:
export PATH=$PATH:/home/sama5d2/multi-serial/toolchain/gcc-arm-none-eabi-5_2-2015q4/bin
export CROSS_COMPILE=arm-none-eabi-
export ARCH=arm

make ARCH=arm CROSS_COMPILE=arm-none-eabi- distclean
make ARCH=arm CROSS_COMPILE=arm-none-eabi- sama5_defconfig
make ARCH=arm CROSS_COMPILE=arm-none-eabi- zImage dtbs

sama5d2 4g 模块 记录_第1张图片
sama5d2 4g 模块 记录_第2张图片
sama5d2 4g 模块 记录_第3张图片
sama5d2 4g 模块 记录_第4张图片

sama5d2 4g 模块 记录_第5张图片

sama5d2 4g 模块 记录_第6张图片
buidroot:
sama5d2 4g 模块 记录_第7张图片
sama5d2 4g 模块 记录_第8张图片
sama5d2 4g 模块 记录_第9张图片

实现4G模块EC20在linux系统下的拨号上网
可以 使用

板子上面:

pppd -V

pppd: unrecognized option ‘-V’
pppd version 2.4.7
Usage: pppd [ options ], where options are:
Communicate over the named device
Set the baud rate to
: Set the local and/or remote interface IP
addresses. Either one may be omitted.
asyncmap Set the desired async map to hex
auth Require authentication from peer
connect

Invoke shell command

to set up the serial line
crtscts Use hardware RTS/CTS flow control
defaultroute Add default route through interface
file Take options from file
modem Use modem control lines
mru Set MRU value to for negotiation
See pppd(8) for more options.

https://blog.csdn.net/wwt18811707971/article/details/54291747

pppd call wcdma &

/etc/ppp/peers/
wcdma wcdma-chat-connect wcdma-chat-disconnect

新的文件系统 sshd 服务启动:

16	sshd配置文件
16.1	/etc/ssh/ sshd_config

# override default of no subsystems
Subsystem       sftp    /usr/libexec/sftp-server
PermitRootLogin yes
Protocol 2

配置网络:

17	网络配置:
/etc/network/ interfaces
# interface file auto-generated by buildroot
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.99.43
netmask 255.255.255.0
gateway 192.168.99.1

#auto eth0
#iface eth0 inet dhcp

G:\SAMA5D2\sam5d2_buildroot配置.docx

保存 内核的配置文件:
make savedefconfig

保存内核配置:
内核中修改和保存defconfig的方法

  1. 要修改在arch/arm/configs下的文件xxx_defconfig
  2. make xxx_defconfig 会生成.config文件。
  3. make menuconfig 修改配置后保存
  4. make savedefconfig 生成defconfgi文件
  5. cp defconfig arch/arm/configs/xxx_defconfig 保存
    这样保存的defconfig文件,配置最小化

生成 可烧写 文件系统:

/home/sama5d2/multi-serial/ubiCreate/
sudo ./sama5d2_rootfs_to_ubi.sh

每次系统重启的时候,4G模块 也需要 重新启动:

b.sh

#!/bin/bash

function InitIO(){
        if [ ! -d "/sys/class/gpio/PC25" ];then
                echo creating
                echo 89 > /sys/class/gpio/export
                echo out > /sys/class/gpio/PC25/direction
                echo 65 > /sys/class/gpio/export
                echo out > /sys/class/gpio/PC1/direction
                echo 66 > /sys/class/gpio/export
                echo out > /sys/class/gpio/PC2/direction
                echo create done
        fi
        echo 1 >/sys/class/gpio/PC2/value
}

InitIO
if [ $1 == 1 ]
then
        echo 1
        echo 1 >/sys/class/gpio/PC1/value
        echo 1 >/sys/class/gpio/PC2/value
else
        echo 0
        echo 0 >/sys/class/gpio/PC2/value
        echo 0 >/sys/class/gpio/PC1/value
fi

/etc/init.d/rcS

在 最后 加上如下语句:

echo "nameserver 8.8.8.8">> /etc/resolv.conf

source /root/b.sh 0
source /root/b.sh 1

系统启动的log为:

# pppd call wcdma &
# pppd options in effect:
debug           # (from /etc/ppp/peers/wcdma)
nodetach                # (from /etc/ppp/peers/wcdma)
dump            # (from /etc/ppp/peers/wcdma)
noauth          # (from /etc/ppp/peers/wcdma)
user password           # (from /etc/ppp/peers/wcdma)
remotename 3gppp                # (from /etc/ppp/peers/wcdma)
/dev/ttyS5              # (from /etc/ppp/peers/wcdma)
9600            # (from /etc/ppp/peers/wcdma)
lock            # (from /etc/ppp/peers/wcdma)
connect /usr/sbin/chat -s -v -f /etc/ppp/peers/wcdma-chat-connect              #                                                                                                              (from /etc/ppp/peers/wcdma)
disconnect /usr/sbin/chat -s -v -f /etc/ppp/peers/wcdma-chat-disconnect        #                                                                                                              (from /etc/ppp/peers/wcdma)
nocrtscts               # (from /etc/ppp/peers/wcdma)
local           # (from /etc/ppp/peers/wcdma)
hide-password           # (from /etc/ppp/peers/wcdma)
novj            # (from /etc/ppp/peers/wcdma)
novjccomp               # (from /etc/ppp/peers/wcdma)
ipcp-accept-local               # (from /etc/ppp/peers/wcdma)
ipcp-accept-remote              # (from /etc/ppp/peers/wcdma)
ipparam 3gppp           # (from /etc/ppp/peers/wcdma)
noipdefault             # (from /etc/ppp/peers/wcdma)
defaultroute            # (from /etc/ppp/peers/wcdma)
usepeerdns              # (from /etc/ppp/peers/wcdma)
noccp           # (from /etc/ppp/peers/wcdma)
abort on (BUSY)
abort on (NO CARRIER)
abort on (NO DIALTONE)
abort on (ERROR)
abort on (NO ANSWER)
timeout set to 120 seconds
send (AT^M)
expect (OK)
AT^M^M
OK
 -- got it

send (^MATZ^M)
expect (OK)
^M
^MATZ^M^M
OK
 -- got it

send (^MAT+CGDCONT=1,"IP","3gnet",,0,0^M)
expect (OK)
^M
^MAT+CGDCONT=1,"IP","3gnet",,0,0^M^M
OK
 -- got it

send (ATDT*99#^M)
expect (CONNECT)
^M
ATDT*99#^M^M
CONNECT
 -- got it

send (\d)
Script /usr/sbin/chat -s -v -f /etc/ppp/peers/wcdma-chat-connect finished (pid 7                                                                                                             48), status = 0x0
Serial connection established.
using channel 1
Using interface ppp0
Connect: ppp0 <--> /dev/ttyS5
sent [LCP ConfReq id=0x1    ]
rcvd [LCP ConfReq id=0x1      ]
No auth is possible
sent [LCP ConfRej id=0x1 ]
rcvd [LCP ConfAck id=0x1    ]
rcvd [LCP ConfReq id=0x2     ]
sent [LCP ConfAck id=0x2     ]
sent [IPCP ConfReq id=0x1   ]
rcvd [IPCP ConfNak id=0x1]
sent [IPCP ConfReq id=0x2   ]
rcvd [IPCP ConfReq id=0x1]
sent [IPCP ConfNak id=0x1 ]
rcvd [IPCP ConfNak id=0x2   ]
sent [IPCP ConfReq id=0x3   ]
rcvd [IPCP ConfReq id=0x2]
sent [IPCP ConfAck id=0x2]
rcvd [IPCP ConfAck id=0x3   ]
Could not determine remote IP address: defaulting to 10.64.64.64
not replacing existing default route via 192.168.99.1
local  IP address 10.15.145.95
remote IP address 10.64.64.64
primary   DNS address 219.146.1.66
secondary DNS address 219.147.1.66

ifconfig 出现:

# ifconfig
eth0      Link encap:Ethernet  HWaddr FE:80:EA:AC:59:EE
          inet addr:192.168.99.46  Bcast:0.0.0.0  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:6455 errors:0 dropped:1 overruns:0 frame:0
          TX packets:28 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:315550 (308.1 KiB)  TX bytes:1243 (1.2 KiB)
          Interrupt:30 Base address:0x8000

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:2 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:140 (140.0 B)  TX bytes:140 (140.0 B)

ppp0      Link encap:Point-to-Point Protocol
          inet addr:10.15.145.95  P-t-P:10.64.64.64  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
          RX packets:12 errors:0 dropped:0 overruns:0 frame:0
          TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:3
          RX bytes:644 (644.0 B)  TX bytes:668 (668.0 B)

测试:

#
# ping -I ppp0 www.baidu.com
PING www.baidu.com (61.135.169.125): 56 data bytes
64 bytes from 61.135.169.125: seq=0 ttl=47 time=336.965 ms
64 bytes from 61.135.169.125: seq=1 ttl=47 time=229.899 ms
64 bytes from 61.135.169.125: seq=2 ttl=47 time=232.929 ms
64 bytes from 61.135.169.125: seq=3 ttl=47 time=240.225 ms
64 bytes from 61.135.169.125: seq=4 ttl=47 time=231.058 ms

设置默认路由:
原来的路由:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.99.1    0.0.0.0         UG    0      0        0 eth0
10.64.64.64     0.0.0.0         255.255.255.255 UH    0      0        0 ppp0
192.168.99.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0

执行,如下指令:

route del default dev eth0

# route add default dev ppp0
# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         0.0.0.0         0.0.0.0         U     0      0        0 ppp0
10.64.64.64     0.0.0.0         255.255.255.255 UH    0      0        0 ppp0
192.168.99.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0

这个时候,也可以通过网线 ssh 通过到板子上面操作。

# dmesg |grep ttyS
Kernel command line: console=ttyS0,115200 earlyprintk mtdparts=atmel_nand:256k(bootstrap)ro,512k(uboot)ro,256K(env),256k(env_redundent),256k(spare),512k(dtb),6M(kernel)ro,-(rootfs) rootfstype=ubifs ubi.mtd=7 root=ubi0:rootfs
f801c000.serial: ttyS1 at MMIO 0xf801c000 (irq = 35, base_baud = 5187500) is a ATMEL_SERIAL
f8020000.serial: ttyS0 at MMIO 0xf8020000 (irq = 36, base_baud = 5187500) is a ATMEL_SERIAL
console [ttyS0] enabled
f8024000.serial: ttyS2 at MMIO 0xf8024000 (irq = 37, base_baud = 5187500) is a ATMEL_SERIAL
fc008000.serial: ttyS3 at MMIO 0xfc008000 (irq = 39, base_baud = 5187500) is a ATMEL_SERIAL
fc00c000.serial: ttyS4 at MMIO 0xfc00c000 (irq = 40, base_baud = 5187500) is a ATMEL_SERIAL
f8034200.serial: ttyS5 at MMIO 0xf8034200 (irq = 175, base_baud = 5187500) is a ATMEL_SERIAL
fc010200.serial: ttyS6 at MMIO 0xfc010200 (irq = 176, base_baud = 5187500) is a ATMEL_SERIAL
fc014200.serial: ttyS7 at MMIO 0xfc014200 (irq = 177, base_baud = 5187500) is a ATMEL_SERIAL
fc018200.serial: ttyS8 at MMIO 0xfc018200 (irq = 178, base_baud = 5187500) is a ATMEL_SERIAL






设置:

4G模块的 波特率:

persist

microcom -s 9600 /dev/ttyS5

ctrl + x 退出

route del default dev eth0
route add default dev ppp0

pppd call wcdma &

AT+IPR 是掉电保存的

sama5d2 4g 模块 记录_第10张图片
sama5d2 4g 模块 记录_第11张图片

sama5d2 4g 模块 记录_第12张图片

^SRVST: 0

^SRVST: 1

^ECCLIST: 112,911

^SRVST: 2

^RSSI: 31

^HCSQ: “LTE”,74,71,246,34

^NWTIME: 19/05/23,09:06:18+32,0

^RSSI: 31

^HCSQ: “LTE”,75,73,166,34

AT指令

# microcom -s 9600 /dev/ttyS5
AT+CCID
ERROR
AT
OK

^RSSI: 17

^HCSQ: "LTE",43,35,166,24
AT+ICCID
ERROR
AT^ICCID=?
ERROR
^RSSI: 18

^HCSQ: "LTE",44,35,116,24
AT^ICCID?
^ICCID: 89860619100005141926

OK

HUAWEI ME909s Series LTE Module AT Command Interface Specification-(V100R001_03, English).pdf

启动脚本:

start_4g.sh

#!/bin/sh
sleep 2
pppd call wcdma  >/dev/null 2>&1 &

停止脚本

stop_4g.sh

#!/bin/sh

killall pppd

rcS:

echo "nameserver 8.8.8.8">> /etc/resolv.conf
source /root/b.sh 0
source /root/b.sh 1

/etc/init.d/start_4g.sh
/etc/init.d/start_modbus_task.sh


#killall
watchdog -t 15 /dev/watchdog0

start_modbus_task.sh

#!/bin/sh
echo '---------start_modbus_task.sh start ---------'
mkdir -p /var/spool/cron/crontabs
cp -p /etc/crontabs/root /var/spool/cron/crontabs
chmod 777 /var/spool/cron/crontabs/root
crond

/root/modbus_client/monitor_modbus_client.sh

echo '---------start_modbus_task.sh stop ---------'

##### vi stop_modbus_task.sh

#!/bin/sh

#crontab -l
#crontab -r
ps -ef | grep modbus_task.py | grep -v grep | awk '{print $1}'|xargs kill -9

start_4g.sh

#! /bin/sh

ddd=`route | grep default |awk '{print $2}'`
echo $ddd > /etc/ppp/default_gw.txt

pppd call wcdma  >/dev/null 2>&1 &

/etc/ppp/ip-down
#!/bin/sh
echo 'ip-down'
route del default dev ppp0
default_gw=`cat /etc/ppp/default_gw.txt`
route add default gw $default_gw
echo "nameserver 8.8.8.8" > /etc/resolv.conf

你可能感兴趣的:(linux_arm)