The friendly Operating System for the Internet of Things
stm32_common/include/periph_cpu_common.h File Reference

Shared CPU specific definitions for the STM32 family. More...

Detailed Description

#include "cpu.h"
+ Include dependency graph for stm32_common/include/periph_cpu_common.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  timer_conf_t
 Timer configuration data. More...
 
struct  pwm_chan_t
 PWM channel. More...
 
struct  pwm_conf_t
 PWM configuration structure. More...
 
struct  uart_conf_t
 UART device configuration. More...
 
struct  spi_conf_t
 SPI configuration data structure. More...
 

Macros

#define PM_NUM_MODES   (2U)
 Number of usable low power modes.
 
#define GPIO_UNDEF   (0xffffffff)
 Definition of a fitting UNDEF value.
 
#define GPIO_PIN(x, y)   ((GPIOA_BASE + (x << 10)) | y)
 Define a CPU specific GPIO pin generator macro.
 
#define SPI_HWCS_MASK   (0xffffff00)
 Define a magic number that tells us to use hardware chip select. More...
 
#define SPI_HWCS(x)   (SPI_HWCS_MASK | x)
 Override the default SPI hardware chip select access macro. More...
 
#define GPIO_MODE(io, pr, ot)   ((io << 0) | (pr << 2) | (ot << 4))
 Generate GPIO mode bitfields. More...
 
#define CPUID_LEN   (12U)
 Length of the CPU_ID in octets.
 
#define TIMER_CHAN   (4U)
 All STM timers have 4 capture-compare channels.
 
#define PERIPH_SPI_NEEDS_TRANSFER_BYTE
 Use the shared SPI functions.
 
#define PERIPH_SPI_NEEDS_TRANSFER_REG
 
#define PERIPH_SPI_NEEDS_TRANSFER_REGS
 

Enumerations

enum  bus_t { APB1, APB2 }
 Available peripheral buses. More...
 
enum  gpio_af_t {
  GPIO_AF0 = 0, GPIO_AF1, GPIO_AF2, GPIO_AF3,
  GPIO_AF4, GPIO_AF5, GPIO_AF6, GPIO_AF7,
  GPIO_AF8, GPIO_AF9, GPIO_AF10, GPIO_AF11,
  GPIO_AF12, GPIO_AF13, GPIO_AF14, GPIO_AF15
}
 Available MUX values for configuring a pin's alternate function. More...
 

Functions

uint32_t periph_apb_clk (uint8_t bus)
 Get the actual bus clock frequency for the APB buses. More...
 
void periph_clk_en (bus_t bus, uint32_t mask)
 Enable the given peripheral clock. More...
 
void periph_clk_dis (bus_t bus, uint32_t mask)
 Disable the given peripheral clock. More...
 
void gpio_init_af (gpio_t pin, gpio_af_t af)
 Configure the alternate function for the given pin. More...
 
void gpio_init_analog (gpio_t pin)
 Configure the given pin to be used as ADC input. More...
 

Macro Definition Documentation

#define GPIO_MODE (   io,
  pr,
  ot 
)    ((io << 0) | (pr << 2) | (ot << 4))

We use 5 bit to encode the mode:

  • bit 0+1: pin mode (input / output)
  • bit 2+3: pull resistor configuration
  • bit 4: output type (0: push-pull, 1: open-drain)

Definition at line 151 of file stm32_common/include/periph_cpu_common.h.

#define SPI_HWCS (   x)    (SPI_HWCS_MASK | x)

Since the CPU does only support one single hardware chip select line, we can detect the usage of non-valid lines by comparing to SPI_HWCS_VALID.

Definition at line 111 of file stm32_common/include/periph_cpu_common.h.

#define SPI_HWCS_MASK   (0xffffff00)

We use a random value here, that does clearly differentiate from any possible GPIO_PIN(x) value.

Definition at line 103 of file stm32_common/include/periph_cpu_common.h.

Enumeration Type Documentation

enum bus_t
Enumerator
APB1 

APB1 bus.

APB2 

APB2 bus.

Definition at line 59 of file stm32_common/include/periph_cpu_common.h.

enum gpio_af_t
Enumerator
GPIO_AF0 

use alternate function 0

GPIO_AF1 

use alternate function 1

GPIO_AF2 

use alternate function 2

GPIO_AF3 

use alternate function 3

GPIO_AF4 

use alternate function 4

GPIO_AF5 

use alternate function 5

GPIO_AF6 

use alternate function 6

GPIO_AF7 

use alternate function 7

GPIO_AF8 

use alternate function 8

GPIO_AF9 

use alternate function 9

GPIO_AF10 

use alternate function 10

GPIO_AF11 

use alternate function 11

GPIO_AF12 

use alternate function 12

GPIO_AF13 

use alternate function 13

GPIO_AF14 

use alternate function 14

GPIO_AF15 

use alternate function 15

Definition at line 116 of file stm32_common/include/periph_cpu_common.h.

Function Documentation

void gpio_init_af ( gpio_t  pin,
gpio_af_t  af 
)
Parameters
[in]pinpin to configure
[in]afalternate function to use
void gpio_init_analog ( gpio_t  pin)
Parameters
[in]pinpin to configure
uint32_t periph_apb_clk ( uint8_t  bus)
Parameters
[in]bustarget APBx bus
Returns
bus clock frequency in Hz
void periph_clk_dis ( bus_t  bus,
uint32_t  mask 
)
Parameters
[in]busbus the peripheral is connected to
[in]maskbit in the RCC enable register
void periph_clk_en ( bus_t  bus,
uint32_t  mask 
)
Parameters
[in]busbus the peripheral is connected to
[in]maskbit in the RCC enable register