AnsweredAssumed Answered

Flash Programming: CW-Debugger vs. TCL vs. TTF

Question asked by Barak Manos on May 24, 2016
Latest reply on May 30, 2016 by ZhangJennie

Here is a problem that I’ve been struggling with unsuccessfully (as of yet).

 

I am using CW Target Tasks in order to burn (program) an image to flash.

 

My target MCU is MC9S08QG4.

 

I have configured the task (TTF file) to execute the following operations:
– Unprotect all sectors
– Erase all sectors
– Program image

 

Flash address range is 0xF000 thru 0xFFFF.

 

For all it matters (though I don’t think that it has anything to do with the problem at hand), the security bits (SEC01:SEC00) are located at 0xFFBF.

 

Now, this task occasionally fails.
The output I get in the console varies.
Here are a few examples:
– Error: Erase sector failed. Operation timeout.
– Error: Protect Command Failed. Operation timeout.Failed to erase sector data.
– Error: Detect frequence Loop count suspended
– Error: Can’t resume target HC/RS/S12Z GDI Protocol Adapter : An error occurred while trying to write registers. The Debugger can not write one register.

 

If it helps, then you can see the entire output (successful and non-successful cases) at:

https://community.freescale.com/thread/391365.

 

Now, I would normally suspect the HW (power supply, cable length, CPU clock / oscillator, physical connections, etc).

However, when I program the same image via the debugger (i.e., Run Configuration –> Debug), it always completes successfully.

 

So there is definitely a “soft” way to resolve the problem that I am experiencing, and I am left to conclude that the CW debugger performs additional operations during the image-download procedure (operations which I have skipped in my task).

 

The question is – what exactly are these operations?

 

I have searched through my project’s Run/Debug settings, but I have not found anything to explain it. In fact, I feel quite limited in the ability to even compare the two methods, as they seem to be using a different interface and/or language:
– The target task uses TCL (though the TTF file is in XML format, so I don’t quite see how I can add TCL commands to it anyway).
– The CW image-download procedure runs via some other functionality, which I do not fully understand.

 

One way to see what CW is actually doing “behind the scene”, is by enabling the Flash Programming Dialog option (in the project’s launch-configuration).
This is a very clumsy utility (dialog-box) which disappears automatically as soon as the image-download process completes, so I need to disconnect the MCU during the process, and be extremely lucky in order to see the entire log up to the point when it’s done.
To make it worse, it doesn’t even allow you to copy the text (though I could “live with that”).

 

In any case, here is what I’ve managed to get from that dialog-box (not including what I believe is just “status messages”):
CMD>RE
CMD>CM C:\Freescale\CW MCU v10.6\MCU\bin\Plugins\support\hc08\gdi\P&E\9s08gq4.s8p
CMD>EM
CMD>PM

 

I suppose that the above is equivalent to Reset, Erase, Program (and that an additional Verify or something similar would probably follow). But how can I emulate that using TCL (or if possible, how can I add it in the TTF file)?

 

The following description in the MCU’s data-sheet provides me with a good reason to suspect that CW sets the FCDIV register during the process:
“Before any program or erase command can be accepted, the FLASH clock divider register (FCDIV) must be written to set the internal clock for the FLASH module to a frequency between 150 kHz and 200 kHz. This register can be written only once, so normally this write is done during reset initialization.”.

 

However, I can’t see how to access chip registers via TCL (and most certainly via TTF).

 

I have also posted this question on Erich Styger's blog, at:

https://mcuoneclipse.com/2012/08/03/codewarrior-flash-programming-from-a-dos-shell/

 

Thank you very much for reading through

Outcomes