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.

TDA4AL-Q1: How do I control gpios in vision app?

Part Number: TDA4AL-Q1

Tool/software:

Hi, TI expert,

I want to modify some pins definition to main_gpio0 for our customization board, these pins will be control camera for power sequence by vision app.

Please help me to check how do I control these gpios and checking the setting is correct or not, thanks.

Firstly, I add gpios defintion to k3-am68-sk-base-board.dts

rpi_header_gpio0_pins_default: rpi-header-gpio0-default-pins {
	pinctrl-single,pins = <
        ...
		J721S2_IOPAD(0x068, PIN_INPUT, 7) /* (U28) MCAN0_RX.GPIO0_26, Camera0_RST, for cam 0 start */
		J721S2_IOPAD(0x06c, PIN_INPUT, 7) /* (V26) MCAN1_TX.GPIO0_27, Camera0_COMREADY */
		J721S2_IOPAD(0x070, PIN_INPUT, 7) /* (R27) MCAN1_RX.GPIO0_28, Camera0_ERRO */
		J721S2_IOPAD(0x074, PIN_INPUT, 7) /* (R28) MCAN2_TX.GPIO0_29, Camera0_TRIGGER */
		J721S2_IOPAD(0x0d8, PIN_INPUT, 7) /* (AG26) SPI0_D0.GPIO0_54, CAM_PWR_EN, */
		J721S2_IOPAD(0x0dc, PIN_INPUT, 7) /* (AH26) SPI0_D1.GPIO0_55, CAM1_LS_EN, for cam 0 end */
	>;
};

Second, I add gpios definition to J721S2_pinmux_data.c

static pinmuxPerCfg_t gGpio0PinCfg[] =
{
    /* MyGPIO0 -> GPIO0_26 -> U28, Camera0_RST, for cam 0 start */
    {
        PIN_MCAN0_RX, PIN_MODE(7) | \
        ((PIN_PULL_DISABLE | PIN_INPUT_ENABLE) & (~PIN_PULL_DIRECTION))
    },
    /* MyGPIO0 -> GPIO0_27 -> V26, Camera0_COMREADY */
    {
        PIN_MCAN1_TX, PIN_MODE(7) | \
        ((PIN_PULL_DISABLE | PIN_INPUT_ENABLE) & (~PIN_PULL_DIRECTION))
    },
    /* MyGPIO0 -> GPIO0_28 -> R27, Camera0_ERRO */
    {
        PIN_MCAN1_RX, PIN_MODE(7) | \
        ((PIN_PULL_DISABLE | PIN_INPUT_ENABLE) & (~PIN_PULL_DIRECTION))
    },
    /* MyGPIO0 -> GPIO0_29 -> R28, Camera0_TRIGGER */
    {
        PIN_MCAN2_TX, PIN_MODE(7) | \
        ((PIN_PULL_DISABLE | PIN_INPUT_ENABLE) & (~PIN_PULL_DIRECTION))
    },
    /* MyGPIO0 -> GPIO0_54 -> AG26, CAM_PWR_EN */
    {
        PIN_SPI0_D0, PIN_MODE(7) | \
        ((PIN_PULL_DISABLE | PIN_INPUT_ENABLE) & (~PIN_PULL_DIRECTION))
    },
    /* MyGPIO0 -> GPIO0_55 -> AH26, CAM1_LS_EN, for cam 0 end */
    {
        PIN_SPI0_D1, PIN_MODE(7) | \
        ((PIN_PULL_DISABLE | PIN_INPUT_ENABLE) & (~PIN_PULL_DIRECTION))
    },
    {PINMUX_END}
};

Third, check main_gpio0 status in k3-j721s2-common-proc-board.dts

&main_gpio0 {
	status = "okay";
};

Forth, I want to control these pin for camera power on in run_app_single_cam.sh.

1. (AG26) SPI0_D0.GPIO0_54 needs to high

2. (AH26) SPI0_D1.GPIO0_55 needs to low

3. (U28) MCAN0_RX.GPIO0_26 needs to high

4. (R28) MCAN2_TX.GPIO0_29 needs to high

5. (V26) MCAN1_TX.GPIO0_27 needs to high

6. (R27) MCAN1_RX.GPIO0_28 needs to high

How do I implement to control gpios, please help me to point out how do I do, thanks.

  • Add one information in k3-am68-sk-base-board.dts

    &main_gpio0 {
    	status = "okay";
    	pinctrl-names = "default";
    	pinctrl-0 = <&rpi_header_gpio0_pins_default>;
    };

  • Well, from which core do you want to control it? 

    From R5F, it is straight forward, just

    - power on hte GPIO module

    - setup the pinmux

    - configure GPIO module.. 

    Regards,

    Brijesh

  • Hi, Brijesh,

    Thanks your reply.

    Yes, it is R5F core.

    Could you help to provide sample code step by step to teach me how do I control this provided by you?

    - power on hte GPIO module

    - setup the pinmux

    - configure GPIO module.. 

    Very thanks.

  • Hi, Brijesh,

    Could you help to add some gpio setting in the function of IMX390_PowerOn for example?

    code path: \imaging\sensor_drv\src\imx390\iss_sensor_imx390.c

    1. (AG26) SPI0_D0.GPIO0_54 needs to high
    2. (AH26) SPI0_D1.GPIO0_55 needs to low
    3. (U28) MCAN0_RX.GPIO0_26 needs to high
    4. (R28) MCAN2_TX.GPIO0_29 needs to high
    5. (V26) MCAN1_TX.GPIO0_27 needs to high
    6. (R27) MCAN1_RX.GPIO0_28 needs to high

    In IMX390_PowerON, we want to set power on sequence by above gpio.

    Please help me to implement. Or provide any sample I can reference.

    static int32_t IMX390_PowerOn(uint32_t chId, void *pSensorHdl)
    {
        int32_t status = 0;
    
        sp1hGainRegValueOld[chId] = 0;
        redGain_prev[chId] = greenGain_prev[chId] = blueGain_prev[chId] = 512;
    
        issLogPrintf("IMX390_PowerOn : chId = 0x%x \n", chId);
    
        return status;
    }
    

    Very thanks.

  • Hi, Brijesh,

    I try to add a function of GPIO_init() to IMX390_PowerOn in iss_sensor_imx390.c

    static int32_t IMX390_PowerOn(uint32_t chId, void *pSensorHdl)
    {
        int32_t status = 0;
    
        sp1hGainRegValueOld[chId] = 0;
        redGain_prev[chId] = greenGain_prev[chId] = blueGain_prev[chId] = 512;
    
        issLogPrintf("IMX390_PowerOn : chId = 0x%x \n", chId);
        GPIO_init(); //add
    
        return status;
    }

    And add header file in iss_sensor_priv.h

    #ifndef x86_64
    #if defined (MCU_PLUS_SDK)
    #include <drivers/i2c/v0/i2c.h>
    #include <board/board_control.h>
    #include <drivers/csirx/v1/hw_include/V1/csirx_if.h>
    #include <drivers/csirx/v1/soc/csirx_soc.h>
    #else
    #include <ti/board/src/devices/board_devices.h>
    #include <ti/drv/i2c/i2c.h>
    #include <ti/drv/i2c/soc/i2c_soc.h>
    
    #include <ti/drv/gpio/GPIO.h> //add
    #include <ti/drv/gpio/soc/GPIO_soc.h> //add
    
    #include <ti/board/src/devices/common/common.h>
    #include <ti/board/board.h>
    #include <ti/board/src/devices/board_devices.h>
    #include <ti/board/src/devices/fpd/ds90ub960.h>
    
    #include <app_remote_service.h>
    #include <app_ipc.h>
    
    #include <ti/drv/csirx/soc/V0/csirx_soc.h>
    #endif

    But when I run build command in sdk_builder $ ./make_sdk.sh

    That always print the Linking fail.

    Linking /home/fih/Workspace/EddieYLChen/test_file/eag_ti-processor-sdk-rtos-j721s2-evm-10_00_00_05_super1/vision_apps/out/J721S2/R5F/FREERTOS/release/vx_app_rtos_linux_mcu2_0.out
    
     undefined first referenced
      symbol       in file
     --------- ----------------
     GPIO_init /home/fih/Workspace/EddieYLChen/test_file/eag_ti-processor-sdk-rtos-j721s2-evm-10_00_00_05_super1/imaging/lib/J721S2/R5F/FREERTOS/release/ti_imaging_sensordrv.lib<iss_sensor_imx390.obj>
    
    error: unresolved symbols remain
    error: errors encountered during linking;
       "/home/fih/Workspace/EddieYLChen/test_file/eag_ti-processor-sdk-rtos-j721s2-
       evm-10_00_00_05_super1/vision_apps/out/J721S2/R5F/FREERTOS/release/vx_app_rt
       os_linux_mcu2_0.out" not built
    tiarmclang: error: tiarmlnk command failed with exit code 1 (use -v to see invocation)
    make[2]: *** [/home/fih/Workspace/EddieYLChen/test_file/eag_ti-processor-sdk-rtos-j721s2-evm-10_00_00_05_super1/sdk_builder/concerto/finale.mak:216: /home/fih/Workspace/EddieYLChen/test_file/eag_ti-processor-sdk-rtos-j721s2-evm-10_00_00_05_super1/vision_apps/out/J721S2/R5F/FREERTOS/release/vx_app_rtos_linux_mcu2_0.out] Error 1
    make[2]: Leaving directory '/home/fih/Workspace/EddieYLChen/test_file/eag_ti-processor-sdk-rtos-j721s2-evm-10_00_00_05_super1/vision_apps'
    make[1]: Leaving directory '/home/fih/Workspace/EddieYLChen/test_file/eag_ti-processor-sdk-rtos-j721s2-evm-10_00_00_05_super1/sdk_builder'
    make[1]: *** [makerules/makefile_vision_apps.mak:42: vision_apps] Error 2
    make: *** [Makefile:65: sdk] Error 2
    
    real    0m18.542s
    user    0m30.954s
    sys     0m5.679s

    Could you help me check why problem make this reason?

    Thanks a lot.

  • Hi,

    Can you please refer to below FAQ? It has an example of writing to GPIO, although it is integrated with DMA, but you can ignore this portion of the code. 

    https://e2e.ti.com/support/processors-group/processors/f/processors-forum/1061801/faq-tda4vm-gpio-dma-trigger-in-tda4-and-test-in-sdk7-1

    Regards,

    Brijesh

  • Hi, Brijesh

    yl is my customer.

    Few question from my side.

    (1) Why do we need to re-build sysfw? Because I do not know the reason to modify sysfw, Our SDK is base PSDK RTOS 10.00.00.05.

    (2) Could you share some sample code for GPIO control in vision app. we just need simple gpio output control in vision app code

    (3) I think customer try to use CSL driver for GPIO control in vision app source, but he seems face build link error. Do you have any suggedtion? Is it right way to use CSL in vision app code?

    https://software-dl.ti.com/jacinto7/esd/processor-sdk-rtos-j721s2/10_00_00_05/exports/docs/pdk_j721s2_10_00_00_27/docs/userguide/j721s2/modules/gpio.html

    Thank You Very Much

    Gibbs

  • Hi Gibbs,

    There is no need to rebuild sysfw. from the FAQ, you just need to take GPIO configuration part. Rest all can be ignored.

    FAQ contains GPIO configuration and it is integrated in vision apps. In the released SDK, there is no example for the GPIO control.

    No need to use CSL driver. You can directly write to registers. GPIO is a simple module, just need to write few registers to toggle output. 

    Regards,

    Brijesh 

  • Hi, Brijesh

    Thanks you reply

    Follow this replies,

    >> No need to use CSL driver. You can directly write to registers. GPIO is a simple module, just need to write few registers to toggle output

    After Studying patch, example should be like as below.

    +static void App_setupPinmux()
    +{
    +    /* Setup GPIO 37 */
    +    *(volatile uint32_t *)0x11c094 = 0x50007 | (2 << 4);
    +    *(volatile uint32_t *)0x11c098 = 0x50007 | (2 << 4);
    +    *(volatile uint32_t *)0x11c09C = 0x50007 | (2 << 4);
    +}
    +
    +static void App_initGpio()
    +{
    +    uint32_t chIdx, bitpos, gpio_id, bank_id;
    +
    +    for (chIdx = 0; chIdx < APP_NUM_CH; chIdx ++)
    +    {
    +        gpio_id = GPIO_START + chIdx;
    +        bitpos = gpio_id % 32;
    +        bank_id = gpio_id / 16;
    +
    +        *(volatile uint32_t *)0x00620044 = (1u << bitpos);
    +        *(volatile uint32_t *)0x00620038 &= ~(1u << bitpos);
    +
    +        *(volatile uint32_t *)0x0062004C = (1u << bitpos);
    +        *(volatile uint32_t *)0x00620054 = (1u << bitpos);
    +
    +        *(volatile uint32_t *)0x0062005C = (1u << bitpos);
    +
    +        *(volatile uint32_t *)0x00620044 = (1u << bitpos);
    +        *(volatile uint32_t *)0x00620038 &= ~(1u << bitpos);
    +
    +        *(volatile uint32_t *)0x00620008 = (1u << bank_id);
    +
    +        *(volatile uint32_t *)0x0062004C = (1u << bitpos);
    +        *(volatile uint32_t *)0x00620054 = (1u << bitpos);
    +    }
    +}
    +
    +static void App_setupGpioMuxIr()
    +{

    Gibbs

  • Hi Gibbs, 

    Yes, that's correct API for GPIO configuration. 

    Regards,

    Brijesh