Download a function into ram and excute it on hcs12

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

Download a function into ram and excute it on hcs12

1,260 Views
hongjianzhang
Contributor III

Our customer has a request on our bootloader, that is, the flash diver must not stored into the flash, it should download from can cummunication and then excute it to do flash download operation. I had noted that our community have some question about how to excute a function on ram, but they were all store into the flash, and when needed or program start, copy to ram, they are still store in flash.  what I need is when: excute compile, I can get a section of target file in ram. not place in flash.  and i have tried to do this, so I modified the prm file: use the ram as read-only type and place function in it, but I couldn't find any code in the ram place in the s19 file. 

The test main.c is like this:

#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */

#define TEST_OLD PT1AD_PT1AD3
#define TEST_TEMP PTR_PTR4
#define TEST_NEW PORTB_PB3

#define TEST_IO TEST_NEW

#pragma CODE_SEG ROM_INTO_RAM2
void Test(void)
{
static volatile unsigned int test_cnt;

test_cnt ++;
if (test_cnt > 40000)
{
test_cnt = 0;
TEST_IO = TRUE;
}
/*TEST_IO = FALSE;*/
}
#pragma CODE_SEG DEFAULT

void main(void)
{
/* put your own code here */
unsigned int cnt2;
EnableInterrupts;

DDR1AD_DDR1AD3 = TRUE;
DDRR_DDRR4 = TRUE;
DDRB_DDRB3 = TRUE;

for(;;)
{
Test();

if (cnt2 ++ > 30000)
{
cnt2 = 0;
TEST_IO = FALSE;
}
_FEED_COP(); /* feeds the dog */
} /* loop forever */
/* please make sure that you never leave main */
}

and the prm file is as below:

/* This is a linker parameter file for the MC9S12HY64 */
NAMES END /* CodeWarrior will pass all the needed files to the linker by command line. But here you may add your own files too. */

SEGMENTS /* Here all RAM/ROM areas of the device are listed. Used in PLACEMENT below. */

/* Register space */
/* IO_SEG = PAGED 0x0000 TO 0x03FF; intentionally not defined */

/* RAM */
RAM = READ_WRITE 0x3000 TO 0x3EFF;

RAM2 = READ_ONLY 0x3F00 TO 0x3FFF;

/* D-Flash */
DFLASH = READ_ONLY 0x010400 TO 0x0113FF;

/* non-paged FLASHs */
ROM_1400 = READ_ONLY 0x1400 TO 0x2FFF;
ROM_4000 = READ_ONLY 0x4000 TO 0x7FFF;
ROM_C000 = READ_ONLY 0xC000 TO 0xFEFF;
/* VECTORS = READ_ONLY 0xFF00 TO 0xFFFF; intentionally not defined: used for VECTOR commands below */
//OSVECTORS = READ_ONLY 0xFF80 TO 0xFFFF; /* OSEK interrupt vectors (use your vector.o) */

/* paged FLASH: 0x8000 TO 0xBFFF; addressed through PPAGE */
PAGE_0C = READ_ONLY 0x0C8000 TO 0x0C93FF;
PAGE_0C_B000 = READ_ONLY 0x0CB000 TO 0x0CBFFF;
PAGE_0E = READ_ONLY 0x0E8000 TO 0x0EBFFF;
/* PAGE_0D = READ_ONLY 0x0D8000 TO 0x0DBFFF; not used: equivalent to ROM_4000 */
/* PAGE_0F = READ_ONLY 0x0F8000 TO 0x0FBEFF; not used: equivalent to ROM_C000 */
END

PLACEMENT /* here all predefined and user segments are placed into the SEGMENTS defined above. */
_PRESTART, /* Used in HIWARE format: jump to _Startup at the code start */
STARTUP, /* startup data structures */
ROM_VAR, /* constant variables */
STRINGS, /* string literals */
VIRTUAL_TABLE_SEGMENT, /* C++ virtual table segment */
//.ostext, /* OSEK */
NON_BANKED, /* runtime routines which must not be banked */
COPY /* copy down information: how to initialize variables */
/* in case you want to use ROM_4000 here as well, make sure
that all files (incl. library files) are compiled with the
option: -OnB=b */
INTO ROM_C000/*, ROM_1400, ROM_4000*/;

DEFAULT_ROM INTO PAGE_0C, PAGE_0C_B000, PAGE_0E;

ROM_INTO_RAM2 INTO RAM2;
//.stackstart, /* eventually used for OSEK kernel awareness: Main-Stack Start */
SSTACK, /* allocate stack first to avoid overwriting variables on overflow */
//.stackend, /* eventually used for OSEK kernel awareness: Main-Stack End */
DEFAULT_RAM INTO RAM;

//.vectors INTO OSVECTORS; /* OSEK */
END

ENTRIES /* keep the following unreferenced variables */
/* OSEK: always allocate the vector table and all dependent objects */
//_vectab OsBuildNumber _OsOrtiStackStart _OsOrtiStart
END

STACKSIZE 0x100

VECTOR 0 _Startup /* reset vector: this is the default entry point for a C/C++ application. */
//VECTOR 0 Entry /* reset vector: this is the default entry point for an Assembly application. */
//INIT Entry /* for assembly applications: that this is as well the initialization entry point */

Labels (1)
Tags (2)
0 Kudos
Reply
3 Replies

961 Views
oceansea
Contributor III

hi,hongjian zhang

请问你的问题解决了吗?我现在也遇到这个问题不知如何下手。

0 Kudos
Reply

961 Views
hongjianzhang
Contributor III

没有,现在公司的其他人已经搞出来了,我就没再深入,大致就是编译成地址无关代码的方法

prayer_hong@163.com

0 Kudos
Reply

961 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi,

The data are always downloaded into Flash and then copied to RAM during startup.

The data would be lost after power-on reset.

Regards,

Daniel

0 Kudos
Reply