2. How to create RAM image:
Create a project in CodeWarrior and select RAM target. Now it is necessary to move entry point (function __start() ) at the start of RAM image – at address 0x4000_0000.
Find file __start.c in installation directory of CodeWarrior and copy it into your project. Add this files to source files in the project. Change the link order – set this file as a first one.
You will get some warnings because we overloaded the __start function.
Then it is necessary to change the linker file – place “init” section at the start of memory and place init_vle at the start of “init” GROUP:
(This is example for MPC5566 but it is similar for other devices)
MEMORY
{
init: org = 0x40000000, len = 0x00001000
pseudo_rom: org = 0x40001000, len = 0x00011000
exception_handlers: org = 0x40012000, len = 0x00001000
internal_ram: org = 0x40013000, len = 0x0000A000
heap : org = 0x4001D000, len = 0x00001000 /* Heap starts */
stack : org = 0x4001E000, len = 0x00001000 /* Start location for Stack */
}
SECTIONS
{
GROUP : {
.init_vle (VLECODE) : {
*(.init)
*(.init_vle)
}
.init : {}
} > init
….
Then the entry point (function __start() ) will be at 0x4000_0000. You can check it in .map file.
As a next step, just for test purposes, you can write some code in this project – for example toggle a LED diode in endless loop.
Build the program, so you have RAM.mot file. This is our RAM image that will be downloaded to RAM.
Because the downloading of code via SCI/CAN is quite slow, make the image as small as possible – edit the linker file. For example, if you don’t need size of pseudo_rom to be 0x11000, change it to smaller size.
Notice that downloading of code also initializes ECC. Area that is not written by BAM will contain ECC errors. If your application wants to use uninitialized RAM, it must be explicitly initialized by your SW.
The RAM.mot cannot be downloaded by BAM directly. It must be continuous image without gaps. You can either write some program on PC that will create continuous binary file or you can download the project into RAM by debugger, then save the content of RAM memory to binary file.
Detailed procedure how to download the image for both SCI and CAN can be found in reference manual.
Be aware that erratum exists on some devices: the size of image must NOT be equal to size of RAM. Last 16 bytes in RAM should not be written by BAM. But as I already wrote, it is better to make the image as small as possible.