boards/stm32f4discovery/include/periph_conf.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Freie Universit├Ąt Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
20 #ifndef PERIPH_CONF_H
21 #define PERIPH_CONF_H
22 
23 #include "periph_cpu.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
33 /* 0: no external high speed crystal available
34  * else: actual crystal frequency [in Hz] */
35 #define CLOCK_HSE (8000000U)
36 /* 0: no external low speed crystal available,
37  * 1: external crystal available (always 32.768kHz) */
38 #define CLOCK_LSE (1)
39 /* give the target core clock (HCLK) frequency [in Hz],
40  * maximum: 168MHz */
41 #define CLOCK_CORECLOCK (168000000U)
42 /* peripheral clock setup */
43 #define CLOCK_AHB_DIV RCC_CFGR_HPRE_DIV1 /* min 25MHz */
44 #define CLOCK_AHB (CLOCK_CORECLOCK / 1)
45 #define CLOCK_APB1_DIV RCC_CFGR_PPRE1_DIV4 /* max 42MHz */
46 #define CLOCK_APB1 (CLOCK_CORECLOCK / 4)
47 #define CLOCK_APB2_DIV RCC_CFGR_PPRE2_DIV2 /* max 84MHz */
48 #define CLOCK_APB2 (CLOCK_CORECLOCK / 2)
49 
55 static const timer_conf_t timer_config[] = {
56  {
57  .dev = TIM2,
58  .max = 0xffffffff,
59  .rcc_mask = RCC_APB1ENR_TIM2EN,
60  .bus = APB1,
61  .irqn = TIM2_IRQn
62  },
63  {
64  .dev = TIM5,
65  .max = 0xffffffff,
66  .rcc_mask = RCC_APB1ENR_TIM5EN,
67  .bus = APB1,
68  .irqn = TIM5_IRQn
69  }
70 };
71 
72 #define TIMER_0_ISR isr_tim2
73 #define TIMER_1_ISR isr_tim5
74 
75 #define TIMER_NUMOF (sizeof(timer_config) / sizeof(timer_config[0]))
76 
82 static const uart_conf_t uart_config[] = {
83  {
84  .dev = USART2,
85  .rcc_mask = RCC_APB1ENR_USART2EN,
86  .rx_pin = GPIO_PIN(PORT_A, 3),
87  .tx_pin = GPIO_PIN(PORT_A, 2),
88  .rx_af = GPIO_AF7,
89  .tx_af = GPIO_AF7,
90  .bus = APB1,
91  .irqn = USART2_IRQn,
92 #ifdef UART_USE_DMA
93  .dma_stream = 6,
94  .dma_chan = 4
95 #endif
96  },
97  {
98  .dev = USART3,
99  .rcc_mask = RCC_APB1ENR_USART3EN,
100  .rx_pin = GPIO_PIN(PORT_D, 9),
101  .tx_pin = GPIO_PIN(PORT_D, 8),
102  .rx_af = GPIO_AF7,
103  .tx_af = GPIO_AF7,
104  .bus = APB1,
105  .irqn = USART3_IRQn,
106 #ifdef UART_USE_DMA
107  .dma_stream = 3,
108  .dma_chan = 4
109 #endif
110  }
111 };
112 
113 #define UART_0_ISR (isr_usart2)
114 #define UART_0_DMA_ISR (isr_dma1_stream6)
115 #define UART_1_ISR (isr_usart3)
116 #define UART_1_DMA_ISR (isr_dma1_stream3)
117 
118 #define UART_NUMOF (sizeof(uart_config) / sizeof(uart_config[0]))
119 
128 #define ADC_CONFIG { \
129  {GPIO_PIN(PORT_A, 1), 0, 1}, \
130  {GPIO_PIN(PORT_A, 4), 0, 4}, \
131  {GPIO_PIN(PORT_C, 1), 1, 11}, \
132  {GPIO_PIN(PORT_C, 2), 1, 12} \
133 }
134 
135 #define ADC_NUMOF (4)
136 
142 static const dac_conf_t dac_config[] = {
143  { .pin = GPIO_PIN(PORT_A, 4), .chan = 0 },
144  { .pin = GPIO_PIN(PORT_A, 5), .chan = 1 }
145 };
146 
147 #define DAC_NUMOF (sizeof(dac_config) / sizeof(dac_config[0]))
148 
154 static const pwm_conf_t pwm_config[] = {
155  {
156  .dev = TIM1,
157  .rcc_mask = RCC_APB2ENR_TIM1EN,
158  .chan = { { .pin = GPIO_PIN(PORT_E, 9), .cc_chan = 0 },
159  { .pin = GPIO_PIN(PORT_E, 11), .cc_chan = 1 },
160  { .pin = GPIO_PIN(PORT_E, 11), .cc_chan = 2 },
161  { .pin = GPIO_PIN(PORT_E, 14), .cc_chan = 3 } },
162  .af = GPIO_AF1,
163  .bus = APB2
164  },
165  {
166  .dev = TIM3,
167  .rcc_mask = RCC_APB1ENR_TIM3EN,
168  .chan = { { .pin = GPIO_PIN(PORT_B, 4), .cc_chan = 0 },
169  { .pin = GPIO_PIN(PORT_B, 5), .cc_chan = 1 },
170  { .pin = GPIO_PIN(PORT_B, 0), .cc_chan = 2 },
171  { .pin = GPIO_PIN(PORT_B, 1), .cc_chan = 3 } },
172  .af = GPIO_AF2,
173  .bus = APB1
174  }
175 };
176 
177 #define PWM_NUMOF (sizeof(pwm_config) / sizeof(pwm_config[0]))
178 
187 static const uint8_t spi_divtable[2][5] = {
188  { /* for APB1 @ 42000000Hz */
189  7, /* -> 164062Hz */
190  6, /* -> 328125Hz */
191  4, /* -> 1312500Hz */
192  2, /* -> 5250000Hz */
193  1 /* -> 10500000Hz */
194  },
195  { /* for APB2 @ 84000000Hz */
196  7, /* -> 328125Hz */
197  7, /* -> 328125Hz */
198  5, /* -> 1312500Hz */
199  3, /* -> 5250000Hz */
200  2 /* -> 10500000Hz */
201  }
202 };
203 
204 static const spi_conf_t spi_config[] = {
205  {
206  .dev = SPI1,
207  .mosi_pin = GPIO_PIN(PORT_A, 7),
208  .miso_pin = GPIO_PIN(PORT_A, 6),
209  .sclk_pin = GPIO_PIN(PORT_A, 5),
210  .cs_pin = GPIO_PIN(PORT_A, 4),
211  .af = GPIO_AF5,
212  .rccmask = RCC_APB2ENR_SPI1EN,
213  .apbbus = APB2
214  },
215  {
216  .dev = SPI2,
217  .mosi_pin = GPIO_PIN(PORT_B, 15),
218  .miso_pin = GPIO_PIN(PORT_B, 14),
219  .sclk_pin = GPIO_PIN(PORT_B, 13),
220  .cs_pin = GPIO_PIN(PORT_B, 12),
221  .af = GPIO_AF5,
222  .rccmask = RCC_APB1ENR_SPI2EN,
223  .apbbus = APB1
224  }
225 };
226 
227 #define SPI_NUMOF (sizeof(spi_config) / sizeof(spi_config[0]))
228 
234 #define I2C_NUMOF (1U)
235 #define I2C_0_EN 1
236 #define I2C_IRQ_PRIO 1
237 #define I2C_APBCLK (CLOCK_APB1)
238 
239 /* I2C 0 device configuration */
240 #define I2C_0_DEV I2C1
241 #define I2C_0_CLKEN() (periph_clk_en(APB1, RCC_APB1ENR_I2C1EN))
242 #define I2C_0_CLKDIS() (periph_clk_dis(APB1, RCC_APB1ENR_I2C1EN))
243 #define I2C_0_EVT_IRQ I2C1_EV_IRQn
244 #define I2C_0_EVT_ISR isr_i2c1_ev
245 #define I2C_0_ERR_IRQ I2C1_ER_IRQn
246 #define I2C_0_ERR_ISR isr_i2c1_er
247 /* I2C 0 pin configuration */
248 #define I2C_0_SCL_PORT GPIOB
249 #define I2C_0_SCL_PIN 6
250 #define I2C_0_SCL_AF 4
251 #define I2C_0_SCL_CLKEN() (periph_clk_en(AHB1, RCC_AHB1ENR_GPIOBEN))
252 #define I2C_0_SDA_PORT GPIOB
253 #define I2C_0_SDA_PIN 7
254 #define I2C_0_SDA_AF 4
255 #define I2C_0_SDA_CLKEN() (periph_clk_en(AHB1, RCC_AHB1ENR_GPIOBEN))
256 
258 #ifdef __cplusplus
259 }
260 #endif
261 
262 #endif /* PERIPH_CONF_H */
263 
use alternate function 7
USART_TypeDef * dev
USART device used.
#define GPIO_PIN(x, y)
Define a CPU specific GPIO pin generator macro.
gpio_t pin
pin connected to the line
use alternate function 1
PWM configuration structure.
LPC_CTxxBx_Type * dev
PWM device.
use alternate function 5
UART device configuration.
DAC line configuration data.
SPI module configuration options.
cc2538_gptimer_t * dev
timer device
Timer configuration data.
use alternate function 2
cc2538_ssi_t * dev
SSI device.