Am335x 平台上GSM 3G/4G modem的一些硬件和软件的杂事

Am335x 平台上GSM 3G/4G modem的一些硬件和软件的杂事

 

项目需求

上帝说要有光, 世界就有了光明。

老板说我们的产品需要移动联网,我的一个月时间就没有了。。。

 

 需求细说

既然老板发话, 做小弟的只能埋头苦干了。

第一个问题就是硬件如何互联?

考虑到我们的AM33x平台开发已经基本完成,万幸的是其中的两个USB口全部以扩展口的方式连接出来。

因此最简单的方式就是直接通过USB口扩展。

直接google “USB GSM”, 出来满屏的U盘形状的GSM模块。 哇, 这么简单就解决了。

“老板, 我们可以直接买一个USB的GSM modem,插到我们的板子上就可以了。”

“真的么, 用的什么牌子的产品? 它的尺寸多大?能放入我们的小盒子里么?”

“这。。具体牌子还没有查, 尺寸也不知道。。。”

“滚!”

 

第二个问题能否寻找到适合我们的产品?

于是去下载N家产品资料,查看产品参数,就一个尺寸问题就把所有的产品排除在外。

“为啥我当初把我们的产品设计的这么小呢, 我真是自己作孽啊”。

(附注:为了美观和其他特性要求,我们的GSM dougle 不能裸露在盒子外面)。

 

第三个问题,在寻寻找找的过程中形成我们自己的需求?

没有现成的产品, 只剩下一条路了:自己设计。

经过3个臭皮匠的一番海阔天空的泛谈, 得出如下结论:

1, 通过USB外扩GSM。

2,使用MiniPCI接口的GSM 模块,比较简单,易于更换,而且产家不少。

3,需要自己设计一个简单PCB板,实现USB到MiniPCIE的转换。

4,调研GSM模块在Linux下的驱动移植。是否需要对应的应用程序?

5,对于问题4, 可以先期购买某一产品在PC机上测试。

具体开发

分为硬件设计和软件开发(BSP支持)

硬件开发

这个硬件是比较简单的。主要就是把USB的信号线连接到MiniPCIe的接口上。

注意这里其实并没有MiniPCIe的接口,只是使用它的物理连接器本身以及他们的电源和地的管脚定义。

1, 将USB信号从am335x的扩展口连接出来。

下图中的I2C和UART有其他用途,和GSMmodem没有关系, 请忽略。

 

2,和MiniPCIe接口的连接关系。

从下图可以看出, AM335x就是D+和D-连接到了Modem中,外加一些GPIO的控制。

需要注意的是Am335x的GPIO是3.3V的电平,而GSM中的一些控制管脚有可能是1.8V的, 需要注意电平转换。

3,GSM模块的电源。

GSM模块可能工作在2G模式下,在该模式下,需要设备提供很大的电流(3A)。

所以电源设计需要满足最大电流的要求。

4,AM335x USB信号的设计。

这里按照Am335x的Host模式设计。

5, 完整的电路设计

第一版设计还有一些缺陷,待改正后上传。

 

6, 参考设计

http://www.imx6rex.com/wp-content/uploads/2016/04/iMX6-Rex-Development-Baseboard-Schematic.pdf

BSP支持

我们的平台是基于Linux的, 所以需要在Linux进行BSP的移植。

SDK版本: ti-processor-sdk-linux-rt-am335x-evm-04.02.00.09

 

1,DTS文件, 将USB0改为主设备。

/* USB0 - Peripheral */
&usb0 {
	pinctrl-0 = <&usb0_pins_default>;
	status = "okay";
	dr_mode = "host";
	//dr_mode = "peripheral";
};

2,在menu config 的配置。

我们选用的GSM modem是华为的ME909s-120p(必须支持国货)。

从供应商那里下载了《华为模块 Linux内核驱动集成指导》。

虽然该文档比较旧(2014年版), 不过大体还是够用。

在该文档中提及到需要代码修改, 以及一些具体的配置选项,可能在比较新的LInux内核中不能一一对应。因此需要我们自己动手尝试。

在此,我将我自己的配置选项贴出:

@@ -1871,8 +1871,17 @@ CONFIG_SMSC_PHY=y
 # CONFIG_VITESSE_PHY is not set
 # CONFIG_XILINX_GMII2RGMII is not set
 # CONFIG_MICREL_KS8995MA is not set
-# CONFIG_PPP is not set
+CONFIG_PPP=m
+CONFIG_PPP_BSDCOMP=m
+CONFIG_PPP_DEFLATE=m
+CONFIG_PPP_FILTER=y
+# CONFIG_PPP_MPPE is not set
+CONFIG_PPP_MULTILINK=y
+# CONFIG_PPPOE is not set
+CONFIG_PPP_ASYNC=m
+CONFIG_PPP_SYNC_TTY=m
 # CONFIG_SLIP is not set
+CONFIG_SLHC=m
 
 #
 # Host-side USB support is needed for USB Network Adapter support
@@ -1890,7 +1899,7 @@ CONFIG_USB_NET_AX88179_178A=m
 CONFIG_USB_NET_CDCETHER=m
 # CONFIG_USB_NET_CDC_EEM is not set
 CONFIG_USB_NET_CDC_NCM=m
-# CONFIG_USB_NET_HUAWEI_CDC_NCM is not set
+CONFIG_USB_NET_HUAWEI_CDC_NCM=m
 # CONFIG_USB_NET_CDC_MBIM is not set
 # CONFIG_USB_NET_DM9601 is not set
 # CONFIG_USB_NET_SR9700 is not set
@@ -3819,7 +3828,7 @@ CONFIG_USB_R8A66597_HCD=m
 #
 CONFIG_USB_ACM=m
 # CONFIG_USB_PRINTER is not set
-# CONFIG_USB_WDM is not set
+CONFIG_USB_WDM=m
 # CONFIG_USB_TMC is not set
 
 #
@@ -3938,7 +3947,8 @@ CONFIG_USB_SERIAL=m
 # CONFIG_USB_SERIAL_TI is not set
 # CONFIG_USB_SERIAL_CYBERJACK is not set
 # CONFIG_USB_SERIAL_XIRCOM is not set
-# CONFIG_USB_SERIAL_OPTION is not set
+CONFIG_USB_SERIAL_WWAN=m
+CONFIG_USB_SERIAL_OPTION=m
 # CONFIG_USB_SERIAL_OMNINET is not set
 # CONFIG_USB_SERIAL_OPTICON is not set
 # CONFIG_USB_SERIAL_XSENS_MT is not set

3, 驱动的测试和检测

通过dmesg的信息,查看已经生成ttyUSB0等设备。

root@am335x-evm:~# dmesg | grep usb
[   57.507976] am335x-phy-driver 47401300.usb-phy: GPIO lookup for consumer reset
[   57.508000] am335x-phy-driver 47401300.usb-phy: using device tree for GPIO lookup
[   57.508018] of_get_named_gpiod_flags: can't parse 'reset-gpios' property of node '/ocp/usb@47400000/usb-phy@47401300[0]'
[   57.508028] of_get_named_gpiod_flags: can't parse 'reset-gpio' property of node '/ocp/usb@47400000/usb-phy@47401300[0]'
[   57.508037] am335x-phy-driver 47401300.usb-phy: using lookup tables for GPIO lookup
[   57.508049] am335x-phy-driver 47401300.usb-phy: lookup for GPIO reset failed
[   57.508060] am335x-phy-driver 47401300.usb-phy: GPIO lookup for consumer vbus-detect
[   57.508067] am335x-phy-driver 47401300.usb-phy: using device tree for GPIO lookup
[   57.508076] of_get_named_gpiod_flags: can't parse 'vbus-detect-gpios' property of node '/ocp/usb@47400000/usb-phy@47401300[0]'
[   57.508084] of_get_named_gpiod_flags: can't parse 'vbus-detect-gpio' property of node '/ocp/usb@47400000/usb-phy@47401300[0]'
[   57.508092] am335x-phy-driver 47401300.usb-phy: using lookup tables for GPIO lookup
[   57.508100] am335x-phy-driver 47401300.usb-phy: lookup for GPIO vbus-detect failed
[   57.508217] 47401300.usb-phy supply vcc not found, using dummy regulator
[   57.646111] am335x-phy-driver 47401b00.usb-phy: GPIO lookup for consumer reset
[   57.646135] am335x-phy-driver 47401b00.usb-phy: using device tree for GPIO lookup
[   57.646154] of_get_named_gpiod_flags: can't parse 'reset-gpios' property of node '/ocp/usb@47400000/usb-phy@47401b00[0]'
[   57.646164] of_get_named_gpiod_flags: can't parse 'reset-gpio' property of node '/ocp/usb@47400000/usb-phy@47401b00[0]'
[   57.646173] am335x-phy-driver 47401b00.usb-phy: using lookup tables for GPIO lookup
[   57.646185] am335x-phy-driver 47401b00.usb-phy: lookup for GPIO reset failed
[   57.646195] am335x-phy-driver 47401b00.usb-phy: GPIO lookup for consumer vbus-detect
[   57.646202] am335x-phy-driver 47401b00.usb-phy: using device tree for GPIO lookup
[   57.646211] of_get_named_gpiod_flags: can't parse 'vbus-detect-gpios' property of node '/ocp/usb@47400000/usb-phy@47401b00[0]'
[   57.646220] of_get_named_gpiod_flags: can't parse 'vbus-detect-gpio' property of node '/ocp/usb@47400000/usb-phy@47401b00[0]'
[   57.646227] am335x-phy-driver 47401b00.usb-phy: using lookup tables for GPIO lookup
[   57.646236] am335x-phy-driver 47401b00.usb-phy: lookup for GPIO vbus-detect failed
[   57.646355] 47401b00.usb-phy supply vcc not found, using dummy regulator
[   57.925713] usbcore: registered new interface driver usbfs
[   57.925823] usbcore: registered new interface driver hub
[   57.926058] usbcore: registered new device driver usb
[   58.194553] musb-hdrc musb-hdrc.0: MUSB HDRC host driver
[   58.200319] musb-hdrc musb-hdrc.0: new USB bus registered, assigned bus number 1
[   58.619238] musb-hdrc musb-hdrc.1: MUSB HDRC host driver
[   58.619307] musb-hdrc musb-hdrc.1: new USB bus registered, assigned bus number 2
[   58.808022] musb-hdrc musb-hdrc.1: VBUS_ERROR in a_wait_vrise (81, <SessEnd), retry #1, port1 00000104
[   58.915451] usb 1-1: new high-speed USB device number 2 using musb-hdrc
[   58.960459] musb-hdrc musb-hdrc.1: VBUS_ERROR in a_wait_vrise (81, <SessEnd), retry #2, port1 00000104
[   59.112908] musb-hdrc musb-hdrc.1: VBUS_ERROR in a_wait_vrise (81, <SessEnd), retry #3, port1 00000104
[   59.265310] musb-hdrc musb-hdrc.1: VBUS_ERROR in a_wait_vrise (80, <SessEnd), retry #3, port1 0008010c
[   62.334720] usbcore: registered new interface driver usbserial
[   62.394630] cdc_ether 1-1:2.0 usb0: register 'cdc_ether' at usb-musb-hdrc.0-1, CDC Ethernet Device, 02:1e:10:1f:00:00
[   62.453873] usbcore: registered new interface driver cdc_ether
[   62.555318] usbcore: registered new interface driver option
[   62.593170] usbserial: USB Serial support registered for GSM modem (1-port)
[   62.693263] usb 1-1: GSM modem (1-port) converter now attached to ttyUSB0
[   62.764627] usb 1-1: GSM modem (1-port) converter now attached to ttyUSB1
[   62.867403] usb 1-1: GSM modem (1-port) converter now attached to ttyUSB2
[   62.965723] usb 1-1: GSM modem (1-port) converter now attached to ttyUSB3
[   63.070435] usb 1-1: GSM modem (1-port) converter now attached to ttyUSB4
[   63.098289] cdc_ether 1-1:2.0 usb0: kevent 11 may have been dropped
[   63.106861] cdc_ether 1-1:2.0 usb0: kevent 12 may have been dropped
[   63.106884] IPv6: ADDRCONF(NETDEV_UP): usb0: link is not ready
[   67.537071] cdc_ether 1-1:2.0 usb0: kevent 12 may have been dropped
root@am335x-evm:~#

另外通过手动输入一些简单的AT命令给ttyUSB0口能够获得输出信息, 进一步确认模块工作正常。

这个时候, 急匆匆和老板汇报:

“老板,老板, 好消息, 好消息!”

“啥?”

“GSM 模块能够正常工作了?”

“真的么?”

“千真万确。 你看, 这都有ttyUSB设备了。”

“啥设备, 他能打电话么, 他能发短信么, 他能上网了么?”

“这。。。还不知道如何打电话,发短信,上网?”

“滚!”

 

GSM连接

虽然GSM的驱动已经可以正常工作,而且通过AT命令也能和模块进行通信,但是GSM模块还是没有“用”起来,

即如何让我们的设备和外部通信,例如能够ping "www.google.com"?

 

本人在老板的一番辱骂下, 继续埋头苦干。

google就是好用啊,马上搜索到对用的文章,在此向文章作者感谢!

https://blog.csdn.net/WXXGoodJob/article/details/78880100

http://www.cnblogs.com/chenfulin5/p/6951290.html?utm_source=itdadao&utm_medium=referral

原来要让GSM模块能“用”, 还需要一个pppd的应用来进行拨号连接。

1, 编译和安装pppd

在默认的Ti SDK中是没有pppd的命令的, 即需要我们自己编译和安装。

编译步骤参考Ti的e2e论坛。

https://e2e.ti.com/support/arm/sitara_arm/f/791/t/666632?PROCESSOR-SDK-AM335X-Package-installation

我把具体的步骤拷贝如下:

Do these steps on your computer.

$ sudo apt-get install git build-essential python diffstat texinfo gawk chrpath dos2unix wget unzip socat doxygen libc6:i386 libncurses5:i386 libstdc++6:i386 libz1:i386

$ sudo dpkg-reconfigure dash
# Select "No" when prompted.

$ wget https://releases.linaro.org/components/toolchain/binaries/6.2-2016.11/arm-linux-gnueabihf/gcc-linaro-6.2.1-2016.11-x86_64_arm-linux-gnueabihf.tar.xz
$ tar -Jxvf gcc-linaro-6.2.1-2016.11-x86_64_arm-linux-gnueabihf.tar.xz -C $HOME

$ git clone git://arago-project.org/git/projects/oe-layersetup.git tisdk
$ cd tisdk
$ ./oe-layertool-setup.sh -f configs/processor-sdk/processor-sdk-04.02.00.09-config.txt
$ cd build
$ . conf/setenv
$ export PATH=$HOME/gcc-linaro-6.2.1-2016.11-x86_64_arm-linux-gnueabihf/bin:$PATH
$ MACHINE=am335x-evm bitbake ppp

Then transfer to your board and install the ipks from <tisdk>/build/arago-tmp-external-linaro-toolchain/work/armv7ahf-neon-linux-gnueabi/ppp/2.4.7-r0/deploy-ipks/armv7ahf-neon/ with opkg.

2,pppd的配置

pppd的配置选项非常多, 具体的意义参看

https://linux.die.net/man/8/pppd

本人在配置的过程中偷懒,直接按照上面的博客文章依葫芦画瓢。

root@am335x-evm:/etc/ppp# cat chap-secrets
# Secrets for authentication using CHAP
# client        server  secret                  IP addresses
"live.vodafone.com"    *     "live.vodafone.com"    *

root@am335x-evm:/etc/ppp# cat gprs-connect-chat
# vim etc/ppp/gprs-connect-chat
#/etc/ppp/gprs-connect-chat
#    chat script for China Mobile, used GPRS module.
TIMEOUT         15
ABORT           "DELAYED"
ABORT           "BUSY"
ABORT           "ERROR"
ABORT           "NO DIALTONE"
ABORT           "NO CARRIER"
TIMEOUT         40
''              AT
OK              ATS0=0
OK              ATE0V1
OK      AT+CGDCONT=1,"IP","live.vodafone.com"
OK              ATDT*99#
CONNECT         ''
root@am335x-evm:/etc/ppp# cat options
# vi /etc/ppp/options
#
#auth
#crtscts
lock
#hide-password
#modem
#mru 296
#mtu 296
#lcp-echo-interval 30
#lcp-echo-failure 4
#noipx
#persist
#asyncmap 0xa0000
#mru 1500
#refuse-chap
#ipcp-max-failure 30
usepeerdns
logfile /home/root/ppplog
root@am335x-evm:/etc/ppp# cat peers/gprs
#     vim  /etc/ppp/peers/gprs
#/etc/ppp/peers/gprs
# This is pppd script for China Mobile, used GPRS Module
# Usage:   root>pppd call gprs
/dev/ttyUSB0
115200
nocrtscts
modem
noauth
debug
#nodetach
hide-password
usepeerdns
noipdefault
defaultroute
user "live.vodafone.com"
0.0.0.0:0.0.0.0
ipcp-accept-local
ipcp-accept-remote
#lcp-echo-failure  12
#lcp-echo-interval 3
#noccp
#novj
#novjccomp
replacedefaultroute
#persist
#connect '/usr/sbin/chat -s -v -f /etc/ppp/gprs-connect-chat'
connect '/usr/sbin/chat -v -s -f /etc/ppp/gprs-connect-chat'
#disconnect '/bin/chat -v -f /etc/ppp/gprs-disconnect-chat'
root@am335x-evm:/etc/ppp#

配置的设定主要是有两个地方需要注意,

(1)APN(Access Point Name)的设定, 这个名称在各个电信供应商的网站上可以查到。

在上面的例子,我在用的是 vodafone的 SIM卡,他的APN 是live.vodafone.com

(2)在gprs-connect-chat文件中有一行

OK              ATDT*99#

其中的*99# 是需要拨号上网的号码。大部分供应商应该是一样的。 不过不同的国家和地区的设定就可能不一样了,需要确认。

3 GSM的链接和测试

在设备的控制终端输入:

pppd call gprs   

可以通过log file查看GSM的连接状态。

在上面的options文件中,设定的log文件位于

logfile /home/root/ppplog。

打开ppplog文件,可以看到具体连接信息。

如果一切正常, Linux会生成一个ppp0的网络接口。

通过ifconfig可以确认。

4, 连接外网。

当当当当。。。到此到了最后一个步骤。

在终端输入: ping 8.8.8.8

8.8.8.8是google的ip。

“需要张贴ping的log信息”。

输入命令:

ping www.google.com

" ping: bad address 'www.google.com' 

太着急了, DNS服务器还没有设定!

创建文件/etc/resolv.conf ,

将ppplog中查看到的DNS服务器写入

nameserver xxx.xxx.xxx

ping www.google.com

“需要张贴ping的log信息”。

 

结束语

"老板,老板,好消息,好消息!"

“啥?”

“GSM 模块能够正常工作了?”

“真的么?”

“千真万确。 你看, 这都能ping google了。”

“太好了, 他能打电话么, 他能发短信么?”

“不能, 因为我们没有语音输入输出,不需要电话功能, 也不需要短信功能,我们只需要上网功能!”

“Well done!”

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值