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

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

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

Jump to solution
10,298 Views
smoles
Contributor II

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

Labels (1)
1 Solution
3,791 Views
smoles
Contributor II

Hi All -   I solved this problem and thought I'd post it here in case anyone else encounters the same issue.

In IAR EWARM 7.2 (probably other versions as well), when you select  target device in project options, the IDE automatically selects default .ddf, .icf, and .board files for your project.

The .board file, in turn, refers to a .flash file which specifies which flashloader 'agent' will be downloaded into your target, which will interact with IDE using breakpoints, etc, when performing the actual download and flash programming procedure.

In the case of the Kinetis MK22FX512xxx12 target, we have:

    "FlashK60Dxxx128K.board" --> "FlashK60Dxxx128K.flash" -->   "FlashK60Dxxx128K.out" flashloader.  (default case, didn't work)

    "FlashK60Fxxx128K.board" --> "FlashK60Fxxx128K.flash" -->   "FlashK60Fxxx128K.out" flashloader.   (2nd attempt, didn't work either)

I felt that the flashloader was suspect, so I was happy to find that the source code for all the flashloaders was located in the .../arm/src/flashloader/Freescale/FlashK60XXXX folder. I was able to open the enclosed project and find that there were multiple configurations, one for each of the K60 variants. While trying to figure out how the flashloader works, I realized that the project configurations only differed by a few precompiler definitions, namely "BLOCK_SIZE", "RAM_BLOCK_SIZE", and "K60Fxxx". It turns out that for my target, RAM_BLOCK_SIZE was required to be 1024 (because the flash 'Program Section' command can only use one-quarter of the FlexRAM), but it was undefined in the configuration and therefore was defaulting to 4096. So, I defined RAM_BLOCK_SIZE to 1024, recompiled the flashloader and tested... and it worked!

But now I wanted a solution which didn't require maintaining my own specially-compiled flashloader, so I searched through all of the other variants and I found that the K64 configuration was already setup as needed.

So, the short answer solution is:

IF TARGETING A KINETIS K22FX512xxx12 DEVICE USING IAR EWARM 7.2 AND CANNOT GET "DOWNLOAD & DEBUG" TO WORK, TRY THE FOLLOWING:

OVERRIDE DEFAULT .board FILE (PROJECT OPTIONS->DEBUGGER-> DOWNLOAD) AND SELECT "FlashK64Fxxx128K.board". THIS WILL SPECIFY A CORRECTLY-CONFIGURED FLASHLOADER THAT SHOULD WORK WITH THE DEVICE.

Hope this helps!

Thanks,

-Steve

View solution in original post

5 Replies
3,791 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Hi Steve,

Looks like your link file has some problem, per cpp-pass.map.txt, the code and ro data take place of where for vector table, and actually for the device that you are using, KSDK has already supported it, so Please kindly refer to Software Development Kit for Kinetis MCUs|Freescale for more details, and there is a new sub space for KSDK topics already, you may ask KSDK questions in https://community.freescale.com/community/kinetis/kinetis-software-development-kit .

Hope that helps,


Have a great day,
Kan

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

0 Kudos
Reply
3,792 Views
smoles
Contributor II

Hi All -   I solved this problem and thought I'd post it here in case anyone else encounters the same issue.

In IAR EWARM 7.2 (probably other versions as well), when you select  target device in project options, the IDE automatically selects default .ddf, .icf, and .board files for your project.

The .board file, in turn, refers to a .flash file which specifies which flashloader 'agent' will be downloaded into your target, which will interact with IDE using breakpoints, etc, when performing the actual download and flash programming procedure.

In the case of the Kinetis MK22FX512xxx12 target, we have:

    "FlashK60Dxxx128K.board" --> "FlashK60Dxxx128K.flash" -->   "FlashK60Dxxx128K.out" flashloader.  (default case, didn't work)

    "FlashK60Fxxx128K.board" --> "FlashK60Fxxx128K.flash" -->   "FlashK60Fxxx128K.out" flashloader.   (2nd attempt, didn't work either)

I felt that the flashloader was suspect, so I was happy to find that the source code for all the flashloaders was located in the .../arm/src/flashloader/Freescale/FlashK60XXXX folder. I was able to open the enclosed project and find that there were multiple configurations, one for each of the K60 variants. While trying to figure out how the flashloader works, I realized that the project configurations only differed by a few precompiler definitions, namely "BLOCK_SIZE", "RAM_BLOCK_SIZE", and "K60Fxxx". It turns out that for my target, RAM_BLOCK_SIZE was required to be 1024 (because the flash 'Program Section' command can only use one-quarter of the FlexRAM), but it was undefined in the configuration and therefore was defaulting to 4096. So, I defined RAM_BLOCK_SIZE to 1024, recompiled the flashloader and tested... and it worked!

But now I wanted a solution which didn't require maintaining my own specially-compiled flashloader, so I searched through all of the other variants and I found that the K64 configuration was already setup as needed.

So, the short answer solution is:

IF TARGETING A KINETIS K22FX512xxx12 DEVICE USING IAR EWARM 7.2 AND CANNOT GET "DOWNLOAD & DEBUG" TO WORK, TRY THE FOLLOWING:

OVERRIDE DEFAULT .board FILE (PROJECT OPTIONS->DEBUGGER-> DOWNLOAD) AND SELECT "FlashK64Fxxx128K.board". THIS WILL SPECIFY A CORRECTLY-CONFIGURED FLASHLOADER THAT SHOULD WORK WITH THE DEVICE.

Hope this helps!

Thanks,

-Steve

3,791 Views
nesrinemhiri
Contributor III

Hi
i do it but the same message appear ''The flash loader program reported an error."

Thu Oct 02, 2014 15:53:12: Failed to load flash loader: C:\Program Files\IAR Systems\Embedded Workbench 6.5\arm\config\flashloader\Freescale\FlashK64Fxxx128K.flash  :smileysad:

0 Kudos
Reply
3,791 Views
smoles
Contributor II

Hi Nesrine,

Does the specified file "FlashK64Fxxx128K.flash" actually exist in  your EWARM 6.5 installation?  I looked in my EWARM 6.5 installation and it does not.

If upgrading your EWARM to version 7+ is not an option, perhaps you can have a look at the flashloader project in  ... Embedded Workbench 6.5/arm/src/flashloader/Freescale/FlashK60XXXX  folder, and use the information in my answer above to build a suitable flashloader file.  One warning... I looked briefly into the project and it seems to handle the various configurations differently, so BLOCK_SIZE, RAM_BLOCK_SIZE, and K60Fxxx precompiler definitions may not be appropriate in that project.  You'll have to figure out how to accomplish the same thing within that project.

Good Luck!

-Steve

0 Kudos
Reply
3,791 Views
nesrinemhiri
Contributor III

Hi Steve

I added the file "FlashK64Fxxx128K.flash"  in my EWARM 6.5 installation,and does not okey.

I need to work with 6.5 version because i do benchmarking so compilator version is needed.

have a nice day

Nesrine

0 Kudos
Reply