AnsweredAssumed Answered

Trouble downloading and debugging K22 project using IAR 7.2... Any ideas?

Question asked by Steve Moles on Sep 19, 2014

Hi All,

I'm trying to get a very simple project running on a custom board, using MK22FX512VLL12 target, and I'm having difficulty getting it to download into flash and run on the device. I am using IAR EWARM v7.2 and an I-Jet debugger, firmware version 4.

 

I first noticed the problem upon porting an existing K20 project to a new K22 target board. Compilation worked fine, but any attempt to "Download and Debug" failed with an error  "The flash loader program reported an error." and "A fatal error has occurred. The debugger will terminate."   I checked all the project options and they seemed reasonable... correct target device "MK22FX512xxx12",  default .board file, use I-Jet interface in SWD mode, etc.

 

I decided to simplify things by starting with a fresh project. I found that a bare-minimum application (e.g.: main() function with while(1) loop only) was able to download fine. It ran to main and stopped, ready to debug. Ok, that worked. So far so good.

 

Next, I decided to add a global constant array to increase the flash image size and see if the problem was related to the download size. What I discovered was that if the array was 688 bytes long (or less), it would download fine (with one caveat, see below...), but if it was 689 bytes (or more), the flash loader error would occur and the debugger would terminate. I compared the linker map files in these two cases and found that in the working case, all of the code fit prior to the Flash Configuration Registers section (0x400 - 0x40f), but in the non-working case, the linker placed the code after these registers, starting at address 0x410.

 

The caveat I referred to  above is that in the working case, although it worked, the Debug log indicated that all was not well:

 

     Fri Sep 19, 2014 14:46:51: ----- Prepare hardware for Flashloader -----

     Fri Sep 19, 2014 14:46:51: Loaded debugee: C:\Program Files (x86)\IAR Systems\Embedded Workbench 7.0\arm\config\flashloader\Freescale\FlashK60Fxxx128K.out

     Fri Sep 19, 2014 14:46:51: Target reset

     Fri Sep 19, 2014 14:46:51: Unloaded macro file: C:\Program Files (x86)\IAR Systems\Embedded Workbench 7.0\arm\config\flashloader\Freescale\FlashK60Xxxx128K.mac

     Fri Sep 19, 2014 14:46:51: Skipping flash loading pass because there is no data in the designated range: 0x10000000-0x13FFFFFF.

     Fri Sep 19, 2014 14:46:51: Downloaded C:\IAR_Projects\TryK22\Debug\Exe\cpp.out to flash memory.

     Fri Sep 19, 2014 14:46:52: Loaded debugee: C:\IAR_Projects\TryK22\Debug\Exe\cpp.out

    Fri Sep 19, 2014 14:46:52: The downloaded program doesn't seem to match the expected memory layout of the target system:

     Fri Sep 19, 2014 14:46:52: No C variables are placed in memory designated as RAM.

     Fri Sep 19, 2014 14:46:52: Some SFRs are placed outside known memory areas, or in memory areas designated as read-only or as RAM:

     Fri Sep 19, 2014 14:46:52:   NV_BACKKEY3 @ 0x00000400, 8 bits

     Fri Sep 19, 2014 14:46:52:   NV_BACKKEY2 @ 0x00000401, 8 bits

     Fri Sep 19, 2014 14:46:52:   NV_BACKKEY1 @ 0x00000402, 8 bits

     Fri Sep 19, 2014 14:46:52:   NV_BACKKEY0 @ 0x00000403, 8 bits

     Fri Sep 19, 2014 14:46:52:   NV_BACKKEY7 @ 0x00000404, 8 bits

     Fri Sep 19, 2014 14:46:52:   and more...

     Fri Sep 19, 2014 14:46:52: Memory is specified as follows:

     Fri Sep 19, 2014 14:46:52:   0x00000000 - 0x0007FFFF  ROM/Flash

     Fri Sep 19, 2014 14:46:52:   0x10000000 - 0x1001FFFF  ROM/Flash

     Fri Sep 19, 2014 14:46:52:   0x14000000 - 0x14000FFF  RAM

     Fri Sep 19, 2014 14:46:52:   0x1FFF0000 - 0x2000FFFF  RAM

     Fri Sep 19, 2014 14:46:52:   0x22000000 - 0x23FFFFFF  Uncached/SFR

     Fri Sep 19, 2014 14:46:52:   0x40000000 - 0x400FFFFF  Uncached/SFR

     Fri Sep 19, 2014 14:46:52:   0x42000000 - 0x43FFFFFF  Uncached/SFR

     Fri Sep 19, 2014 14:46:52:   0x60000000 - 0xDFFFFFFF  Uncached/SFR

     Fri Sep 19, 2014 14:46:52:   0xE0000000 - 0xE00FFFFF  Uncached/SFR

     Fri Sep 19, 2014 14:46:52: C Variables range from 0x00000040 to 0x000002EF

     Fri Sep 19, 2014 14:46:52: SFRs range from 0x00000400 to 0xE0080033

     Fri Sep 19, 2014 14:46:52: LowLevelReset(software, delay 200)

     Fri Sep 19, 2014 14:46:52: Recognized CPUID=0x410fc241 Cortex-M4 r0p1 arch ARMv7-M

    ... etc...

 

Do any of you know what might be the problem? It could be that I'm specifying the wrong project options, or perhaps IAR support files (.ddf / .board / .flash, etc...) have not caught up with this relatively new device. Is the flashloader overwriting the flash config section? Is the watchdog not getting disabled properly? Any suggestions or advice would  be welcome! I've attached a debug logs and map files for pass and fail cases..., and the steps to reproduce the problem are below.

 

TO REPRODUCE THE PROBLEM:

1) Start EWARM 7.2

2) Create a new Workspace

3) Create a new project, (C++ w/ main), name it "TryK22"

4) In Project Options, make the following changes:

     a) General Options-> Target Device = Freescale MK22FX512xxx12

     b) Linker->List-> Check "Generate Linker Map File"

     c) Debugger->Setup->Driver = I-Jet

     d) Debugger->Download-> Check "Use flash loader(s)" and "Override default board file"; Select "FlashK60Fxxx128K.board".

     e) I-Jet/JTAGJet ->  Setup -> Uncheck "From the probe" (my project is not powered from debugger)

     f) I-Jet/JTAGJet -> Setup -> check "Log Communication"

     g) I-Jet/JTAGJet -> JTAG/SWD -> Select "SWD"

5) Edit the main.cpp as follows:

 

#if 0

     // The array has total length 688 bytes (including null).

     // It will "Download and Debug" just fine and run to main as expected.

     const char dummyArray[] = {

       "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"

       "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"

       "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"

       "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"

       "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"

       "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"

       "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567"

     };

#else

     // The array has total length 689 bytes (including null).

     // Attempted "Download and Debug" FAILS!

     const char dummyArray[] = {

       "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"

       "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"

       "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"

       "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"

       "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"

       "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"

       "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678"

     };

#endif


int main()

{

  while(1) {

    // make any reference to dummyArray, so it won't be optimized away...

    if(dummyArray[10]=='A')

       break;

  }

  return 0;

}


6) Connect I-Jet to target, power up target, and press "Download and Debug"...  (should fail)

7) Then, change the #if 0  to #if 1, then press on "Download and Debug" (should pass)


Thanks!

-Steve

Original Attachment has been moved to: cpp-fail.map.txt.zip

Original Attachment has been moved to: cpp-pass.map.txt.zip

Original Attachment has been moved to: main.cpp.txt.zip

Original Attachment has been moved to: debug-log-pass.txt.zip

Original Attachment has been moved to: cspycomm-fail.log.zip

Original Attachment has been moved to: cspycomm-pass.log.zip

Original Attachment has been moved to: debug-log-fail.txt.zip

Outcomes