微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > 嵌入式系统设计讨论 > 3.MTX20开发板串口测试方法,adb+wifi,添加新的驱动和应用程序验证。

3.MTX20开发板串口测试方法,adb+wifi,添加新的驱动和应用程序验证。

时间:10-02 整理:3721RD 点击:
嵌入式开发调试方法很重要,我们先来看看MTX20板子的调试方式。
一)串口log,本来以为96boards的板子应该是一样,可实际结果不一样(MTX20使用android系统,另外一块板子使用linux系统,难道是这个原因?),注意USB转TTL线是1.8V



PC端串口调试助手设置如下,可选择的最大波特率,比较特殊。说明一下此时串口输出的log比较多,还没有完全搞清楚输出机制,不一定每次开机都可以有串口log输出原因未知。


二)adb+wifi调试
adb+usb方式很简单,注意MTX20开发板USB Device和HOST模式切换。
adb+wifi设置步骤:
1.adb+usb输入情况下:
adb shell
getprop service.adb.tcp.port 5555
setprop service.adb.tcp.port 5555
stop adbd
(此时adb连接自动断开)
2.不断电,将usb切换到host模式
设置wifi静态ip地址: 192.168.9.233
3.设置setting-》Developer options-》USB debugging开启
4.adb+wifi连接:
adb connect 192.168.9.233:5555
adb shell可以正常连接开发板。
三)添加新驱动和应用测试
1.驱动源代码和位置

  1. #include <linux/init.h>
  2. #include <linux/module.h>
  3. #include <linux/device.h>
  4. #include <linux/platform_device.h>
  5. #include <linux/sysfs.h>
  6. #include <linux/slab.h>
  7. #include <linux/kernel.h>
  8. #include <linux/kobject.h>
  9. #include <linux/string.h>
  10. #include <linux/of.h>

  11. #include <linux/cdev.h>  
  12. #include <linux/fs.h>  
  13. #include <linux/vmalloc.h>

  14. struct xble_device_data {
  15.         struct block_device *binding;
  16.         int inuse;
  17. };

  18. #define mtx20_unflatten_dts_TIP "mtx20_unflatten_dts_tip"
  19. #define DEV_NAME        "ds1302_cdev"  
  20. char mtx20_unflatten_dts_code[64] = "mtx20_unflatten_dts, mtx20_unflatten_dts_show";
  21. int     ds1302_major = 217;  
  22. dev_t   ds1302_devno;  
  23. struct ds1302_cdev_t {  
  24.     struct cdev cdev;  
  25. } ds1302_dev;  

  26. static struct class *xble_class;
  27. static struct xble_device_data *xble_devices;
  28. static DEFINE_MUTEX(xble_mutex);
  29. static int max_xble_minors = 2;

  30. module_param(max_xble_minors, int, 0);
  31. MODULE_PARM_DESC(max_xble_minors, "Maximum number of xble devices (1-65536)");
  32. int g_nNum = 99;

  33. int ds1302_open(struct inode *inode, struct file *filep)  
  34. {
  35.         int nNum = 99;
  36.         pr_warn("20170116 open nNum=%d g_nNum=%d\n", nNum, g_nNum);
  37.         printk( "20170116 open =11= g_nNum=%d\n", g_nNum);
  38.         return 0;  
  39. }  
  40.   
  41. static const struct file_operations ds1302_fops = {  
  42.     .owner = THIS_MODULE,  
  43.     .open = ds1302_open,  
  44. };  
  45. static ssize_t show(struct device_driver *driver, char *buf)
  46. {
  47.         if(NULL != buf)
  48.         {
  49.                 /* Newline is not appended on purpose, for convenience of reader programs */
  50.                 snprintf(buf, PAGE_SIZE, "%s\n", mtx20_unflatten_dts_code);
  51.                 return strlen(buf);
  52.         }

  53.         return 0;
  54. }
  55. DRIVER_ATTR(mtx20_unflatten_dts, 0444, show, NULL);

  56. static struct attribute *mtx20_unflatten_dts_attrs[] = {
  57.         &driver_attr_mtx20_unflatten_dts.attr,
  58.         NULL,
  59. };

  60. static struct attribute_group mtx20_unflatten_dts_group = {
  61.         .name ="mtx20_unflatten_dts",
  62.         .attrs = mtx20_unflatten_dts_attrs,
  63. };

  64. static const struct attribute_group *mtx20_unflatten_dts_groups[] = {
  65.         &mtx20_unflatten_dts_group,
  66.         NULL,
  67. };

  68. static char *xble_devnode(struct device *dev, umode_t *mode)
  69. {
  70.         return kasprintf(GFP_KERNEL, "xble/%s", dev_name(dev));
  71. }
  72. static int mtx20_unflatten_dts_probe(struct platform_device *pdev)
  73. {
  74.         int nNum;
  75.         int         ret;  
  76.         const char *m_string;
  77.         printk("-0000-mtx20_unflatten_dts_probe\n");
  78.         if(NULL == pdev)
  79.         {
  80.                 printk("xiaomi_test: mtx20_unflatten_dts_probe failed, pdev is NULL\n");
  81.                 return 0;
  82.         }
  83.         pr_warn("mtx20_unflatten_dts_probe 0004\n");

  84.         if(NULL == pdev->dev.of_node)
  85.         {
  86.                 printk( "xiaomi_test: mtx20_unflatten_dts_probe failed, of_node is NULL\n");
  87.                 return 0;
  88.         }
  89.         /* mtx20_unflatten_dts_TIP*/
  90.         if(of_property_read_bool(pdev->dev.of_node, mtx20_unflatten_dts_TIP))
  91.         {
  92.                 printk( "mtx20_unflatten_dts_probe: dtsi<%s> is existing\n", mtx20_unflatten_dts_TIP);
  93.         }
  94.         if (of_property_read_u32(pdev->dev.of_node, "linux,code", &nNum))
  95.         {
  96.                 printk(KERN_INFO "=11= nNum=%d\n", nNum);
  97.         }
  98.         else
  99.         {
  100.                 printk(KERN_INFO "=0101= nNum=%d\n", nNum);
  101.         }
  102.         g_nNum = nNum;
  103.         if (of_property_read_string(pdev->dev.of_node, "linux,string", &m_string))
  104.         {
  105.                 printk(KERN_INFO "=11= m_string=%s\n", m_string);
  106.         }
  107.         else
  108.         {
  109.                 printk(KERN_INFO "=12= m_string=%s\n", m_string);
  110.         }
  111.                 printk(KERN_INFO "=0102= nNum=%d\n", nNum);



  112.     if (ds1302_major) {  
  113.         ds1302_devno = MKDEV(ds1302_major, 0);  
  114.         register_chrdev_region(ds1302_devno, 1, DEV_NAME);  
  115.     } else {  
  116.         alloc_chrdev_region(&ds1302_devno, 0, 1, DEV_NAME);  
  117.     }  
  118.         printk("-00001-mtx20_unflatten_dts_probe max_xble_minors=%d\n", max_xble_minors);
  119.                 printk(KERN_INFO "=0103= nNum=%d\n", nNum);
  120.         xble_devices = vzalloc(sizeof(struct xble_device_data) * max_xble_minors);
  121.         if (!xble_devices) {
  122.                 printk(KERN_ERR "Not enough memory for xble device structures\n");
  123.                 ret = -ENOMEM;
  124.         printk("-000011-mtx20_unflatten_dts_probe max_xble_minors=%d\n", max_xble_minors);
  125.                 goto error;
  126.         }
  127.                 printk(KERN_INFO "=0104= nNum=%d\n", nNum);
  128.    cdev_init(&ds1302_dev.cdev, &ds1302_fops);  
  129.     ds1302_dev.cdev.owner = THIS_MODULE;  
  130.   
  131.     if ((ret = cdev_add(&ds1302_dev.cdev, ds1302_devno, 1) < 0)) {  
  132.         unregister_chrdev_region(ds1302_devno, 1);  
  133.         goto error;  
  134.     }  
  135.                 printk(KERN_INFO "=0105= nNum=%d\n", nNum);
  136.                 xble_class = class_create(THIS_MODULE, "xble");
  137.         if (IS_ERR(xble_class)) {
  138.                 printk(KERN_ERR "Error creating xble class.\n");
  139.                 cdev_del(&ds1302_dev.cdev);
  140.                 ret = PTR_ERR(xble_class);
  141.                 goto error_region;
  142.         }
  143.                 printk(KERN_INFO "=0106= nNum=%d\n", nNum);
  144.         xble_class->devnode = xble_devnode;
  145.         device_create(xble_class, NULL, MKDEV(ds1302_major, 0), NULL, "xblectl");
  146.                 printk(KERN_INFO "=0107= nNum=%d\n", nNum);
  147. error_region:
  148.         unregister_chrdev_region(ds1302_devno, max_xble_minors);
  149. error:
  150.         vfree(xble_devices);

  151.         return 0;
  152. }

  153. static struct of_device_id mtx20_unflatten_dts_info_match_table[] = {
  154.         { .compatible = "mediatek,mtx20_unflatten_dts",},
  155.         { },
  156. };

  157. static struct platform_driver mtx20_unflatten_dts = {
  158.         .driver = {
  159.                 .name  = "mtx20_unflatten_dts",
  160.                 .owner  = THIS_MODULE,
  161.                 .groups = mtx20_unflatten_dts_groups,
  162.                 .of_match_table = mtx20_unflatten_dts_info_match_table,
  163.         },

  164.         .probe = mtx20_unflatten_dts_probe,
  165.         .remove = NULL,
  166. };

  167. static int __init mtx20_unflatten_dts_init(void)
  168. {
  169.         pr_warn("mtx20_unflatten_dts_init 0004\n");
  170.         return platform_driver_register(&mtx20_unflatten_dts);
  171. }

  172. static void __exit mtx20_unflatten_dts_exit(void)
  173. {
  174.         device_destroy(xble_class, ds1302_devno);
  175.         class_destroy(xble_class);
  176.   cdev_del(&ds1302_dev.cdev);  
  177.   unregister_chrdev_region(ds1302_devno, 1);  
  178.         platform_driver_unregister(&mtx20_unflatten_dts);
  179. }

  180. module_init(mtx20_unflatten_dts_init);
  181. module_exit(mtx20_unflatten_dts_exit);
  182. MODULE_LICENSE("GPL");

复制代码

位置:android6.0.0/kernel-3.18/drivers/pinctrl/mediatek下,这个位置可以任意只要可以编译即可。
2.dts设置

  1.   mtx20_unflatten_dts: mtx20_unflatten_dts@10030000 {
  2.                         compatible = "mediatek,mtx20_unflatten_dts";
  3.                         #address-cells = <3>;
  4.                         #size-cells = <1>;
  5.                         mtx20_unflatten_dts_tip;
  6.                         linux,code = <20170111>;
  7.                         linux,string = "MediaTek X20-0000-";
  8.                 };

复制代码

android-6.0.0/kernel-3.18/arch/arm64/boot/dts下mt6797.dtsi文件中。
3.linux kernel编译开关设置
android-6.0.0/kernel-3.18/arch/arm64下Kconfig文件中添加
select MTX20_UNFLATTEN_DTS
然后编译更新boot.img。
4.应用程序源代码

  1. #include <stdlib.h>
  2. #include <time.h>
  3. #include <string.h>
  4. #include <wchar.h>
  5. #include <fcntl.h>
  6. #include <stdio.h>
  7. #include <unistd.h>
  8. #include <utils/Log.h>

  9. #define CHIP_ADDR 0x50   //24CXX
  10. //#define I2C_DEV "/sys/class/xble/xblectl"
  11. #define I2C_DEV "/dev/xblectl"
  12. //static int read_eeprom(int fd,char buff[],int addr,int count)
  13. //{
  14. //     int res;
  15. //     lseek(fd, 64, SEEK_SET);
  16. //     if (write(fd,&addr,1)!=1)
  17. //     {
  18. //    printf("Can't write %s's addr %d\n",I2C_DEV,addr);
  19. //    return -1;
  20. //     }
  21. //     res = read(fd,buff,count);
  22. //     printf("read %d bytes at 0x%02x\n\r",res,addr);
  23. //     return res;
  24. //}
  25. //static int write_eeprom(int fd,char buff[],int addr,int count)
  26. //{
  27. //   int res;
  28. //   int i;
  29. //   static char sendbuffer[PAGE_SIZE+1];
  30. //  
  31. //   memcpy(sendbuffer+1,buff,count);
  32. //   sendbuffer[0]=addr;
  33. //   
  34. //   res = write(fd,&sendbuffer,count+1);
  35. //   printf("write %d bytes at 0x%02x buff[0]=%c\n",res,sendbuffer[0], buff[0]);
  36. //   return res;
  37. //}
  38. int main(void)
  39. {
  40. int fd,i,res;
  41. unsigned char str1[PAGE_SIZE] = "aaaaaaaaaaaaaaaaaaaaaaaaa";
  42. unsigned char s2[PAGE_SIZE] = "11111111111111111111111111111111";
  43. unsigned char buf[PAGE_SIZE] = {0};

  44. fd=open(I2C_DEV,O_RDWR);
  45. if(fd<0)
  46.    {
  47.     printf("Can't Open %s !\n\r",I2C_DEV);
  48.     return -1;
  49.    }

  50.         //LOGE("==20170109 open =buf = %s\n 0x4d=<%c>\n", buf, 0x4d);

  51.   printf("=^^^^^^^^^^^^=buf = %s\n 0x4d=<%c>\r", buf, 0x4d);
  52.   close(fd);
  53.   return 0;
  54. }

复制代码


5应用程序编译,随意找一个目录,修改一下Android.mk文件,把我们的程序添加进去,编译即可。


6.测试



这三部分掌握后,基本上就可以为MTX20开发板添加任何驱动和应用程序。
上一篇:开发环境
下一篇:nand flash 的坏块问题

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top