General Purpose Input/Output (GPIO)

Output Test

To perform GPIO output test, the following steps are mandatory.

  1. Select a GPIO pin and set the GPIO mode to output.

    GPIO_InitStruct.GPIO_Pin = GPIO_Pin;
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
    
  2. Initialize the hardware using the parameters mentioned above.

    GPIO_Init(GPIO_InitTypeDef *GPIO_InitStruct);
    
  3. Write a logic value to a specified output port pin.

    GPIO_WriteBit(u32 GPIO_Pin, u32 Pin_State);
    

Input Test

To perform GPIO input test, the following steps are mandatory.

  1. Select a GPIO pin and set the GPIO mode to input. .. code-block:: c

    GPIO_InitStruct.GPIO_Pin = GPIO_Pin; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN;

  2. Initialize the hardware using the parameters mentioned above.

    GPIO_Init(GPIO_InitTypeDef *GPIO_InitStruct);
    
  3. Read a specified output port pin.

    GPIO_ReadDataBit(u32 GPIO_Pin);
    

Interrupt Test

To perform GPIO interrupt test, the following steps are mandatory.

  1. Select a GPIO pin, set the GPIO pin mode to interrupt, no pull, and configure the interrupt trigger type, polarity, debounce.

    GPIO_InitStruct.GPIO_Pin = GPIO_Pin;
    GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_INT;
    GPIO_InitStruct.GPIO_ITTrigger = trigger_type;
    GPIO_InitStruct.GPIO_ITPolarity = polarity;
    GPIO_InitStruct.GPIO_ITDebounce=GPIO_INT_DEBOUNCE_ENABLE(or GPIO_INT_DEBOUNCE_DISABLE);
    
  2. Initialize the hardware using the parameters in step (1).

    GPIO_Init(GPIO_InitTypeDef *GPIO_InitStruct);
    
  3. Register and enable the GPIO interrupt.

    InterruptRegister(GPIO_INTHandler,GPIO_DEV_TABLE[port].IrqNum, (u32)GPIO_DEV_TABLE[por t].GPIOx, 10);
    InterruptEn(GPIO_DEV_TABLE[port].IrqNum, 10);
    
  4. (Optional) Configure the GPIO interrupt mode.

    GPIO_INTMode(u32 GPIO_Pin, u32 NewState, u32 GPIO_ITTrigger, u32 GPIO_ITPolarity, u32 GPIO_ITDebounce);
    
  5. Register the user handler.

    GPIO_UserRegIrq(GPIO_Pin, gpio_test_irq_handler, (&GPIO_InitStruct_Temp));
    
  6. Enable the specified GPIO pin interrupt.

    GPIO_INTConfig(GPIO_Pin, ENABLE);