Hi All,
There is a question about GPIO setting.
I would like to open a gpio file containing pin setting. The code as below. After open the output_set, all of them are set as output, but the pin status only BSP_2972_STANDBY and BSP_2972_RST (D0,D7) are correct. In another words, BSP_9127_RST,BSP_HS_8524_MUTE,BSP_HS_8524_MODE (E24,E25,E26) are set as output LOW.(expect HIGH)
Why I can't control the pin status?
Thank you in advance.
Mini
The environment is [MQX3.8.1] & [CW10.2].
The chip is K20DN512.
-----------------------------------------------------------------------
#define BSP_9127_RST (GPIO_PORT_E | GPIO_PIN24)
#define BSP_2972_STANDBY (GPIO_PORT_D | GPIO_PIN0)
#define BSP_2972_RST (GPIO_PORT_D | GPIO_PIN7)
#define BSP_HS_8524_MUTE (GPIO_PORT_E | GPIO_PIN25)
#define BSP_HS_8524_MODE (GPIO_PORT_E | GPIO_PIN26)
-----------------------------------------------------------------------
GPIO_PIN_STRUCT output_set[] = {
BSP_9127_RST | GPIO_PIN_STATUS_1,
BSP_2972_STANDBY | GPIO_PIN_STATUS_0,
BSP_2972_RST | GPIO_PIN_STATUS_1,
BSP_HS_8524_MUTE | GPIO_PIN_STATUS_1,
BSP_HS_8524_MODE | GPIO_PIN_STATUS_1,
GPIO_LIST_END
};
/* Open and set port pins as output */
output_port = fopen("gpio:write", (char_ptr) &output_set);
if (NULL == output_port)
{
printf("Open to output_port failed.\n");
}
-----------------------------------------------------------------------
已解决! 转到解答。
Thanks Rick,
I can control the pin correct when using "ioctl". the problem is when I wanna open a gpio file containing pin setting, some of the pins are not correct.
There is a MQX bug I found (For Kinetis). For your reference.
in mqx\source\io\gpio\kgpio\io_gpio_kgpio.c
line number: 322 uint_8 pin;
It should be uint_32 pin;
cause the width of the GPIO register is 32bits, if give it a byte, only bit 0~7 can work correctly.
that's why some of the pins are correct(D0,D7), and some of them(E24,E25,E26) are not.
you have to issue the ioctl command or nothing gets done
for example: I am multiplexing my analog inputs and need to change the address selector through the GPIO.
uint_32 unc500_scan_vinp(ADC_RESULT_STRUCT * result,uint_8 selector )
{
ADC_RESULT_STRUCT data;
uint_32 err;
if(selector & 1)
a2d_input_slct[0] |= GPIO_PIN_STATUS_1;
else
a2d_input_slct[0] &= ~GPIO_PIN_STATUS_1;
if(selector & 2)
a2d_input_slct[1] |= GPIO_PIN_STATUS_1;
else
a2d_input_slct[1] &= ~GPIO_PIN_STATUS_1;
if(selector & 4)
a2d_input_slct[2] |= GPIO_PIN_STATUS_1;
else
a2d_input_slct[2] &= ~GPIO_PIN_STATUS_1;
ioctl(a2d_selector_fh,GPIO_IOCTL_WRITE, (char_ptr) &a2d_input_slct);
ioctl(adc8_fh, IOCTL_ADC_FIRE_TRIGGER, (pointer) ADC_TRIGGER_8);
if (_lwevent_wait_ticks(&evn_vinp,1,TRUE,0) != MQX_OK)
{
return FALSE;
}
if (_lwevent_clear(&evn_vinp,0x01) != MQX_OK)
{
return FALSE;
}
err = read(adc8_fh,& data, sizeof(data ));
result -> result = data.result;
return err;
}
Thanks Rick,
I can control the pin correct when using "ioctl". the problem is when I wanna open a gpio file containing pin setting, some of the pins are not correct.
There is a MQX bug I found (For Kinetis). For your reference.
in mqx\source\io\gpio\kgpio\io_gpio_kgpio.c
line number: 322 uint_8 pin;
It should be uint_32 pin;
cause the width of the GPIO register is 32bits, if give it a byte, only bit 0~7 can work correctly.
that's why some of the pins are correct(D0,D7), and some of them(E24,E25,E26) are not.