-
Notifications
You must be signed in to change notification settings - Fork 0
/
system_TM4C123GH6PM.c
633 lines (585 loc) · 23.9 KB
/
system_TM4C123GH6PM.c
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
/**************************************************************************//**
* @file system_TM4C123GH6PM.c
* @brief CMSIS Device System Source File for
* Texas Instruments TIVA TM4C123 Device Series
* @version V1.00
* @date 27. March 2013
*
* @note Comments added
******************************************************************************/
#include <stdint.h>
#include "TM4C123GH6PM.h"
/*----------------------------------------------------------------------------
DEFINES
*----------------------------------------------------------------------------*/
//
//--------------------- Clock Configuration ----------------------------------
//
// <e> Clock Configuration
// <i> Uncheck this box to skip the clock configuration.
//
// The following controls whether the system clock is configured in the
// SystemInit() function. If it is defined to be 1 then the system clock
// will be configured according to the macros in the rest of this file.
// If it is defined to be 0, then the system clock configuration is bypassed.
//
#define CLOCK_SETUP 1
//********************************* RCC ***************************************
//
// <h> Run-Mode Clock Configuration (RCC)
// <o> SYSDIV: System Clock Divisor <2-16>
// <i> Specifies the divisor used to generate the system clock from
// <i> either the PLL output of 200 MHz, or the chosen oscillator.
//
// The following value is the system clock divisor. This will be applied if
// USESYSDIV (see below) is enabled. The valid range of dividers is 2-16.
//
#define CFG_RCC_SYSDIV 4
// <q> USESYSDIV: Enable System Clock Divider
// <i> Check this box to use the System Clock Divider
//
// The following controls whether the system clock divider is used. If the
// value is 1, then the system clock divider is used, and the value of the
// system divider is defined by SYSDIV (see above). If the value is 0, then
// the system clock divider is not used.
//
#define CFG_RCC_USESYSDIV 1
// <q> USEPWMDIV: Enable PWM Clock Divider
// <i> Check this box to use the PWM Clock Divider
//
// The following controls whether the PWM clock divider is used. If the
// value is 1, then the PWM clock divider is used, and the value of the
// PWM divider is defined by PWMDIV (see below). If the value is 0, then
// the PWM clock divider is not used.
//
#define CFG_RCC_USEPWMDIV 1
// <o> PWMDIV: PWM Unit Clock Divisor
// <0=> 0: SysClk / 2
// <1=> 1: SysClk / 4
// <2=> 2: SysClk / 8
// <3=> 3: SysClk / 16
// <4=> 4: SysClk / 32
// <5=> 5: SysClk / 64
// <6=> 6: SysClk / 64
// <7=> 7: SysClk / 64 (default)
// <i> Specifies the divisor used to generate the PWM time base,
// <i> from the System Clock
//
// The following value determines the PWM clock divider. It is used if
// USEPWMDIV is enabled (see above). Otherwise the PWM clock is the same as
// the system clock. The value of the divider is determined by the table
// above.
//
#define CFG_RCC_PWMDIV 7
// <q> PWRDN: PLL Power Down
// <i> Check this box to disable the PLL. You must also choose
// <i> PLL Bypass.
//
// If the following value is 1, then the PLL is powered down. Keep this value
// as 1 if you do not need to use the PLL. In this case, BYPASS (see below)
// must also be set to 1. If you are using the PLL, then this value must be
// set to 0.
//
#define CFG_RCC_PWRDN 0
// <q> BYPASS: PLL Bypass
// <i> Check this box to not use the PLL for the System Clock
//
// Set the following value to 1 to bypass the PLL and not use it for the
// system clock. You must set this to 1 if PWRDN (above) is set to 1. Set
// this to 0 if you are using the PLL.
//
#define CFG_RCC_BYPASS 0
// <o> XTAL: Crystal Value
// < 0=> 0: 1.0000 MHz (can not be used with PLL)
// < 1=> 1: 1.8432 MHz (can not be used with PLL)
// < 2=> 2: 2.0000 MHz (can not be used with PLL)
// < 3=> 3: 2.4576 MHz (can not be used with PLL)
// < 4=> 4: 3.579545 MHz
// < 5=> 5: 3.6864 MHz
// < 6=> 6: 4.0000 MHz
// < 7=> 7: 4.096 MHz
// < 8=> 8: 4.9152 MHz
// < 9=> 9: 5.0000 MHz
// <10=> 10: 5.12 MHz
// <11=> 11: 6.0000 MHz (default)
// <12=> 12: 6.144 MHz
// <13=> 13: 7.3728 MHz
// <14=> 14: 8.0000 MHz
// <15=> 15: 8.192 MHz
// <16=> 16: 10.0 MHz
// <17=> 17: 12.0 MHz
// <18=> 18: 12.288 MHz
// <19=> 19: 13.56 MHz
// <20=> 20: 14.31818 MHz
// <21=> 21: 16.0 MHz
// <22=> 22: 16.384 MHz
// <i> This is the crystal frequency used for the main oscillator
//
// This value defines the crystal frequency for the main oscillator, according
// to the table in the comments above. If an external crystal is used, then
// this value must be set to match the value of the crystal.
//
#define CFG_RCC_XTAL 21
// <o> OSCSRC: Oscillator Source
// <0=> 0: MOSC Main oscillator
// <1=> 1: IOSC Internal oscillator (default)
// <2=> 2: IOSC/4 Internal oscillator / 4 (this is necessary if used as input to PLL)
// <3=> 3: 30kHz 30-KHz internal oscillator
// <i> Chooses the oscillator that is used for the system clock,
// <i> or the PLL input.
//
// The following value chooses the oscillator source according to the table in
// the comments above.
//
#define CFG_RCC_OSCSRC 0
// <q> IOSCDIS: Internal Oscillator Disable
// <i> Check this box to turn off the internal oscillator
//
// Set the following value to 1 to turn off the internal oscillator. This
// value can be set to 1 if you are not using the internal oscillator.
//
#define CFG_RCC_IOSCDIS 1
// <q> MOSCDIS: Main Oscillator Disable
// <i> Check this box to turn off the main oscillator
//
// Set the following value to 1 to turn off the main oscillator. This
// value can be set to 1 if you are not using the main oscillator.
//
#define CFG_RCC_MOSCDIS 0
// </h>
//********************************* RCC2 **************************************
//
// <h> Run-Mode Clock Configuration 2 (RCC2)
// <q> USERCC2: Use RCC2
// <i> Check this box to override some fields in RCC. RCC2 provides
// <i> more bits for the system clock divider, and provides an
// <i> additional oscillator source. If you do not need these
// <i> additional features, then leave this box unchecked.
//
// Set the following value to 1 to use the RCC2 register. The RCC2 register
// overrides some of the fields in the RCC register if it is used.
//
#define CFG_RCC2_USERCC2 0
// <o> SYSDIV2: System Clock Divisor <2-64>
// <i> Specifies the divisor used to generate the system clock from
// <i> either the PLL output of 200 MHz, or the oscillator.
//
// The following value is the system clock divisor. This will be applied if
// USESYSDIV in RCC is enabled. The valid range of dividers is 2-64.
//
#define CFG_RCC_SYSDIV2 4
// <q> PWRDN2: Power Down PLL
// <i> Check this box to disable the PLL. You must also choose
// <i> PLL Bypass.
//
// If the following value is 1, then the PLL is powered down. Keep this value
// as 1 if you do not need to use the PLL. In this case, BYPASS2 (see below)
// must also be set to 1. If you are using the PLL, then this value must be
// set to 0.
//
#define CFG_RCC_PWRDN2 0
// <q> BYPASS2: Bypass PLL
// <i> Check this box to not use the PLL for the System Clock
//
// Set the following value to 1 to bypass the PLL and not use it for the
// system clock. You must set this to 1 if PWRDN2 (above) is set to 1. Set
// this to 0 if you are using the PLL.
//
#define CFG_RCC_BYPASS2 0
// <o> OSCSRC2: Oscillator Source
// <0=> 0: MOSC Main oscillator
// <1=> 1: IOSC Internal oscillator (default)
// <2=> 2: IOSC/4 Internal oscillator / 4 (this is necessary if used as input to PLL)
// <3=> 3: 30kHz 30-kHz internal oscillator
// <7=> 7: 32kHz 32.768-kHz external oscillator
// <i> The oscillator that is used for the system clock, or the PLL input.
//
// The following value chooses the oscillator source according to the table in
// the comments above.
//
#define CFG_RCC_OSCSRC2 0
// </h>
//
// </e>
//-------- <<< end of configuration section >>> ------------------------------
//
// The following macros are used to program the RCC and RCC2 registers in
// the SystemInit() function. Edit the macros above to change these values.
//
#define RCC_Val \
( \
((CFG_RCC_SYSDIV - 1) << 23) | \
(CFG_RCC_USESYSDIV << 22) | \
(CFG_RCC_USEPWMDIV << 20) | \
(CFG_RCC_PWMDIV << 17) | \
(CFG_RCC_PWRDN << 13) | \
(CFG_RCC_BYPASS << 11) | \
(CFG_RCC_XTAL << 6) | \
(CFG_RCC_OSCSRC << 4) | \
(CFG_RCC_IOSCDIS << 1) | \
(CFG_RCC_MOSCDIS << 1)\
)
#define RCC2_Val \
( \
(CFG_RCC2_USERCC2 << 31) | \
((CFG_RCC_SYSDIV2 - 1) << 23) | \
(CFG_RCC_PWRDN2 << 13) | \
(CFG_RCC_BYPASS2 << 11) | \
(CFG_RCC_OSCSRC2 << 4)\
)
/*----------------------------------------------------------------------------
Define clocks
*----------------------------------------------------------------------------*/
#define XTALM (16000000UL) /* Main oscillator freq */
#define XTALI (12000000UL) /* Internal oscillator freq */
#define XTAL30K ( 30000UL) /* Internal 30K oscillator freq */
#define XTAL32K ( 32768UL) /* external 32K oscillator freq */
#define PLL_CLK (400000000UL) /* PLL clock of 40MHz. */
#define ADC_CLK (PLL_CLK/25)
#define CAN_CLK (PLL_CLK/50)
/* Determine clock frequency according to clock register values */
#if (RCC2_Val & (1UL<<31)) /* is rcc2 used ? */
#if (RCC2_Val & (1UL<<11)) /* check BYPASS */
#if (((RCC2_Val>>4) & 0x07) == 0x0)
#if (((RCC_Val>>6) & 0x1F) == 0x0)
#define __CORE_CLK_PRE 1000000UL
#elif (((RCC_Val>>6) & 0x1F) == 0x1)
#define __CORE_CLK_PRE 1843200UL
#elif (((RCC_Val>>6) & 0x1F) == 0x2)
#define __CORE_CLK_PRE 2000000UL
#elif (((RCC_Val>>6) & 0x1F) == 0x3)
#define __CORE_CLK_PRE 2457600UL
#elif (((RCC_Val>>6) & 0x1F) == 0x4)
#define __CORE_CLK_PRE 3579545UL
#elif (((RCC_Val>>6) & 0x1F) == 0x5)
#define __CORE_CLK_PRE 3686400UL
#elif (((RCC_Val>>6) & 0x1F) == 0x6)
#define __CORE_CLK_PRE 4000000UL
#elif (((RCC_Val>>6) & 0x1F) == 0x7)
#define __CORE_CLK_PRE 4096000UL
#elif (((RCC_Val>>6) & 0x1F) == 0x8)
#define __CORE_CLK_PRE 4915200UL
#elif (((RCC_Val>>6) & 0x1F) == 0x9)
#define __CORE_CLK_PRE 5000000UL
#elif (((RCC_Val>>6) & 0x1F) == 0xA)
#define __CORE_CLK_PRE 5120000UL
#elif (((RCC_Val>>6) & 0x1F) == 0xB)
#define __CORE_CLK_PRE 6000000UL
#elif (((RCC_Val>>6) & 0x1F) == 0xC)
#define __CORE_CLK_PRE 6144000UL
#elif (((RCC_Val>>6) & 0x1F) == 0xD)
#define __CORE_CLK_PRE 7372800UL
#elif (((RCC_Val>>6) & 0x1F) == 0xE)
#define __CORE_CLK_PRE 8000000UL
#elif (((RCC_Val>>6) & 0x1F) == 0xF)
#define __CORE_CLK_PRE 8192000UL
#elif (((RCC_Val>>6) & 0x1F) == 0x10)
#define __CORE_CLK_PRE 10000000UL
#elif (((RCC_Val>>6) & 0x1F) == 0x11)
#define __CORE_CLK_PRE 12000000UL
#elif (((RCC_Val>>6) & 0x1F) == 0x12)
#define __CORE_CLK_PRE 12288000UL
#elif (((RCC_Val>>6) & 0x1F) == 0x13)
#define __CORE_CLK_PRE 13560000UL
#elif (((RCC_Val>>6) & 0x1F) == 0x14)
#define __CORE_CLK_PRE 14318180UL
#elif (((RCC_Val>>6) & 0x1F) == 0x15)
#define __CORE_CLK_PRE 16000000UL
#else
#define __CORE_CLK_PRE 16384000UL
#endif
#elif (((RCC2_Val>>4) & 0x07) == 0x1)
#define __CORE_CLK_PRE XTALI
#elif (((RCC2_Val>>4) & 0x07) == 0x2)
#define __CORE_CLK_PRE (XTALI/4)
#else
#define __CORE_CLK_PRE XTAL30K
#endif
#else
#define __CORE_CLK_PRE PLL_CLK
#endif
#if (RCC_Val & (1UL<<22)) /* check USESYSDIV */
#if (RCC2_Val & (1UL<<11))
#define __CORE_CLK (__CORE_CLK_PRE / (((RCC2_Val>>23) & (0x3F)) + 1))
#else
#define __CORE_CLK (__CORE_CLK_PRE / (((RCC2_Val>>23) & (0x3F)) + 1) / 2)
#endif
#else
#define __CORE_CLK __CORE_CLK_PRE
#endif
#else
#if (RCC_Val & (1UL<<11)) /* check BYPASS */
#if (((RCC_Val>>4) & 0x03) == 0x0)
#if (((RCC_Val>>6) & 0x1F) == 0x0)
#define __CORE_CLK_PRE 1000000UL
#elif (((RCC_Val>>6) & 0x1F) == 0x1)
#define __CORE_CLK_PRE 1843200UL
#elif (((RCC_Val>>6) & 0x1F) == 0x2)
#define __CORE_CLK_PRE 2000000UL
#elif (((RCC_Val>>6) & 0x1F) == 0x3)
#define __CORE_CLK_PRE 2457600UL
#elif (((RCC_Val>>6) & 0x1F) == 0x4)
#define __CORE_CLK_PRE 3579545UL
#elif (((RCC_Val>>6) & 0x1F) == 0x5)
#define __CORE_CLK_PRE 3686400UL
#elif (((RCC_Val>>6) & 0x1F) == 0x6)
#define __CORE_CLK_PRE 4000000UL
#elif (((RCC_Val>>6) & 0x1F) == 0x7)
#define __CORE_CLK_PRE 4096000UL
#elif (((RCC_Val>>6) & 0x1F) == 0x8)
#define __CORE_CLK_PRE 4915200UL
#elif (((RCC_Val>>6) & 0x1F) == 0x9)
#define __CORE_CLK_PRE 5000000UL
#elif (((RCC_Val>>6) & 0x1F) == 0xA)
#define __CORE_CLK_PRE 5120000UL
#elif (((RCC_Val>>6) & 0x1F) == 0xB)
#define __CORE_CLK_PRE 6000000UL
#elif (((RCC_Val>>6) & 0x1F) == 0xC)
#define __CORE_CLK_PRE 6144000UL
#elif (((RCC_Val>>6) & 0x1F) == 0xD)
#define __CORE_CLK_PRE 7372800UL
#elif (((RCC_Val>>6) & 0x1F) == 0xE)
#define __CORE_CLK_PRE 8000000UL
#elif (((RCC_Val>>6) & 0x1F) == 0xF)
#define __CORE_CLK_PRE 8192000UL
#elif (((RCC_Val>>6) & 0x1F) == 0x10)
#define __CORE_CLK_PRE 10000000UL
#elif (((RCC_Val>>6) & 0x1F) == 0x11)
#define __CORE_CLK_PRE 12000000UL
#elif (((RCC_Val>>6) & 0x1F) == 0x12)
#define __CORE_CLK_PRE 12288000UL
#elif (((RCC_Val>>6) & 0x1F) == 0x13)
#define __CORE_CLK_PRE 13560000UL
#elif (((RCC_Val>>6) & 0x1F) == 0x14)
#define __CORE_CLK_PRE 14318180UL
#elif (((RCC_Val>>6) & 0x1F) == 0x15)
#define __CORE_CLK_PRE 16000000UL
#else
#define __CORE_CLK_PRE 16384000UL
#endif
#elif (((RCC_Val>>4) & 0x03) == 0x1)
#define __CORE_CLK_PRE XTALI
#elif (((RCC_Val>>4) & 0x03) == 0x2)
#define __CORE_CLK_PRE (XTALI/4)
#else
#define __CORE_CLK_PRE XTAL30K
#endif
#else
#define __CORE_CLK_PRE PLL_CLK
#endif
#if (RCC_Val & (1UL<<22)) /* check USESYSDIV */
#if (RCC_Val & (1UL<<11)) /* check BYPASS */
#define __CORE_CLK (__CORE_CLK_PRE / (((RCC_Val>>23) & (0x0F)) + 1))
#else
#define __CORE_CLK (__CORE_CLK_PRE / (((RCC_Val>>23) & (0x0F)) + 1) / 2)
#endif
#else
#define __CORE_CLK __CORE_CLK_PRE
#endif
#endif
/*----------------------------------------------------------------------------
Clock Variable definitions
*----------------------------------------------------------------------------*/
uint32_t SystemCoreClock = __CORE_CLK; /*!< System Clock Frequency (Core Clock)*/
/*----------------------------------------------------------------------------
Clock functions
*----------------------------------------------------------------------------*/
/* Get the OSC clock
* xtal: crystal value (XTAL field in RCC)
* oscSrc: oscillator source (OSCSRC field in RCC)
*/
static uint32_t getOscClk (uint32_t xtal, uint32_t oscSrc) {
uint32_t oscClk = XTALI;
switch (oscSrc) { /* switch OSCSRC */
case 0: /* MOSC Main oscillator */
switch (xtal) { /* switch XTAL */
case 0x0:
oscClk = 1000000UL;
break;
case 0x1:
oscClk = 1843200UL;
break;
case 0x2:
oscClk = 2000000UL;
break;
case 0x3:
oscClk = 2457600UL;
break;
case 0x4:
oscClk = 3579545UL;
break;
case 0x5:
oscClk = 3686400UL;
break;
case 0x6:
oscClk = 4000000UL;
break;
case 0x7:
oscClk = 4096000UL;
break;
case 0x8:
oscClk = 4915200UL;
break;
case 0x9:
oscClk = 5000000UL;
break;
case 0xA:
oscClk = 5120000UL;
break;
case 0xB:
oscClk = 6000000UL;
break;
case 0xC:
oscClk = 6144000UL;
break;
case 0xD:
oscClk = 7372800UL;
break;
case 0xE:
oscClk = 8000000UL;
break;
case 0xF:
oscClk = 8192000UL;
break;
case 0x10:
oscClk = 10000000UL;
break;
case 0x11:
oscClk = 12000000UL;
break;
case 0x12:
oscClk = 12288000UL;
break;
case 0x13:
oscClk = 13560000UL;
break;
case 0x14:
oscClk = 14318180UL;
break;
case 0x15:
oscClk = 16000000UL;
break;
case 0x16:
oscClk = 16384000UL;
break;
}
break;
case 1: /* IOSC Internal oscillator */
oscClk = XTALI;
break;
case 2: /* IOSC/4 Internal oscillator/4 */
oscClk = XTALI/4;
break;
case 3: /* 30kHz internal oscillator */
oscClk = XTAL30K;
break;
}
return oscClk;
}
void SystemCoreClockUpdate(void)
{
uint32_t rcc, rcc2;
/* Run-Mode Clock Configuration (RCC) and Run-Mode Clock Configuration 2 (RCC2).
* Determine clock frequency according to clock register values. */
rcc = SYSCTL->RCC;
rcc2 = SYSCTL->RCC2;
/* Check if rcc2 is used.
* In this project, no.
* if (rcc2 & SYSCTL_RCC2_USERCC2) */
if (rcc2 & (1UL << 31))
{
/* Check if BYPASS the PLL and use the OSC source.
* In this project, no.
* if (rcc2 & SYSCTL_RCC2_BYPASS2) */
if (rcc2 & (1UL << 11))
{
SystemCoreClock = getOscClk(((rcc >> 6) & 0x0F),
((rcc2 >> 4) & 0x07));
}
else
{
SystemCoreClock = PLL_CLK;
}
if (rcc & (1UL << 22))
{ /* check USESYSDIV */
if (rcc2 & (1UL << 11))
{
SystemCoreClock = SystemCoreClock
/ (((rcc2 >> 23) & (0x3F)) + 1);
}
else
{
SystemCoreClock = SystemCoreClock
/ (((rcc2 >> 23) & (0x3F)) + 1) / 2;
}
}
}
else
{
/* Check if BYPASS the PLL and use the OSC source.
* In this project, no.
* if (RCC_Val & (1UL<<11)) { */
if (rcc & (1UL << 11))
{ /* check BYPASS *//* Simulation does not work at this point */
SystemCoreClock = getOscClk(((rcc >> 6) & 0x1F),
((rcc >> 4) & 0x03));
}
else
{
SystemCoreClock = PLL_CLK;
}
/* Check if the System Clock Divider is used.
* if (rcc & SYSCTL_RCC_USE_SYSDIV) */
if (rcc & (1UL << 22))
{
// if (rcc2 & SYSCTL_RCC_BYPASS)
if (rcc & (1UL << 11))
{ /* check BYPASS *//* Simulation does not work at this point */
// if (RCC_Val & (1UL<<11)) { /* check BYPASS */
SystemCoreClock = SystemCoreClock
/ (((rcc >> 23) & (0x0F)) + 1);
}
else
{
/* Divide the PLL by the SYSDIV value. */
SystemCoreClock = SystemCoreClock / (((rcc >> 23) & (0x0F)) + 1)
/ 2;
}
}
}
}
void SystemInit(void)
{
#if(CLOCK_SETUP)
volatile uint32_t i;
#endif
/* FPU settings ------------------------------------------------------------*/
#if (__FPU_USED == 1)
SCB->CPACR |= ((3UL << 10 * 2) | /* set CP10 Full Access */
(3UL << 11 * 2)); /* set CP11 Full Access */
#endif
#if(CLOCK_SETUP)
SYSCTL->RCC2 = 0x07C06810; /* set default value 0x07C06810 */
SYSCTL->RCC = 0x078E3AD1; /* set default value 0x078E3AD1 */
SYSCTL->RCC = (RCC_Val | (1UL << 11) | (1UL << 13)) & ~(1UL << 22); /* set value with BYPASS, PWRDN set, USESYSDIV reset */
SYSCTL->RCC2 = (RCC2_Val | (1UL << 11) | (1UL << 13)); /* set value with BYPASS, PWRDN set */
for (i = 0; i < 1000; i++)
; /* wait a while */
SYSCTL->RCC = (RCC_Val | (1UL << 11)) & ~(1UL << 22); /* set value with BYPASS, USESYSDIV reset */
SYSCTL->RCC2 = (RCC2_Val | (1UL << 11)); /* set value with BYPASS */
for (i = 0; i < 1000; i++)
; /* wait a while */
SYSCTL->RCC = (RCC_Val | (1 << 11)); /* set value with BYPASS */
if ((((RCC_Val & (1UL << 13)) == 0) && ((RCC2_Val & (1UL << 31)) == 0))
|| (((RCC2_Val & (1UL << 13)) == 0)
&& ((RCC2_Val & (1UL << 31)) != 0)))
{
while ((SYSCTL->RIS & (1UL << 6)) != (1UL << 6))
; /* wait until PLL is locked */
}
SYSCTL->RCC = (RCC_Val); /* set value */
SYSCTL->RCC2 = (RCC2_Val); /* set value */
for (i = 0; i < 10000; i++)
; /* wait a while */
#endif
}