X20持續重覆設定GPIO腳會造成系統crash
就是我在持續並且重覆設定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.
