Problem with execute-from-SRAM on MKL25Z128 (FRDM-KL25Z) in AN2295-base bootloader

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

Problem with execute-from-SRAM on MKL25Z128 (FRDM-KL25Z) in AN2295-base bootloader

1,128 Views
WolfgangW
Contributor I

Hi,

 

I am trying to get something like the AN2295 bootloader running on a KL25Z128.

 

I took some original version from Freescale (sorry, as there are so many versions floating around it is difficult to tell which one it actually is) that claimed to work with CW10.3 and Kinetis L, but had to modify it quite heavily to get it to compile and at least partially run with CW10.3 and the Freedom board.

 

My modifications:

- use PLL-based clock

- no trimming or calibration; fixed baud rate only (commented out calibration in hc08sprog, too)

 

There are two strange things now:

1) hc08sprog always complains

"WARNING! The protocol version [0x08] (Kinetis) does not match the one associated with the device with following SDID [0x000].

Protocol version for given SDID should be [0x02] (S08).

Continuing with reported protocol version anyway.

 

Something is screwed up, please report!"

although the bytes sent from KL25Z should be ok. well, don't care for now...

2) flashing works when I execute the code from flash, but when I try to relocate the flashing routines, the debugger halts at the default exception handler immediately when the in-ram function is called.

I tried the relocation from AN2295 code as well as the one outlined in AN4695_1 for gcc-based compiler in Codewarrior. The relocation address of 0x20000000 is correct (I can see the correct code there in the debugger and the PC also seems correct), but still the exception occurs.

- Is there an easy way to see which exception occurred?

- what might be the cause? Is there some general preparation needed to execute code from SRAM?

 

Any help is appreciated!

I attached my project in case it can give some details I forgot to mention here.

 

Best regards,
Wolfgang

Original Attachment has been moved to: bootloader3.zip

Labels (1)
0 Kudos
5 Replies

646 Views
WolfgangW
Contributor I

Some correction/additional information:

It seems the exception does not happen when calling the in-RAM code but after the first few instructions; my assembler knowledge is near non-existent or at least severely rusty, so I do not understand yet what is going on there.

The other thing is I incorrectly stated using CW 10.3, but actually it is CW 10.4 (light) I am using.

This is the disassembly:

FLASH_FlashCommandSequenceStart:

29 {

20000000: ldrh r1,[r0,#4]

20000002: ldrh r0,[r0,#6]

20000004: movs r2,#136

20000006: lsls r0,r0,#16

20000008: orrs r0,r1

2000000a: ldr r3,[r0,#4]

30 Byte* ptrFccobReg = (Byte*)&FLASH_BASE_PTR->FCCOB3;

2000000c: lsls r3,r2,#23

2000000e: str r3,[r0,#4]

31 Byte* ptrCommandObj = (Byte*)&CommandObj;

20000010: bl 0x1FFFFFC4 (0x1fffffc4) ; 0x1fffffc4

And this is the trace the debugger prints out:

Thread [ID: 0x0] (Suspended: Signal 'Halt' received. Description: User halted thread.)

2 Default_Handler() kinetis_sysinit.c:31 0x00000410

1 FLASH_FlashCommandSequenceStart() flash_kinetisRamFunc.c:29 0x2000000a

Maybe somebody with better assembly skills can see immediately what's wrong - it seems to have something to do with the parameters, but I did not figure out what it does.

Best regards,

Wolfgang

0 Kudos

646 Views
pavel_krenek
NXP Employee
NXP Employee

Hi Wolfgang,

first of all if you want to use bootloader AN2295 and modified this bootloader, I would try to test our official version (latest on the web or community). If the bootloader is functional on the KL25 you can continue with modification of it etc.

The curious behavior what you mentioned above looks like not correct setting of the UART speed which is also based on clock settings (PLL). Regarding the RAM execution I think that problem is that the debugger not correct show you the steps and jump to ram you must try to step by step this routine and the assembly window must be opened and after that you may see the correct execution of the code from the RAM.

Hope that helps,

Regards,

Pavel

646 Views
WolfgangW
Contributor I

Hi Pavel,

thanks for caring!

Which is the current code? I tried this one you posted on 09.07.2013, seemingly rev. 12:

https://community.freescale.com/servlet/JiveServlet/download/338991-263421/an2295_kinetis_beta.zip

I am not able to directly import this into CW 10.4; when trying to manually add the files and settings, I get a project that does not compile, seemingly because it is not yet adapted to the GCC toolchain used in CW 10.4 and also maybe because some settings are wrong (processor family selection), which I did not get set up correctly using CW.

If you could let me know how to import this into CW 10.4, I can start anew with a fresh (and hopefully working) project.

Best regards,

Wolfgang

0 Kudos

646 Views
pavel_krenek
NXP Employee
NXP Employee

Hi Wolfgang,

yes this one is the latest version of the AN2295, but in the near time will be the latest version available on the Freescale webpages.

Regards,

Pavel

0 Kudos

646 Views
WolfgangW
Contributor I

Hi Pavel,

I have the problem mostly solved. Code execution from RAM is now working - I had the linker command file messed up during merging AN4695 and AN2295 it seems, with the entry for __S_romp fixed (or at least screwed up differently ;-), the code gets correctly relocated and the in-RAM execution works.

Now I can concentrate on the other glitches like the protocol version mismatch warning.

Best regards,

Wolfgang

PS: I can't attach the linker command file here, I will try to attach it to the original posting.

0 Kudos