Hi Ping,
Here's the complete step.
The link to the zipped file is the same:
https://drive.google.com/open?id=0BzU22QN_dx0LLUZJT25PcjU0TXc
Porting K64_120 for K22F_1M0.
1) Create new directory:
NXP_Kinetis_Bootloader_2_0_0\src\platform\devices\MK22FA12_MK64
(The extra MK64 is to indicate that it's ported from MK64 files).
Copy over everything from:
C:\Freescale\KSDK_1.3.0\platform\devices\MK22FA12\include\*
into :
NXP_Kinetis_Bootloader_2_0_0\src\platform\devices\MK22FA12_MK64
2) Create new directory:
C:\Freescale\NXP_Kinetis_Bootloader_2_0_0\NXP_Kinetis_Bootloader_2_0_0\targets\MK22FA12_MK64
Copy over everything from:
C:\Freescale\NXP_Kinetis_Bootloader_2_0_0\NXP_Kinetis_Bootloader_2_0_0\targets\MK64F12
to
C:\Freescale\NXP_Kinetis_Bootloader_2_0_0\NXP_Kinetis_Bootloader_2_0_0\targets\MK22FA12_MK64
Then go inside:
C:\Freescale\NXP_Kinetis_Bootloader_2_0_0\NXP_Kinetis_Bootloader_2_0_0\targets\MK22FA12_MK64\src
and rename all the filename that contains the target name from "MK64F12" to "MK22FA12"
3) Copy over:
C:\Freescale\KSDK_1.3.0\platform\devices\MK22FA12\startup\system_MK22FA12.*
to:
C:\Freescale\NXP_Kinetis_Bootloader_2_0_0\NXP_Kinetis_Bootloader_2_0_0\src\platform\devices\MK22FA12_MK64
Copy over:
C:\Freescale\KSDK_1.3.0\platform\devices\MK22FA12\linker\* (directories arm,
gcc, iar)
into
C:\Freescale\NXP_Kinetis_Bootloader_2_0_0\NXP_Kinetis_Bootloader_2_0_0\src\platform\devices\MK22FA12_MK64
Copy the assembly startup files startup_MK22FA12.s from:
C:\Freescale\KSDK_1.3.0\platform\devices\MK22FA12\startup\<arm|gcc|iar>\
to
C:\Freescale\NXP_Kinetis_Bootloader_2_0_0\NXP_Kinetis_Bootloader_2_0_0\src\platform\devices\MK22FA12_MK64\<arm|gcc|iar>
4) Copy 'startup' directory from:
C:\Freescale\KSDK_1.3.0\platform\devices\MK22FA12\startup
to:
C:\Freescale\NXP_Kinetis_Bootloader_2_0_0\NXP_Kinetis_Bootloader_2_0_0\targets\MK22FA12_MK64\src\startup
5) For fsl_clock.c/h
I was debating between copying either from:
1st: C:\Freescale\KSDK_1.3.0\platform\system\src\clock\MK22FA12
Or from:
2nd: C:\Freescale\NXP_Kinetis_Bootloader_2_0_0\NXP_Kinetis_Bootloader_2_0_0\src\platform\devices\MK64F12
But, I found that the one from KSDK_1.3.0 is not compatible (when building),
so I used the 2nd option: MK64F12 from Bootloader 2.0.0 .
6) Linker files
Copy:
C:\Freescale\NXP_Kinetis_Bootloader_2_0_0\NXP_Kinetis_Bootloader_2_0_0\targets\common\linker\iar\MK64F12
To:
C:\Freescale\NXP_Kinetis_Bootloader_2_0_0\NXP_Kinetis_Bootloader_2_0_0\targets\common\linker\iar\MK22FA12_MK64
And rename the files in the new directory to start with K22FN1M0xxx12_*
7) Create a new file:
C:\Freescale\NXP_Kinetis_Bootloader_2_0_0\NXP_Kinetis_Bootloader_2_0_0\src\platform\devices\MK22FA12_MK64\fsl_device_registers.h,
whose content is essentially the following:
#if (defined(CPU_MK22FX512AVLH12) || defined(CPU_MK22FN1M0AVLH12) || defined(CPU_MK22FX512AVLK12) || \
defined(CPU_MK22FN1M0AVLK12) || defined(CPU_MK22FX512AVLL12) || defined(CPU_MK22FN1M0AVLL12) || \
defined(CPU_MK22FX512AVLQ12) || defined(CPU_MK22FN1M0AVLQ12) || defined(CPU_MK22FX512AVMC12) || \
defined(CPU_MK22FN1M0AVMC12) || defined(CPU_MK22FX512AVMD12) || defined(CPU_MK22FN1M0AVMD12))
#define K22FA12_SERIES
/* CMSIS-style register definitions */
#include "MK22FA12.h"
/* Extension register definitions */
#include "MK22FA12_extension.h"
/* CPU specific feature definitions */
#include "MK22FA12_features.h"
#else
#error "No valid CPU defined!"
#endif
-------------- PART 2: Modifying the project.
Open:
C:\Freescale\NXP_Kinetis_Bootloader_2_0_0\NXP_Kinetis_Bootloader_2_0_0\targets\MK22FA12_MK64\bootloader.eww
Then remove all projects but the freedom_bootloader project. (This is
optional I guess, but if you leave the other project, then you might hit some
K64F files during search with CTRL+SHIFT+F).
1) Modify the directory name from k64f12 to k22fa12
and change the files
(see image on p .134 reference manual of bootloader 2.0.0)
2) replace
clock_config_*
hardware_init_*
memory_map_*
peripherals_*
with the one from: C:\Freescale\NXP_Kinetis_Bootloader_2_0_0\NXP_Kinetis_Bootloader_2_0_0\targets\MK22FA12_MK64\src
3) Change the *.icf file under 'link' folder to the file here:
C:\Freescale\NXP_Kinetis_Bootloader_2_0_0\NXP_Kinetis_Bootloader_2_0_0\targets\common\linker\iar\MK22FA12_MK64\
4) In the project\src\startup, change startup_*.s and system_*.c to these:
C:\Freescale\NXP_Kinetis_Bootloader_2_0_0\NXP_Kinetis_Bootloader_2_0_0\targets\MK22FA12_MK64\src\startup\iar\startup_MK22FA12.s
C:\Freescale\NXP_Kinetis_Bootloader_2_0_0\NXP_Kinetis_Bootloader_2_0_0\targets\MK22FA12_MK64\src\startup\system_MK22FA12.c
5) Right click on project name and in "General Options" -> Target, change
Device name to "NXP MK22FN1M0xxx12"
In "C/C++ Compiler"-> Preprocessor, change the include path:
$PROJ_DIR$/../../../../src/platform/devices/MK64F12
to:
C:\Freescale\NXP_Kinetis_Bootloader_2_0_0\NXP_Kinetis_Bootloader_2_0_0\src\platform\devices\MK22FA12_MK64
Still in this screen, change the symbol:
CPU_MK64FN1M0VMD12
to
CPU_MK22FN1M0AVMC12
In the project options, go to "Linker" -> Config and change:
$/../../../common/linker/iar/MK64F12/K64FN1Mxxx12_application_0x0000.icf
to
C:\Freescale\NXP_Kinetis_Bootloader_2_0_0\NXP_Kinetis_Bootloader_2_0_0\targets\common\linker\iar\MK22FA12_MK64\K22FN1M0xxx12_application_0x0000.icf
----------------- PART 3: Building
1) To build successfully I had to completely comment out
CLOCK_SetEnetTime0Clock and CLOCK_SetRmii0Clock in fsl_clock.c
(Based on grep, I don't think they're used).
2) I also decided to remove the directory:
src/drivers/mmcau
from the project when it complained during build.
3) The last complaint I got is about:
CLK_RECOVER_CTRL
and
CLK_RECOVER_IRC_EN
This is what I mentioned in my previous comment, that 64F and 22F1M seem to
differ in this register, i.e., 22F1M doesn't have these fields.
I just disabled this for now.
#if !CWATI
USB0->CLK_RECOVER_IRC_EN = 0x03;
USB0->CLK_RECOVER_CTRL |= USB_CLK_RECOVER_CTRL_CLOCK_RECOVER_EN_MASK;
USB0->CLK_RECOVER_CTRL |= 0x20;
#endif
---------------------- PART 4: Running
1) I used JLink, so I had to change the Project Properties "Debugger" -> Setup
from "CMSIS DAP" to "J-Link".
2) When trying to load I got the following, and then the device is not
responsive to JLINK.
Fri Sep 02, 2016 16:00:14: Found 1 JTAG device, Total IRLen = 4:
Fri Sep 02, 2016 16:00:14: 3196 bytes downloaded and verified (18.15 Kbytes/sec)
Fri Sep 02, 2016 16:00:14: Loaded debugee: C:\Program Files (x86)\IAR Systems\Embedded Workbench 7.4\arm\config\flashloader\NXP\FlashK64Fxxx128K.out
Fri Sep 02, 2016 16:00:14: Target reset
Fri Sep 02, 2016 16:00:15: The flash loader program reported an error.
(This definitely messed up the device, to recover I ran Jlink and typed "device
?" then choose the right device. I did it few times.)
Anyways, so I changed the Project Options "Debugger" -> Download:
- uncheck "Verify Download"
- uncheck "Use flash loader(s)"
So in the "Download" view all boxes are unchecked.
---------------------- PART 5: Moment of Truth
1) Plug in USB of the 22F_1M0 device to PC then power on the device. PC will show that "USB is not
recognized".
Then Open KinetisFlashTool and try to connect.
You can't connect via UART because there's no COM Port (USB not recognized by
Windows), and HID connect doesn't work.
Btw I've installed the CDC driver on my PC, so regular project that I have,
using CDC, could be recognized OK by my Windows.
The link to the zipped file is the same:
https://drive.google.com/open?id=0BzU22QN_dx0LLUZJT25PcjU0TXc
Thanks,
Cecylia