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.

MSP432 TI-RTOS GPIO configure

Good day, please tell me how to configure the GPIO in tirtos_msp43x_2_14_03_28. In the TI-RTOS User's Guide is written about GPIO_PinConfig and GPIO_setConfig (unsigned int index, GPIO_PinConfig pinConfig), but I can't understand how to use it. I want to configure P4.1 as output and set high logic level, how can I do it?

  • GPIO_setConfig() is used to reconfigure a pin during runtime, after the initial configuration has been applied according to the GPIO_PinConfig array.  The GPIO_PinConfig array defines a set of pins to configure along with their configuration, and GPIO_setConfig() changes one of those (that's what the index parameter is for, to specify which element of the GPIO_PinConfig array to change).

    An example of a GPIO_PinConfig array can be found in one of the MSP432 examples:
        tirtos_msp43x_2_14_03_28/tirtos_msp43x_2_14_03_28_examples/MSP432/TI/MSP_EXP432P401R/gpiointerrupt/MSP_EXP432P401R.c

    Here is the array:

    /*
     * Array of Pin configurations
     * NOTE: The order of the pin configurations must coincide with what was
     *       defined in MSP_EXP432P401R.h
     * NOTE: Pins not used for interrupts should be placed at the end of the
     *       array.  Callback entries can be omitted from callbacks array to
     *       reduce memory usage.
     */
    GPIO_PinConfig gpioPinConfigs[] = {
        /* Input pins */
        /* MSP_EXP432P401R_S1 */
        GPIOMSP432_P1_1 | GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_RISING,
        /* MSP_EXP432P401R_S2 */
        GPIOMSP432_P1_4 | GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_RISING,

        /* Output pins */
        /* MSP_EXP432P401R_LED1 */
        GPIOMSP432_P1_0 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW,
        /* MSP_EXP432P401R_LED_RED */
        GPIOMSP432_P2_0 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW,

        /*
         * MSP_EXP432P401R_LED_GREEN & MSP_EXP432P401R_LED_BLUE are used for
         * PWM examples.  Uncomment the following lines if you would like to control
         * the LEDs with the GPIO driver.
         */
        /* MSP_EXP432P401R_LED_GREEN */
        //GPIOMSP432_P2_1 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW,
        /* MSP_EXP432P401R_LED_BLUE */
        //GPIOMSP432_P2_2 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW
    };

    Note that this example array is not configuring P4.1 that you want, but you can change this array to configure just P4.1 (and make sure to follow the note in the comment above about matching the order in the corresponding enum MSP_EXP432P401R_GPIOName in MSP_EXP432P401R.h).

    Once you have specified P4.1 in this array (I assume that is symbol GPIOMSP432_P4_1) and called GPIO_init(), the pin will be configured.  GPIO_setConfig() could be used to change this configuration at runtime (where the index parameter would match the index in the above array).

    Does this make sense?

    Regards,

    - Rob

  • Yes, thank You very much! But I still have a few questions. GPIO_init() must be called only once? And GPIO_PinConfig array must be defined before GPIO_init() is called? Thus, to configure the pin, I have to change the GPIO_PinConfig array in the MSP_EXP432P401R.c file and add a line to MSP_EXP432P401R_GPIOName in the MSP_EXP432P401R.h file? If I want to reconfigure it, I must call GPIO_setConfig(index, pinConfig), where index - sequence pin number in MSP_EXP432P401R_GPIOName structure, and pinConfig = GPIOMSP432_P4_1 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW, I right? And the last question, can I configure pins by MSPWare?

  • Artem Ilchenko said:
    GPIO_init() must be called only once?

    You can see for yourself what it does by looking in tirtos_msp43x_2_14_03_28/packages/ti/drivers/gpio/GPIOMSP432.c.  Here you will see that it calls GPIO_setConfig() and GPIO_setCallback(), based on the GPIOMSP432_config structure.  If you changed that config after already having called GPIO_init() then you would need to call it a second time in order for your config change to apply.  Calling it a second time without having changed the config would re-initialize the GPIOs, which could be useful if you manually called GPIO_setConfig() after the first GPIO_init() and you wanted to "reset" things.

    But typically you would just call it once.

    Artem Ilchenko said:
    And GPIO_PinConfig array must be defined before GPIO_init() is called?

    Yes.

    Artem Ilchenko said:
    Thus, to configure the pin, I have to change the GPIO_PinConfig array in the MSP_EXP432P401R.c file and add a line to MSP_EXP432P401R_GPIOName in the MSP_EXP432P401R.h file?

    Yes.  Either add an element or replace an existing one that you don't need, while ensuring that the MSP_EXP432P401R_GPIOName enum stays in sync.

    Artem Ilchenko said:
     If I want to reconfigure it, I must call GPIO_setConfig(index, pinConfig), where index - sequence pin number in MSP_EXP432P401R_GPIOName structure, and pinConfig = GPIOMSP432_P4_1 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW, I right?

    Yes, that sounds like the right approach (although, as alluded to above, you could change the GPIO_PinConfig global array and call GPIO_init() again, but that's not as clean as calling GPIO_setConfig() alone).

    Artem Ilchenko said:
    And the last question, can I configure pins by MSPWare?

    I will need to consult a colleague about MSPWare.

    Regards,

    - Rob

  • Thank you for the answers! About MSPWare, TI-RTOS function Board_initUART() performs the following code:

    /* Set P1.2 & P1.3 in UART mode */
    MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,
    GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION);
    
    /* Set P3.2 & P3.3 in UART mode */
    MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P3,
    GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION);
    
    /* Initialize the UART driver */
    UART_init();

    I so understand, that I can configure ports, using these functions. I would like to clarify to what extent this is acceptable.

  • Artem Ilchenko said:

    TI-RTOS function Board_initUART() performs the following code:

    /* Set P1.2 & P1.3 in UART mode */
    MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,
    GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION);
    
    /* Set P3.2 & P3.3 in UART mode */
    MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P3,
    GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION);
    
    /* Initialize the UART driver */
    UART_init();

    I so understand, that I can configure ports, using these functions. I would like to clarify to what extent this is acceptable.

    Yes, you can use the MAP_GPIO_setAsPeripheralModuleFunctionInputPin() driverlib API (as well as other driverlib APIs), just make sure you don't change any pins that you want TI-RTOS drivers to manage in your application.

    Regards,

    - Rob