微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 手机设计讨论 > MTK手机平台交流 > X20持續重覆設定GPIO腳會造成系統crash

X20持續重覆設定GPIO腳會造成系統crash

时间:10-02 整理:3721RD 点击:
各位大神們好,小弟目前在X20板上遇到一個很弔詭的事。
就是我在持續並且重覆設定GPIO腳時會造成系統crash,不知道有沒有人遇到過?
給個簡單的程式碼如下,一直持續呼叫就會出現。
#define PIN_LED_ON 28
mt_set_gpio_mode(PIN_LED_ON,GPIO_MODE_00);
mt_set_gpio_dir(PIN_LED_ON,GPIO_DIR_OUT);
mt_set_gpio_out(PIN_LED_ON,GPIO_OUT_ONE);

若有任何想法,歡迎討論,謝謝。

你这具体 怎么调用的?将你的整个代码拿出来看看。

我就是在我的驅動中將file_operations的write方法實作下面的內容,然後在adb中去下echo P0 > XXX_driver。
ssize_t ops_write(struct file *filp, const char *buff, size_t len, loff_t *off){
        if(buff&&(len>2)){
                int nVal = 0;
                char *pszVal = (char*)&buff[1];
                char *endptr;
                nVal = (int)simple_strtol(pszVal, &endptr, 10);
                if(endptr != pszVal){
                        switch(buff[0]){
                                case 'P':
                                        mt_set_gpio_mode(PIN_LED_ON,GPIO_MODE_00);
                                        mt_set_gpio_dir(PIN_LED_ON,GPIO_DIR_OUT);
                                        mt_set_gpio_out(PIN_LED_ON,GPIO_OUT_ONE);
                                        break;
                        }
                }
        }
}
然後確認一下LED腳有點亮,然後就把命令改成while true;do echo P0 > XXX_driver;done,這樣持續不到一分鐘就會crash了。

目前發現加入sleep會解決這個問題…但不知道是其原因為何?
加入sleep的代碼如下:
case 'P':
           mt_set_gpio_mode(PIN_LED_ON,GPIO_MODE_00);
           msleep(1);
           mt_set_gpio_dir(PIN_LED_ON,GPIO_DIR_OUT);
           msleep(1);
           mt_set_gpio_out(PIN_LED_ON,GPIO_OUT_ONE);
           msleep(1);
           break;

Do you want to try add a gpio_free() ?

add where?

case 'P':
           mt_set_gpio_mode(PIN_LED_ON,GPIO_MODE_00);
           msleep(1);
           mt_set_gpio_dir(PIN_LED_ON,GPIO_DIR_OUT);
           msleep(1);
           mt_set_gpio_out(PIN_LED_ON,GPIO_OUT_ONE);
           msleep(1);
           gpio_free();
           break;

Now it works without gpio_free().
But It will crash without msleep().

gpio functions will call spin_lock_irqsave internally, and system may crash when you continously mask local IRQs.

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

网站地图

Top