Mercurial > louis > kiibohd-controller
comparison Lib/mk20dx.c @ 340:e8841d3c6db5
mk20dx256vlh7 working!
- Interrupt vector table position fix (affected everything in the firmware)
- Added fault debug messages
- Fixed usbMuxUart
author | Jacob Alexander <haata@kiibohd.com> |
---|---|
date | Sat, 13 Jun 2015 20:42:12 -0700 |
parents | 772f9bea482b |
children | 2bcf6800b851 |
comparison
equal
deleted
inserted
replaced
339:2f415c0b4b28 | 340:e8841d3c6db5 |
---|---|
29 * SOFTWARE. | 29 * SOFTWARE. |
30 */ | 30 */ |
31 | 31 |
32 // ----- Includes ----- | 32 // ----- Includes ----- |
33 | 33 |
34 // Debug Includes | |
35 #if defined(_bootloader_) | |
36 #include <inttypes.h> | |
37 #include <debug.h> | |
38 #else | |
39 #include <print.h> | |
40 #endif | |
41 | |
34 // Local Includes | 42 // Local Includes |
35 #include "mk20dx.h" | 43 #include "mk20dx.h" |
36 | 44 |
37 | 45 |
38 | 46 |
60 // ----- Interrupts ----- | 68 // ----- Interrupts ----- |
61 | 69 |
62 // NVIC - Default ISR | 70 // NVIC - Default ISR |
63 void fault_isr() | 71 void fault_isr() |
64 { | 72 { |
73 print("Fault!"); | |
65 while ( 1 ) | 74 while ( 1 ) |
66 { | 75 { |
67 // keep polling some communication while in fault | 76 // keep polling some communication while in fault |
68 // mode, so we don't completely die. | 77 // mode, so we don't completely die. |
69 if ( SIM_SCGC4 & SIM_SCGC4_USBOTG ) usb_isr(); | 78 if ( SIM_SCGC4 & SIM_SCGC4_USBOTG ) usb_isr(); |
85 { | 94 { |
86 systick_millis_count++; | 95 systick_millis_count++; |
87 } | 96 } |
88 | 97 |
89 | 98 |
99 // NVIC - Non-Maskable Interrupt ISR | |
100 void nmi_default_isr() | |
101 { | |
102 print("NMI!"); | |
103 } | |
104 | |
105 | |
106 // NVIC - Hard Fault ISR | |
107 void hard_fault_default_isr() | |
108 { | |
109 print("Hard Fault!"); | |
110 } | |
111 | |
112 | |
113 // NVIC - Memory Manager Fault ISR | |
114 void memmanage_fault_default_isr() | |
115 { | |
116 print("Memory Manager Fault!"); | |
117 } | |
118 | |
119 | |
120 // NVIC - Bus Fault ISR | |
121 void bus_fault_default_isr() | |
122 { | |
123 print("Bus Fault!"); | |
124 } | |
125 | |
126 | |
127 // NVIC - Usage Fault ISR | |
128 void usage_fault_default_isr() | |
129 { | |
130 print("Usage Fault!"); | |
131 } | |
132 | |
133 | |
90 // NVIC - Default ISR/Vector Linking | 134 // NVIC - Default ISR/Vector Linking |
91 void nmi_isr() __attribute__ ((weak, alias("unused_isr"))); | 135 void nmi_isr() __attribute__ ((weak, alias("nmi_default_isr"))); |
92 void hard_fault_isr() __attribute__ ((weak, alias("unused_isr"))); | 136 void hard_fault_isr() __attribute__ ((weak, alias("hard_fault_default_isr"))); |
93 void memmanage_fault_isr() __attribute__ ((weak, alias("unused_isr"))); | 137 void memmanage_fault_isr() __attribute__ ((weak, alias("memmanage_fault_default_isr"))); |
94 void bus_fault_isr() __attribute__ ((weak, alias("unused_isr"))); | 138 void bus_fault_isr() __attribute__ ((weak, alias("bus_fault_default_isr"))); |
95 void usage_fault_isr() __attribute__ ((weak, alias("unused_isr"))); | 139 void usage_fault_isr() __attribute__ ((weak, alias("usage_fault_default_isr"))); |
96 void svcall_isr() __attribute__ ((weak, alias("unused_isr"))); | 140 void svcall_isr() __attribute__ ((weak, alias("unused_isr"))); |
97 void debugmonitor_isr() __attribute__ ((weak, alias("unused_isr"))); | 141 void debugmonitor_isr() __attribute__ ((weak, alias("unused_isr"))); |
98 void pendablesrvreq_isr() __attribute__ ((weak, alias("unused_isr"))); | 142 void pendablesrvreq_isr() __attribute__ ((weak, alias("unused_isr"))); |
99 void systick_isr() __attribute__ ((weak, alias("systick_default_isr"))); | 143 void systick_isr() __attribute__ ((weak, alias("systick_default_isr"))); |
100 | 144 |
392 // For more details see: | 436 // For more details see: |
393 // http://cache.freescale.com/files/training/doc/dwf/AMF_ENT_T1031_Boston.pdf (page 8) | 437 // http://cache.freescale.com/files/training/doc/dwf/AMF_ENT_T1031_Boston.pdf (page 8) |
394 // http://cache.freescale.com/files/microcontrollers/doc/app_note/AN4507.pdf | 438 // http://cache.freescale.com/files/microcontrollers/doc/app_note/AN4507.pdf |
395 // http://cache.freescale.com/files/32bit/doc/ref_manual/K20P64M72SF1RM.pdf (28.34.6) | 439 // http://cache.freescale.com/files/32bit/doc/ref_manual/K20P64M72SF1RM.pdf (28.34.6) |
396 // | 440 // |
397 0xFF, 0xFF, 0xFF, 0xFF, // Program Flash Protection Bytes FPROT0-3 // XXX TODO PROTECT | 441 0xFF, 0xFF, 0xFF, 0xFE, // Program Flash Protection Bytes FPROT0-3 |
398 | 442 |
399 0xBE, // Flash security byte FSEC | 443 0xBE, // Flash security byte FSEC |
400 0x03, // Flash nonvolatile option byte FOPT | 444 0x03, // Flash nonvolatile option byte FOPT |
401 0xFF, // EEPROM Protection Byte FEPROT | 445 0xFF, // EEPROM Protection Byte FEPROT |
402 0xFF, // Data Flash Protection Byte FDPROT | 446 0xFF, // Data Flash Protection Byte FDPROT |
501 // Enable clocks to always-used peripherals | 545 // Enable clocks to always-used peripherals |
502 SIM_SCGC5 = 0x00043F82; // Clocks active to all GPIO | 546 SIM_SCGC5 = 0x00043F82; // Clocks active to all GPIO |
503 SIM_SCGC6 = SIM_SCGC6_FTM0 | SIM_SCGC6_FTM1 | SIM_SCGC6_ADC0 | SIM_SCGC6_FTFL; | 547 SIM_SCGC6 = SIM_SCGC6_FTM0 | SIM_SCGC6_FTM1 | SIM_SCGC6_ADC0 | SIM_SCGC6_FTFL; |
504 #if defined(_mk20dx128_) | 548 #if defined(_mk20dx128_) |
505 SIM_SCGC6 |= SIM_SCGC6_RTC; | 549 SIM_SCGC6 |= SIM_SCGC6_RTC; |
506 #elif defined(_mk20dx256_) | 550 #elif defined(_mk20dx256_) || defined(_mk20dx256vlh7_) |
507 SIM_SCGC3 = SIM_SCGC3_ADC1 | SIM_SCGC3_FTM2; | 551 SIM_SCGC3 = SIM_SCGC3_ADC1 | SIM_SCGC3_FTM2; |
508 SIM_SCGC6 |= SIM_SCGC6_RTC; | 552 SIM_SCGC6 |= SIM_SCGC6_RTC; |
509 #endif | 553 #endif |
510 | 554 |
511 #if defined(_mk20dx128_) || defined(_mk20dx256_) // Teensy 3s | 555 #if defined(_mk20dx128_) || defined(_mk20dx256_) // Teensy 3s |
542 // USB Clock and FLL select | 586 // USB Clock and FLL select |
543 SIM_SOPT2 = SIM_SOPT2_USBSRC | SIM_SOPT2_TRACECLKSEL; | 587 SIM_SOPT2 = SIM_SOPT2_USBSRC | SIM_SOPT2_TRACECLKSEL; |
544 | 588 |
545 // Teensy 3.0 and 3.1 and Kiibohd-dfu (mk20dx256vlh7) | 589 // Teensy 3.0 and 3.1 and Kiibohd-dfu (mk20dx256vlh7) |
546 #else | 590 #else |
547 SCB_VTOR = 0; // use vector table in flash | 591 #if defined(_mk20dx128_) || defined(_mk20dx256_) |
592 // use vector table in flash | |
593 SCB_VTOR = 0; | |
594 #endif | |
548 | 595 |
549 // default all interrupts to medium priority level | 596 // default all interrupts to medium priority level |
550 for ( unsigned int i = 0; i < NVIC_NUM_INTERRUPTS; i++ ) | 597 for ( unsigned int i = 0; i < NVIC_NUM_INTERRUPTS; i++ ) |
551 { | 598 { |
552 NVIC_SET_PRIORITY( i, 128 ); | 599 NVIC_SET_PRIORITY( i, 128 ); |