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.

[FAQ] TDA4VM: Using PDK GPIO driver

Part Number: TDA4VM

Hi,

Can someone share simple steps to toggle GPIO and configuring GPIO interrupt using PDK GPIO driver.

  • Toggling a GPIO PIN

    To toggle a GPIO Pin using the GPIO driver, do the following steps:

    1. PinMuxing

    Make sure that the pin you are using is set in GPIO mode. You can use the following API from board library.

    Board_pinmuxSetReg(SOC_DOMAIN, OFFSET, MODE);

    2. Set the base address

    Set the base address according the domain in which GPIO instance lies.

    GPIO_socGetInitCfg(Port, &gpio_cfg);
    
    gpio_cfg.baseAddr = CSL_xxxx_GPIO0_BASE;
    
    GPIO_socSetInitCfg(Port, &gpio_cfg);
    
    Where Port is GPIO instance in the given domain
     

    3. GPIO Init

    Do GPIO init. Before calling GPIO init, make sure the following structures are defined.

    GPIO_PinConfig gpioPinConfigs[] =
    
    {
    
        PIN | DIR,
        PIN | DIR,
    ….
    ….
    
    };
     

    Where PIN should be a hexadecimal value 0xABCD

    Where AB represents Port number and CD represents the Pin number. For example, for configuring WKUP_GPIO0_16: PIN = 0x0010 and DIR = GPIO_CFG_OUTPUT or GPIO_CFG_INPUT

    GPIO_CallbackFxn gpioCallbackFunctions[] =
    
    {
        NULL,
        NULL
    
    };
     

    You can set the callback function using this structure, but for this use case we can keep it NULL 

    GPIO_v0_Config{
    
        GPIO_PinConfig *pinConfigs;     /*! Pointer to the board's PinConfig array */
    
        GPIO_CallbackFxn *callbacks;     /*! Pointer to the board's callback array */
    
        uint32_t numberOfPinConfigs;     /*! Number of pin configs defined */
    
        uint32_t numberOfCallbacks;      /*! Number of callbacks defined */
    
        /*! Interrupt priority used for call back interrupts. Setting ~0 will
    
         * configure the lowest possible priority
    
         */
    
        uint32_t intPriority;
    
    }

    Call GPIO_init();

    4. Call GPIO_write(PIN_INDEX, 0/1); to change the state of GPIO

    Here PIN_INDEX is the index of  gpioPinConfigs structure for which you want to change the state.

     

    Configuring GPIO interrupt

    • Modify the GPIO_PinConfig structure to add the pin for which the interrupt needs to be triggered
      • Set the interrupt trigger - rising or falling or both edges. For example:
        • PIN1 | GPIO_CFG_IN_INT_RISING | GPIO_CFG_INPUT
    • Before GPIO init do interrupt related configuration

    gpio_cfg.baseAddr = CSL_xxxx_GPIO0_BASE;
    
    intCfg = gpio_cfg.intCfg;
    
    bankNum = PinNumber/16;
    
    intCfg[PinNumber].intNum = IntRTR_OUTPUT_0 + bankNum;
    
    intCfg[PinNumber].intcMuxNum = INVALID_INTC_MUX_NUM;
    
    intCfg[PinNumber].intcMuxInEvent = 0;
    
    intCfg[PinNumber].intcMuxOutEvent = 0;
     

    • Call GPIO_init();
    • Set the callback by calling GPIO_setCallback(PIN_Index, call back API)
    • GPIO_enableInt(PIN_INDEX)

    Where PIN_INDEX is the index of  gpioPinConfigs structure for which you want to change the state.