1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: 15: 16: 17: 18: 19:
20:
21: #ifndef __TK_SYSDEF_DEPEND_CPU_H__
22: #define __TK_SYSDEF_DEPEND_CPU_H__
23:
24: #include "../../../machine.h"
25:
26:
27: #include "../core/armv7m/sysdef.h"
28:
29:
30: 31: 32:
33:
34:
35: #if CPU_STM32L476 | CPU_STM32L486
36: #define INTERNAL_RAM_SIZE 0x00018000
37: #define INTERNAL_RAM_START 0x20000000
38: #endif
39:
40: #define INTERNAL_RAM_END (INTERNAL_RAM_START+INTERNAL_RAM_SIZE)
41:
42:
43: 44: 45:
46: #define INITIAL_SP INTERNAL_RAM_END
47:
48:
49:
50: 51: 52:
53:
54: #define SYSCFG_BASE 0x40010000
55:
56: #define SYSCFG_MEMRMP (SYSCFG_BASE+0x0000)
57: #define SYSCFG_CFGR1 (SYSCFG_BASE+0x0004)
58: #define SYSCFG_EXTICR1 (SYSCFG_BASE+0x0008)
59: #define SYSCFG_EXTICR2 (SYSCFG_BASE+0x000C)
60: #define SYSCFG_EXTICR3 (SYSCFG_BASE+0x0010)
61: #define SYSCFG_EXTICR4 (SYSCFG_BASE+0x0014)
62: #define SYSCFG_SCSR (SYSCFG_BASE+0x0018)
63: #define SYSCFG_CFGR2 (SYSCFG_BASE+0x001C)
64: #define SYSCFG_SWPR (SYSCFG_BASE+0x0020)
65: #define SYSCFG_SKR (SYSCFG_BASE+0x0024)
66: #define SYSCFG_SWPR2 (SYSCFG_BASE+0x0028)
67:
68:
69:
70: 71: 72:
73:
74: #define FLASH_BASE 0x40022000
75:
76: #define FLASH_ACR (FLASH_BASE+0x0000)
77: #define FLASH_PDKEYR (FLASH_BASE+0x0004)
78: #define FLASH_KEYR (FLASH_BASE+0x0008)
79: #define FLASH_OPTKEYR (FLASH_BASE+0x000C)
80: #define FLASH_SR (FLASH_BASE+0x0010)
81: #define FLASH_CR (FLASH_BASE+0x0014)
82: #define FLASH_ECCR (FLASH_BASE+0x0018)
83: #define FLASH_OPTR (FLASH_BASE+0x0020)
84: #define FLASH_PCROP1SR (FLASH_BASE+0x0024)
85: #define FLASH_PCROP1ER (FLASH_BASE+0x0028)
86: #define FLASH_WRP1AR (FLASH_BASE+0x002C)
87: #define FLASH_WRP1BR (FLASH_BASE+0x0030)
88: #define FLASH_PCROP2SR (FLASH_BASE+0x0044)
89: #define FLASH_PCROP2ER (FLASH_BASE+0x0048)
90: #define FLASH_WRP2AR (FLASH_BASE+0x004C)
91: #define FLASH_WRP2BR (FLASH_BASE+0x0050)
92: #define FLASH_CFGR (FLASH_BASE+0x0130)
93:
94:
95:
96: #define FLASH_ACR_SLEEP_PD 0x00004000
97: #define FLASH_ACR_RUN_PD 0x00002000
98: #define FLASH_ACR_DCRST 0x00001000
99: #define FLASH_ACR_ICRST 0x00000800
100: #define FLASH_ACR_DCEN 0x00000400
101: #define FLASH_ACR_ICEN 0x00000200
102: #define FLASH_ACR_PRFTEN 0x00000100
103: #define FLASH_ACR_LATENCY_MASK 0x00000007
104: #define FLASH_ACR_LATENCY(n) (((_UW)(n)<<0) & FLASH_ACR_LATENCY_MASK)
105:
106:
107: 108: 109:
110: 111: 112:
113: #define PWR_BASE 0x40007000
114: #define PWR_CR1 (PWR_BASE+0x0000)
115: #define PWR_CR2 (PWR_BASE+0x0004)
116: #define PWR_CR3 (PWR_BASE+0x0008)
117: #define PWR_CR4 (PWR_BASE+0x000C)
118: #define PWR_SR1 (PWR_BASE+0x0010)
119: #define PWR_SR2 (PWR_BASE+0x0014)
120: #define PWR_SCR (PWR_BASE+0x0018)
121: #define PWR_PUCRA (PWR_BASE+0x0020)
122: #define PWR_PDCRA (PWR_BASE+0x0024)
123: #define PWR_PUCRB (PWR_BASE+0x0028)
124: #define PWR_PDCRB (PWR_BASE+0x002C)
125: #define PWR_PUCRC (PWR_BASE+0x0030)
126: #define PWR_PDCRC (PWR_BASE+0x0034)
127: #define PWR_PUCRD (PWR_BASE+0x0038)
128: #define PWR_PDCRD (PWR_BASE+0x003C)
129: #define PWR_PUCRE (PWR_BASE+0x0040)
130: #define PWR_PDCRE (PWR_BASE+0x0044)
131: #define PWR_PUCRF (PWR_BASE+0x0048)
132: #define PWR_PDCRF (PWR_BASE+0x004C)
133: #define PWR_PUCRG (PWR_BASE+0x0050)
134: #define PWR_PDCRG (PWR_BASE+0x0054)
135: #define PWR_PUCRH (PWR_BASE+0x0058)
136: #define PWR_PDCRH (PWR_BASE+0x005C)
137: #define PWR_PUCRI (PWR_BASE+0x0060)
138: #define PWR_PDCRI (PWR_BASE+0x0064)
139:
140:
141: #define PWR_CR1_LPR 0x00004000
142:
143: #define PWR_CR1_VOS 0x00000600
144: #define PWR_CR1_VOS_RANGE1 0x00000200
145: #define PWR_CR1_VOS_RANGE2 0x00000400
146:
147: #define PWR_CR1_DBP 0x00000100
148: #define PWR_CR1_LPMS 0x00000007
149: #define PWR_CR1_LPMS_STOP0 0x00000000
150: #define PWR_CR1_LPMS_STOP1 0x00000001
151: #define PWR_CR1_LPMS_STOP2 0x00000002
152: #define PWR_CR1_LPMS_STANDBY 0x00000003
153: #define PWR_CR1_LPMS_SHUTDOWN 0x00000004
154:
155:
156:
157: #define PWR_CR1_INIT (PWR_CR1_VOS_RANGE1)
158:
159: 160: 161:
162: #define RCC_BASE 0x40021000
163: #define RCC_CR (RCC_BASE + 0x0000)
164: #define RCC_ICSCR (RCC_BASE + 0x0004)
165: #define RCC_CFGR (RCC_BASE + 0x0008)
166: #define RCC_PLLCFGR (RCC_BASE + 0x000C)
167: #define RCC_PLLSAI1CFGR (RCC_BASE + 0x0010)
168: #define RCC_PLLSAI2CFGR (RCC_BASE + 0x0014)
169: #define RCC_CIER (RCC_BASE + 0x0018)
170: #define RCC_CIFR (RCC_BASE + 0x001C)
171: #define RCC_CICR (RCC_BASE + 0x0020)
172: #define RCC_AHB1RSTR (RCC_BASE + 0x0028)
173: #define RCC_AHB2RSTR (RCC_BASE + 0x002C)
174: #define RCC_AHB3RSTR (RCC_BASE + 0x0030)
175: #define RCC_APB1RSTR1 (RCC_BASE + 0x0038)
176: #define RCC_APB1RSTR2 (RCC_BASE + 0x003C)
177: #define RCC_APB2RSTR (RCC_BASE + 0x0040)
178: #define RCC_AHB1ENR (RCC_BASE + 0x0048)
179: #define RCC_AHB2ENR (RCC_BASE + 0x004C)
180: #define RCC_AHB3ENR (RCC_BASE + 0x0050)
181: #define RCC_APB1ENR1 (RCC_BASE + 0x0058)
182: #define RCC_APB1ENR2 (RCC_BASE + 0x005C)
183: #define RCC_APB2ENR (RCC_BASE + 0x0060)
184: #define RCC_AHB1SMENR (RCC_BASE + 0x0068)
185: #define RCC_AHB2SMENR (RCC_BASE + 0x006C)
186: #define RCC_AHB3SMENR (RCC_BASE + 0x0070)
187: #define RCC_APB1SMENR1 (RCC_BASE + 0x0078)
188: #define RCC_APB1SMENR2 (RCC_BASE + 0x007C)
189: #define RCC_APB2SMENR (RCC_BASE + 0x0080)
190: #define RCC_CCIPR (RCC_BASE + 0x0088)
191: #define RCC_BDCR (RCC_BASE + 0x0090)
192: #define RCC_CSR (RCC_BASE + 0x0094)
193: #define RCC_CRRCR (RCC_BASE + 0x0098)
194: #define RCC_CCIPR2 (RCC_BASE + 0x009C)
195:
196:
197: #define RCC_CR_PLLSAI2RDY 0x20000000
198: #define RCC_CR_PLLSAI2ON 0x10000000
199: #define RCC_CR_PLLSAI1RDY 0x08000000
200: #define RCC_CR_PLLSAI1ON 0x04000000
201: #define RCC_CR_PLLRDY 0x02000000
202: #define RCC_CR_PLLON 0x01000000
203: #define RCC_CR_CSSON 0x00080000
204: #define RCC_CR_HSEBYP 0x00040000
205: #define RCC_CR_HSERDY 0x00020000
206: #define RCC_CR_HSEON 0x00010000
207: #define RCC_CR_HSIASFS 0x00000800
208: #define RCC_CR_HSIRDY 0x00000400
209: #define RCC_CR_HSIKERON 0x00000200
210: #define RCC_CR_HSION 0x00000100
211: #define RCC_CR_MSIRANGE 0x000000F0
212: #define RCC_CR_MSIRGSEL 0x00000008
213: #define RCC_CR_MSIPLLEN 0x00000004
214: #define RCC_CR_MSIRDY 0x00000002
215: #define RCC_CR_MSION 0x00000001
216:
217:
218: #define RCC_CR_MSIRANGE_100K 0x00000000
219: #define RCC_CR_MSIRANGE_200K 0x00000010
220: #define RCC_CR_MSIRANGE_400K 0x00000020
221: #define RCC_CR_MSIRANGE_800K 0x00000030
222: #define RCC_CR_MSIRANGE_1M 0x00000040
223: #define RCC_CR_MSIRANGE_2M 0x00000050
224: #define RCC_CR_MSIRANGE_4M 0x00000060
225: #define RCC_CR_MSIRANGE_8M 0x00000070
226: #define RCC_CR_MSIRANGE_16M 0x00000080
227: #define RCC_CR_MSIRANGE_24M 0x00000090
228: #define RCC_CR_MSIRANGE_32M 0x000000A0
229: #define RCC_CR_MSIRANGE_48M 0x000000B0
230:
231:
232: #define RCC_CFGR_MCOPRE 0x70000000
233: #define RCC_CFGR_MCOSEL 0x0F000000
234: #define RCC_CFGR_STOPWUCK 0x00008000
235: #define RCC_CFGR_PPRE2 0x00003800
236: #define RCC_CFGR_PPRE1 0x00000700
237: #define RCC_CFGR_HPRE 0x000000F0
238: #define RCC_CFGR_SWS 0x0000000C
239: #define RCC_CFGR_SW 0x00000003
240:
241: #define RCC_CFGR_SWS_MSI 0x00000000
242: #define RCC_CFGR_SWS_HSI16 0x00000004
243: #define RCC_CFGR_SWS_HSE 0x00000008
244: #define RCC_CFGR_SWS_PLL 0x0000000C
245:
246: #define RCC_CFGR_SW_MSI 0x00000000
247: #define RCC_CFGR_SW_HSI16 0x00000001
248: #define RCC_CFGR_SW_HSE 0x00000002
249: #define RCC_CFGR_SW_PLL 0x00000003
250:
251:
252: #define RCC_PLLCFGR_PLLR 0x06000000
253: #define RCC_PLLCFGR_PLLREN 0x01000000
254: #define RCC_PLLCFGR_PLLQ 0x00600000
255: #define RCC_PLLCFGR_PLLQEN 0x00100000
256: #define RCC_PLLCFGR_PLLP 0x00020000
257: #define RCC_PLLCFGR_PLLPEN 0x00010000
258: #define RCC_PLLCFGR_PLLN 0x00007F00
259: #define RCC_PLLCFGR_PLLM 0x000000F0
260: #define RCC_PLLCFGR_PLLSRC 0x00000003
261:
262:
263: #define RCC_APB1ENR1_LPTIM1EN 0x80000000
264: #define RCC_APB1ENR1_OPAMPEN 0x40000000
265: #define RCC_APB1ENR1_DAC1EN 0x20000000
266: #define RCC_APB1ENR1_PWREN 0x10000000
267: #define RCC_APB1ENR1_CAN1EN 0x02000000
268: #define RCC_APB1ENR1_CRSEN 0x01000000
269: #define RCC_APB1ENR1_I2C3EN 0x00800000
270: #define RCC_APB1ENR1_I2C2EN 0x00400000
271: #define RCC_APB1ENR1_I2C1EN 0x00200000
272: #define RCC_APB1ENR1_UART5EN 0x00100000
273: #define RCC_APB1ENR1_UART4EN 0x00080000
274: #define RCC_APB1ENR1_USART3EN 0x00040000
275: #define RCC_APB1ENR1_USART2EN 0x00020000
276: #define RCC_APB1ENR1_SPI3EN 0x00008000
277: #define RCC_APB1ENR1_SPI2EN 0x00004000
278: #define RCC_APB1ENR1_WWDGEN 0x00000800
279: #define RCC_APB1ENR1_RTCAPBEN 0x00000400
280: #define RCC_APB1ENR1_TIM7EN 0x00000020
281: #define RCC_APB1ENR1_TIM6EN 0x00000010
282: #define RCC_APB1ENR1_TIM5EN 0x00000008
283: #define RCC_APB1ENR1_TIM4EN 0x00000004
284: #define RCC_APB1ENR1_TIM3EN 0x00000002
285: #define RCC_APB1ENR1_TIM2EN 0x00000001
286:
287:
288: #define RCC_APB1ENR2_LPTIM2EN 0x00000020
289: #define RCC_APB1ENR2_SWPMI1EN 0x00000004
290: #define RCC_APB1ENR2_I2C4EN 0x00000002
291: #define RCC_APB1ENR2_LPUART1EN 0x00000001
292:
293:
294: #define RCC_APB2ENR_DFSDM1EN 0x01000000
295: #define RCC_APB2ENR_SAI2EN 0x00400000
296: #define RCC_APB2ENR_SAI1EN 0x00200000
297: #define RCC_APB2ENR_TIM17EN 0x00040000
298: #define RCC_APB2ENR_TIM16EN 0x00020000
299: #define RCC_APB2ENR_TIM15EN 0x00010000
300: #define RCC_APB2ENR_USART1EN 0x00004000
301: #define RCC_APB2ENR_TIM8EN 0x00002000
302: #define RCC_APB2ENR_SPI1EN 0x00001000
303: #define RCC_APB2ENR_TIM1EN 0x00000800
304: #define RCC_APB2ENR_SDMMC1EN 0x00000400
305: #define RCC_APB2ENR_FWEN 0x00000080
306: #define RCC_APB2ENR_SYSCFGEN 0x00000001
307:
308:
309: #define RCC_AHB2ENR_GPIOAEN 0x00000001
310: #define RCC_AHB2ENR_GPIOBEN 0x00000002
311: #define RCC_AHB2ENR_GPIOCEN 0x00000004
312: #define RCC_AHB2ENR_GPIODEN 0x00000008
313: #define RCC_AHB2ENR_GPIOEEN 0x00000010
314: #define RCC_AHB2ENR_GPIOFEN 0x00000020
315: #define RCC_AHB2ENR_GPIOGEN 0x00000040
316: #define RCC_AHB2ENR_GPIOHEN 0x00000080
317: #define RCC_AHB2ENR_GPIOIEN 0x00000100
318: #define RCC_AHB2ENR_ADCEN 0x00002000
319:
320:
321: 322: 323:
324:
325:
326: #define MIN_TIMER_PERIOD 1
327: #define MAX_TIMER_PERIOD 50
328:
329:
330:
331: 332: 333:
334: #define N_INTVEC 82
335: #define N_SYSVEC 16
336:
337: 338: 339:
340: #define INTPRI_BITWIDTH 4
341:
342:
343:
344: 345: 346:
347: #define INTPRI_MAX_EXTINT_PRI 1
348: #define INTPRI_SVC 0
349: #define INTPRI_SYSTICK 1
350: #define INTPRI_PENDSV 15
351:
352: 353: 354:
355: #define TIMER_INTLEVEL 0
356:
357:
358: 359: 360:
361: #define EXTI_BASE 0x40010400
362:
363: #define EXTI_IMR1 (EXTI_BASE + 0x00)
364: #define EXTI_EMR1 (EXTI_BASE + 0x04)
365: #define EXTI_RTSR1 (EXTI_BASE + 0x08)
366: #define EXTI_FTSR1 (EXTI_BASE + 0x0C)
367: #define EXTI_SWIER1 (EXTI_BASE + 0x10)
368: #define EXTI_PR1 (EXTI_BASE + 0x14)
369: #define EXTI_IMR2 (EXTI_BASE + 0x20)
370: #define EXTI_EMR2 (EXTI_BASE + 0x24)
371: #define EXTI_RTSR2 (EXTI_BASE + 0x28)
372: #define EXTI_FTSR2 (EXTI_BASE + 0x2C)
373: #define EXTI_SWIER2 (EXTI_BASE + 0x30)
374: #define EXTI_PR2 (EXTI_BASE + 0x34)
375:
376:
377: 378: 379:
380:
381:
382: 383: 384:
385: #define GPIOA_BASE 0x48000000
386: #define GPIOB_BASE 0x48000400
387: #define GPIOC_BASE 0x48000800
388: #define GPIOD_BASE 0x48000C00
389: #define GPIOE_BASE 0x48001000
390: #define GPIOF_BASE 0x48000400
391: #define GPIOG_BASE 0x48000800
392: #define GPIOH_BASE 0x48000C00
393: #define GPIOI_BASE 0x48002000
394:
395: #define GPIO_MODER(n) (GPIO##n##_BASE + 0x00)
396: #define GPIO_OTYPER(n) (GPIO##n##_BASE + 0x04)
397: #define GPIO_OSPEEDR(n) (GPIO##n##_BASE + 0x08)
398: #define GPIO_PUPDR(n) (GPIO##n##_BASE + 0x0C)
399: #define GPIO_IDR(n) (GPIO##n##_BASE + 0x10)
400: #define GPIO_ODR(n) (GPIO##n##_BASE + 0x14)
401: #define GPIO_BSRR(n) (GPIO##n##_BASE + 0x18)
402: #define GPIO_LCKR(n) (GPIO##n##_BASE + 0x1C)
403: #define GPIO_AFRL(n) (GPIO##n##_BASE + 0x20)
404: #define GPIO_AFRH(n) (GPIO##n##_BASE + 0x24)
405: #define GPIO_BRR(n) (GPIO##n##_BASE + 0x28)
406: #define GPIO_ASCR(n) (GPIO##n##_BASE + 0x2C)
407:
408:
409: 410: 411:
412: #define CPU_HAS_PTMR (1)
413:
414:
415: #define TIM2_BASE 0x40000000
416: #define TIM3_BASE 0x40000400
417: #define TIM4_BASE 0x40000800
418: #define TIM5_BASE 0x40000C00
419: #define TIM6_BASE 0x40001000
420: #define TIM7_BASE 0x40001400
421:
422: #define TIMxCR1 0x00
423: #define TIMxCR2 0x04
424: #define TIMxSMCR 0x08
425: #define TIMxDIER 0x0C
426: #define TIMxSR 0x10
427: #define TIMxEGR 0x14
428: #define TIMxCCMR1 0x18
429: #define TIMxCCMR2 0x1C
430: #define TIMxCCER 0x20
431: #define TIMxCNT 0x24
432: #define TIMxPSC 0x28
433: #define TIMxARR 0x2C
434: #define TIMxCCR1 0x34
435: #define TIMxCCR2 0x38
436: #define TIMxCCR3 0x3C
437: #define TIMxCCR4 0x40
438: #define TIMxDCR 0x48
439: #define TIMxDMAR 0x4C
440: #define TIMxOR1 0x50
441: #define TIMxOR2 0x60
442:
443: #define TIMxCR1_CEN (1<<0)
444: #define TIMxCR1_OPM (1<<3)
445: #define TIMxCR1_DIR (1<<4)
446: #define TIMxDIER_UIE (1<<0)
447: #define TIMxSR_UIF (1<<0)
448: #define TIMxEGR_UG (1<<0)
449:
450:
451: #define TIM2PSC_PSC_INIT 0
452: #define TIM3PSC_PSC_INIT 0
453: #define TIM4PSC_PSC_INIT 0
454: #define TIM5PSC_PSC_INIT 0
455:
456:
457: #define INTNO_TIM2 28
458: #define INTNO_TIM3 29
459: #define INTNO_TIM4 30
460: #define INTNO_TIM5 50
461:
462:
463: #define INTPRI_TIM2 5
464: #define INTPRI_TIM3 5
465: #define INTPRI_TIM4 5
466: #define INTPRI_TIM5 5
467:
468:
469: #define PTMR_MAX_CNT16 (0x0000FFFF)
470: #define PTMR_MAX_CNT32 (0xFFFFFFFF)
471:
472:
473: 474: 475:
476: #define CPU_HAS_FPU 1
477: #define CPU_HAS_DPS 0
478:
479: 480: 481:
482: #if USE_FPU
483: #define NUM_COPROCESSOR 1
484: #else
485: #define NUM_COPROCESSOR 0
486: #endif
487:
488: #endif