New to Kinetis, KDS/KSDK, and K22f - need GPIO help

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

New to Kinetis, KDS/KSDK, and K22f - need GPIO help

1,657 Views
jverive
Contributor III

I'm new to all of this, and would like to control GPIO ports on the board. Are there any examples/demos that show how to configure these pins as inputs/outputs and then read from or write to them? I come from the Arduino world where things are a little simpler, but I'm not afraid to get my hands dirty. I just need a step in the right direction (the KSDK demo programs aren't helpful in this regard as to using the GPIO ports). Any help would be very much appreciated.

Labels (1)
Tags (2)
0 Kudos
8 Replies

826 Views
ivadorazinova
NXP Employee
NXP Employee

Hi Jeff,

you can try it configure with PE. It is needed KDS 2.0. and KSDK 1.1.0.

How to toggle LED in KDS 2.0 with KSDK 1.1.0 and Processor Expert

The tutorial is written for KL-03Z but there is also support for your board K22F.

support_k22f.png

I hope it helps you,

Best Regards,

Iva

0 Kudos

826 Views
intractablesubt
Contributor III
0 Kudos

826 Views
jverive
Contributor III

Thanks for the response. However, when I use the code in the tutorial, I get errors:

make:*** {Sources/main.o] Error 1

nested redefinition of 'enum_gpio_pins'

redeclaration of 'enum_gpio_pins'

There is also a warning:

Invalid project path: Include path not found (C:\Freescale\KSDK_1.0.0\rtos).

What am I doing wrong?

---------

#include "fsl_device_registers.h"

#include "board.h"

enum _gpio_pins

{

kGpioLED4  = GPIO_MAKE_PIN(HW_PORTE, 0x1A),//PTE26

};

static int i = 0;

int main(void)

{

short value = 1;    /* Write your code here */

hardware_init();

GPIO_DRV_SetPinDir(kGpioLED4, kGpioDigitalOutput);

/* This for loop should be replaced. By default this loop allows a single stepping. */

for (;;) {

for (i = 0; i<0xFFFFFF; i++)

{

}

value = value^1;

GPIO_DRV_WritePinOutput(kGpioLED4, value);

}

/* Never leave main */

return 0;

}

0 Kudos

826 Views
intractablesubt
Contributor III

Hi Jeff,

It sounds like your project is a PE project and that there is already a fsl_gpio component instantiated. In this case the component would declare a _gpio_pins enum and you don't need to do it in your code. You would then only need access the pin using the  GPIO_DRV_WritePinOutput(kGpioLED4, value); call, assuming kGpioLED4 is defined in the fsl_gpio component. If you created your project using a board definition then there are probably pins defined in the component.

0 Kudos

826 Views
jverive
Contributor III

William,

The project is created using the Kinetis Design Studio Project wizard, selecting Board>Kinetis>FRDM-K22F in the Devices prompt. PE is not selected.

Where can I see where pins are being defined? Like I said, I have been using the Arduino family of devices, and there is a lot less "grunt work" that has to be done to use GPIO pins. I realize that the Arduino IDE is hiding most/all of the register/pin configuration process, and I don't mind doing it explicitly for the K22F, but as a new KDS user (and new to Kinetis micros and boards) this is all very confusing to me. That's why a demo would be so helpful.

By the way, after following the tutorial (substituting the K22F directories/files for K64F ones where appropriate), I get the following errors when building the project:

nested redefinition of 'enum _gpio_pins'

redeclaration of 'enum _gpio_pins'

Am I doing something majorly wrong, or am I close to getting operating code?

-------

#include "fsl_device_registers.h"

#include "board.h"

enum _gpio_pins

{

kGpioLED4  = GPIO_MAKE_PIN(HW_PORTE, 0x1A),//PTE26

};

static int i = 0;

int main(void)

{

short value = 1;    /* Write your code here */

hardware_init();

GPIO_DRV_SetPinDir(kGpioLED4, kGpioDigitalOutput);

/* This for loop should be replaced. By default this loop allows a single stepping. */

for (;;) {

for (i = 0; i<0xFFFFFF; i++)

{

}

value = value^1;

GPIO_DRV_WritePinOutput(kGpioLED4, value);

}

/* Never leave main */

return 0;

}

0 Kudos

826 Views
jverive
Contributor III

Okay - board.h has an #include for _gpio_pins, so I commented out the enum { }; in my program. The redeclaration error goes away, but now I get

fatal error: fsl_gpio_common.h: No such file or directory

Indeed, no such file exists anywhere in my KSDK distribution (at least File Explorer's Search function can't find it. The file is referenced in a 'pin_mux.c' file that I am warned not to modify, as it is system generated.

It seems like it's one step forward, two steps back every time I think I'm making progress. Can you sense my frustration?

0 Kudos

829 Views
dave408
Senior Contributor II

Hi Jeff, I feel your pain, but with a bit of perseverance you'll get through it, I think.  Are you still having trouble?  I have a FRDM-K22F that I was using today and was able to get GPIO working and just blinked the onboard LED.  Let me know.

0 Kudos

829 Views
jverive
Contributor III

Forget the first #include (fsl_device_registers.h) - I have it commented out in my code.

0 Kudos