GlobLib
HAL and API libraries for MCUs and hardware.

This module contains low level functions GPIO access. More...

Files

file  stm32f103cb_gpio.h
 Header file for stm32f103 GPIO.
 

Enumerations

Functions

mcu_error pinSetup (gpio_mode mode, gpio_port port, gpio_pin pin)
 Setup a GPIO pin for a given function. More...
 
void pinHigh (gpio_port port, gpio_pin pin)
 Set a given gpio pin on a port to logic high. More...
 
void pinLow (gpio_port port, gpio_pin pin)
 Set a given gpio pin on a port to logic low. More...
 
void pinWrite (gpio_port port, gpio_pin pin, gpio_state state)
 Set a given gpio pin on a port to a logic state. More...
 
void pinToggle (gpio_port port, gpio_pin pin)
 Toggle the output of a given pin on a port. More...
 
uint8_t pinRead (gpio_port port, gpio_pin pin)
 Read the current digital value of an input pin. More...
 
mcu_error GPIO_ISREnable (gpio_port port, gpio_pin pin, gpio_isr trigger, void(*handle)(void))
 Setup interrupts on a gpio port / pin. More...
 
mcu_error GPIO_ISRDisable (gpio_pin pin)
 Disable interrupts on a gpio port / pin. More...
 

Detailed Description

This module contains low level functions GPIO access.

This header file is included in other modules. It acts as a bridge between peripheral modules such as USART and the cmsis libraries they use.

Author
Stuart Ianna
Version
0.1
Date
May 2018
Warning
None
Bug:
None
Todo:
  • Interrupt priorities
Compilers
  • arm-none-eabi-gcc (15:4.9.3+svn231177-1) 4.9.3 20150529 (prerelease)
Minimum working example (blinky)
//Change to include appropriate MCU target
int main(void){
//Setup port C pin 13 for digital output
while(1){
//Toggle the pin's output value
//Wait a bit
for(int i = 0; i < 0x7FFF; i++);
}
return 0;
}
Minimum working example (Pin input)
//Change to include appropriate MCU target
int main(void){
//Setup port C pin 13 for digital output
//Setup port A pin 6 for digital input
while(1){
//Set output to pin input value (Inverse logic);
//Wait a bit
for(int i = 0; i < 0x7FFF; i++);
}
return 0;
}
Minimum working example (interrupt)
//Change to include appropriate MCU target
//Function to call for interrupt event
void callme(void);
int main(void){
//Setup port C pin 13 for digital output
//Setup the ISR
while(1){
//Do nothing
}
return 0;
}
void callme(void){
//Toggle the pin's output value
}

Enumeration Type Documentation

enum gpio_isr

GPIO interrupt options for pins.

corresponds with the memory address offset used.

Enumerator
GPIO_RISING 

Interrupt occurs on rising edge detection.

GPIO_FALLING 

Interrupt occurs on falling edge detection.

GPIO_BOTH 

Interrupt occurs on rising and falling edge detection.

Definition at line 96 of file stm32f103cb_gpio.h.

enum gpio_mem

GPIO memory address base and offsets.

These macros are used intenally to access GPIO configuration ports

Enumerator
GPIO_BASE 

Base memory address for GPIO peripheral.

CRL_OFFSET 

Control register low memory offset.

CRH_OFFSET 

Control register high memory offset.

IDR_OFFSET 

Port input data register.

ODR_OFFSET 

Port output data register.

BSRR_OFFSET 

Port bit set/reset register.

BRR_OFFSET 

Port bit reset register.

LCKR_OFFSET 

Port configuration lock register.

Definition at line 131 of file stm32f103cb_gpio.h.

enum gpio_mode

GPIO setup options.

These values are used when setting up the pin for use. Hexidecimal values used are memory address offsets to access the port.

Enumerator
GPIO_DI 

Setup the port for digital input.

GPIO_DO 

Setup the port for digital output.

GPIO_UART_TX 

Setup the port for USART transmit.

GPIO_UART_RX 

Setup the port for USART receive.

GPIO_I2C 

Setup the port for I2C.

GPIO_PWM 

Setup the port for output PWM.

GPIO_IC 

Setup the port for input capture.

GPIO_ADC 

Setup the port for ADC.

GPIO_SPI_OUT 

Setup the port for output SPI.

GPIO_SPI_IN 

Setup the port for input SPI.

Definition at line 58 of file stm32f103cb_gpio.h.

enum gpio_pin

GPIO pins available for each port.

These macros are used to access the hardware pins for each port. Each hexidecimal number corresponds with the memory address offset used.

Enumerator
PIN0 

Pin 0 of the port.

PIN1 

Pin 1 of the port.

PIN2 

Pin 2 of the port.

PIN3 

Pin 3 of the port.

PIN4 

Pin 4 of the port.

PIN5 

Pin 5 of the port.

PIN6 

Pin 6 of the port.

PIN7 

Pin 7 of the port.

PIN8 

Pin 8 of the port.

PIN9 

Pin 9 of the port.

PIN10 

Pin 10 of the port.

PIN11 

Pin 11 of the port.

PIN12 

Pin 12 of the port.

PIN13 

Pin 13 of the port.

PIN14 

Pin 14 of the port.

PIN15 

Pin 15 of the port.

Definition at line 107 of file stm32f103cb_gpio.h.

enum gpio_port

GPIO ports available for the MCU.

These values are used to access the hardware pins for each port. Each hexidecimal number corresponds with the memory address offset used.

Enumerator
PORTA 

Port A of the MCU.

PORTB 

Port B of the MCU.

PORTC 

Port C of the MCU.

Definition at line 85 of file stm32f103cb_gpio.h.

enum gpio_state

GPIO pin states.

These values are used when writing a value to a pin with pinWrite().

Enumerator
GPIO_LOW 

Set the corresponding pin to logic low.

GPIO_HIGH 

Set the corresponding pin to logic high.

Definition at line 75 of file stm32f103cb_gpio.h.

Function Documentation

mcu_error GPIO_ISRDisable ( gpio_pin  pin)

Disable interrupts on a gpio port / pin.

This function clears all previous setting of the interrupt.

Parameters
pinThe pin of the port, defined by gpio_pin
Returns
error code defined by mcu_error

Definition at line 484 of file stm32f103cb_gpio.c.

mcu_error GPIO_ISREnable ( gpio_port  port,
gpio_pin  pin,
gpio_isr  trigger,
void(*)(void)  handle 
)

Setup interrupts on a gpio port / pin.

The MCU can only support one external interrupt per pin number. For example, pin 2 cannot have an interrupt on port A and B, E_GPIO_ISR is return if this is attempted.

Parameters
portThe port of the MCU, defined by gpio_port
pinThe pin of the port, defined by gpio_pin
triggerThe interrupt trigger, define by gpio_isr
handlePointer to the function to be called on interrupt event.
Returns
none

Definition at line 133 of file stm32f103cb_gpio.c.

void pinHigh ( gpio_port  port,
gpio_pin  pin 
)

Set a given gpio pin on a port to logic high.

Pin must be set for digital output to use this function

Parameters
portThe port of the MCU, defined by gpio_port
pinThe pin of the port, defined by gpio_pin
Returns
none.

Definition at line 91 of file stm32f103cb_gpio.c.

void pinLow ( gpio_port  port,
gpio_pin  pin 
)

Set a given gpio pin on a port to logic low.

Pin must be set for digital output to use this function

Parameters
portThe port of the MCU, defined by gpio_port
pinThe pin of the port, defined by gpio_pin
Returns
none.

Definition at line 97 of file stm32f103cb_gpio.c.

uint8_t pinRead ( gpio_port  port,
gpio_pin  pin 
)

Read the current digital value of an input pin.

Pin must be set for digital input to use this function

Parameters
portThe port of the MCU, defined by gpio_port
pinThe pin of the port, defined by gpio_pin
Returns
The value of the pin. 1 = Logic high, 0 = logic low.

Definition at line 123 of file stm32f103cb_gpio.c.

mcu_error pinSetup ( gpio_mode  mode,
gpio_port  port,
gpio_pin  pin 
)

Setup a GPIO pin for a given function.

This function is also employed by other modules to configure pins and ports.

Parameters
modeThe mode for the pin to operate, defined by gpio_mode
portThe port of the MCU, defined by gpio_port
pinThe pin of the port, defined by gpio_pin
Returns
none.

Definition at line 44 of file stm32f103cb_gpio.c.

void pinToggle ( gpio_port  port,
gpio_pin  pin 
)

Toggle the output of a given pin on a port.

Pin must be set for digital output to use this function

Parameters
portThe port of the MCU, defined by gpio_port
pinThe pin of the port, defined by gpio_pin
Returns
none.

Definition at line 116 of file stm32f103cb_gpio.c.

void pinWrite ( gpio_port  port,
gpio_pin  pin,
gpio_state  state 
)

Set a given gpio pin on a port to a logic state.

Pin must be set for digital output to use this function

Parameters
stateThe state to set the pin to, defined by gpio_state
portThe port of the MCU, defined by gpio_port
pinThe pin of the port, defined by gpio_pin
Returns
none.

Definition at line 103 of file stm32f103cb_gpio.c.