💾
EC
  • Introduction
  • EC Course
    • Syllabus
    • Preparation for EC
    • Tutorial
      • Tutorial: arduino-stm32
        • Tutorial: arduino-stm32 Installation
        • Tutorial: arduino-stm32 Part1
        • Tutorial: arduino-stm32 Part2
      • Tutorial: MDK uVision
        • Tutorial: Installing MDK uVision
        • Tutorial: Create a Project with uVision
        • Tutorial: Adding library header in uVision
        • Tutorial: Re-using Project Configuration
        • Debugging in uVision
      • Tutorial: PlatformIO in CLion
      • Tutorial: PlatformIO in VSCode
      • Tutorial: Repository Management
      • Tutorial: Managing library header files
      • Tutorial: PinName Configuration
      • Tutorial: Bitwise Macro
      • Tutorial: Custom initialization
      • Tutorial: Documentation
      • Tutorial: Creating Application API
      • Tutorial: 7-Segment Display
      • Tutorial: DC motor driver connection
      • Tutorial: USART with TeraTerm
      • Tutorial: Finite State Machine programming
      • Tutorial: Bluetooth
      • Tutorial: Zigbee with Nucleo board
    • LAB
      • LAB Report Template
      • LAB: Smart mini-fan with STM32-duino
      • LAB: Portable Fan with mbed
      • LAB: GPIO Digital InOut
      • LAB: GPIO Digital InOut 7-segment
      • LAB: EXTI & SysTick
      • LAB: Timer & PWM
      • LAB: Stepper Motor
      • LAB: Input Capture - Ultrasonic
      • LAB: USART - LED, Bluetooth
      • LAB: ADC - IR reflective sensor
      • LAB: Line Tracing RC Car
    • Sample code
      • Code Templates
    • Hardware
      • Nucleo-F411RE
      • LAB Hardware
        • Electronic Chips
        • HUINS Embedded Kit
    • Projects
      • Line Tracing Car Project
      • Design Project
        • Past Projects
      • Project Grading Criteria
    • Study Resource for MCU
      • Hexa-Decimal Table
      • Bitwise Op for Register
      • System Clock
      • Timer
      • USART
      • ADC
  • STM32 M4 Programming
    • Documentation
      • C++ API Docs
    • Firmware Library
      • PinName Configuration
      • GPIO Digital
      • RCC
      • EXTI_SysTick
      • TIMER
      • USART
    • Troubleshooting
    • mbed for STM32
      • Tutorial: mbed-Part 1
      • Tutorial: mbed - Part 2
      • Tutorial: mbed - Part 3
      • Using mbed API on uVision
    • mbed OS
  • Other Programming
    • Arduino
    • Socket Programming
      • Window Socket Programming
      • Arduino WiFi
    • Cube-MX
    • Github
    • Markdown
      • Example: API documentation
    • MATLAB
  • C Programming
    • C-Programming Lessons
      • Installing Visual Studio Community
        • Visual Studio Community 2022
      • Installing VS Code(Mac/Linux)
      • Creating Header Lib
      • Pointer
      • Array
      • 2D Array
      • Structure
      • Dynamic Alloc
      • Bitwise Operation
  • Numerical Programming
    • Syllabus
    • Preparation for NP
    • Math Review
    • Tutorial
      • TA Session Video
      • Tutorial: NP Library Header Files
      • Tutorial - Sine Taylor
      • Tutorial: Passing a Function, Function callback
      • Tutorial: Nonlinear solver
      • Tutorial: Differentiation
      • Tutorial: Integration
      • Tutorial: Matrix Structure
      • Tutorial: Eigenvalue problem
      • Tutorial: ODE-IVP
      • Tutorial: Curve Fitting
      • Tutorial: Create Github Repos of NP lib
      • Tutorial: Version Control in Github
      • Tutorial: Documentation with Markdown
      • Exercise: Version Control and Documentation
    • Example: MATLAB
    • Example: NP Library
    • Assignment
      • Assignment Factorial and Power
      • Assignment: Version Control and Documentation
    • Problem Bank
Powered by GitBook
On this page
  • Embedded Controller HAL Library
  • GPIO Digital InOut
  • Header File
  • GPIO_init()
  • GPIO_mode()
  • GPIO_write()
  • GPIO_read()
  • GPIO_ospeed()
  • GPIO_otype()
  • GPIO_pupdr()
  • Class or Header name
  • Function Name

Was this helpful?

  1. STM32 M4 Programming

Documentation

PreviousADCNextC++ API Docs

Last updated 9 months ago

Was this helpful?

for the example documentation

Embedded Controller HAL Library

Written by: Your Name

Program: C/C++

IDE/Compiler: Keil uVision 5

OS: WIn10

MCU: STM32F411RE, Nucleo-64

Table of Contents

GPIO Digital InOut

Header File

#include "ecGPIO.h"

#include "stm32f411xe.h"
#include "ecRCC.h"

#ifndef __ECGPIO_H
#define __ECGPIO_H

// MODER
#define INPUT  		0x00
#define OUTPUT 		0x01
#define AF     		0x02
#define ANALOG 		0x03

// IDR & ODR
#define HIGH 		1
#define LOW  		0

// OSPEED
#define LOW_SPEED		0x00
#define MID_SPEED		0x01
#define FAST_SPEED		0x02
#define HIGH_SPEED		0x03

// OTYPER
#define PUSH_PULL 		0	// Push-pull
#define OPEN_DRAIN 		1 	// Open-Drain

// PUDR
#define NO_PUPD			0x00 	// No pull-up, pull-down
#define PULL_UP			0x01 	// Pull-up
#define PULL_DOWN 		0x02 	// Pull-down	
#define RESERVED 		0x03 	// Reserved

// PIN
#define LED_PIN 		5
#define BUTTON_PIN 		13

#ifdef __cplusplus
 extern "C" {
#endif /* __cplusplus */
	 
void GPIO_init(GPIO_TypeDef *Port, int pin, int mode);
void GPIO_mode(GPIO_TypeDef* Port, int pin, int mode);
void GPIO_write(GPIO_TypeDef *Port, int pin, int output);
int  GPIO_read(GPIO_TypeDef *Port, int pin);
void GPIO_ospeed(GPIO_TypeDef* Port, int pin, int speed);
void GPIO_otype(GPIO_TypeDef* Port, int pin, int type);
void GPIO_pupdr(GPIO_TypeDef* Port, int pin, int pupd);

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif

GPIO_init()

Initializes GPIO pins with default setting and Enables GPIO Clock. Mode: In/Out/AF/Analog

void GPIO_init(GPIO_TypeDef *Port, int pin, int mode);

Parameters

  • Port: Port Number, GPIOA~GPIOH

  • pin: pin number (int) 0~15

  • mode: INPUT(0), OUTPUT(1), AF(02), ANALOG (03)

Example code

GPIO_init(GPIOA, 5, OUTPUT);
GPIO_init(GPIOC, 13, INPUT); //GPIO_init(GPIOC, 13, 0);

GPIO_mode()

Configures GPIO pin modes: In/Out/AF/Analog

void GPIO_init(GPIO_TypeDef *Port, int pin, int mode);

Parameters

  • Port: Port Number, GPIOA~GPIOH

  • pin: pin number (int) 0~15

  • mode: INPUT (0), OUTPUT (1), AF(02), ANALOG (03)

Example code

GPIO_mode(GPIOA, 5, OUTPUT);

GPIO_write()

Write the data to GPIO pin: High, Low

write(GPIO_TypeDef *Port, int pin, int output);

Parameters

  • Port: Port Number, GPIOA~GPIOH

  • pin: pin number (int) 0~15

  • output: LOW(0), HIGH(1)

Example code

GPIO_write(GPIOA, 5, 1);  // 1: High

GPIO_read()

Read the data from GPIO pin

int  GPIO_read(GPIO_TypeDef *Port, int pin);

Parameters

  • Port: Port Number, GPIOA~GPIOH

  • pin: pin number (int) 0~15

Example code

GPIO_read(GPIOC, 13);

GPIO_ospeed()

Configures output speed of GPIO pin : Low, Mid, Fast, High

void GPIO_ospeed(GPIO_TypeDef* Port, int pin, int speed);

Parameters

  • Port: Port Number, GPIOA~GPIOH

  • pin: pin number (int) 0~15

  • speed: LOW_SPEED(0), MID_SPEED(1), FAST_SPEED(2) , HIGH_SPEED(3)

Example code

GPIO_ospeed(GPIOA, 5, 2);  // 2: FAST_SPEED

GPIO_otype()

Configures output type of GPIO pin: Push-Pull / Open-Drain

void GPIO_otype(GPIO_TypeDef* Port, int pin, int type);

Parameters

  • Port: Port Number, GPIOA~GPIOH

  • pin: pin number (int) 0~15

  • type: PUSH_PULL(0), OPEN_DRAIN(1)

Example code

GPIO_otype(GPIOA, 5, 0);  // 0: Push-Pull

GPIO_pupdr()

Configures Pull-up/Pull-down mode of GPIO pin: No Pull-up, Pull-down/ Pull-up/ Pull-down/ Reserved

void GPIO_pupdr(GPIO_TypeDef* Port, int pin, int pupd);

Parameters

  • Port: Port Number, GPIOA~GPIOH

  • pin: pin number (int) 0~15

  • pupd: NO_PUPD(0), PULL_UP(1), PULL_DOWN(2), RESERVED(3)

Example code

GPIO_pupdr(GPIOA, 5, 0);  // 0: No Pull-up, Pull-down

Class or Header name

Function Name

Parameters

  • p1

  • p2

Example code

See Class Github
GPIO Digital In/Out
Header File
GPIO_init()
GPIO_mode()
GPIO_write()
GPIO_read()
GPIO_ospeed()
GPIO_otype()
GPIO_pupdr()