嵌入式开发调试方法很重要,我们先来看看MTX20板子的调试方式。
一)串口log,本来以为96boards的板子应该是一样,可实际结果不一样(MTX20使用android系统,另外一块板子使用linux系统,难道是这个原因?),注意USB转TTL线是1.8V。
PC端串口调试助手设置如下,可选择的最大波特率,比较特殊。说明一下此时串口输出的log比较多,还没有完全搞清楚输出机制,不一定每次开机都可以有串口log输出原因未知。
二)adb+wifi调试
adb+u***方式很简单,注意MTX20 开发板USB Device和HOST模式切换。
adb+wifi设置步骤:
1.adb+u***输入情况下:
adb shell
getprop service.adb.tcp.port 5555
setprop service.adb.tcp.port 5555
stop adbd
(此时adb连接自动断开)
2. 不断电,将u***切换到host模式
设置wifi静态ip地址: 192.168.9.233
3.设置set ting-》Developer options-》USB debugging开启
4.adb+wifi连接:
adb connect 192.168.9.233:5555
adb shell可以正常连接开发板。
三)添加新驱动和应用测试
1.驱动源代码和位置
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- struct xble_device_data {
- struct block_device *binding;
- int inuse;
- };
-
- #define mtx20_unflatten_dts_TIP "mtx20_unflatten_dts_tip"
- #define DEV_NAME "ds1302_cdev"
- char mtx20_unflatten_dts_code[64] = "mtx20_unflatten_dts, mtx20_unflatten_dts_show";
- int ds1302_major = 217;
- dev_t ds1302_devno;
- struct ds1302_cdev_t {
- struct cdev cdev;
- } ds1302_dev;
- static struct class *xble_class;
- static struct xble_device_data *xble_devices;
- static DEFINE_MUTEX(xble_mutex);
- static int max_xble_minors = 2;
- module_param(max_xble_minors, int, 0);
- MODULE_PARM_DESC(max_xble_minors, "Maximum number of xble devices (1-65536)");
- int g_nNum = 99;
- int ds1302_open(struct inode *inode, struct file *filep)
- {
- int nNum = 99;
- pr_warn("20170116 open nNum=%d g_nNum=%dn", nNum, g_nNum);
- printk( "20170116 open =11= g_nNum=%dn", g_nNum);
- return 0;
- }
-
- static const struct file_operations ds1302_fops = {
- .owner = THIS_MODULE,
- .open = ds1302_open,
- };
- static ssize_t show(struct device_driver *driver, char *buf)
- {
- if(NULL != buf)
- {
- /* Newline is not appended on purpose, for convenience of reader programs */
- snprintf(buf, PAGE_SIZE, "%sn", mtx20_unflatten_dts_code);
- return strlen(buf);
- }
- return 0;
- }
- DRIVER_ATTR(mtx20_unflatten_dts, 0444, show, NULL);
- static struct attribute *mtx20_unflatten_dts_attrs[] = {
- &driver_attr_mtx20_unflatten_dts.attr,
- NULL,
- };
- static struct attribute_group mtx20_unflatten_dts_group = {
- .name ="mtx20_unflatten_dts",
- .attrs = mtx20_unflatten_dts_attrs,
- };
- static const struct attribute_group *mtx20_unflatten_dts_groups[] = {
- &mtx20_unflatten_dts_group,
- NULL,
- };
- static char *xble_devnode(struct device *dev, umode_t *mode)
- {
- return kasprintf(GFP_KERNEL, "xble/%s", dev_name(dev));
- }
- static int mtx20_unflatten_dts_probe(struct platform_device *pdev)
- {
- int nNum;
- int ret;
- const char *m_string;
- printk("-0000-mtx20_unflatten_dts_proben");
- if(NULL == pdev)
- {
- printk("xiaomi_test: mtx20_unflatten_dts_probe failed, pdev is NULLn");
- return 0;
- }
- pr_warn("mtx20_unflatten_dts_probe 0004n");
- if(NULL == pdev->dev.of_node)
- {
- printk( "xiaomi_test: mtx20_unflatten_dts_probe failed, of_node is NULLn");
- return 0;
- }
- /* mtx20_unflatten_dts_TIP*/
- if(of_property_read_bool(pdev->dev.of_node, mtx20_unflatten_dts_TIP))
- {
- printk( "mtx20_unflatten_dts_probe: dtsi<%s> is existingn", mtx20_unflatten_dts_TIP);
- }
- if (of_property_read_u32(pdev->dev.of_node, "linux,code", &nNum))
- {
- printk(KERN_INFO "=11= nNum=%dn", nNum);
- }
- else
- {
- printk(KERN_INFO "=0101= nNum=%dn", nNum);
- }
- g_nNum = nNum;
- if (of_property_read_string(pdev->dev.of_node, "linux,string", &m_string))
- {
- printk(KERN_INFO "=11= m_string=%sn", m_string);
- }
- else
- {
- printk(KERN_INFO "=12= m_string=%sn", m_string);
- }
- printk(KERN_INFO "=0102= nNum=%dn", nNum);
- if (ds1302_major) {
- ds1302_devno = MKDEV(ds1302_major, 0);
- register_chrdev_region(ds1302_devno, 1, DEV_NAME);
- } else {
- alloc_chrdev_region(&ds1302_devno, 0, 1, DEV_NAME);
- }
- printk("-00001-mtx20_unflatten_dts_probe max_xble_minors=%dn", max_xble_minors);
- printk(KERN_INFO "=0103= nNum=%dn", nNum);
- xble_devices = vzalloc(sizeof(struct xble_device_data) * max_xble_minors);
- if (!xble_devices) {
- printk(KERN_ERR "Not enough memory for xble device structuresn");
- ret = -ENOMEM;
- printk("-000011-mtx20_unflatten_dts_probe max_xble_minors=%dn", max_xble_minors);
- goto error;
- }
- printk(KERN_INFO "=0104= nNum=%dn", nNum);
- cdev_init(&ds1302_dev.cdev, &ds1302_fops);
- ds1302_dev.cdev.owner = THIS_MODULE;
-
- if ((ret = cdev_add(&ds1302_dev.cdev, ds1302_devno, 1) < 0)) {
- unregister_chrdev_region(ds1302_devno, 1);
- goto error;
- }
- printk(KERN_INFO "=0105= nNum=%dn", nNum);
- xble_class = class_create(THIS_MODULE, "xble");
- if (IS_ERR(xble_class)) {
- printk(KERN_ERR "Error creating xble class.n");
- cdev_del(&ds1302_dev.cdev);
- ret = PTR_ERR(xble_class);
- goto error_region;
- }
- printk(KERN_INFO "=0106= nNum=%dn", nNum);
- xble_class->devnode = xble_devnode;
- device_create(xble_class, NULL, MKDEV(ds1302_major, 0), NULL, "xblectl");
- printk(KERN_INFO "=0107= nNum=%dn", nNum);
- error_region:
- unregister_chrdev_region(ds1302_devno, max_xble_minors);
- error:
- vfree(xble_devices);
- return 0;
- }
- static struct of_device_id mtx20_unflatten_dts_info_match_table[] = {
- { .compatible = "mediatek,mtx20_unflatten_dts",},
- { },
- };
- static struct platform_driver mtx20_unflatten_dts = {
- .driver = {
- .name = "mtx20_unflatten_dts",
- .owner = THIS_MODULE,
- .groups = mtx20_unflatten_dts_groups,
- .of_match_table = mtx20_unflatten_dts_info_match_table,
- },
- .probe = mtx20_unflatten_dts_probe,
- .remove = NULL,
- };
- static int __init mtx20_unflatten_dts_init(void)
- {
- pr_warn("mtx20_unflatten_dts_init 0004n");
- return platform_driver_register(&mtx20_unflatten_dts);
- }
- static void __exit mtx20_unflatten_dts_exit(void)
- {
- device_destroy(xble_class, ds1302_devno);
- class_destroy(xble_class);
- cdev_del(&ds1302_dev.cdev);
- unregister_chrdev_region(ds1302_devno, 1);
- platform_driver_unregister(&mtx20_unflatten_dts);
- }
- module_init(mtx20_unflatten_dts_init);
- module_exit(mtx20_unflatten_dts_exit);
- MODULE_LICENSE("GPL");
复制代码
位置:android6.0.0/kernel-3.18/drivers/pinctrl/mediatek下,这个位置可以任意只要可以编译即可。
2.dts设置
- mtx20_unflatten_dts: mtx20_unflatten_dts@10030000 {
- compatible = "mediatek,mtx20_unflatten_dts";
- #address-cells = <3>;
- #size-cells = <1>;
- mtx20_unflatten_dts_tip;
- linux,code = <20170111>;
- linux,string = "MediaTek X20-0000-";
- };
复制代码
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.应用程序源代码
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #define CHIP_ADDR 0x50 //24CXX
- //#define I2C_DEV "/sys/class/xble/xblectl"
- #define I2C_DEV "/dev/xblectl"
- //static int read_eeprom(int fd,char buff[],int addr,int count)
- //{
- // int res;
- // lseek(fd, 64, SEEK_SET);
- // if (write(fd,&addr,1)!=1)
- // {
- // printf("Can't write %s's addr %dn",I2C_DEV,addr);
- // return -1;
- // }
- // res = read(fd,buff,count);
- // printf("read %d bytes at 0x%02xnr",res,addr);
- // return res;
- //}
- //static int write_eeprom(int fd,char buff[],int addr,int count)
- //{
- // int res;
- // int i;
- // static char sendbuffer[PAGE_SIZE+1];
- //
- // memcpy(sendbuffer+1,buff,count);
- // sendbuffer[0]=addr;
- //
- // res = write(fd,&sendbuffer,count+1);
- // printf("write %d bytes at 0x%02x buff[0]=%cn",res,sendbuffer[0], buff[0]);
- // return res;
- //}
- int main(void)
- {
- int fd,i,res;
- unsigned char str1[PAGE_SIZE] = "aaaaaaaaaaaaaaaaaaaaaaaaa";
- unsigned char s2[PAGE_SIZE] = "11111111111111111111111111111111";
- unsigned char buf[PAGE_SIZE] = {0};
- fd=open(I2C_DEV,O_RDWR);
- if(fd<0)
- {
- printf("Can't Open %s !!!nr",I2C_DEV);
- return -1;
- }
- //LOGE("==20170109 open =buf = %sn 0x4d=<%c>n", buf, 0x4d);
- printf("=^^^^^^^^^^^^=buf = %sn 0x4d=<%c>r", buf, 0x4d);
- close(fd);
- return 0;
- }
复制代码
5应用程序编译,随意找一个目录,修改一下Android.mk文件,把我们的程序添加进去,编译即可。
6.测试
这三部分掌握后,基本上就可以为MTX20开发板添加任何驱动和应用程序。
|