stm32_common/include/periph_cpu_common.h File Reference

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

Detailed Description

Shared CPU specific definitions for the STM32 family.

Author
Hauke Petersen hauke.nosp@m..pet.nosp@m.ersen.nosp@m.@fu-.nosp@m.berli.nosp@m.n.de
Vincent Dupont vince.nosp@m.nt@o.nosp@m.takey.nosp@m.s.co.nosp@m.m

Definition in file stm32_common/include/periph_cpu_common.h.

#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  dac_conf_t
 DAC line configuration data. More...
 
struct  timer_conf_t
 Timer configuration. 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 module configuration options. 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)
 CPU specific LSI clock speed. More...
 
#define PROVIDES_PM_LAYERED_OFF
 We provide our own pm_off() function for all STM32-based CPUs.
 
#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

◆ CPUID_LEN

#define CPUID_LEN   (12U)

CPU specific LSI clock speed.

Length of the CPU_ID in octets

This is the same for all members of the stm32 family

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

◆ GPIO_MODE

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

Generate GPIO mode bitfields.

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 176 of file stm32_common/include/periph_cpu_common.h.

◆ SPI_HWCS

#define SPI_HWCS (   x)    (SPI_HWCS_MASK | x)

Override the default SPI hardware chip select access macro.

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 136 of file stm32_common/include/periph_cpu_common.h.

◆ SPI_HWCS_MASK

#define SPI_HWCS_MASK   (0xffffff00)

Define a magic number that tells us to use hardware chip select.

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

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

Enumeration Type Documentation

◆ bus_t

enum bus_t

Available peripheral buses.

Enumerator
APB1 

APB1 bus.

APB2 

APB2 bus.

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

◆ gpio_af_t

enum gpio_af_t

Available MUX values for configuring a pin's alternate function.

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 141 of file stm32_common/include/periph_cpu_common.h.

Function Documentation

◆ gpio_init_af()

void gpio_init_af ( gpio_t  pin,
gpio_af_t  af 
)

Configure the alternate function for the given pin.

Parameters
[in]pinpin to configure
[in]afalternate function to use

◆ gpio_init_analog()

void gpio_init_analog ( gpio_t  pin)

Configure the given pin to be used as ADC input.

Parameters
[in]pinpin to configure

◆ periph_apb_clk()

uint32_t periph_apb_clk ( uint8_t  bus)

Get the actual bus clock frequency for the APB buses.

Parameters
[in]bustarget APBx bus
Returns
bus clock frequency in Hz

◆ periph_clk_dis()

void periph_clk_dis ( bus_t  bus,
uint32_t  mask 
)

Disable the given peripheral clock.

Parameters
[in]busbus the peripheral is connected to
[in]maskbit in the RCC enable register

◆ periph_clk_en()

void periph_clk_en ( bus_t  bus,
uint32_t  mask 
)

Enable the given peripheral clock.

Parameters
[in]busbus the peripheral is connected to
[in]maskbit in the RCC enable register