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");
_mqx_exit(-1);
}
while (TRUE) { // loop here }
// FOLLOW ISR DECLARATION ETC..
_mqx_exit(0);
}
Thanks in advance to anyone can solve this.
Giulio
Solved! Go to Solution.
Solved!
The solutuin is to set:
#define BSPCFG_ENABLE_GPIODEV 1
in user_config.h
Maybe this kind of settlement wasn't necessary in earlier versions, but it doen's matter....
Bye
Hi all,
at point 4 I have make a mistake copying the code, the open istruction is
input_file = fopen("gpio:read", (char_ptr) &input_pins);
instead of
input_file = fopen("gpio:input", (char_ptr) &input_pins);
The problem, obviusly, isn' solved, and is the same as reported on the preceding post.
G.
Solved!
The solutuin is to set:
#define BSPCFG_ENABLE_GPIODEV 1
in user_config.h
Maybe this kind of settlement wasn't necessary in earlier versions, but it doen's matter....
Bye
Hi Giulio,
Congratulations on getting the GPIO to work. That driver is big and abstracted greatly so you did good work.
As FYI the GPIO driver is being deprecated. The LWGPIO driver is much more compact and efficient. If you can switch I'd recommend doing so.
Regards,
David
Similar topic, another question: Is it possible to have more than once callback functions to handle the GPIO interrupt?
Example:
GPIO_PIN_STRUCT gpio_1[] = {BSP_SW1|GPIO_PIN_IRQ_RISING, BSP_SW2|GPIO_PIN_IRQ_RISING, GPIO_LIST_END};
GPIO_PIN_STRUCT gpio_2[] = {BSP_SW3|GPIO_PIN_IRQ_RISING, BSP_SW4|GPIO_PIN_IRQ_RISING, GPIO_LIST_END};
hd1 = fopen ( "gpio:read", (char_ptr)&gpio_1 );
hd2 = fopen ( "gpio:read", (char_ptr)&gpio_2 );
ioctl ( hd1, GPIO_IOCTL_SET_IRQ_FUNCTION, (pointer)gpio_callback_1 );
ioctl ( hd2, GPIO_IOCTL_SET_IRQ_FUNCTION, (pointer)gpio_callback_2 );