Drive Pins or Port with MQX (TWRMCF51MM256)

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Drive Pins or Port with MQX (TWRMCF51MM256)

708 Views
danielecortella
Contributor V

Hi all, i have some question with the use of gpio with mqx. I have to drive some pin for control a LCD with parallel interface. I have created some struct :

const uint_32 control_pin[] =

{

BSP_LCD_CS | GPIO_PIN_STATUS_0,

BSP_LCD_WR | GPIO_PIN_STATUS_0,

BSP_LCD_RS | GPIO_PIN_STATUS_0,

GPIO_LIST_END

};

and

const uint_32 data_pin[] =

{

BSP_LCD_D0 | GPIO_PIN_STATUS_0,

BSP_LCD_D1 | GPIO_PIN_STATUS_0,

BSP_LCD_D2 | GPIO_PIN_STATUS_0,

BSP_LCD_D3 | GPIO_PIN_STATUS_0,

BSP_LCD_D4 | GPIO_PIN_STATUS_0,

BSP_LCD_D5 | GPIO_PIN_STATUS_0,

BSP_LCD_D6 | GPIO_PIN_STATUS_0,

BSP_LCD_D7 | GPIO_PIN_STATUS_0,

GPIO_LIST_END

};

now i have to command this pins. i have create only a struct for the control_pin and one for the data_pin. I have then to set the control_pin and after pass the data to the data_pin

FILE_PTR control_file = fopen(“gpio:output”, &control_pin);

FILE_PTR data_file = fopen(“gpio:output”, &data_pin);

now i want to set the pin CS, WR and RS but with different value then i have try this operation

ioctl(control_file, GPIO_IOCTL_WRITE , &control_pin[CS]);

ioctl(control_file, GPIO_IOCTL_WRITE , &control_pin[WR]);

ioctl(control_file, GPIO_IOCTL_WRITE , &control_pin[RD]);

i want to write 1 or 0 to a specific pin of the struct control_pin without create three different struct, is possible??

after that i have to pass a variable data to the data_pin then, is right do this ??

ioctl(data_file, GPIO_IOCTL_WRITE_LOG1 , &data);

Please help me, i'm at the begin so i have many difficulties to use mqx. Thanks all!!

0 Kudos
7 Replies

357 Views
c0170
Senior Contributor III

Hello Daniele Cortellazzi,

my initial question is what version of MQX are you using? Is there lwgpio driver available for your board? That will be much easier to start with. GPIO driver became obsolete some time ago ( can't recall actual version of MQX at the moment).

Regards,

0xc0170

0 Kudos

357 Views
danielecortella
Contributor V

I'm using MQX 3.8.1, yes the lwgpio are available but with this driver you can control only one pin for time and we need the possibility to pass the data to the LCD in only one operation without write ten lines of code. The problem is that, i have declared the pins but they did not changes the output value, and i did not understand if is a problem with the code or hardware (the pins aren't connected with other interface).

Thanks

0 Kudos

357 Views
danielecortella
Contributor V

I have found this post from Anthony Huereca:

Rhyme is correct, that function is part of the MQX initialization sequence where the very basic configuration is setup. Anything that you would need to have initialized before an RTOS could even start, like the clocks.

The typical files you'd be modifying when porting to a new board are all in the BSP folder (\mqx\source\bsp\<board_name>), and are:

bsp_cm.c - Initialize clocks

init_hw.c - Initialize Flexbus, DDR, etc

init_gpio.c - Initialize the specific pin muxing needed for a peripheral module

init_*.c - Set the parameters for a module (baud rate, buffer size, etc)

Then in \config\<board_name>\user_config.h you would set which UART/SPI/I2C/etc you would want to use on your board.

Those #defines are then used in init_bsp.c to determine which modules to initialize.

if the output port did not work could be a problem with init_gpio.c that i did not change? there is not a guide that explain what to do? For example in my program i have to use all the pins of port H for transmit the data, what i have to change for control this pin? Thanks

0 Kudos

357 Views
anthony_huereca
NXP Employee
NXP Employee

Hi Daniele,

  I doubt it has anything to do with init_gpio.c since when you open the GPIO driver, it should re-write the MUX pins to set those desired pins as GPIO.

  The original GPIO driver was phased out due to the complexity in using it as you've discovered, and was replaced by LWGPIO. But in MQX 3.8, you should still be able to look at the gpio driver example in \mqx\examples\gpio which may help give you some idea of where to go. I'm not too familiar with the original GPIO driver unfortunately.

  It may be easiest in your case just to control the GPIO pins at the register level instead of using the MQX driver. It's not as clean nor portable, but it would allow you the flexibility and ease you're looking for. You can look at the

-Anthony

0 Kudos

357 Views
danielecortella
Contributor V

Yes, i have seen the lwgpio driver but the problem is that you can not control more then one pin for time, then the code that you have to write for a parallel port become very long. The other problem is that i can't control for example the port H, if i write a pin high with the lwgpio the output don't change, is like there is a mask that not permit to write the port not used normaly on the towerboard. Why? Thanks

0 Kudos

357 Views
anthony_huereca
NXP Employee
NXP Employee

Hi,

  There's nothing on the tower board that would cause the GPIO on port H to not work. I don't have the ability to try that out myself, but I can recommend looking at the lwgpio example that should blink some LEDs on your board, that that same code should toggle port H pins for you too.

-Anthony

0 Kudos

357 Views
danielecortella
Contributor V

Thanks for the answer, i will try to control directly the registers of the gpio and see if this works .

0 Kudos