This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTOS/LAUNCHXL-CC2640R2: GPIO configuration - Static/dynamic - TI-RTOS

Part Number: LAUNCHXL-CC2640R2

Tool/software: TI-RTOS

I'm trying to configure a GPIO to cause an interrupt, as the input goes from high to low. I'm using the GPIO-driver, but whether I try to configure it static with the config arrays or dynamic in run-time, I can't get it right. 


1. Underneath you can see my code for the static configuration, int the following order: 1. BoardGpioInitTable, 2. gpioCallbackFunctions, 3. gpioPinConfigs

1. BoardGpioInitTable:

const PIN_Config BoardGpioInitTable[] = {

    CC2640R2_LAUNCHXL_PIN_RLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,       /* LED initially off */
    CC2640R2_LAUNCHXL_PIN_GLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,       /* LED initially off */
    CC2640R2_LAUNCHXL_PIN_BTN1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS,          /* Button is active low */
    CC2640R2_LAUNCHXL_PIN_BTN2 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS,          /* Button is active low */
    CC2640R2_LAUNCHXL_DIO22 | PIN_INPUT_EN | PIN_IRQ_NEGEDGE | PIN_HYSTERESIS,    /* !!! MY CONFIG !!!  */
    CC2640R2_LAUNCHXL_SPI_FLASH_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN,  /* External flash chip select */
    CC2640R2_LAUNCHXL_UART_RX | PIN_INPUT_EN | PIN_PULLDOWN,                                              /* UART RX via debugger back channel */
    CC2640R2_LAUNCHXL_UART_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL,                        /* UART TX via debugger back channel */
    CC2640R2_LAUNCHXL_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN,                                            /* SPI master out - slave in */
    CC2640R2_LAUNCHXL_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN,                                            /* SPI master in - slave out */
    CC2640R2_LAUNCHXL_SPI0_CLK | PIN_INPUT_EN | PIN_PULLDOWN,                                             /* SPI clock */

    PIN_TERMINATE
};

2. gpioCallbackFunctions: 

GPIO_CallbackFxn gpioCallbackFunctions[] = {
    NULL,  /* !!! MY CONFIG !!! */
    NULL,  /* Button 1 */
    NULL,  /* Button 2 */
    NULL,  /* CC2640R2_LAUNCHXL_SPI_MASTER_READY */
    NULL,  /* CC2640R2_LAUNCHXL_SPI_SLAVE_READY */
}; 

3. gpioPinConfigs: 

GPIO_PinConfig gpioPinConfigs[] = {
    /* Input pins */
    GPIOCC26XX_DIO_22 | GPIO_DO_NOT_CONFIG,  /* !!! MY CONFIG !!! */
    GPIOCC26XX_DIO_13 | GPIO_DO_NOT_CONFIG,  /* Button 1 */
    GPIOCC26XX_DIO_14 | GPIO_DO_NOT_CONFIG,  /* Button 2 */

    GPIOCC26XX_DIO_15 | GPIO_DO_NOT_CONFIG,  /* CC2640R2_LAUNCHXL_SPI_MASTER_READY */
    GPIOCC26XX_DIO_21 | GPIO_DO_NOT_CONFIG,  /* CC2640R2_LAUNCHXL_SPI_SLAVE_READY */

    /* Output pins */
    GPIOCC26XX_DIO_07 | GPIO_DO_NOT_CONFIG,  /* Green LED */
    GPIOCC26XX_DIO_06 | GPIO_DO_NOT_CONFIG,  /* Red LED */
    GPIOCC26XX_DIO_30 | GPIO_DO_NOT_CONFIG,  /* TMP116_EN */

    /* SPI Flash CSN */
    GPIOCC26XX_DIO_20 | GPIO_DO_NOT_CONFIG,

    /* SD CS */
    GPIOCC26XX_DIO_21 | GPIO_DO_NOT_CONFIG,

    /* Sharp Display - GPIO configurations will be done in the Display files */
    GPIOCC26XX_DIO_24 | GPIO_DO_NOT_CONFIG, /* SPI chip select */
    GPIOCC26XX_DIO_22 | GPIO_DO_NOT_CONFIG, /* LCD power control */
    GPIOCC26XX_DIO_23 | GPIO_DO_NOT_CONFIG, /*LCD enable */

};

As far as I understand, the Board_init does setup the configuration table for all IOs, and any IOs that isn't stated in the BoardGpioInitTable will be set to default values. Later on, when the GPIO_init is called, the previous IO table is copied to the configArray, and the pins are reconfigured if they haven't been "ORed" with the "GPIO_DO_NOT_CONFIG"-macro in the gpioPinConfigs-table. The callback functions for the interrupt-pins are stated in the gpioCallbackFunctions, respectively to the BaordGpioInitTable's order of the pins. I've done it dynamic, with the following line: 

GPIO_setCallback(Board_DIO22, DIO22_intFxn);

When I do it this way, the program goes in exception-mode, after I try to configure the callback function dynamic. 


2. Underneath you can see the default static tables, as I try to configure the IOs dynamic. 

1. BoardGpioInitTable:

const PIN_Config BoardGpioInitTable[] = {

    CC2640R2_LAUNCHXL_PIN_RLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,       /* LED initially off */
    CC2640R2_LAUNCHXL_PIN_GLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,       /* LED initially off */
    CC2640R2_LAUNCHXL_PIN_BTN1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS,          /* Button is active low */
    CC2640R2_LAUNCHXL_PIN_BTN2 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS,          /* Button is active low */
    CC2640R2_LAUNCHXL_SPI_FLASH_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN,  /* External flash chip select */
    CC2640R2_LAUNCHXL_UART_RX | PIN_INPUT_EN | PIN_PULLDOWN,                                              /* UART RX via debugger back channel */
    CC2640R2_LAUNCHXL_UART_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL,                        /* UART TX via debugger back channel */
    CC2640R2_LAUNCHXL_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN,                                            /* SPI master out - slave in */
    CC2640R2_LAUNCHXL_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN,                                            /* SPI master in - slave out */
    CC2640R2_LAUNCHXL_SPI0_CLK | PIN_INPUT_EN | PIN_PULLDOWN,                                             /* SPI clock */

    PIN_TERMINATE
};

2. gpioCallbackFunctions: 
GPIO_CallbackFxn gpioCallbackFunctions[] = {
    NULL,  /* Button 1 */
    NULL,  /* Button 2 */
    NULL,  /* CC2640R2_LAUNCHXL_SPI_MASTER_READY */
    NULL,  /* CC2640R2_LAUNCHXL_SPI_SLAVE_READY */
};

3. gpioPinConfigs: 
GPIO_PinConfig gpioPinConfigs[] = {
    /* Input pins */
    GPIOCC26XX_DIO_13 | GPIO_DO_NOT_CONFIG,  /* Button 1 */
    GPIOCC26XX_DIO_14 | GPIO_DO_NOT_CONFIG,  /* Button 2 */

    GPIOCC26XX_DIO_15 | GPIO_DO_NOT_CONFIG,  /* CC2640R2_LAUNCHXL_SPI_MASTER_READY */
    GPIOCC26XX_DIO_21 | GPIO_DO_NOT_CONFIG,  /* CC2640R2_LAUNCHXL_SPI_SLAVE_READY */

    /* Output pins */
    GPIOCC26XX_DIO_07 | GPIO_DO_NOT_CONFIG,  /* Green LED */
    GPIOCC26XX_DIO_06 | GPIO_DO_NOT_CONFIG,  /* Red LED */
    GPIOCC26XX_DIO_30 | GPIO_DO_NOT_CONFIG,  /* TMP116_EN */

    /* SPI Flash CSN */
    GPIOCC26XX_DIO_20 | GPIO_DO_NOT_CONFIG,

    /* SD CS */
    GPIOCC26XX_DIO_21 | GPIO_DO_NOT_CONFIG,

    /* Sharp Display - GPIO configurations will be done in the Display files */
    GPIOCC26XX_DIO_24 | GPIO_DO_NOT_CONFIG, /* SPI chip select */
    GPIOCC26XX_DIO_22 | GPIO_DO_NOT_CONFIG, /* LCD power control */
    GPIOCC26XX_DIO_23 | GPIO_DO_NOT_CONFIG, /*LCD enable */

};

Underneath you can see my dynamic configuration, that is done after I've called the Board_init and the GPIO_init: 

/* Configure the button pin */
GPIO_setConfig(Board_DIO22, GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_FALLING);

/* install Button callback */
GPIO_setCallback(Board_DIO22, DIO22_intFxn);

/* Enable interrupts */
GPIO_enableInt(Board_DIO22);

When I do it this way, the code runs, but doesn't interrupt on falling nor rising edges. 

I've tried to debug the code, and see how the DIO22-configuration-register changes through the configuration, with the GPIO_getConfig()-fxn, as written below: 

GPIO_getConfig(Board_DIO22, &testDIO22); // testDIO22 = 00100001000000110010111101011000b
GPIO_setConfig(Board_DIO22, GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_FALLING);
GPIO_getConfig(Board_DIO22, &testDIO22); // testDIO22 =00100000000000000010111101011000b

I see that the 5 lower bits are not "10110 = 22", as I'd expect. The upper 16 pins are right though, according to my dynamic configuration settings. I don't understand why bit 29 = '1' though. 


I've tried to look up other posts, but with no luck. Neither have I found an answer in the driver-manuals. So my questions are:
1. How to configure GPIOs static
2. How to configure GPIOs dynamic 

  • Hi Peter,

    I think your problem lies in the fact that you use "Board_DIO22". This define should be the DIO number (22) on the device which is not the same as the GPIO index which the GPIO driver expects. In the CC2640R2_LAUNCHXL.h file, you should find an CC2640R2_LAUNCHXL_GPIONames enum which maps 1 to 1 with the gpioPinConfigs struct.

    For example, in your case, if you want to address the "MY CONFIG" GPIO, you would address index 0 as it is the first in the array, not Board_DIO22 (which would be the 22nd element in the array).
  • Hi M-W - thank you for your response, it makes much more sense now, and solves both my dynamic configuration and the dynamic configuration.

    But now I wonder, if this is the correct way to set up the GPIOs, because it seems a bit complicated to edit in the LAUNCHXL.h file, to make it possible to configure the GPIOs with success?
    How should it be done if a new so far unconfigured GPIO, should be configured?
  • Hi Peter,

    Adding new GPIOs to the driver in run-time (and with that, I mean GPIOs not defined in the struct) is not supported. You would need to have any GPIO you expect to use in this table.

    The alternative which I typically recommend is the PIN driver. It does not depend on any pre-defined structures in the board file but takes a configuration struct as a "open" argument. Generally, I would say the PIN driver for the CC13xx/CC26xx is the one you should be using if you are free to make the selection between PIN and GPIO. A positive point with using PIN is that your flash footprint will most likely go down as GPIO is a wrapper around the PIN driver.