Problems porting AN4368 to Kinetis KN22

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problems porting AN4368 to Kinetis KN22

1,614 Views
ARQuattr
Contributor IV

I have been trying to port the code in the AN4368 project from the K60 target to a K22 target.  I managed to get the project to compile after changing the definitions header and lcf, etc. as well as changing a number of register names throughout the code to work with the K22.  However when I go to program the device with a P&E Micro Multilink Universal, I get errors as shown below.  (I didn't change the name of the debug configuration from K60...)

I'm not sure if this is some issue with the linker, or my programmer settings?  Any thoughts?

=== CodeWarrior GDI protocol log ===

GDI DLL: C:\Freescale\CW MCU v10.2\MCU\bin\Plugins\Debugger\protocols\..\..\support\arm\gdi\arm_pne_gdi.dll

CPU: K20FN1M0

GDI: DiGdiOpen()

GDI: => DI_OK

GDI: DiGdiGetFeatures()

GDI: => DI_OK

GDI: Identification: ARM Cortex M4 P&E to GDI wrapper, Version: 1.0.1, MeeAvailable: true, NrCpusAvailable: 1

GDI: DiGdiAddCallBack(cb_type = 0x4000)

GDI: => DI_OK

GDI: DiGdiInitIO()

GDI: Mtwks Callback(MTWKS_CB_SETMEEID, 1) => DI_OK

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : CWDBG, Entry : LaunchConfiguration, Value : Kinetis_MK60N512VMD100_bootloader_host MK60N512VMD100_INTERNAL_FLASH, R) => DI_OK

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : PEDEBUG, Entry : DO_DEBUG_OUTPUT, Value : HFSUIDFH5390FJIfnsdofnfjsdoiFHSIDO, R) => DI_ERR_NONFATAL

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : PEDEBUG, Entry : DEPENDENCY_CHECK, Value : HFSUIDFH5390FJIfnsdofnfjsdoiFHSIDO, R) => DI_ERR_NONFATAL

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : PEDEBUG, Entry : UUID, Value : HFSUIDFH5390FJIfnsdofnfjsdoiFHSIDO, R) => DI_ERR_NONFATAL

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : CWDBG, Entry : Processor, Value : K20FN1M0, R) => DI_OK

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : PEDEBUG, Entry : ERASE_PROGRAM_WITHOUT_ASKING, Value : 0, R) => DI_OK

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : PEDEBUG, Entry : AUTO_SYNC, Value : 1, R) => DI_OK

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : PEDEBUG, Entry : DOTRIM, Value : 0, R) => DI_OK

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : PEDEBUG, Entry : CURRENT_ALGORITHM_INDEX, Value : 0, R) => DI_OK

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : PEDEBUG, Entry : PRESERVE1_START, Value : 0, R) => DI_OK

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : PEDEBUG, Entry : PRESERVE1_END, Value : 3, R) => DI_OK

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : PEDEBUG, Entry : PRESERVE1_ACTIVE, Value : 0, R) => DI_OK

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : PEDEBUG, Entry : PRESERVE2_START, Value : 0, R) => DI_OK

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : PEDEBUG, Entry : PRESERVE2_END, Value : 3, R) => DI_OK

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : PEDEBUG, Entry : PRESERVE2_ACTIVE, Value : 0, R) => DI_OK

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : PEDEBUG, Entry : PRESERVE3_START, Value : 0, R) => DI_OK

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : PEDEBUG, Entry : PRESERVE3_END, Value : 3, R) => DI_OK

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : PEDEBUG, Entry : PRESERVE3_ACTIVE, Value : 0, R) => DI_OK

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : K20FN1M0, Entry : PRESERVE_EEPROM_START, Value : HFSUIDFH5390FJIfnsdofnfjsdoiFHSIDO, R) => DI_ERR_NONFATAL

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : K20FN1M0, Entry : PRESERVE_EEPROM_END, Value : HFSUIDFH5390FJIfnsdofnfjsdoiFHSIDO, R) => DI_ERR_NONFATAL

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : K20FN1M0, Entry : PRESERVE_EEPROM, Value : HFSUIDFH5390FJIfnsdofnfjsdoiFHSIDO, R) => DI_ERR_NONFATAL

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : PEDEBUG, Entry : ALTERNATIVE_ALGORITHM_PATH, Value : HFSUIDFH5390FJIfnsdofnfjsdoiFHSIDO, R) => DI_ERR_NONFATAL

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : PEDEBUG, Entry : ALTERNATIVE_ALGORITHM_CHECKBOX, Value : 0, R) => DI_OK

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : PEDEBUG, Entry : PARTITION_PARAM, Value : HFSUIDFH5390FJIfnsdofnfjsdoiFHSIDO, R) => DI_ERR_NONFATAL

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : PEDEBUG, Entry : DO_PARTITIONING, Value : HFSUIDFH5390FJIfnsdofnfjsdoiFHSIDO, R) => DI_ERR_NONFATAL

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : PEDEBUG, Entry : CUSTOM_TRIM, Value : 0, R) => DI_OK

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : K20FN1M0, Entry : TRIM_VALUE, Value : HFSUIDFH5390FJIfnsdofnfjsdoiFHSIDO, R) => DI_ERR_NONFATAL

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : PEDEBUG, Entry : NGS_TRIM_OVERRIDE_REFERENCE_FREQUENCY, Value : 3276800, R) => DI_OK

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : PEDEBUG, Entry : ENABLE_FLASH_PROGRAMMING_DIALOG, Value : 0, R) => DI_OK

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : STARTUP, Entry : SPECIFY_NETWORKCARD_ENABLED, Value : 0, R) => DI_OK

INF: Ethernet functionality not enabled - Socket Error # 10065  No route to host.

INF: Windows NT detected.

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : STARTUP, Entry : IO_DELAY_CNT, Value : HFSUIDFH5390FJIfnsdofnfjsdoiFHSIDO, R) => DI_ERR_NONFATAL

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : STARTUP12, Entry : show_hstep_assembly_details, Value : HFSUIDFH5390FJIfnsdofnfjsdoiFHSIDO, R) => DI_ERR_NONFATAL

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : CWDBG, Entry : Connect, Value : 0, R) => DI_OK

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : STARTUP, Entry : eclipse_show_connection_assistant, Value : HFSUIDFH5390FJIfnsdofnfjsdoiFHSIDO, R) => DI_ERR_NONFATAL

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : STARTUP, Entry : FREQ_FX, Value : 4, R) => DI_OK

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : STARTUP, Entry : FREQ_NORMAL, Value : 0, R) => DI_OK

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : STARTUP, Entry : FREQ_OSJTAG, Value : 0, R) => DI_OK

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : STARTUP, Entry : FREQ_CYCLONE, Value : 3, R) => DI_OK

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : STARTUP, Entry : FREQ_TRACELINK, Value : 3, R) => DI_OK

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : STARTUP, Entry : FREQ_LIGHTNING, Value : HFSUIDFH5390FJIfnsdofnfjsdoiFHSIDO, R) => DI_ERR_NONFATAL

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : STARTUP, Entry : RESET_DELAY, Value : 0, R) => DI_OK

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : STARTUP, Entry : PORT, Value : 21, R) => DI_OK

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : STARTUP, Entry : interface_selection, Value : 1, R) => DI_OK

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : PORT, Entry : IP, Value : HFSUIDFH5390FJIfnsdofnfjsdoiFHSIDO, R) => DI_ERR_NONFATAL

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : STARTUP, Entry : FORCE_MASS_ERASE, Value : 0, R) => DI_OK

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : STARTUP, Entry : USE_SWD, Value : 0, R) => DI_OK

GDI: Mtwks Callback(MTWKS_CB_PROJECTACCESS, Section : STARTUP, Entry : CPUTARGETTYPENAME, Value : HFSUIDFH5390FJIfnsdofnfjsdoiFHSIDO, R) => DI_ERR_NONFATAL

INF: P&E Interface detected - Flash Version 6.10

INF: Device is K20FN1M0.

INF: Mode is In-Circuit Debug.

GDI: => DI_OK

GDI: DiMeeConnect(exec_env_id = 1)

GDI: => DI_OK

GDI: DiExecGetStatus(cpu_status = (cause = GDI_WAIT_MISCELLANEOUS, brkpt_id = 0, reason = unknown state))

GDI: DiRegisterRead(PC (id:0xF))

GDI: => DI_OK

GDI: PC (id:0xF) -> 0xFFFFFFFE

GDI: DiRegisterRead(SP (id:0xD))

GDI: => DI_OK

GDI: SP (id:0xD) -> 0xFFFFFFFC

GDI: DiRegisterRead(LR (id:0xE))

GDI: => DI_OK

GDI: LR (id:0xE) -> 0xFFFFFFFF

GDI: DiRegisterRead(XPSR (id:0x10))

GDI: => DI_OK

GDI: XPSR (id:0x10) -> 0x1000000

GDI: DiMemoryRead(addr = 0xFFFFFF00, space = 1, mem_items = 256, size = 1)

GDI: => DI_ERR_NONFATAL

GDI: A bus error occurred while accessing memory

GDI: DiMemoryDownload(StartDownload)

GDI: => DI_ERR_FATAL

GDI: A bus error occurred while accessing memory

Labels (1)
7 Replies

936 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Angelo,

Would you please introduce the steps of code migration? Then it would help to figure out  what exact problems with your code.

I'm looking forward to your reply.
Have a great day,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply

936 Views
ARQuattr
Contributor IV

If I remember all my steps correctly, I did the following:

1. Started with the project from this thread: compile errors on AN4368 USB bootloader

2. Merged the updated code from this thread: Re: USB Memory Stick Issue with AN4368 USB MSD Host Bootloader

3. Removed the MK60...h include in the project, and replaced with MK22F12.h (copied from CW folder).

4. Changed the lcf files to the K22 versions, e.g. from MK60N512VMD100_flash.lcf to K22FN1M0M12_flash.lcf.

5. Replaced all instances of MCU_MK60N512VMD100 in preprocessor directives with MCU_MK22F12, in Loader.c, main.c, P2.c [edit] and Bootloader.h

6. Replaced all references to registers named FTFL_xxxx, to FTFE_xxxx, in main.c, and flash_FTFL.c.

7. Changed MCG_C5_PRDIV() to MCG_C5_PRDIV0(), MCG_C6_VDIV() to MCG_C6_VDIV0(), and MCG_S_LOCK_MASK to MCG_S_LOCK0_MASK in P2.c

8. Changed size of __fun[] array from 0x77 to 0x61, and removed vectors 0x62 to 0x77 in the vector table, in vectors.c

9. Added a new target in the debug configurations for the K22 device.  (When I did this originally in CW 10.2 it didn't give the option for K22 so I picked K20, and as Adrian suggested this may be the reason I had problems.  I imported this project in CW10.5 and it does have the option for the K22 device I'm using so I'm going to try that again.)

[edit] 10. Change the #include <MK60N512VMD100.h> line to #include <MK22F12.h> in derivative.h

[Edit]  After loading this project back in CW10.5 which allowed me to change the target MCU to the K22 device I'm using, I was able to program the device, but then it wouldn't execute.  It stopped at the following line in pll-init() in P2.c:

   /* wait for Reference clock Status bit to clear */

    while (MCG_S & MCG_S_IREFST_MASK){};

It seems I haven't done a proper job of porting the clock management to this device.

0 Kudos
Reply

936 Views
rhana
Contributor III

Hello Angelo,

  I am also attempting to port the msd host bootloader described in AN4368 to the kinetis k22. We have been able to compile in Codewarrior 10.6, but the USB isn't working on the system when we test, I will try the steps outlined above. Has the USB worked for you?

0 Kudos
Reply

936 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Angelo,

I think your method seems like a little complicated and I've replied the SR(1-2225215354) you created.

In the reply, I've provided a new sceanario for you and please refer to it.
Have a great day,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

936 Views
rhana
Contributor III

Hello,

   I am also attempting to port AN4368 to the Kinetis K22. The code was able to build in CW10.6 after many changes however the USB did not work when it was loaded onto a k22 system. (Stepping through with a debugger indicated polling USB, but it seemed like there were no USB events triggering activity .) How would you recommend proceeding? It looks like you have a new scenario, what is your suggestion? Thanks.

-RH

0 Kudos
Reply

936 Views
adriancano
NXP Employee
NXP Employee

Hi,

I recommend you to use CodeWarrior 10.6 since this one has support for the K22 devices. I see you are setting as the target cpu a Kientis K20FN1M0, if you are using K22 of 120 MHz there are important differences between these two devices.

Check that with the newest version of CodeWarrior.

hope this information can help you.

Regards,

-----------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. It would be nice!

-----------------------------------------------------------------------------------------------------------------------

936 Views
ARQuattr
Contributor IV

I noticed that it showed K20FN1M0 also and wasn't sure why, since I included the MK22F12.h file and I'm not sure if where else to select the specific device variant.  Originally when I tried to compile in CW10.5 it did nothing and I'm not sure why, but eventually got it working in 10.2, and then it compiled in 10.5 also.

[EDIT] You're right.  Now I remember where I set that K20 selection, when I created the target, since CW10.2 didn't include the K22 device.  I'm going to change that in CW10.5 and try again.

0 Kudos
Reply