-
Notifications
You must be signed in to change notification settings - Fork 3
/
board.h
113 lines (90 loc) · 3.82 KB
/
board.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
* board.h
*
* Created on: 12 ñåíò. 2015 ã.
* Author: Kreyl
*/
#pragma once
#include <inttypes.h>
// ==== General ====
#define BOARD_NAME "Locket3"
#define APP_NAME "LastAllianceGreen"
// MCU type as defined in the ST header.
#define STM32L151xB
// Freq of external crystal if any. Leave it here even if not used.
#define CRYSTAL_FREQ_HZ 12000000
#define SYS_TIM_CLK (Clk.APB1FreqHz)
#define I2C_REQUIRED FALSE
#define ADC_REQUIRED FALSE
#if 1 // ========================== GPIO =======================================
// PortMinTim_t: GPIO, Pin, Tim, TimChnl, invInverted, omPushPull, TopValue
// UART
#define UART_GPIO GPIOA
#define UART_TX_PIN 9
#define UART_RX_PIN 10
#define UART_AF AF7 // for USART1 @ GPIOA
// LED
#define LED_R_PIN { GPIOB, 1, TIM3, 4, invNotInverted, omPushPull, 255 }
#define LED_G_PIN { GPIOB, 0, TIM3, 3, invNotInverted, omPushPull, 255 }
#define LED_B_PIN { GPIOB, 5, TIM3, 2, invNotInverted, omPushPull, 255 }
// Button
#define BTN_PIN { GPIOA, 0, pudPullDown }
// Vibro
#define VIBRO_TOP 22
#define VIBRO_PIN { GPIOB, 8, TIM4, 3, invNotInverted, omPushPull, VIBRO_TOP }
// Beeper
#define BEEPER_TOP 22
#define BEEPER_PIN { GPIOB, 9, TIM11, 1, invNotInverted, omPushPull, BEEPER_TOP }
#endif // GPIO
#if 1 // ========================= Timer =======================================
#endif // Timer
#if I2C_REQUIRED // ====================== I2C =================================
#endif
#if 1 // =========================== SPI =======================================
#endif
#if 1 // ========================== USART ======================================
#define UART USART1
#define UART_TX_REG UART->DR
#define UART_RX_REG UART->DR
#endif
#if ADC_REQUIRED // ======================= Inner ADC ==========================
// Clock divider: clock is generated from the APB2
#define ADC_CLK_DIVIDER adcDiv2
// ADC channels
#define BAT_CHNL 1
#define ADC_VREFINT_CHNL 17 // All 4xx and F072 devices. Do not change.
#define ADC_CHANNELS { BAT_CHNL, ADC_VREFINT_CHNL }
#define ADC_CHANNEL_CNT 2 // Do not use countof(AdcChannels) as preprocessor does not know what is countof => cannot check
#define ADC_SAMPLE_TIME ast55d5Cycles
#define ADC_SAMPLE_CNT 8 // How many times to measure every channel
#define ADC_MAX_SEQ_LEN 16 // 1...16; Const, see ref man
#define ADC_SEQ_LEN (ADC_SAMPLE_CNT * ADC_CHANNEL_CNT)
#if (ADC_SEQ_LEN > ADC_MAX_SEQ_LEN) || (ADC_SEQ_LEN == 0)
#error "Wrong ADC channel count and sample count"
#endif
#endif
#if 1 // =========================== DMA =======================================
#define STM32_DMA_REQUIRED TRUE
// ==== Uart ====
// Remap is made automatically if required
//#define UART_DMA_TX STM32_DMA1_STREAM4
//#define UART_DMA_RX STM32_DMA1_STREAM5
#define UART_DMA_CHNL 0 // Dummy
#if I2C_REQUIRED // ==== I2C ====
#define I2C_ACC_DMA_TX STM32_DMA1_STREAM4
#define I2C_ACC_DMA_RX STM32_DMA1_STREAM5
#endif
#if ADC_REQUIRED
/* DMA request mapped on this DMA channel only if the corresponding remapping bit is cleared in the SYSCFG_CFGR1
* register. For more details, please refer to Section10.1.1: SYSCFG configuration register 1 (SYSCFG_CFGR1) on
* page173 */
#define ADC_DMA STM32_DMA1_STREAM1
#define ADC_DMA_MODE STM32_DMA_CR_CHSEL(0) | /* DMA2 Stream4 Channel0 */ \
DMA_PRIORITY_LOW | \
STM32_DMA_CR_MSIZE_HWORD | \
STM32_DMA_CR_PSIZE_HWORD | \
STM32_DMA_CR_MINC | /* Memory pointer increase */ \
STM32_DMA_CR_DIR_P2M | /* Direction is peripheral to memory */ \
STM32_DMA_CR_TCIE /* Enable Transmission Complete IRQ */
#endif // ADC
#endif // DMA