MTK串口驱动测试方法

ANDROID drivers类 专栏收录该内容
68 篇文章 3 订阅

1.uart口配置:
将uart log和meta配置端口配置为其他端口,空出来的uart1专门用作此功能通信调试。备注:硬件主板上只有uart1口能够飞线出来调试。修改方法:
参考:[FAQ07420]如何设置吐uart log的uart口
JB5.MP之前的版本:
alps/medaitek/custom/[$project]/preloader/inc/cust_bldr.h
#define CFG_UART_LOG    (UART4) //(UART1) 
#define CFG_UART_META  (UART4) //(UART1)
JB5.MP之后的版本:
alps\mediatek\custom\$project\preloader\cust_bldr.mak
CFG_UART_LOG :=UART4  #UART1
CFG_UART_META :=UART4 #UART1

2.提升UART port的permission,同样以UART1为例
alps/medaitek/config/[$project]/init.project.rc中,添加:
chmod 0666 /dev/ttyMT0
chown system system /dev/ttyMT0

uart物理端口与系统设备名称对应关系:
uart1--/dev/ttyMT0
uart2--/dev/ttyMT1
uart3--/dev/ttyMT2
uart4--/dev/ttyMT3

3.平台相关serialport api代码:
上层api: 
alps\frameworks\base\core\java\android\hardware\SerialPort.java
JNI定义:
alps\frameworks\base\core\jni\android_hardware_SerialPort.cpp
系统demo apk:
alps\frameworks\base\tests\SerialChat
备注1: 此api目前验证还不ok,还在持续确认中;

备注2:验证可以调试ok的api机制可以参考: android_serialport_api,这个框架被托管在: 
https://code.google.com/p/android-serialport-api/  谷歌的代码库,无奈国内无法下载 
https://github.com/cepr/android-serialport-api  GITHUB的地址
*********************************************************************************************************

硬件平台: tiny4412ADK + S700 4GB Flash

Android版本:Android-5.0.2

Linux版本: Linux-3.0.86

Bootloader:Superboot

 

image

 

下面的例子是基于Andrioid源码中自带的一个串口应用SerialChat,Android已经把与之相关的Freamwork、JNI代码,其中直接在JNI中调用了Linux的系统调用,没有遵循Android的HAL架构,根本就没有提供HAL。

下面是相关的代码路径:

APP:

frameworks/base/tests/SerialChat/

SerialManager:

frameworks/base/core/java/android/hardware/SerialManager.java

SerialService:

frameworks/base/services/core/java/com/android/server/SerialService.java

SerialPort:

frameworks/base/core/java/android/hardware/SerialPort.java

JNI:

frameworks/base/services/core/jni/com_android_server_SerialService.cpp

frameworks/base/core/jni/android_hardware_SerialPort.cpp

AIDL:

frameworks/base/core/java/android/hardware/ISerialManager.aidl

 

编译:

root@ubuntu:~/tiny4412_android5/android-5.0.2# . setenv 
including device/lge/mako/vendorsetup.sh
including device/lge/hammerhead/vendorsetup.sh
including device/generic/mini-emulator-x86_64/vendorsetup.sh
including device/generic/mini-emulator-armv7-a-neon/vendorsetup.sh
including device/generic/mini-emulator-mips/vendorsetup.sh
including device/generic/mini-emulator-x86/vendorsetup.sh
including device/generic/mini-emulator-arm64/vendorsetup.sh
including device/friendly-arm/tiny4412/vendorsetup.sh
including device/moto/shamu/vendorsetup.sh
including device/samsung/manta/vendorsetup.sh
including device/asus/deb/vendorsetup.sh
including device/asus/fugu/vendorsetup.sh
including device/asus/tilapia/vendorsetup.sh
including device/asus/grouper/vendorsetup.sh
including device/asus/flo/vendorsetup.sh
including sdk/bash_completion/adb.bash
 
root@ubuntu:~/tiny4412_android5/android-5.0.2# mmm frameworks/base/tests/SerialChat/
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=5.0.2
TARGET_PRODUCT=full_tiny4412
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a-neon
TARGET_CPU_VARIANT=cortex-a9
TARGET_2ND_ARCH=
TARGET_2ND_ARCH_VARIANT=
TARGET_2ND_CPU_VARIANT=
HOST_ARCH=x86_64
HOST_OS=linux
HOST_OS_EXTRA=Linux-3.13.0-32-generic-x86_64-with-Ubuntu-14.04-trusty
HOST_BUILD_TYPE=release
BUILD_ID=LRX22G
OUT_DIR=out
============================================
make: Entering directory `/root/tiny4412_android5/android-5.0.2'
target Java: SerialChat (out/target/common/obj/APPS/SerialChat_intermediates/classes)
Copying: out/target/common/obj/APPS/SerialChat_intermediates/classes-jarjar.jar
Copying: out/target/common/obj/APPS/SerialChat_intermediates/emma_out/lib/classes-jarjar.jar
Copying: out/target/common/obj/APPS/SerialChat_intermediates/classes.jar
Proguard: out/target/common/obj/APPS/SerialChat_intermediates/proguard.classes.jar
ProGuard, version 4.10
Reading program jar [/root/tiny4412_android5/android-5.0.2/out/target/common/obj/APPS/SerialChat_intermediates/classes.jar]
Reading library jar [/root/tiny4412_android5/android-5.0.2/out/target/common/obj/JAVA_LIBRARIES/core-junit_intermediates/classes.jar]
Reading library jar [/root/tiny4412_android5/android-5.0.2/out/target/common/obj/JAVA_LIBRARIES/core-libart_intermediates/classes.jar]
Reading library jar [/root/tiny4412_android5/android-5.0.2/out/target/common/obj/JAVA_LIBRARIES/ext_intermediates/classes.jar]
Reading library jar [/root/tiny4412_android5/android-5.0.2/out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes.jar]
Preparing output jar [/root/tiny4412_android5/android-5.0.2/out/target/common/obj/APPS/SerialChat_intermediates/proguard.classes.jar]
  Copying resources from program jar [/root/tiny4412_android5/android-5.0.2/out/target/common/obj/APPS/SerialChat_intermediates/classes.jar]
target Dex: SerialChat
Copying: out/target/common/obj/APPS/SerialChat_intermediates/classes.dex
target Package: SerialChat (out/target/product/tiny4412/obj/APPS/SerialChat_intermediates/package.apk)
Install: out/target/product/tiny4412/data/app/SerialChat/SerialChat.apk
make: Leaving directory `/root/tiny4412_android5/android-5.0.2'
 
#### make completed successfully (13 seconds) ####

安装:

adb install –r out/target/product/tiny4412/data/app/SerialChat/SerialChat.apk

点击运行,会出错退出。

现在作如下修改:

  • frameworks/base/tests/SerialChat/Android.mk
   1:  #
   2:  # Copyright (C) 2011 The Android Open Source Project
   3:  #
   4:  # Licensed under the Apache License, Version 2.0 (the "License");
   5:  # you may not use this file except in compliance with the License.
   6:  # You may obtain a copy of the License at
   7:  #
   8:  #      http://www.apache.org/licenses/LICENSE-2.0
   9:  #
  10:  # Unless required by applicable law or agreed to in writing, software
  11:  # distributed under the License is distributed on an "AS IS" BASIS,
  12:  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13:  # See the License for the specific language governing permissions and
  14:  # limitations under the License.
  15:  #
  16:   
  17:  LOCAL_PATH:= $(call my-dir)
  18:  include $(CLEAR_VARS)
  19:   
  20:  LOCAL_MODULE_TAGS := tests
  21:   
  22:  LOCAL_SRC_FILES := $(call all-subdir-java-files)
  23:   
  24:  LOCAL_PACKAGE_NAME := SerialChat
  25:   
  26:  LOCAL_CERTIFICATE := platform
  27:   
  28:  include $(BUILD_PACKAGE)
  • frameworks/base/tests/SerialChat/AndroidManifest.xml
   1:  <?xml version="1.0" encoding="utf-8"?>
   2:  <!-- Copyright (C) 2011 The Android Open Source Project
   3:   
   4:       Licensed under the Apache License, Version 2.0 (the "License");
   5:       you may not use this file except in compliance with the License.
   6:       You may obtain a copy of the License at
   7:   
   8:            http://www.apache.org/licenses/LICENSE-2.0
   9:   
  10:       Unless required by applicable law or agreed to in writing, software
  11:       distributed under the License is distributed on an "AS IS" BASIS,
  12:       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13:       See the License for the specific language governing permissions and
  14:       limitations under the License.
  15:  -->
  16:   
  17:  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  18:      package="com.android.serialchat"
  19:      android:sharedUserId="android.uid.system">
  20:   
  21:      <uses-permission android:name="android.permission.SERIAL_PORT"/>
  22:   
  23:      <application android:label="Serial Chat">
  24:          <activity android:name="SerialChat" android:label="Serial Chat">
  25:              <intent-filter>
  26:                  <action android:name="android.intent.action.MAIN" />
  27:                  <category android:name="android.intent.category.DEFAULT" />
  28:                  <category android:name="android.intent.category.LAUNCHER" />
  29:              </intent-filter>
  30:          </activity>
  31:      </application>
  32:  </manifest>
  • frameworks/base/core/res/res/values/config.xml

为什么要修改这个文件呢?在这个文件中配置那些设备节点作为串口设备,在tiny4412平台一共有四个串口,COM0和COM3在底板上用DB9引了出来,对应的设备节点是/dev/ttySAC0、/dev/ttySAC1、/dev/ttySAC2、/dev/ttySAC3,所以修改如下:

 <!-- List of paths to serial ports that are available to the serial manager.         for example, /dev/ttyUSB0  --><string-array translatable="false" name="config_serialPorts">    <item>"/dev/ttySAC0"</item>    <item>"/dev/ttySAC1"</item>    <item>"/dev/ttySAC2"</item>    <item>"/dev/ttySAC3"</item></string-array>

在frameworks/base/tests/SerialChat/src/com/android/serialchat/SerialChat.java中:

    @Override
    public void onResume() {
        super.onResume();
 
        String[] ports = mSerialManager.getSerialPorts();
        if (ports != null && ports.length > 0) {
            try {
                mSerialPort = mSerialManager.openSerialPort(ports[0], 115200);
                if (mSerialPort != null) {
                    new Thread(this).start();
                }
            } catch (IOException e) {
            }
        }
 
    }

从上面的代码可以发现,调用getSerialPorts返回的就是在config.xml中配置的串口设备,这里ports[0]就是”/dev/ttySAC0”,在这里我们使用COM3,对应的是ports[3],所以这里作如下修改:

mSerialPort = mSerialManager.openSerialPort(ports[3], 115200);

重新编译:

mmm frameworks/base/core/res/   # 编译出来的是framework-res.apk,替换/system/framework下的framework-res.apk

mmm frameworks/base/tests/SerialChat/ # 先卸载,在安装 (卸载 adb uninstall com.android.serialchat)

 

下面是测试结果:

  • 这个是串口调试助手,运行在PC机上。

image

  • 下面是tiny4412上运行SerialChat,输入完毕点击image即可发送。

image

 

下载地址: http://pan.baidu.com/s/1nWHP0


参考文章:http://www.th7.cn/Program/Android/201506/486142.shtml
              :http://blog.csdn.net/cbk861110/article/details/42583469

  • 0
    点赞
  • 0
    评论
  • 2
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值