Kinetis: Placing Clock Init routines in RAM --> How to do it

Discussion created by Guest on Feb 18, 2011

Here is the background:

 

I was using the Kinetis K40 tower board with Codewarrior 10 and was trying to get the external crystal to drive the MCG unit.

 

Here is the issue:  The K40 errata e2448 says that I need to place a certain portion of my code in RAM to execute a certain portion of the clock setup code. There is an example that is on the K40 tower website of how to do this BUT all the examples are for the IAR compiler, not Codewarrior. IAR uses a keyword _ramfunc to do this.   I could not find an equivalent in CW. Now, my clock code does work when I start a new project in Codewarrior and target the entire project to RAM.   I needed this to work with the FLASH linker file for stand-alone operation.  When executing from Flash the code "runs away" to a random address.   Also,  The code generated by the device initialization wizard does not function because of e2448.  It appears to set the registers correctly but it is not aware of e2448.

 

Here is a worked around to this issues:

 

1st  copy this into the Default linker script for the K40 (FLASH version)

 

_ROMCodeToCopy = ___ROM_AT + SIZEOF(.app_data);
.copyToRAM:
AT(_ROMCodeToCopy) {
. =
ALIGN (0x4);
__START_COPYTORAM = .;
*(CopyToRAM)
__END_COPYTORAM = .;
} >> m_data

 

Next,  declare RAM functions like this:

 

 

#pragma section CopyToRAM begin
void InitClock()
{
 ..

..

..}

 #pragma section CopyToRAM end

 

 See Attached project.   There is a small bug in the InitClock routine.  It fires an interrupt but does return OK.

 

 

Hopefully this will be useful to someone else

Original Attachment has been moved to: 149-LED_BLINK_96MHZ.zip

Outcomes