I've been working on a project of mine wherein I am using a Kinetis microcontroller.
The particular microcontroller in question is a MK20DX256VLH7, found on a Teensy 3.1 board. I've been programming for the bare metal, using some header files that I found
here.
My problem is this: Those header files are
wrong. I found a header file that starts with the following preamble:
Code:
/*
** ###################################################################
** Processors: MK20DX64VLH7
** MK20DX128VLH7
** MK20DX256VLH7
** MK20DX64VLK7
** MK20DX128VLK7
** MK20DX256VLK7
** MK20DX128VLL7
** MK20DX256VLL7
** MK20DX64VMB7
** MK20DX128VMB7
** MK20DX256VMB7
** MK20DX128VML7
** MK20DX256VML7
**
** Compilers: ARM Compiler
** Freescale C/C++ for Embedded ARM
** GNU C Compiler
** IAR ANSI C/C++ Compiler for ARM
**
** Reference manual: K20P144M72SF1RM Rev. 0, Nov 2011
** Version: rev. 1.4, 2013-06-24
**
** Abstract:
** This header file implements peripheral memory map for MK20D7
** processor.
**
** Copyright: 1997 - 2013 Freescale, Inc. All Rights Reserved.
**
** http: www.freescale.com
** mail: support@freescale.com
**
** Revisions:
** - rev. 1.0 (2012-01-15)
** Initial public version.
** - rev. 1.1 (2012-02-13)
** SysTick peripheral added.
** - rev. 1.2 (2012-04-13)
** Added new #define symbol MCU_MEM_MAP_VERSION_MINOR.
** Added new #define symbols <peripheralType>_BASE_PTRS.
** - rev. 1.3 (2013-04-05)
** Changed start of doxygen comment.
** - rev. 1.4 (2013-06-24)
** NV_FOPT register - NMI_DIS bit added.
**
** ###################################################################
*/
/*!
* @file MK20D7.h
* @version 1.4
* @date 2013-06-24
* @brief Peripheral memory map for MK20D7
*
* This header file implements peripheral memory map for MK20D7 processor.
*/
This header which claims to be authored by freescale clearly states that it covers the MK20DX256VLH7.
Now, this was working fine until I decided I had better try using some simple interrupts. I started using the PIT module to give me some interrupts like so:
Code:
...
SIM_SCGC6 |= SIM_SCGC6_PIT_MASK;
// turn on PIT
PIT_MCR = 0x00;
// Timer 1
PIT_LDVAL1 = 0x0003E7FF; // setup timer 1 for 256000 cycles
PIT_TCTRL1 = PIT_TCTRL_TIE_MASK; // enable Timer 1 interrupts
PIT_TCTRL1 |= PIT_TCTRL_TEN_MASK; // start Timer 1
enable_irq(INT_PIT1);
EnableInterrupts
...
EnableInterrupts is just a macro executing the appropriate assembly instruction to activate interrupts.
So, I loaded this on my teensy and...nothing happened. No interrupts were executed (I had it blinking an LED in the interrupt). I looked closer and saw that INT_PIT1 was defined as vector "85". I compared this to the K20 Sub-Family manual and found that INT_PIT1 should be 69. So, I told it to enable irq 69 and voila! It started blinking my LED.
Clearly, the header file is wrong. I see two options:
1. I rewrite the 8000 line header file. Hopefully just the IRQ's are off and not the memory locations as well.
2. Actually find some freescale-provided header files that are correct for this processor.
I'd prefer option 2, but I've been tearing my hair out trying to find a header file that will work. The ones listed in the
documentation on freescale's website (under snippets) are just for the *DZ10 series of the Kinetis K-series. Further, the ones in the file referenced by the site I referenced earlier are also wrong.
The only file I can find that is correct is the one that comes with the teensyduino software provided by PJRC (who makes the Teensy 3.1). The problem with using this file is that I would need to rewrite the crt0.S file that I'm using to match the names of the ISRs that it uses (which isn't a terrible task, but I'd like to avoid it).
Where do I find this sort of documentation? Do I need to call Freescale? Can I only get this stuff if I'm a company purchasing in bulk?
I'm willing to rewrite stuff to work (and I don't consider it difficult...just inconvenient), but I'd really prefer to get something from the manufacturer.