G
golson
I have written a C function to copy a flash write routine that is in
Flash memory to RAM memory. I have then created a function that
uses a Function Pointer to run the copied function in RAM.
My problem is that I have not successfully been able to run the
function out of
RAM.
Here is my function
void write_data_params(void)
{
int (* p) (unsigned short *src_addr, unsigned long dst_addr, int
write_size); // p is a pointer to a function
short_int_array[0] = 0x2211;
short_int_array[1] = 0x4433;
short_int_array[2] = 0x6655;
short_int_array[3] = 0x8877;
short_int_array[4] = 0xaa99;
short_int_array[5] = 0xbbaa;
short_int_array[6] = 0xddcc;
short_int_array[7] = 0xffee;
short_int_array[8] = 0x2221;
short_int_array[9] = 0x2423;
short_int_array[10] = 0x2625;
short_int_array[11] = 0x2827;
short_int_array[12] = 0x2a29;
short_int_array[13] = 0x2c2b;
short_int_array[14] = 0x2e2d;
short_int_array[15] = 0x302f;
short_int_array[16] = 0x3231;
short_int_array[17] = 0x3433;
short_int_array[18] = 0x3635;
short_int_array[19] = 0x3837;
ret_value_flash_data_write = fmWriteFunctoRam(); // write function
to RAM
// p = (UHWORD *) fmDataWriteG; // when using this statement
running function inflash
p = (int (*) (unsigned short *, unsigned long, int )) 0x10005000;
sprintf(str, " p %x *p %x \r\n", p, ( UHWORD*)p); // p
10005000 *p 10005000
uprintLine(str);
ret_value_flash_data_write = p(short_int_array, 0x30000, 40);
return;
}
Result when I try running this function
p 10005000 *p 10005000
Soft reset occurred
Memory dump:
10005000: E1A0C00D E92DD800 E24CB004 E24DD064
10005010: E50B0010 E50B1014 E50B2018 E3A03000
10005020: E50B301C E59F003C EBFFE328 E24B206C
10005030: E51B3010 E1D3C0B0 E51B3018 E58D3000
I tried to see the Value at location p which is the function pointer.
it shows to be 10005000 and the Address shows to be the same value
10005000.
when I do a memory dump I can see the data at 10005000 is E1A0C00D.
After the statement
ret_value_flash_data_write = p(short_int_array, 0x30000, 40);
the function should run in RAM. But it gives a invalid instruction
and a Soft Reset occurs.
I tried assigning p to be the Function Address located in the FLASH
MEMORY with the statement
// p = (UHWORD *) fmDataWriteG; // when using this statement running
function inflash
and it did run.
Unfortunately, I need to run the function in RAM and Not FLASH for my
application.
Thank You for your help
Flash memory to RAM memory. I have then created a function that
uses a Function Pointer to run the copied function in RAM.
My problem is that I have not successfully been able to run the
function out of
RAM.
Here is my function
void write_data_params(void)
{
int (* p) (unsigned short *src_addr, unsigned long dst_addr, int
write_size); // p is a pointer to a function
short_int_array[0] = 0x2211;
short_int_array[1] = 0x4433;
short_int_array[2] = 0x6655;
short_int_array[3] = 0x8877;
short_int_array[4] = 0xaa99;
short_int_array[5] = 0xbbaa;
short_int_array[6] = 0xddcc;
short_int_array[7] = 0xffee;
short_int_array[8] = 0x2221;
short_int_array[9] = 0x2423;
short_int_array[10] = 0x2625;
short_int_array[11] = 0x2827;
short_int_array[12] = 0x2a29;
short_int_array[13] = 0x2c2b;
short_int_array[14] = 0x2e2d;
short_int_array[15] = 0x302f;
short_int_array[16] = 0x3231;
short_int_array[17] = 0x3433;
short_int_array[18] = 0x3635;
short_int_array[19] = 0x3837;
ret_value_flash_data_write = fmWriteFunctoRam(); // write function
to RAM
// p = (UHWORD *) fmDataWriteG; // when using this statement
running function inflash
p = (int (*) (unsigned short *, unsigned long, int )) 0x10005000;
sprintf(str, " p %x *p %x \r\n", p, ( UHWORD*)p); // p
10005000 *p 10005000
uprintLine(str);
ret_value_flash_data_write = p(short_int_array, 0x30000, 40);
return;
}
Result when I try running this function
p 10005000 *p 10005000
Soft reset occurred
peekw 0x10005000 10> peekw 0x10005000 10
Memory dump:
10005000: E1A0C00D E92DD800 E24CB004 E24DD064
10005010: E50B0010 E50B1014 E50B2018 E3A03000
10005020: E50B301C E59F003C EBFFE328 E24B206C
10005030: E51B3010 E1D3C0B0 E51B3018 E58D3000
I tried to see the Value at location p which is the function pointer.
it shows to be 10005000 and the Address shows to be the same value
10005000.
when I do a memory dump I can see the data at 10005000 is E1A0C00D.
After the statement
ret_value_flash_data_write = p(short_int_array, 0x30000, 40);
the function should run in RAM. But it gives a invalid instruction
and a Soft Reset occurs.
I tried assigning p to be the Function Address located in the FLASH
MEMORY with the statement
// p = (UHWORD *) fmDataWriteG; // when using this statement running
function inflash
and it did run.
Unfortunately, I need to run the function in RAM and Not FLASH for my
application.
Thank You for your help