-
Notifications
You must be signed in to change notification settings - Fork 51
/
family-mk.c
814 lines (738 loc) · 31.2 KB
/
family-mk.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
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
/*
* Routines specific for PIC32 MK family.
*
* Copyright (C) 2013 Serge Vakulenko
*
* This file is part of PIC32PROG project, which is distributed
* under the terms of the GNU General Public License (GPL).
* See the accompanying file "COPYING" for more details.
*/
#include <stdio.h>
#include "pic32.h"
#include <stdint.h>
#define PRIMARY 0
#define ALTERNATE 1
void print_mk_devcfg3(uint32_t devcfg3, uint32_t alternate);
void print_mk_devcfg2(uint32_t devcfg2, uint32_t alternate);
void print_mk_devcfg1(uint32_t devcfg1, uint32_t alternate);
void print_mk_devcfg0(uint32_t devcfg0, uint32_t alternate);
void print_mk_devcp(uint32_t devcp, uint32_t alternate);
void print_mk_devsign(uint32_t devsign, uint32_t alternate);
void print_mk_devseq(uint32_t devseq, uint32_t alternate);
void print_mk_devsn(uint32_t devsn0, uint32_t devsn1, uint32_t devsn2,
uint32_t devsn3);
/*
* Print configuration for MK family.
*/
void print_mk(unsigned cfg0, unsigned cfg1, unsigned cfg2, unsigned cfg3,
unsigned cfg4, unsigned cfg5, unsigned cfg6, unsigned cfg7,
unsigned cfg8, unsigned cfg9, unsigned cfg10, unsigned cfg11,
unsigned cfg12, unsigned cfg13, unsigned cfg14, unsigned cfg15,
unsigned cfg16, unsigned cfg17)
{
printf("Boot flash 1 bits\n");
print_mk_devcfg3(cfg0, PRIMARY);
print_mk_devcfg2(cfg1, PRIMARY);
print_mk_devcfg1(cfg2, PRIMARY);
print_mk_devcfg0(cfg3, PRIMARY);
print_mk_devcp(cfg4, PRIMARY);
print_mk_devsign(cfg5, PRIMARY);
print_mk_devseq(cfg6, PRIMARY);
printf("Boot flash 2 bits\n");
print_mk_devcfg3(cfg7, ALTERNATE);
print_mk_devcfg2(cfg8, ALTERNATE);
print_mk_devcfg1(cfg9, ALTERNATE);
print_mk_devcfg0(cfg10, ALTERNATE);
print_mk_devcp(cfg11, ALTERNATE);
print_mk_devsign(cfg12, ALTERNATE);
print_mk_devseq(cfg13, ALTERNATE);
// UUID of chip
print_mk_devsn(cfg14, cfg15, cfg16, cfg17);
// Write out which is in the Lower Boot Alias, and which Upper
// If DEVSEQ TSEQ val in Boot flash 1 is >= than in Boot flash 2,
// Then it is the Lower Boot Alias. Else it is Boot flash 2.
if ((cfg6 & 0xFFFF) >= (cfg13 & 0xFFFF)){
printf(" Boot flash 1 aliased by Lower Boot Alias.\n Boot flash 2 is aliased by Upper Boot alias\n");
}
else{
printf(" Boot flash 2 aliased by Lower Boot Alias.\n Boot flash 1 is aliased by Upper Boot Alias\n");
}
}
// When printing values, shift so the value fits into the first 4 bits.
// That way, can align it under each nibble.
// If there's more bits, shift so it fits into 8 bits, and display as %02x
// ALL values are in hex.
void print_mk_devsn(uint32_t devsn0, uint32_t devsn1, uint32_t devsn2,
uint32_t devsn3){
printf(" UUID: 0x%08x 0x%08x 0x%08x 0x%08x\n", devsn0, devsn1, devsn2, devsn3);
}
void print_mk_devcfg3(uint32_t devcfg3, uint32_t alternate){
// DEVCFG3
if (PRIMARY == alternate){
printf(" BF1DEVCFG3 = 0x%08X\n", devcfg3);
}
else{
printf(" BF2DEVCFG3 = 0x%08X\n", devcfg3);
}
if (devcfg3 & MK_DEVCFG3_FVBUSIO1){
printf(" %01x VBUSON pin: controlled by USB1 module\n", MK_DEVCFG3_FVBUSIO1 >> 28);
}
else{
printf(" %01x VBUSON pin: controlled by port function\n", 0);
}
if (devcfg3 & MK_DEVCFG3_FUSBIDIO1){
printf(" %01x USBID pin: controlled by USB1 module\n", MK_DEVCFG3_FUSBIDIO1 >> 28);
}
else{
printf(" %01x USBID pin: controlled by port function\n", 0);
}
if (devcfg3 & MK_DEVCFG3_IOL1WAY){
printf(" %01x Peripheral Pin Select - Allow only one configuration\n", MK_DEVCFG3_IOL1WAY >> 28);
}
else{
printf(" %01x Peripheral Pin Select - Allow multiple configurations\n", 0);
}
if (devcfg3 & MK_DEVCFG3_PMDL1WAY){
printf(" %01x Permission Module Disable - Allow only one configuration\n", MK_DEVCFG3_PMDL1WAY >> 28);
}
else{
printf(" %01x Permission Module Disable - Allow multiple configurations\n", 0);
}
if (devcfg3 & MK_DEVCFG3_PGL1WAY){
printf(" %01x Permission Group Lock - Allow only one configuration\n", MK_DEVCFG3_PGL1WAY >> 24);
}
else{
printf(" %01x Permission Group Lock - Allow multiple configurations\n", 0);
}
if (devcfg3 & MK_DEVCFG3_FVBUSIO2){
printf(" %01x VBUSON pin: controlled by USB2 module\n", MK_DEVCFG3_FVBUSIO2 >> 20);
}
else{
printf(" %01x VBUSON pin: controlled by port function\n", 0);
}
if (devcfg3 & MK_DEVCFG3_FUSBIDIO2){
printf(" %01x USBID pin: controlled by USB2 module\n", MK_DEVCFG3_FUSBIDIO2 >> 20);
}
else{
printf(" %01x USBID pin: controlled by port function\n", 0);
}
if (devcfg3 & MK_DEVCFG3_PWMLOCK){
printf(" %01x Write access to PWM IOCONx not locked\n", MK_DEVCFG3_PWMLOCK >> 20);
}
else{
printf(" %01x Write access to PWM IOCONx locked\n", 0);
}
printf(" %04X USERID\n", devcfg3 & MK_DEVCFG3_USERID_MASK);
}
void print_mk_devcfg2(uint32_t devcfg2, uint32_t alternate){
// DEVCFG2
if (PRIMARY == alternate){
printf(" BF1DEVCFG2 = 0x%08X\n", devcfg2);
}
else{
printf(" BF2DEVCFG2 = 0x%08X\n", devcfg2);
}
if (devcfg2 & MK_DEVCFG2_UPLLEN){
printf(" %01x USB PLL is disabled\n", MK_DEVCFG2_UPLLEN >> 28);
}
else{
printf(" %01x USB PLL is disabled\n", 0);
}
if (devcfg2 & MK_DEVCFG2_BORSEL){
printf(" %01x BOR trip voltage 2.1V (non-Opamp device operation)\n", MK_DEVCFG2_BORSEL >> 28);
}
else{
printf(" %01x BOR trip voltage 2.8V (Opamp device operation)\n", 0);
}
if (devcfg2 & MK_DEVCFG2_FDSEN){
printf(" %01x DS bit (DSCON<15>) is enabled on WAIT command\n", MK_DEVCFG2_FDSEN >> 28);
}
else{
printf(" %01x DS bit (DSCON<15>) is disabled\n", 0);
}
if (devcfg2 & MK_DEVCFG2_DSWDTEN){
printf(" %01x Enable DSWDT dring Deep Sleep\n", MK_DEVCFG2_DSWDTEN >> 24);
}
else{
printf(" %01x Disable DSWDT dring Deep Sleep\n", 0);
}
if (devcfg2 & MK_DEVCFG2_DSWDTOSC){
printf(" %01x LPRC as DSWDT reference clock\n", MK_DEVCFG2_DSWDTOSC >> 24);
}
else{
printf(" %01x SOSC as DSWDT reference clock\n", 0);
}
switch (devcfg2 & MK_DEVCFG2_DSWDTPS_MASK){
case MK_DEVCFG2_DSWDTPS_236:
printf(" %02x WDT Postscale 1:2^36 (25.7 days)\n", (devcfg2 & MK_DEVCFG2_DSWDTPS_MASK) >> 20);
break;
case MK_DEVCFG2_DSWDTPS_235:
printf(" %02x WDT Postscale 1:2^35 (12.8 days)\n", (devcfg2 & MK_DEVCFG2_DSWDTPS_MASK) >> 20);
break;
case MK_DEVCFG2_DSWDTPS_234:
printf(" %02x WDT Postscale 1:2^34 (6.4 days)\n", (devcfg2 & MK_DEVCFG2_DSWDTPS_MASK) >> 20);
break;
case MK_DEVCFG2_DSWDTPS_233:
printf(" %02x WDT Postscale 1:2^33 (77.0 hours)\n", (devcfg2 & MK_DEVCFG2_DSWDTPS_MASK) >> 20);
break;
case MK_DEVCFG2_DSWDTPS_232:
printf(" %02x WDT Postscale 1:2^32 (38.5 hours)\n", (devcfg2 & MK_DEVCFG2_DSWDTPS_MASK) >> 20);
break;
case MK_DEVCFG2_DSWDTPS_231:
printf(" %02x WDT Postscale 1:2^31 (19.2 hours)\n", (devcfg2 & MK_DEVCFG2_DSWDTPS_MASK) >> 20);
break;
case MK_DEVCFG2_DSWDTPS_230:
printf(" %02x WDT Postscale 1:2^30 (9.6 hours)\n", (devcfg2 & MK_DEVCFG2_DSWDTPS_MASK) >> 20);
break;
case MK_DEVCFG2_DSWDTPS_229:
printf(" %02x WDT Postscale 1:2^29 (4.8 hours)\n", (devcfg2 & MK_DEVCFG2_DSWDTPS_MASK) >> 20);
break;
case MK_DEVCFG2_DSWDTPS_228:
printf(" %02x WDT Postscale 1:2^28 (2.4 hours)\n", (devcfg2 & MK_DEVCFG2_DSWDTPS_MASK) >> 20);
break;
case MK_DEVCFG2_DSWDTPS_227:
printf(" %02x WDT Postscale 1:2^27 (72.2 minutes)\n", (devcfg2 & MK_DEVCFG2_DSWDTPS_MASK) >> 20);
break;
case MK_DEVCFG2_DSWDTPS_226:
printf(" %02x WDT Postscale 1:2^26 (36.1 minutes)\n", (devcfg2 & MK_DEVCFG2_DSWDTPS_MASK) >> 20);
break;
case MK_DEVCFG2_DSWDTPS_225:
printf(" %02x WDT Postscale 1:2^25 (18.0 minutes)\n", (devcfg2 & MK_DEVCFG2_DSWDTPS_MASK) >> 20);
break;
case MK_DEVCFG2_DSWDTPS_224:
printf(" %02x WDT Postscale 1:2^24 (9.0 minutes)\n", (devcfg2 & MK_DEVCFG2_DSWDTPS_MASK) >> 20);
break;
case MK_DEVCFG2_DSWDTPS_223:
printf(" %02x WDT Postscale 1:2^23 (4.5 minutes)\n", (devcfg2 & MK_DEVCFG2_DSWDTPS_MASK) >> 20);
break;
case MK_DEVCFG2_DSWDTPS_222:
printf(" %02x WDT Postscale 1:2^22 (135.5 seconds)\n", (devcfg2 & MK_DEVCFG2_DSWDTPS_MASK) >> 20);
break;
case MK_DEVCFG2_DSWDTPS_221:
printf(" %02x WDT Postscale 1:2^21 (67.7 seconds)\n", (devcfg2 & MK_DEVCFG2_DSWDTPS_MASK) >> 20);
break;
case MK_DEVCFG2_DSWDTPS_220:
printf(" %02x WDT Postscale 1:2^20 (33.825 seconds)\n", (devcfg2 & MK_DEVCFG2_DSWDTPS_MASK) >> 20);
break;
case MK_DEVCFG2_DSWDTPS_219:
printf(" %02x WDT Postscale 1:2^19 (16.912 seconds)\n", (devcfg2 & MK_DEVCFG2_DSWDTPS_MASK) >> 20);
break;
case MK_DEVCFG2_DSWDTPS_218:
printf(" %02x WDT Postscale 1:2^18 (8.456 seconds)\n", (devcfg2 & MK_DEVCFG2_DSWDTPS_MASK) >> 20);
break;
case MK_DEVCFG2_DSWDTPS_217:
printf(" %02x WDT Postscale 1:2^17 (4.228 seconds)\n", (devcfg2 & MK_DEVCFG2_DSWDTPS_MASK) >> 20);
break;
case MK_DEVCFG2_DSWDTPS_65536:
printf(" %02x WDT Postscale 1:2^16 (2.114 seconds)\n", (devcfg2 & MK_DEVCFG2_DSWDTPS_MASK) >> 20);
break;
case MK_DEVCFG2_DSWDTPS_32768:
printf(" %02x WDT Postscale 1:2^15 (1.057 seconds)\n", (devcfg2 & MK_DEVCFG2_DSWDTPS_MASK) >> 20);
break;
case MK_DEVCFG2_DSWDTPS_16384:
printf(" %02x WDT Postscale 1:2^14 (528.5 milliseconds)\n", (devcfg2 & MK_DEVCFG2_DSWDTPS_MASK) >> 20);
break;
case MK_DEVCFG2_DSWDTPS_8192:
printf(" %02x WDT Postscale 1:2^13 (264.3 milliseconds)\n", (devcfg2 & MK_DEVCFG2_DSWDTPS_MASK) >> 20);
break;
case MK_DEVCFG2_DSWDTPS_4096:
printf(" %02x WDT Postscale 1:2^12 (132.1 milliseconds)\n", (devcfg2 & MK_DEVCFG2_DSWDTPS_MASK) >> 20);
break;
case MK_DEVCFG2_DSWDTPS_2048:
printf(" %02x WDT Postscale 1:2^11 (66.1 milliseconds)\n", (devcfg2 & MK_DEVCFG2_DSWDTPS_MASK) >> 20);
break;
case MK_DEVCFG2_DSWDTPS_1024:
printf(" %02x WDT Postscale 1:2^10 (33 milliseconds)\n", (devcfg2 & MK_DEVCFG2_DSWDTPS_MASK) >> 20);
break;
case MK_DEVCFG2_DSWDTPS_512:
printf(" %02x WDT Postscale 1:2^9 (16.5 milliseconds)\n", (devcfg2 & MK_DEVCFG2_DSWDTPS_MASK) >> 20);
break;
case MK_DEVCFG2_DSWDTPS_256:
printf(" %02x WDT Postscale 1:2^8 (8.3 milliseconds)\n", (devcfg2 & MK_DEVCFG2_DSWDTPS_MASK) >> 20);
break;
case MK_DEVCFG2_DSWDTPS_128:
printf(" %02x WDT Postscale 1:2^7 (4.1 milliseconds)\n", (devcfg2 & MK_DEVCFG2_DSWDTPS_MASK) >> 20);
break;
case MK_DEVCFG2_DSWDTPS_64:
printf(" %02x WDT Postscale 1:2^6 (2.1 milliseconds)\n", (devcfg2 & MK_DEVCFG2_DSWDTPS_MASK) >> 20);
break;
case MK_DEVCFG2_DSWDTPS_32:
printf(" %02x WDT Postscale 1:2^5 (1 millisecond)\n", (devcfg2 & MK_DEVCFG2_DSWDTPS_MASK) >> 20);
break;
}
if (devcfg2 & MK_DEVCFG2_DSBOREN){
printf(" %01x Enable ZPBOR during deep sleep\n", MK_DEVCFG2_DSBOREN >> 20);
}
else{
printf(" %01x Disable ZPBOR during deep sleep\n", 0);
}
if (devcfg2 & MK_DEVCFG2_VBATBOREN){
printf(" %01x Enable ZPBOR during VBAT mode\n", MK_DEVCFG2_VBATBOREN >> 16);
}
else{
printf(" %01x Disable ZPBOR during VBAT mode\n", 0);
}
switch (devcfg2 & MK_DEVCFG2_FPLLODIV_MASK){
case MK_DEVCFG2_FPLLODIV_32_1:
case MK_DEVCFG2_FPLLODIV_32_2:
case MK_DEVCFG2_FPLLODIV_32_3:
printf(" %01x PLL output divided by 32\n", (devcfg2 & MK_DEVCFG2_FPLLODIV_MASK) >> 16);
break;
case MK_DEVCFG2_FPLLODIV_16:
printf(" %01x PLL output divided by 16\n", (devcfg2 & MK_DEVCFG2_FPLLODIV_MASK) >> 16);
break;
case MK_DEVCFG2_FPLLODIV_8:
printf(" %01x PLL output divided by 8\n", (devcfg2 & MK_DEVCFG2_FPLLODIV_MASK) >> 16);
break;
case MK_DEVCFG2_FPLLODIV_4:
printf(" %01x PLL output divided by 4\n", (devcfg2 & MK_DEVCFG2_FPLLODIV_MASK) >> 16);
break;
case MK_DEVCFG2_FPLLODIV_2_1:
case MK_DEVCFG2_FPLLODIV_2_2:
printf(" %01x PLL output divided by 2\n", (devcfg2 & MK_DEVCFG2_FPLLODIV_MASK) >> 16);
break;
}
printf(" %02x PLL output divided by %d\n",
(devcfg2 & MK_DEVCFG2_FPLLMULT_MASK) >> MK_DEVCFG2_FPLLMULT_SHIFT,
((devcfg2 & MK_DEVCFG2_FPLLMULT_MASK) >> MK_DEVCFG2_FPLLMULT_SHIFT) + MK_DEVCFG2_FPLLMULT_MIN_VAL);
if (devcfg2 & MK_DEVCFG2_FPLLICLK){
printf(" %01x FRC is selected as input to System PLL\n", MK_DEVCFG2_FPLLICLK >> 4);
}
else{
printf(" %01x POSC is selected as input to System PLL\n", 0);
}
switch (devcfg2 & MK_DEVCFG2_FPLLRNG_MASK){
case MK_DEVCFG2_FPLLRNG_34_64:
printf(" %01x System PLL Input clock range 34-64 MHz\n", (devcfg2 & MK_DEVCFG2_FPLLRNG_MASK) >> 4);
break;
case MK_DEVCFG2_FPLLRNG_21_42:
printf(" %01x System PLL Input clock range 21-42 MHz\n", (devcfg2 & MK_DEVCFG2_FPLLRNG_MASK) >> 4);
break;
case MK_DEVCFG2_FPLLRNG_13_26:
printf(" %01x System PLL Input clock range 13-26 MHz\n", (devcfg2 & MK_DEVCFG2_FPLLRNG_MASK) >> 4);
break;
case MK_DEVCFG2_FPLLRNG_8_16:
printf(" %01x System PLL Input clock range 8-16 MHz\n", (devcfg2 & MK_DEVCFG2_FPLLRNG_MASK) >> 4);
break;
case MK_DEVCFG2_FPLLRNG_5_10:
printf(" %01x System PLL Input clock range 5-10 MHz\n", (devcfg2 & MK_DEVCFG2_FPLLRNG_MASK) >> 4);
break;
case MK_DEVCFG2_FPLLRNG_BYPASS:
printf(" %01x System PLL Input clock range BYPASS\n", (devcfg2 & MK_DEVCFG2_FPLLRNG_MASK) >> 4);
break;
default:
printf(" %01x System PLL Input clock range RESERVED\n", (devcfg2 & MK_DEVCFG2_FPLLRNG_MASK) >> 4);
break;
}
switch (devcfg2 & MK_DEVCFG2_FPLLIDIV_MASK){
case MK_DEVCFG2_FPLLIDIV_8:
printf(" %01x PLL input - Divide by 8\n", devcfg2 & MK_DEVCFG2_FPLLIDIV_MASK);
break;
case MK_DEVCFG2_FPLLIDIV_7:
printf(" %01x PLL input - Divide by 7\n", devcfg2 & MK_DEVCFG2_FPLLIDIV_MASK);
break;
case MK_DEVCFG2_FPLLIDIV_6:
printf(" %01x PLL input - Divide by 6\n", devcfg2 & MK_DEVCFG2_FPLLIDIV_MASK);
break;
case MK_DEVCFG2_FPLLIDIV_5:
printf(" %01x PLL input - Divide by 5\n", devcfg2 & MK_DEVCFG2_FPLLIDIV_MASK);
break;
case MK_DEVCFG2_FPLLIDIV_4:
printf(" %01x PLL input - Divide by 4\n", devcfg2 & MK_DEVCFG2_FPLLIDIV_MASK);
break;
case MK_DEVCFG2_FPLLIDIV_3:
printf(" %01x PLL input - Divide by 3\n", devcfg2 & MK_DEVCFG2_FPLLIDIV_MASK);
break;
case MK_DEVCFG2_FPLLIDIV_2:
printf(" %01x PLL input - Divide by 2\n", devcfg2 & MK_DEVCFG2_FPLLIDIV_MASK);
break;
case MK_DEVCFG2_FPLLIDIV_1:
printf(" %01x PLL input - Divide by 1\n", devcfg2 & MK_DEVCFG2_FPLLIDIV_MASK);
break;
}
}
void print_mk_devcfg1(uint32_t devcfg1, uint32_t alternate){
// DEVCFG1
if (PRIMARY == alternate){
printf(" BF1DEVCFG1 = 0x%08X\n", devcfg1);
}
else{
printf(" BF2DEVCFG1 = 0x%08X\n", devcfg1);
}
if (devcfg1 & MK_DEVCFG1_FDMTEN){
printf(" %01x Deadman Timer enabled and CANNOT be disabled in SW\n", MK_DEVCFG1_FDMTEN >> 28);
}
else{
printf(" %01x Deadman Timer disabled and can be enabled in SW\n", 0);
}
if ( ((devcfg1 & MK_DEVCFG1_DMTCNT_MASK) >> MK_DEVCFG1_DMTCNT_SHIFT) >
(MK_DEVCFG1_DMTCNT_MAX_EXPONENT - MK_DEVCFG1_DMTCNT_MIN_EXPONENT)){
printf(" %02x Deadman Timer Count Select: RESERVED\n", (devcfg1 & MK_DEVCFG1_DMTCNT_MASK) >> 24);
}
else{
printf(" %02x Deadman Timer Count Select: 2^%d (%d)\n",
(devcfg1 & MK_DEVCFG1_DMTCNT_MASK) >> 24,
8 + ((devcfg1 & MK_DEVCFG1_DMTCNT_MASK) >> MK_DEVCFG1_DMTCNT_SHIFT),
1<<(8 + ((devcfg1 & MK_DEVCFG1_DMTCNT_MASK) >> MK_DEVCFG1_DMTCNT_SHIFT)));
}
switch (devcfg1 & MK_DEVCFG1_FWDTWINSZ_MASK){
case MK_DEVCFG1_FWDTWINSZ_25:
printf(" %01x Watchdog Timer Window Size 25%%\n", (devcfg1 & MK_DEVCFG1_FWDTWINSZ_MASK) >> 24);
break;
case MK_DEVCFG1_FWDTWINSZ_27_5:
printf(" %01x Watchdog Timer Window Size 37.5%%\n", (devcfg1 & MK_DEVCFG1_FWDTWINSZ_MASK) >> 24);
break;
case MK_DEVCFG1_FWDTWINSZ_50:
printf(" %01x Watchdog Timer Window Size 50%%\n", (devcfg1 & MK_DEVCFG1_FWDTWINSZ_MASK) >> 24);
break;
case MK_DEVCFG1_FWDTWINSZ_75:
printf(" %01x Watchdog Timer Window Size 75%%\n", (devcfg1 & MK_DEVCFG1_FWDTWINSZ_MASK) >> 24);
break;
}
if (devcfg1 & MK_DEVCFG1_FWDTEN){
printf(" %01x Watchdog timer is enabled, CANNOT be disabled in SW\n", MK_DEVCFG1_FWDTEN >> 20);
}
else{
printf(" %01x Watchdog Timer disabled and can be enabled in SW\n", 0);
}
if (devcfg1 & MK_DEVCFG1_WINDIS){
printf(" %01x Watchdog timer is in non-window mode\n", MK_DEVCFG1_WINDIS >> 20);
}
else{
printf(" %01x Watchdog Timer is in window mode\n", 0);
}
if (devcfg1 & MK_DEVCFG1_WDTSPGM){
printf(" %01x Watchdog timer stops during Flash programming\n", MK_DEVCFG1_WDTSPGM >> 20);
}
else{
printf(" %01x Watchdog Timer runs during Flash programming\n", 0);
}
switch (devcfg1 & MK_DEVCFG1_WDTPS_MASK){
case MK_DEVCFG1_WDTPS_524288:
printf(" %02x Watchdog Timer Postscale 1:524288\n", MK_DEVCFG1_WDTPS_1048576 >> 16);
break;
case MK_DEVCFG1_WDTPS_262144:
printf(" %02x Watchdog Timer Postscale 1:262144\n", MK_DEVCFG1_WDTPS_262144 >> 16);
break;
case MK_DEVCFG1_WDTPS_131072:
printf(" %02x Watchdog Timer Postscale 1:131072\n", MK_DEVCFG1_WDTPS_131072 >> 16);
break;
case MK_DEVCFG1_WDTPS_65536:
printf(" %02x Watchdog Timer Postscale 1:65536\n", MK_DEVCFG1_WDTPS_65536 >> 16);
break;
case MK_DEVCFG1_WDTPS_32768:
printf(" %02x Watchdog Timer Postscale 1:32768\n", MK_DEVCFG1_WDTPS_32768 >> 16);
break;
case MK_DEVCFG1_WDTPS_16384:
printf(" %02x Watchdog Timer Postscale 1:16384\n", MK_DEVCFG1_WDTPS_16384 >> 16);
break;
case MK_DEVCFG1_WDTPS_8192:
printf(" %02x Watchdog Timer Postscale 1:8192\n", MK_DEVCFG1_WDTPS_8192 >> 16);
break;
case MK_DEVCFG1_WDTPS_4096:
printf(" %02x Watchdog Timer Postscale 1:4096\n", MK_DEVCFG1_WDTPS_4096 >> 16);
break;
case MK_DEVCFG1_WDTPS_2048:
printf(" %02x Watchdog Timer Postscale 1:2048\n", MK_DEVCFG1_WDTPS_2048 >> 16);
break;
case MK_DEVCFG1_WDTPS_1024:
printf(" %02x Watchdog Timer Postscale 1:1024\n", MK_DEVCFG1_WDTPS_1024 >> 16);
break;
case MK_DEVCFG1_WDTPS_512:
printf(" %02x Watchdog Timer Postscale 1:512\n", MK_DEVCFG1_WDTPS_512 >> 16);
break;
case MK_DEVCFG1_WDTPS_256:
printf(" %02x Watchdog Timer Postscale 1:256\n", MK_DEVCFG1_WDTPS_256 >> 16);
break;
case MK_DEVCFG1_WDTPS_128:
printf(" %02x Watchdog Timer Postscale 1:128\n", MK_DEVCFG1_WDTPS_128 >> 16);
break;
case MK_DEVCFG1_WDTPS_64:
printf(" %02x Watchdog Timer Postscale 1:64\n", MK_DEVCFG1_WDTPS_64 >> 16);
break;
case MK_DEVCFG1_WDTPS_32:
printf(" %02x Watchdog Timer Postscale 1:32\n", MK_DEVCFG1_WDTPS_32 >> 16);
break;
case MK_DEVCFG1_WDTPS_16:
printf(" %02x Watchdog Timer Postscale 1:16\n", MK_DEVCFG1_WDTPS_16 >> 16);
break;
case MK_DEVCFG1_WDTPS_8:
printf(" %02x Watchdog Timer Postscale 1:8\n", MK_DEVCFG1_WDTPS_8 >> 16);
break;
case MK_DEVCFG1_WDTPS_4:
printf(" %02x Watchdog Timer Postscale 1:4\n", MK_DEVCFG1_WDTPS_4 >> 16);
break;
case MK_DEVCFG1_WDTPS_2:
printf(" %02x Watchdog Timer Postscale 1:2\n", MK_DEVCFG1_WDTPS_2 >> 16);
break;
case MK_DEVCFG1_WDTPS_1:
printf(" %02x Watchdog Timer Postscale 1:1\n", MK_DEVCFG1_WDTPS_1 >> 16);
break;
case MK_DEVCFG1_WDTPS_1048576:
default:
printf(" %02x Watchdog Timer Postscale 1:1048579\n", MK_DEVCFG1_WDTPS_1048576 >> 16);
break;
}
switch (devcfg1 & MK_DEVCFG1_FCKSM_MASK){
case MK_DEVCFG1_FCKSM_3:
printf(" %01x Clock switching enabled, clock monitoring enabled\n", MK_DEVCFG1_FCKSM_3 >> 12);
break;
case MK_DEVCFG1_FCKSM_2:
printf(" %01x Clock switching disabled, clock monitoring enabled\n", MK_DEVCFG1_FCKSM_2 >> 12);
break;
case MK_DEVCFG1_FCKSM_1:
printf(" %01x Clock switching enabled, clock monitoring disabled\n", MK_DEVCFG1_FCKSM_1 >> 12);
break;
case MK_DEVCFG1_FCKSM_0:
printf(" %01x Clock switching disabled, clock monitoring disabled\n", MK_DEVCFG1_FCKSM_0 >> 12);
break;
}
if (devcfg1 & MK_DEVCFG1_OSCIOFNC){
printf(" %01x CLKO output disabled\n", MK_DEVCFG1_OSCIOFNC >> 8);
}
else{
printf(" %01x CLKO output active on OSC2\n", 0);
}
switch (devcfg1 & MK_DEVCFG1_POSCMOD_MASK){
case MK_DEVCFG1_POSCMOD_DISABLED:
printf(" %01x POSC disabled\n", MK_DEVCFG1_POSCMOD_DISABLED >> 8);
break;
case MK_DEVCFG1_POSCMOD_HS:
printf(" %01x POSC set to HS Oscillator mode\n", MK_DEVCFG1_POSCMOD_HS >> 8);
break;
case MK_DEVCFG1_POSCMOD_RESERVED:
printf(" %01x POSC - RESERVED setting\n", MK_DEVCFG1_POSCMOD_RESERVED >> 8);
break;
case MK_DEVCFG1_POSCMOD_EC:
printf(" %01x POSC set to EC mode\n", MK_DEVCFG1_POSCMOD_EC >> 8);
break;
}
if (devcfg1 & MK_DEVCFG1_IESO){
printf(" %01x Internal External Switchover enabled\n", MK_DEVCFG1_IESO >> 4);
}
else{
printf(" %01x Internal External Switchover disabled\n", 0);
}
if (devcfg1 & MK_DEVCFG1_FSOSCEN){
printf(" %01x SOSC enabled\n", MK_DEVCFG1_FSOSCEN >> 4);
}
else{
printf(" %01x SOSC disabled\n", 0);
}
switch (devcfg1 & MK_DEVCFG1_DMTINV_MASK){
case MK_DEVCFG1_DMTINV_127_128:
printf(" %02x Deadman Timer Window is 127/128 counter value\n", MK_DEVCFG1_DMTINV_127_128);
break;
case MK_DEVCFG1_DMTINV_63_64:
printf(" %02x Deadman Timer Window is 63/64 counter value\n", MK_DEVCFG1_DMTINV_63_64);
break;
case MK_DEVCFG1_DMTINV_31_32:
printf(" %02x Deadman Timer Window is 31/32 counter value\n", MK_DEVCFG1_DMTINV_31_32);
break;
case MK_DEVCFG1_DMTINV_15_16:
printf(" %02x Deadman Timer Window is 15/16 counter value\n", MK_DEVCFG1_DMTINV_15_16);
break;
case MK_DEVCFG1_DMTINV_7_8:
printf(" %02x Deadman Timer Window is 7/8 counter value\n", MK_DEVCFG1_DMTINV_7_8);
break;
case MK_DEVCFG1_DMTINV_3_4:
printf(" %02x Deadman Timer Window is 3/4 counter value\n", MK_DEVCFG1_DMTINV_3_4);
break;
case MK_DEVCFG1_DMTINV_1_2:
printf(" %02x Deadman Timer Window is 1/2 counter value\n", MK_DEVCFG1_DMTINV_1_2);
break;
case MK_DEVCFG1_DMTINV_0:
printf(" %02x Deadman Timer Window value is 0\n", MK_DEVCFG1_DMTINV_0);
break;
}
switch (devcfg1 & MK_DEVCFG1_FNOSC_MASK){
case MK_DEVCFG1_FNOSC_LPRC:
printf(" %01x LPRC selected as Oscillator\n", MK_DEVCFG1_FNOSC_LPRC);
break;
case MK_DEVCFG1_FNOSC_SOSC:
printf(" %01x SOSC selected as Oscillator\n", MK_DEVCFG1_FNOSC_SOSC);
break;
case MK_DEVCFG1_FNOSC_USBPLL:
printf(" %01x USB PLL selected as Oscillator\n", MK_DEVCFG1_FNOSC_USBPLL);
break;
case MK_DEVCFG1_FNOSC_POSC:
printf(" %01x POSC selected as Oscillator\n", MK_DEVCFG1_FNOSC_POSC);
break;
case MK_DEVCFG1_FNOSC_SYSTEMPLL:
printf(" %01x System PLL selected as Oscillator\n", MK_DEVCFG1_FNOSC_SYSTEMPLL);
break;
case MK_DEVCFG1_FNOSC_FRC:
printf(" %01x FRC + divider selected as Oscillator\n", MK_DEVCFG1_FNOSC_FRC);
break;
default:
printf(" %01x RESERVED bit selected for Oscillator\n", MK_DEVCFG1_FNOSC_FRC);
break;
}
}
void print_mk_devcfg0(uint32_t devcfg0, uint32_t alternate){
// DEVCFG0
if (PRIMARY == alternate){
printf(" BF1DEVCFG0 = 0x%08X\n", devcfg0);
}
else{
printf(" BF2DEVCFG0 = 0x%08X\n", devcfg0);
}
if (devcfg0 & MK_DEVCFG0_EJTAGBEN){
printf(" %01x Normal EJTAG functionality\n", MK_DEVCFG0_EJTAGBEN >> 28);
}
else{
printf(" %01x Reduced EJTAG functionality\n", 0);
}
if (devcfg0 & MK_DEVCFG0_POSCBOOST){
printf(" %01x Boost the kick start of the POSC\n", MK_DEVCFG0_POSCBOOST >> 20);
}
else{
printf(" %01x Normal start of the POSC\n", 0);
}
switch (devcfg0 & MK_DEVCFG0_POSCGAIN_MASK){
case MK_DEVCFG0_POSCGAIN_3:
printf(" %02x POSC gain level 3 (highest)\n", MK_DEVCFG0_POSCGAIN_3 >> 16);
break;
case MK_DEVCFG0_POSCGAIN_2:
printf(" %02x POSC gain level 2\n", MK_DEVCFG0_POSCGAIN_2 >> 16);
break;
case MK_DEVCFG0_POSCGAIN_1:
printf(" %02x POSC gain level 1\n", MK_DEVCFG0_POSCGAIN_1 >> 16);
break;
case MK_DEVCFG0_POSCGAIN_0:
printf(" %02x POSC gain level 0 (lowest)\n", MK_DEVCFG0_POSCGAIN_0 >> 16);
break;
}
if (devcfg0 & MK_DEVCFG0_SOSCBOOST){
printf(" %01x Boost the kick start of the SOSC\n", MK_DEVCFG0_SOSCBOOST >> 16);
}
else{
printf(" %01x Normal start of the SOSC\n", 0);
}
switch (devcfg0 & MK_DEVCFG0_SOSCGAIN_MASK){
case MK_DEVCFG0_SOSCGAIN_3:
printf(" %01x SOSC gain level 3 (highest)\n", MK_DEVCFG0_SOSCGAIN_3 >> 16);
break;
case MK_DEVCFG0_SOSCGAIN_2:
printf(" %01x SOSC gain level 2\n", MK_DEVCFG0_SOSCGAIN_2 >> 16);
break;
case MK_DEVCFG0_SOSCGAIN_1:
printf(" %01x SOSC gain level 1\n", MK_DEVCFG0_SOSCGAIN_1 >> 16);
break;
case MK_DEVCFG0_SOSCGAIN_0:
printf(" %01x SOSC gain level 0 (lowest)\n", MK_DEVCFG0_SOSCGAIN_0 >> 16);
break;
}
if (devcfg0 & MK_DEVCFG0_SMCLR){
printf(" %01x MCLR pin generates normal system Reset\n", MK_DEVCFG0_SMCLR >> 12);
}
else{
printf(" %01x MCLR pin generates a POR Reset\n", 0);
}
printf(" %01x Debug mode CPU Access Permission bits\n", (devcfg0 & MK_DEVCFG0_DBGPER_MASK) >> 12);
if ((devcfg0 & MK_DEVCFG0_DBGPER_MASK) & MK_DEVCFG0_DBGPER_GRP2){
printf(" CPU access to Permissions Group 2: ALLOWED\n");
}
else{
printf(" CPU access to Permissions Group 2: DENIED\n");
}
if ((devcfg0 & MK_DEVCFG0_DBGPER_MASK) & MK_DEVCFG0_DBGPER_GRP1){
printf(" CPU access to Permissions Group 1: ALLOWED\n");
}
else{
printf(" CPU access to Permissions Group 1: DENIED\n");
}
if ((devcfg0 & MK_DEVCFG0_DBGPER_MASK) & MK_DEVCFG0_DBGPER_GRP0){
printf(" CPU access to Permissions Group 0: ALLOWED\n");
}
else{
printf(" CPU access to Permissions Group 0: DENIED\n");
}
if (devcfg0 & MK_DEVCFG0_FSLEEP){
printf(" %01x Flash powered down in sleep mode\n", MK_DEVCFG0_FSLEEP >> 8);
}
else{
printf(" %01x Flash power down controlled by VREGS bit\n", 0);
}
if (devcfg0 & MK_DEVCFG0_BOOTISA){
printf(" %01x Boot and exception code is MIPS32\n", MK_DEVCFG0_BOOTISA >> 4);
}
else{
printf(" %01x Boot and exception code is microMIPS\n", 0);
}
if (devcfg0 & MK_DEVCFG0_TRCEN){
printf(" %01x Trace features enabled\n", MK_DEVCFG0_TRCEN >> 4);
}
else{
printf(" %01x Trace features disabled\n", 0);
}
switch (devcfg0 & MK_DEVCFG0_ICESEL_MASK){
case MK_DEVCFG0_ICESEL_1:
printf(" %02x PGEC1/PGED1 pair in use\n", MK_DEVCFG0_ICESEL_1);
break;
case MK_DEVCFG0_ICESEL_2:
printf(" %02x PGEC2/PGED2 pair in use\n", MK_DEVCFG0_SOSCGAIN_2);
break;
case MK_DEVCFG0_ICESEL_3:
printf(" %02x PGEC3/PGED3 pair in use\n", MK_DEVCFG0_SOSCGAIN_1);
break;
case MK_DEVCFG0_ICESEL_RESERVED:
printf(" %02x Reserved setting\n", MK_DEVCFG0_ICESEL_RESERVED);
break;
}
if (devcfg0 & MK_DEVCFG0_JTAGEN){
printf(" %01x JTAG enabled\n", MK_DEVCFG0_JTAGEN);
}
else{
printf(" %01x JTAG disabled\n", 0);
}
switch (devcfg0 & MK_DEFCFG0_DEBUG_MASK){
case MK_DEFCFG0_DEBUG_3:
printf(" %01x JTAG enabled, ICSP disabled, ICD disabled\n", MK_DEFCFG0_DEBUG_3);
break;
case MK_DEFCFG0_DEBUG_2:
printf(" %01x JTAG enabled, ICSP disabled, ICD enabled\n", MK_DEFCFG0_DEBUG_2);
break;
case MK_DEFCFG0_DEBUG_1:
printf(" %01x JTAG disabled, ICSP enabled, ICD disabled\n", MK_DEFCFG0_DEBUG_1);
break;
case MK_DEFCFG0_DEBUG_0:
printf(" %01x JTAG disabled, ICSP enabled, ICD enabled\n", MK_DEFCFG0_DEBUG_0);
break;
}
}
void print_mk_devcp(uint32_t devcp, uint32_t alternate){
// DEVCP
if (PRIMARY == alternate){
printf(" BF1DEVCP0 = 0x%08X\n", devcp);
}
else{
printf(" BF2DEVCP0 = 0x%08X\n", devcp);
}
if (devcp & MK_DEVCP0_CP){
printf(" %01x Code-protect disabled\n", MK_DEVCP0_CP >> 28);
}
else{
printf(" %01x Code protect enabled\n", 0);
}
}
void print_mk_devsign(uint32_t devsign, uint32_t alternate){
// DEVSIGN
if (PRIMARY == alternate){
printf(" BF1DEVSIGN0 = 0x%08X\n", devsign);
}
else{
printf(" BF2DEVSIGN0 = 0x%08X\n", devsign);
}
}
void print_mk_devseq(uint32_t devseq, uint32_t alternate){
// DEVSEQ
if (PRIMARY == alternate){
printf(" BF1SEQ = 0x%08X\n", devseq);
}
else{
printf(" BF2SEQ = 0x%08X\n", devseq);
}
printf(" %04x CSEQ: Boot flash complement Sequence number\n", (devseq & 0xFFFF0000) >> 16);
printf(" %04x TSEQ: Boot flash true Sequence number\n", (devseq & 0xFFFF));
}