OpenMPTL - STM32 (common)
C++ Microprocessor Template Library
tim.hpp
Go to the documentation of this file.
1 /*
2  * OpenMPTL - C++ Microprocessor Template Library
3  *
4  * Copyright (C) 2012-2017 Axel Burri <axel@tty0.ch>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 /*
22  * This program contains derivative representations of CMSIS System
23  * View Description (SVD) files, and is subject to the "End User
24  * License Agreement for STMicroelectronics" (see "STM_License.html"
25  * in the containing directory).
26  */
27 
28 #ifndef ARM_CORTEX_STM32_COMMON_REG_TIM_HPP_INCLUDED
29 #define ARM_CORTEX_STM32_COMMON_REG_TIM_HPP_INCLUDED
30 
31 #include <register.hpp>
32 
33 namespace mptl {
34 
35 /**
36  * Advanced timer
37  *
38  * Note that the registers are actually only 16bit wide, but accessing
39  * them with 32bit is faster in general.
40  *
41  * NOTE: not all register bits are valid for all timer, especially:
42  * - General-porpose timers (TIM2 to TIM5) are a subset of "advanced timer"
43  * - General-porpose timers (TIM9 to TIM14) are another subset of "advanced timer"
44  * - Basic timers (TIM6, TIM7) are another subset of "advanced timer"
45  *
46  * For simplicity reasons, they are not defined separately.
47  * Check the reference manual for details about which register bits
48  * are valid for the timers you use.
49  */
50 template<reg_addr_t _base_addr>
51 struct TIM_common
52 {
53  static constexpr reg_addr_t base_addr = _base_addr;
54 
55  /**
56  * Control register 1
57  */
58  struct CR1
59  : public reg< std::uint_fast16_t, base_addr + 0x0, rw, 0x0000 >
60  {
62 
63  using CKD = regbits< type, 8, 2 >; /**< Clock division */
64  using ARPE = regbits< type, 7, 1 >; /**< Auto-reload preload enable */
65  using CMS = regbits< type, 5, 2 >; /**< Center-aligned mode selection */
66  using DIR = regbits< type, 4, 1 >; /**< Direction */
67  using OPM = regbits< type, 3, 1 >; /**< One-pulse mode */
68  using URS = regbits< type, 2, 1 >; /**< Update request source */
69  using UDIS = regbits< type, 1, 1 >; /**< Update disable */
70  using CEN = regbits< type, 0, 1 >; /**< Counter enable */
71  };
72 
73  /**
74  * Control register 2
75  */
76  struct CR2
77  : public reg< std::uint_fast16_t, base_addr + 0x4, rw, 0x0000 >
78  {
80 
81  using OIS4 = regbits< type, 14, 1 >; /**< Output Idle state 4 */
82  using OIS3N = regbits< type, 13, 1 >; /**< Output Idle state 3 */
83  using OIS3 = regbits< type, 12, 1 >; /**< Output Idle state 3 */
84  using OIS2N = regbits< type, 11, 1 >; /**< Output Idle state 2 */
85  using OIS2 = regbits< type, 10, 1 >; /**< Output Idle state 2 */
86  using OIS1N = regbits< type, 9, 1 >; /**< Output Idle state 1 */
87  using OIS1 = regbits< type, 8, 1 >; /**< Output Idle state 1 */
88  using TI1S = regbits< type, 7, 1 >; /**< TI1 selection */
89  using MMS = regbits< type, 4, 3 >; /**< Master mode selection */
90  using CCDS = regbits< type, 3, 1 >; /**< Capture/compare DMA selection */
91  using CCUS = regbits< type, 2, 1 >; /**< Capture/compare control update selection */
92  using CCPC = regbits< type, 0, 1 >; /**< Capture/compare preloaded control */
93  };
94 
95  /**
96  * Slave mode control register
97  */
98  struct SMCR
99  : public reg< std::uint_fast16_t, base_addr + 0x8, rw, 0x0000 >
100  {
102 
103  using ETP = regbits< type, 15, 1 >; /**< External trigger polarity */
104  using ECE = regbits< type, 14, 1 >; /**< External clock enable */
105  using ETPS = regbits< type, 12, 2 >; /**< External trigger prescaler */
106  using ETF = regbits< type, 8, 4 >; /**< External trigger filter */
107  using MSM = regbits< type, 7, 1 >; /**< Master/Slave mode */
108  using TS = regbits< type, 4, 3 >; /**< Trigger selection */
109  using SMS = regbits< type, 0, 3 >; /**< Slave mode selection */
110  };
111 
112  /**
113  * DMA/Interrupt enable register
114  */
115  struct DIER
116  : public reg< std::uint_fast16_t, base_addr + 0xc, rw, 0x0000 >
117  {
119 
120  using TDE = regbits< type, 14, 1 >; /**< Trigger DMA request enable */
121  using COMDE = regbits< type, 13, 1 >; /**< COM DMA request enable */
122  using CC4DE = regbits< type, 12, 1 >; /**< Capture/Compare 4 DMA request enable */
123  using CC3DE = regbits< type, 11, 1 >; /**< Capture/Compare 3 DMA request enable */
124  using CC2DE = regbits< type, 10, 1 >; /**< Capture/Compare 2 DMA request enable */
125  using CC1DE = regbits< type, 9, 1 >; /**< Capture/Compare 1 DMA request enable */
126  using UDE = regbits< type, 8, 1 >; /**< Update DMA request enable */
127  using TIE = regbits< type, 6, 1 >; /**< Trigger interrupt enable */
128  using CC4IE = regbits< type, 4, 1 >; /**< Capture/Compare 4 interrupt enable */
129  using CC3IE = regbits< type, 3, 1 >; /**< Capture/Compare 3 interrupt enable */
130  using CC2IE = regbits< type, 2, 1 >; /**< Capture/Compare 2 interrupt enable */
131  using CC1IE = regbits< type, 1, 1 >; /**< Capture/Compare 1 interrupt enable */
132  using UIE = regbits< type, 0, 1 >; /**< Update interrupt enable */
133  using BIE = regbits< type, 7, 1 >; /**< Break interrupt enable */
134  using COMIE = regbits< type, 5, 1 >; /**< COM interrupt enable */
135  };
136 
137  /**
138  * Status register
139  */
140  struct SR
141  : public reg< std::uint_fast16_t, base_addr + 0x10, rw, 0x0000 >
142  {
144 
145  using CC4OF = regbits< type, 12, 1 >; /**< Capture/Compare 4 overcapture flag */
146  using CC3OF = regbits< type, 11, 1 >; /**< Capture/Compare 3 overcapture flag */
147  using CC2OF = regbits< type, 10, 1 >; /**< Capture/compare 2 overcapture flag */
148  using CC1OF = regbits< type, 9, 1 >; /**< Capture/Compare 1 overcapture flag */
149  using BIF = regbits< type, 7, 1 >; /**< Break interrupt flag */
150  using TIF = regbits< type, 6, 1 >; /**< Trigger interrupt flag */
151  using COMIF = regbits< type, 5, 1 >; /**< COM interrupt flag */
152  using CC4IF = regbits< type, 4, 1 >; /**< Capture/Compare 4 interrupt flag */
153  using CC3IF = regbits< type, 3, 1 >; /**< Capture/Compare 3 interrupt flag */
154  using CC2IF = regbits< type, 2, 1 >; /**< Capture/Compare 2 interrupt flag */
155  using CC1IF = regbits< type, 1, 1 >; /**< Capture/compare 1 interrupt flag */
156  using UIF = regbits< type, 0, 1 >; /**< Update interrupt flag */
157  };
158 
159  /**
160  * Event generation register
161  */
162  struct EGR
163  : public reg< std::uint_fast16_t, base_addr + 0x14, wo, 0x0000 >
164  {
166 
167  using BG = regbits< type, 7, 1 >; /**< Break generation */
168  using TG = regbits< type, 6, 1 >; /**< Trigger generation */
169  using COMG = regbits< type, 5, 1 >; /**< Capture/Compare control update generation */
170  using CC4G = regbits< type, 4, 1 >; /**< Capture/compare 4 generation */
171  using CC3G = regbits< type, 3, 1 >; /**< Capture/compare 3 generation */
172  using CC2G = regbits< type, 2, 1 >; /**< Capture/compare 2 generation */
173  using CC1G = regbits< type, 1, 1 >; /**< Capture/compare 1 generation */
174  using UG = regbits< type, 0, 1 >; /**< Update generation */
175  };
176 
177  /**
178  * Capture/compare mode register 1 (output mode)
179  */
181  : public reg< std::uint_fast16_t, base_addr + 0x18, rw, 0x0000 >
182  {
184 
185  using OC2CE = regbits< type, 15, 1 >; /**< Output Compare 2 clear enable */
186  using OC2M = regbits< type, 12, 3 >; /**< Output Compare 2 mode */
187  using OC2PE = regbits< type, 11, 1 >; /**< Output Compare 2 preload enable */
188  using OC2FE = regbits< type, 10, 1 >; /**< Output Compare 2 fast enable */
189  using CC2S = regbits< type, 8, 2 >; /**< Capture/Compare 2 selection */
190  using OC1CE = regbits< type, 7, 1 >; /**< Output Compare 1 clear enable */
191  using OC1M = regbits< type, 4, 3 >; /**< Output Compare 1 mode */
192  using OC1PE = regbits< type, 3, 1 >; /**< Output Compare 1 preload enable */
193  using OC1FE = regbits< type, 2, 1 >; /**< Output Compare 1 fast enable */
194  using CC1S = regbits< type, 0, 2 >; /**< Capture/Compare 1 selection */
195  };
196 
197  /**
198  * Capture/compare mode register 1 (input mode)
199  */
200  struct CCMR1_Input
201  : public reg< std::uint_fast16_t, base_addr + 0x18, rw, 0x0000 >
202  {
204 
205  using IC2F = regbits< type, 12, 4 >; /**< Input capture 2 filter */
206  using IC2PSC = regbits< type, 10, 2 >; /**< Input capture 2 prescaler */
207  using CC2S = regbits< type, 8, 2 >; /**< Capture/Compare 2 selection */
208  using IC1F = regbits< type, 4, 4 >; /**< Input capture 1 filter */
209  using IC1PSC = regbits< type, 2, 2 >; /**< Input capture 1 prescaler */
210  using CC1S = regbits< type, 0, 2 >; /**< Capture/Compare 1 selection */
211  };
212 
213  /**
214  * Capture/compare mode register 2 (output mode)
215  */
217  : public reg< std::uint_fast16_t, base_addr + 0x1c, rw, 0x0000 >
218  {
220 
221  using OC4CE = regbits< type, 15, 1 >; /**< Output compare 4 clear enable */
222  using OC4M = regbits< type, 12, 3 >; /**< Output compare 4 mode */
223  using OC4PE = regbits< type, 11, 1 >; /**< Output compare 4 preload enable */
224  using OC4FE = regbits< type, 10, 1 >; /**< Output compare 4 fast enable */
225  using CC4S = regbits< type, 8, 2 >; /**< Capture/Compare 4 selection */
226  using OC3CE = regbits< type, 7, 1 >; /**< Output compare 3 clear enable */
227  using OC3M = regbits< type, 4, 3 >; /**< Output compare 3 mode */
228  using OC3PE = regbits< type, 3, 1 >; /**< Output compare 3 preload enable */
229  using OC3FE = regbits< type, 2, 1 >; /**< Output compare 3 fast enable */
230  using CC3S = regbits< type, 0, 2 >; /**< Capture/Compare 3 selection */
231  };
232 
233  /**
234  * Capture/compare mode register 2 (input mode)
235  */
236  struct CCMR2_Input
237  : public reg< std::uint_fast16_t, base_addr + 0x1c, rw, 0x0000 >
238  {
240 
241  using IC4F = regbits< type, 12, 4 >; /**< Input capture 4 filter */
242  using IC4PSC = regbits< type, 10, 2 >; /**< Input capture 4 prescaler */
243  using CC4S = regbits< type, 8, 2 >; /**< Capture/Compare 4 selection */
244  using IC3F = regbits< type, 4, 4 >; /**< Input capture 3 filter */
245  using IC3PSC = regbits< type, 2, 2 >; /**< Input capture 3 prescaler */
246  using CC3S = regbits< type, 0, 2 >; /**< Capture/compare 3 selection */
247  };
248 
249  /**
250  * Capture/compare enable register
251  */
252  struct CCER
253  : public reg< std::uint_fast16_t, base_addr + 0x20, rw, 0x0000 >
254  {
256 
257  using CC4P = regbits< type, 13, 1 >; /**< Capture/Compare 3 output Polarity */
258  using CC4E = regbits< type, 12, 1 >; /**< Capture/Compare 4 output enable */
259  using CC3NP = regbits< type, 11, 1 >; /**< Capture/Compare 3 output Polarity */
260  using CC3NE = regbits< type, 10, 1 >; /**< Capture/Compare 3 complementary output enable */
261  using CC3P = regbits< type, 9, 1 >; /**< Capture/Compare 3 output Polarity */
262  using CC3E = regbits< type, 8, 1 >; /**< Capture/Compare 3 output enable */
263  using CC2NP = regbits< type, 7, 1 >; /**< Capture/Compare 2 output Polarity */
264  using CC2NE = regbits< type, 6, 1 >; /**< Capture/Compare 2 complementary output enable */
265  using CC2P = regbits< type, 5, 1 >; /**< Capture/Compare 2 output Polarity */
266  using CC2E = regbits< type, 4, 1 >; /**< Capture/Compare 2 output enable */
267  using CC1NP = regbits< type, 3, 1 >; /**< Capture/Compare 1 output Polarity */
268  using CC1NE = regbits< type, 2, 1 >; /**< Capture/Compare 1 complementary output enable */
269  using CC1P = regbits< type, 1, 1 >; /**< Capture/Compare 1 output Polarity */
270  using CC1E = regbits< type, 0, 1 >; /**< Capture/Compare 1 output enable */
271  };
272 
273  /**
274  * Counter
275  */
277 
278  /**
279  * Prescaler
280  */
282 
283  /**
284  * Auto-reload register
285  */
287 
288  /**
289  * Capture/compare register 1
290  */
292 
293  /**
294  * Capture/compare register 2
295  */
297 
298  /**
299  * Capture/compare register 3
300  */
302 
303  /**
304  * Capture/compare register 4
305  */
307 
308  /**
309  * DMA control register
310  */
311  struct DCR
312  : public reg< std::uint_fast16_t, base_addr + 0x48, rw, 0x0000 >
313  {
315 
316  using DBL = regbits< type, 8, 5 >; /**< DMA burst length */
317  using DBA = regbits< type, 0, 5 >; /**< DMA base address */
318  };
319 
320  /**
321  * DMA address for full transfer
322  */
324 
325  /**
326  * Repetition counter register
327  */
328  struct RCR
329  : public reg< std::uint_fast16_t, base_addr + 0x30, rw, 0x0000 >
330  {
332 
333  using REP = regbits< type, 0, 8 >; /**< Repetition counter value */
334  };
335 
336  /**
337  * Break and dead-time register
338  */
339  struct BDTR
340  : public reg< std::uint_fast16_t, base_addr + 0x44, rw, 0x0000 >
341  {
343 
344  using MOE = regbits< type, 15, 1 >; /**< Main output enable */
345  using AOE = regbits< type, 14, 1 >; /**< Automatic output enable */
346  using BKP = regbits< type, 13, 1 >; /**< Break polarity */
347  using BKE = regbits< type, 12, 1 >; /**< Break enable */
348  using OSSR = regbits< type, 11, 1 >; /**< Off-state selection for Run mode */
349  using OSSI = regbits< type, 10, 1 >; /**< Off-state selection for Idle mode */
350  using LOCK = regbits< type, 8, 2 >; /**< Lock configuration */
351  using DTG = regbits< type, 0, 8 >; /**< Dead-time generator setup */
352  };
353 };
354 
355 } // namespace mptl
356 
357 #endif // ARM_CORTEX_STM32_COMMON_REG_TIM_HPP_INCLUDED
Event generation register.
Definition: tim.hpp:162
Capture/compare mode register 1 (output mode)
Definition: tim.hpp:180
Capture/compare mode register 2 (output mode)
Definition: tim.hpp:216
uintptr_t reg_addr_t
Control register 2.
Definition: tim.hpp:76
Break and dead-time register.
Definition: tim.hpp:339
Slave mode control register.
Definition: tim.hpp:98
Capture/compare enable register.
Definition: tim.hpp:252
static constexpr reg_addr_t base_addr
Definition: tim.hpp:53
Control register 1.
Definition: tim.hpp:58
Capture/compare mode register 1 (input mode)
Definition: tim.hpp:200
Capture/compare mode register 2 (input mode)
Definition: tim.hpp:236
Status register.
Definition: tim.hpp:140
DMA/Interrupt enable register.
Definition: tim.hpp:115
DMA control register.
Definition: tim.hpp:311
Advanced timer.
Definition: tim.hpp:51
Repetition counter register.
Definition: tim.hpp:328