]> git.donarmstrong.com Git - kiibohd-controller.git/commitdiff
mk20dx256vlh7 working!
authorJacob Alexander <haata@kiibohd.com>
Sun, 14 Jun 2015 03:42:12 +0000 (20:42 -0700)
committerJacob Alexander <haata@kiibohd.com>
Sun, 14 Jun 2015 21:33:40 +0000 (14:33 -0700)
- Interrupt vector table position fix (affected everything in the firmware)
- Added fault debug messages
- Fixed usbMuxUart

Bootloader/CMakeLists.txt
Debug/print/print.c
Lib/mk20dx.c
Lib/mk20dx256vlh7.ld
Output/uartOut/arm/uart_serial.c
Output/usbMuxUart/output_com.c
Output/usbMuxUart/output_com.h
main.c

index 14b1b0853e16a44ddacc491778a15a256bacd947..ad5a3952e5b59c99bcced59ad0ad0a73eeec8b71 100644 (file)
@@ -91,7 +91,10 @@ endforeach()
 ###
 # Directory Includes
 #
 ###
 # Directory Includes
 #
-include_directories( ${CMAKE_SOURCE_DIR}/../Lib )
+include_directories (
+       ${CMAKE_SOURCE_DIR}/../Lib
+       ${CMAKE_SOURCE_DIR}
+)
 
 
 
 
 
 
index 522f6f4062127c6e593d2ff4bb08a2aeff3d22f9..c93ec5082a4c9ad566d33f183d2b85862ef1e9a9 100644 (file)
@@ -64,7 +64,7 @@ void _print( const char* s )
        {
                Output_putchar( c );
        }
        {
                Output_putchar( c );
        }
-#elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) // ARM
+#elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_) // ARM
        Output_putstr( (char*)s );
 #endif
 }
        Output_putstr( (char*)s );
 #endif
 }
index 1fa3e1510719b8a7c5740bc12ef08c8a8f129ab1..2b1194337c5ca17c4de510c1b4cd142315b5c7af 100644 (file)
 
 // ----- Includes -----
 
 
 // ----- Includes -----
 
+// Debug Includes
+#if defined(_bootloader_)
+#include <inttypes.h>
+#include <debug.h>
+#else
+#include <print.h>
+#endif
+
 // Local Includes
 #include "mk20dx.h"
 
 // Local Includes
 #include "mk20dx.h"
 
@@ -62,6 +70,7 @@ void ResetHandler();
 // NVIC - Default ISR
 void fault_isr()
 {
 // NVIC - Default ISR
 void fault_isr()
 {
+       print("Fault!");
        while ( 1 )
        {
                // keep polling some communication while in fault
        while ( 1 )
        {
                // keep polling some communication while in fault
@@ -87,12 +96,47 @@ void systick_default_isr()
 }
 
 
 }
 
 
+// NVIC - Non-Maskable Interrupt ISR
+void nmi_default_isr()
+{
+       print("NMI!");
+}
+
+
+// NVIC - Hard Fault ISR
+void hard_fault_default_isr()
+{
+       print("Hard Fault!");
+}
+
+
+// NVIC - Memory Manager Fault ISR
+void memmanage_fault_default_isr()
+{
+       print("Memory Manager Fault!");
+}
+
+
+// NVIC - Bus Fault ISR
+void bus_fault_default_isr()
+{
+       print("Bus Fault!");
+}
+
+
+// NVIC - Usage Fault ISR
+void usage_fault_default_isr()
+{
+       print("Usage Fault!");
+}
+
+
 // NVIC - Default ISR/Vector Linking
 // NVIC - Default ISR/Vector Linking
-void nmi_isr()              __attribute__ ((weak, alias("unused_isr")));
-void hard_fault_isr()       __attribute__ ((weak, alias("unused_isr")));
-void memmanage_fault_isr()  __attribute__ ((weak, alias("unused_isr")));
-void bus_fault_isr()        __attribute__ ((weak, alias("unused_isr")));
-void usage_fault_isr()      __attribute__ ((weak, alias("unused_isr")));
+void nmi_isr()              __attribute__ ((weak, alias("nmi_default_isr")));
+void hard_fault_isr()       __attribute__ ((weak, alias("hard_fault_default_isr")));
+void memmanage_fault_isr()  __attribute__ ((weak, alias("memmanage_fault_default_isr")));
+void bus_fault_isr()        __attribute__ ((weak, alias("bus_fault_default_isr")));
+void usage_fault_isr()      __attribute__ ((weak, alias("usage_fault_default_isr")));
 void svcall_isr()           __attribute__ ((weak, alias("unused_isr")));
 void debugmonitor_isr()     __attribute__ ((weak, alias("unused_isr")));
 void pendablesrvreq_isr()   __attribute__ ((weak, alias("unused_isr")));
 void svcall_isr()           __attribute__ ((weak, alias("unused_isr")));
 void debugmonitor_isr()     __attribute__ ((weak, alias("unused_isr")));
 void pendablesrvreq_isr()   __attribute__ ((weak, alias("unused_isr")));
@@ -394,7 +438,7 @@ const uint8_t flashconfigbytes[16] = {
        //  http://cache.freescale.com/files/microcontrollers/doc/app_note/AN4507.pdf
        //  http://cache.freescale.com/files/32bit/doc/ref_manual/K20P64M72SF1RM.pdf (28.34.6)
        //
        //  http://cache.freescale.com/files/microcontrollers/doc/app_note/AN4507.pdf
        //  http://cache.freescale.com/files/32bit/doc/ref_manual/K20P64M72SF1RM.pdf (28.34.6)
        //
-       0xFF, 0xFF, 0xFF, 0xFF, // Program Flash Protection Bytes FPROT0-3 // XXX TODO PROTECT
+       0xFF, 0xFF, 0xFF, 0xFE, // Program Flash Protection Bytes FPROT0-3
 
        0xBE, // Flash security byte FSEC
        0x03, // Flash nonvolatile option byte FOPT
 
        0xBE, // Flash security byte FSEC
        0x03, // Flash nonvolatile option byte FOPT
@@ -503,7 +547,7 @@ void ResetHandler()
        SIM_SCGC6 = SIM_SCGC6_FTM0 | SIM_SCGC6_FTM1 | SIM_SCGC6_ADC0 | SIM_SCGC6_FTFL;
 #if defined(_mk20dx128_)
        SIM_SCGC6 |= SIM_SCGC6_RTC;
        SIM_SCGC6 = SIM_SCGC6_FTM0 | SIM_SCGC6_FTM1 | SIM_SCGC6_ADC0 | SIM_SCGC6_FTFL;
 #if defined(_mk20dx128_)
        SIM_SCGC6 |= SIM_SCGC6_RTC;
-#elif defined(_mk20dx256_)
+#elif defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
        SIM_SCGC3 = SIM_SCGC3_ADC1 | SIM_SCGC3_FTM2;
        SIM_SCGC6 |= SIM_SCGC6_RTC;
 #endif
        SIM_SCGC3 = SIM_SCGC3_ADC1 | SIM_SCGC3_FTM2;
        SIM_SCGC6 |= SIM_SCGC6_RTC;
 #endif
@@ -544,7 +588,10 @@ void ResetHandler()
 
 // Teensy 3.0 and 3.1 and Kiibohd-dfu (mk20dx256vlh7)
 #else
 
 // Teensy 3.0 and 3.1 and Kiibohd-dfu (mk20dx256vlh7)
 #else
-       SCB_VTOR = 0;   // use vector table in flash
+#if defined(_mk20dx128_) || defined(_mk20dx256_)
+       // use vector table in flash
+       SCB_VTOR = 0;
+#endif
 
        // default all interrupts to medium priority level
        for ( unsigned int i = 0; i < NVIC_NUM_INTERRUPTS; i++ )
 
        // default all interrupts to medium priority level
        for ( unsigned int i = 0; i < NVIC_NUM_INTERRUPTS; i++ )
index 7bc029218df4801c66c07ee9f470af86a97054ec..315baeef62fd38b0e85033d697882687af81f88d 100644 (file)
@@ -40,8 +40,7 @@ SECTIONS
 {
        .text :
        {
 {
        .text :
        {
-               . = 0;
-               KEEP(* (.vectors))
+               . = 0; KEEP(* (.vectors)) /* MUST BE AT 0 */
                *(.startup*)
                . = 0x400; KEEP(* (.flashconfig)) /* MUST BE AT 0x400 */
                *(.text*)
                *(.startup*)
                . = 0x400; KEEP(* (.flashconfig)) /* MUST BE AT 0x400 */
                *(.text*)
index d0ae0dfb10ad647fcb1df56215f1a45c0f42bdc9..db7a3aac0d8f280385120cfac67b3d7dba9023f6 100644 (file)
@@ -113,8 +113,7 @@ void uart2_status_isr()
                        // Cleanup
                        available = UART_D;
                        UART_CFIFO = UART_CFIFO_RXFLUSH;
                        // Cleanup
                        available = UART_D;
                        UART_CFIFO = UART_CFIFO_RXFLUSH;
-                       sei();
-                       return;
+                       goto done;
                }
 
                // Read UART0 into buffer until FIFO is empty
                }
 
                // Read UART0 into buffer until FIFO is empty
@@ -143,6 +142,7 @@ void uart2_status_isr()
                }
        }
 
                }
        }
 
+done:
        sei(); // Re-enable Interrupts
 }
 
        sei(); // Re-enable Interrupts
 }
 
index f33249a435d4a1d029f2390dba6b05c7fa836868..a9859b485539a999c1925dfad037f99affeeb1b3 100644 (file)
@@ -229,6 +229,21 @@ void Output_consCtrlSend_capability( uint8_t state, uint8_t stateType, uint8_t *
 }
 
 
 }
 
 
+// Ignores the given key status update
+// Used to prevent fall-through, this is the None keyword in KLL
+void Output_noneSend_capability( uint8_t state, uint8_t stateType, uint8_t *args )
+{
+       // Display capability name
+       if ( stateType == 0xFF && state == 0xFF )
+       {
+               print("Output_noneSend()");
+               return;
+       }
+
+       // Nothing to do, because that's the point :P
+}
+
+
 // Sends a System Control code to the USB Output buffer
 void Output_sysCtrlSend_capability( uint8_t state, uint8_t stateType, uint8_t *args )
 {
 // Sends a System Control code to the USB Output buffer
 void Output_sysCtrlSend_capability( uint8_t state, uint8_t stateType, uint8_t *args )
 {
index e73fd09c7fd1df82e7227380594d26d925e61d89..d6b583644276e0757bea986fe6447f53f8db7409 100644 (file)
@@ -36,7 +36,7 @@
 
 // Max size of key buffer needed for NKRO
 // Boot mode uses only the first 6 bytes
 
 // Max size of key buffer needed for NKRO
 // Boot mode uses only the first 6 bytes
-#define USB_NKRO_BITFIELD_SIZE_KEYS 26
+#define USB_NKRO_BITFIELD_SIZE_KEYS 27
 #define USB_BOOT_MAX_KEYS 6
 
 
 #define USB_BOOT_MAX_KEYS 6
 
 
@@ -51,9 +51,10 @@ typedef enum USBKeyChangeState {
        USBKeyChangeState_MainKeys      = 0x02,
        USBKeyChangeState_SecondaryKeys = 0x04,
        USBKeyChangeState_TertiaryKeys  = 0x08,
        USBKeyChangeState_MainKeys      = 0x02,
        USBKeyChangeState_SecondaryKeys = 0x04,
        USBKeyChangeState_TertiaryKeys  = 0x08,
-       USBKeyChangeState_System        = 0x10,
-       USBKeyChangeState_Consumer      = 0x20,
-       USBKeyChangeState_All           = 0x3F,
+       USBKeyChangeState_QuartiaryKeys = 0x10,
+       USBKeyChangeState_System        = 0x20,
+       USBKeyChangeState_Consumer      = 0x40,
+       USBKeyChangeState_All           = 0x7F,
 } USBKeyChangeState;
 
 
 } USBKeyChangeState;
 
 
@@ -87,6 +88,7 @@ extern          uint8_t  Output_DebugMode; // 0 - Debug disabled, 1 - Debug enab
 // ----- Capabilities -----
 
 void Output_consCtrlSend_capability( uint8_t state, uint8_t stateType, uint8_t *args );
 // ----- Capabilities -----
 
 void Output_consCtrlSend_capability( uint8_t state, uint8_t stateType, uint8_t *args );
+void Output_noneSend_capability( uint8_t state, uint8_t stateType, uint8_t *args );
 void Output_sysCtrlSend_capability( uint8_t state, uint8_t stateType, uint8_t *args );
 void Output_usbCodeSend_capability( uint8_t state, uint8_t stateType, uint8_t *args );
 
 void Output_sysCtrlSend_capability( uint8_t state, uint8_t stateType, uint8_t *args );
 void Output_usbCodeSend_capability( uint8_t state, uint8_t stateType, uint8_t *args );
 
diff --git a/main.c b/main.c
index 1fa2177d1dd3ba4dd99b6cac4ffa6db7aff81b03..98e72e16821deaef9e05bc315f611c0d85602b7d 100644 (file)
--- a/main.c
+++ b/main.c
@@ -33,6 +33,7 @@
 #include <led.h>
 #include <print.h>
 
 #include <led.h>
 #include <print.h>
 
+extern volatile uint32_t systick_millis_count;
 
 
 // ----- Functions -----
 
 
 // ----- Functions -----