最近有个项目需要实现快速开机出摄像头预览(2s内),但是我的板子linux上的qt应用起来都要10s左右了,于是在硬件上增加了一个屏驱芯片TW8836,这是一个mcu,可以直接获取摄像头数据送到lcd显示。
板子上电后首先由8836点亮屏幕并输出摄像头预览,待arm起来后控制8836切换显示,8836接受arm lvds信号并送到lcd显示,同时8836将camera数据(bt656)回传给arm.
由于我们这边主要是搞arm,没有更多的预留时间去熟悉研究8836这颗mcu的用法,但是我们板子上还有一颗当做看门狗的stm32,可以通过iic设置8836的寄存器,从而实现相应功能,最后硬件大致框图如下
板子上电前期,stm32先通过iic控制8836输出camera预览,待arm起来后,再由arm通过iic控制8836显示arm输出的内容。这过程中就涉及到两个主机公国iic控制同一个从机的逻辑。
首先验证smt32单独通过iic单独控制8836,验证ok。
其次验证arm单独通过iic单独控制8836,验证ok。
但是将stm32 、8836及arm都通过iic连接在一起的时候,stm32可以与8836通讯,但是arm无法与8836通讯。
对应log如下:
[root@t3_p3 ~]# insmod gt9xx_ts.ko [ 24.608866] kyleprint: >>> goodix_ts_init [ 24.613541] ctp_fetch_sysconfig_para: ctp_power_io is invalid. [ 24.621138] tab:-----------------ms 1---------------------- [ 24.627253] GTP9xx***CTP*** ctp_wakeup:status:0,ms = 0 [ 24.633091] GTP9xx***config_info.wakeup_gpio.gpio = 227 [ 24.690100] GTP9xx***CTP*** ctp_wakeup:status:1,ms = 0 [ 24.695742] GTP9xx***config_info.wakeup_gpio.gpio = 227 [ 24.720675] i2c-core: driver [gt9xx] using legacy suspend method [ 24.727331] i2c-core: driver [gt9xx] using legacy resume method [ 24.734093] GTP9xxctp_detect: addr = 45 [ 24.738550] sunxi_i2c_do_xfer()902 - [i2c2] incomplete xfer (status: 0x20, dev addr: 0x45) [ 24.747991] sunxi_i2c_do_xfer()902 - [i2c2] incomplete xfer (status: 0x20, dev addr: 0x45) [ 24.757244] i2c_test:I2C retry timeout, reset chip. [ 24.780260] sunxi_i2c_do_xfer()902 - [i2c2] incomplete xfer (status: 0x20, dev addr: 0x45) [ 24.789830] sunxi_i2c_do_xfer()902 - [i2c2] incomplete xfer (status: 0x20, dev addr: 0x45) [ 24.799080] i2c_test:I2C retry timeout, reset chip. [ 24.820227] sunxi_i2c_do_xfer()902 - [i2c2] incomplete xfer (status: 0x20, dev addr: 0x45) [ 24.829752] sunxi_i2c_do_xfer()902 - [i2c2] incomplete xfer (status: 0x20, dev addr: 0x45) [ 24.838982] i2c_test:I2C retry timeout, reset chip. [ 24.860384] sunxi_i2c_do_xfer()902 - [i2c2] incomplete xfer (status: 0x20, dev addr: 0x45) [ 24.869811] sunxi_i2c_do_xfer()902 - [i2c2] incomplete xfer (status: 0x20, dev addr: 0x45) [ 24.879086] i2c_test:I2C retry timeout, reset chip. [ 24.900415] sunxi_i2c_do_xfer()902 - [i2c2] incomplete xfer (status: 0x20, dev addr: 0x45) [ 24.909992] sunxi_i2c_do_xfer()902 - [i2c2] incomplete xfer (status: 0x20, dev addr: 0x45) [ 24.919239] i2c_test:I2C retry timeout, reset chip. [ 25.150324] sunxi_i2c_do_xfer()902 - [i2c2] incomplete xfer (status: 0x20, dev addr: 0x45) [ 25.159883] sunxi_i2c_do_xfer()902 - [i2c2] incomplete xfer (status: 0x20, dev addr: 0x45) [ 25.169112] i2c_test:get tw8836_id failed ret = -70 [ 25.380296] sunxi_i2c_do_xfer()902 - [i2c2] incomplete xfer (status: 0x20, dev addr: 0x45) [ 25.389787] sunxi_i2c_do_xfer()902 - [i2c2] incomplete xfer (status: 0x20, dev addr: 0x45) [ 25.399036] i2c_test:get tw8836_id failed ret = -70 [ 25.610448] sunxi_i2c_do_xfer()902 - [i2c2] incomplete xfer (status: 0x20, dev addr: 0x45) [ 25.620066] sunxi_i2c_do_xfer()902 - [i2c2] incomplete xfer (status: 0x20, dev addr: 0x45) [ 25.629189] i2c_test:get tw8836_id failed ret = -70 [ 25.840414] sunxi_i2c_do_xfer()902 - [i2c2] incomplete xfer (status: 0x20, dev addr: 0x45) [ 25.849863] sunxi_i2c_do_xfer()902 - [i2c2] incomplete xfer (status: 0x20, dev addr: 0x45) [ 25.859075] i2c_test:get tw8836_id failed ret = -70 [ 26.070362] sunxi_i2c_do_xfer()902 - [i2c2] incomplete xfer (status: 0x20, dev addr: 0x45) [ 26.079971] sunxi_i2c_do_xfer()902 - [i2c2] incomplete xfer (status: 0x20, dev addr: 0x45) [ 26.089269] i2c_test:get tw8836_id failed ret = -70 [ 26.300313] sunxi_i2c_do_xfer()902 - [i2c2] incomplete xfer (status: 0x20, dev addr: 0x45) [ 26.309776] sunxi_i2c_do_xfer()902 - [i2c2] incomplete xfer (status: 0x20, dev addr: 0x45) [ 26.319022] i2c_test:get tw8836_id failed ret = -70 [ 26.530240] sunxi_i2c_do_xfer()902 - [i2c2] incomplete xfer (status: 0x20, dev addr: 0x45) [ 26.539667] sunxi_i2c_do_xfer()902 - [i2c2] incomplete xfer (status: 0x20, dev addr: 0x45) [ 26.549098] i2c_test:get tw8836_id failed ret = -70 [ 26.760332] sunxi_i2c_do_xfer()902 - [i2c2] incomplete xfer (status: 0x20, dev addr: 0x45) [ 26.769763] sunxi_i2c_do_xfer()902 - [i2c2] incomplete xfer (status: 0x20, dev addr: 0x45) [ 26.779047] i2c_test:get tw8836_id failed ret = -70 [ 26.990276] sunxi_i2c_do_xfer()902 - [i2c2] incomplete xfer (status: 0x20, dev addr: 0x45) [ 26.999848] sunxi_i2c_do_xfer()902 - [i2c2] incomplete xfer (status: 0x20, dev addr: 0x45) [ 27.009101] i2c_test:get tw8836_id failed ret = -70 [ 27.220466] sunxi_i2c_do_xfer()902 - [i2c2] incomplete xfer (status: 0x20, dev addr: 0x45) [ 27.230077] sunxi_i2c_do_xfer()902 - [i2c2] incomplete xfer (status: 0x20, dev addr: 0x45) [ 27.239151] i2c_test:get tw8836_id failed ret = -70 [ 27.244752] ctp_detect:I2C connection might be something wrong
iic从设备没有响应,只能用示波器抓波形观察,发现sda数据项一直处于高电平无法拉低,但是在stm32与8836通讯的时候却可以正常高低切换。
回想对比,发现问题的根本原因是,我在stm32操作完iic后没有将scl和sda释放,因为stm32那边的iic走的是软件模拟的方式,空闲状态下SDA和SCL两个io口都被我拉高了,导致arm这边无法将电平拉低。
最后在stm iic部分,每次操作完iic就将SDA 和SCL释放,设置成输入状态。
释放io口后arm已经可以正常与8836通讯,能够正常获取到chip id 0x36
[ 686.617078] kyleprint: >>> goodix_ts_init [ 686.621729] ctp_fetch_sysconfig_para: ctp_power_io is invalid. [ 686.630192] goodix_ts_init:requst irq gpio fail! [ 686.635399] tab:-----------------ms 1---------------------- [ 686.635399] GTP9xx***CTP*** ctp_wakeup:status:0,ms = 0 [ 686.635399] GTP9xx***config_info.wakeup_gpio.gpio = 227 [ 686.690186] GTP9xx***CTP*** ctp_wakeup:status:1,ms = 0 [ 686.695816] GTP9xx***config_info.wakeup_gpio.gpio = 227 [ 686.721011] i2c-core: driver [gt9xx] using legacy suspend method [ 686.727638] i2c-core: driver [gt9xx] using legacy resume method [ 686.734423] GTP9xxctp_detect: addr = 45 [ 686.739420] i2c_test pass [ 686.950714] i2c_test: i= 1 get tw8836_id 0x00 ret 2 [ 686.956180] i2c_test: i= 1 get tw8836_id 0x36 ret 2 [ 687.170542] i2c_test: i= 2 get tw8836_id 0x00 ret 2 [ 687.176041] i2c_test: i= 2 get tw8836_id 0x36 ret 2 [ 687.390399] i2c_test: i= 3 get tw8836_id 0x00 ret 2 [ 687.395851] i2c_test: i= 3 get tw8836_id 0x36 ret 2 [ 687.610415] i2c_test: i= 4 get tw8836_id 0x00 ret 2 [ 687.615858] i2c_test: i= 4 get tw8836_id 0x36 ret 2 [ 687.830542] i2c_test: i= 5 get tw8836_id 0x00 ret 2 [ 687.835980] i2c_test: i= 5 get tw8836_id 0x36 ret 2 [ 688.050448] i2c_test: i= 6 get tw8836_id 0x00 ret 2 [ 688.055920] i2c_test: i= 6 get tw8836_id 0x36 ret 2 [ 688.270492] i2c_test: i= 7 get tw8836_id 0x00 ret 2 [ 688.275955] i2c_test: i= 7 get tw8836_id 0x36 ret 2 [ 688.490476] i2c_test: i= 8 get tw8836_id 0x00 ret 2 [ 688.495963] i2c_test: i= 8 get tw8836_id 0x36 ret 2 [ 688.710888] i2c_test: i= 9 get tw8836_id 0x00 ret 2 [ 688.716341] i2c_test: i= 9 get tw8836_id 0x36 ret 2 [ 688.930820] i2c_test: i= 10 get tw8836_id 0x00 ret 2 [ 688.936359] i2c_test: i= 10 get tw8836_id 0x36 ret 2