AnsweredAssumed Answered

MQX 3.8 GPIO on MCF52235 (  fopen("gpio:read",... ) problem

Question asked by lupogrigio on May 8, 2012
Latest reply on Jul 13, 2012 by Fabi

Hi All,


I have a problem doing a very simple operation using the gpio driver, both as simple pin and as 

interrupt pin. I have controlled things as pin definition, irq capability...yet


I'm simply trying to read an input pin (a button in MCF52235EVB) by mean of the gpio driver, but the program

end after trying to open the input file descriptor, and say "Error opening pin file".


I have found a similar post of the past year reporting this error, but no solution is provided. I don't now if

it is an error due to porting from MQX 3.7 to MQX 3.8. The instruction I'm following to leanr MQX are based on

the 3.5 version.


The operation I do are: 


0. Define the pin

     #define SW1 (GPIO_PORT_NQ | GPIO_PIN4 | GPIO_PIN_IRQ) 

1. Define a file descriptor  

     static FILE_PTR input_file = NULL;

2. Define the pin list array

    uint_32 input_pins [] =  {SW1, GPIO_LIST_END };

3. Define the Task template and...

   TASK_TEMPLATE_STRUCT MQX_template_list[] = { 

       {MAIN_TASK, Main_task, 1500, 5, "main", MQX_AUTO_START_TASK}, 

       {0, 0, 0, 0, 0, 0, }

4. Open the input file inside MainTask procedure

       void Main_task(uint_32 initial_data) {
       printf("\n GPIO Driver ---- Lab.2 ---- \n");
       input_file = fopen("gpio:input", (char_ptr) &input_pins);    
       if (input_file)        {
           printf("Pin file opened. \n");
        } else    {

          printf("Error opening pin file - Error n. %d. \n",input_file);
         _mqx_exit(0);      // <--------- PROGRAM END HERE!!!!

      if (IO_OK != ioctl(input_file,GPIO_IOCTL_SET_IRQ_FUNCTION,(char_ptr) &PinISR)) {
         printf("Register IRQ failed. \n");

    while (TRUE) { // loop here  }





Thanks in advance to anyone can solve this.