FRDM-KL26Z GPIO programming knowhow?

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

FRDM-KL26Z GPIO programming knowhow?

687 Views
danieltruong
Contributor IV

Hi,

 

I've just had a FRDM-KL26Z board and some SW tools (KSDK and KDS) installed. Starting to browse some code to see how the GPIOs are configured and programmed.

It gets down to the following code with the pin names defined as kGpioLED1kGpioLED2, etc. and I just can't figure out how they are defined the way as shown. It's got to have a place where user can manually enters the related information (as it differs from board to board). In the comments just above the code, gpioPinLookupTable is mentioned for this purpose. Can someone help give me a pointer as to where I can obtain this table and hopefully I can customize it for my project?

 

Thank you in advance,

Daniel

---------------

 

/*! @file */

/*!*/

/*! This file contains gpio pin definitions used by gpio peripheral driver.*/

/*! The enums in _gpio_pins map to the real gpio pin numbers defined in*/

/*! gpioPinLookupTable. And this might be different in different board.*/

 

/*******************************************************************************

 * Definitions

 ******************************************************************************/

 

/*! @brief gpio pin names.*/

/*!*/

/*! This should be defined according to board setting.*/

/* gpio_pins.h */

enum _gpio_pins

{

    kGpioLED1        = GPIO_MAKE_PIN(GPIOE_IDX, 31u),  /* FRDM-KL26Z4 Green LED */

    kGpioLED2        = GPIO_MAKE_PIN(GPIOE_IDX, 29u),  /* FRDM-KL26Z4 Red LED */

    kGpioLED3        = GPIO_MAKE_PIN(GPIOD_IDX, 5u),   /* FRDM-KL26Z4 Blue LED */

    kGpioSW1         = GPIO_MAKE_PIN(GPIOC_IDX, 3u),   /* FRDM-KL26Z4 switchPin1 */

};

 

Labels (1)
2 Replies

465 Views
danieltruong
Contributor IV

Hi Xiangjun,

That helps a lot. I got it now.

Thank you so much.

--Daniel

0 Kudos

465 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Daniel,

Regarding the GPIO pin, each GPIO port is given an index,the GPIOA is defined as 0, GPIOB is defined as 1, GPIOC is defined as 2, GPIOD is defined as 3..., for the code, kGpioLED1        = GPIO_MAKE_PIN(GPIOE_IDX, 31u), , pls refer to the file fsl_gpio_driver.h, which is located at:

C:\DriverE\Freescale\KSDK_1.3.0\platform\drivers\inc

/*! @brief Indicates the end of a pin configuration structure.*/
#define GPIO_PINS_OUT_OF_RANGE (0xFFFFFFFFU)

/*! @brief Bits shifted for the GPIO port number. */
#define GPIO_PORT_SHIFT (0x8U)

/*! @brief Combines the port number and the pin number into a single scalar value. */
#define GPIO_MAKE_PIN(r,p) (((r)<< GPIO_PORT_SHIFT) | (p))

/*! @brief Extracts the port number from a combined port and pin value.*/
#define GPIO_EXTRACT_PORT(v) (((v) >> GPIO_PORT_SHIFT) & 0xFFU)

/*! @brief Extracts the pin number from a combined port and pin value.*/
#define GPIO_EXTRACT_PIN(v) ((v) & 0xFFU)

In other words, GPIO pin number is defined as a 16 bits word(byte1,byte0 ), the byte0 is the pin index which ranges from 0 to 31, the byte1 is the GPIO port index, GPIOA is 0, GPIOB is 1, GPIOC is 2..., In the fsl_gpio_driver.c which is located at:C:\DriverE\Freescale\KSDK_1.3.0\platform\drivers\src, you can find the code:

void GPIO_DRV_SetPinDir(uint32_t pinName, gpio_pin_direction_t direction)
{
    GPIO_Type * gpioBase = g_gpioBase[GPIO_EXTRACT_PORT(pinName)];
    uint32_t pin = GPIO_EXTRACT_PIN(pinName);

    GPIO_HAL_SetPinDir(gpioBase, pin, direction);
}

Hope it can help you.

BTW, I suggest you use SDK2.0, which use totally different structure for GPIO.

BR

Xiangjun Rong