Part Number: MSP432P401R
Tool/software: Code Composer Studio
Hello,
Tried using memcpy () to simply run-time relocation several functions like this: (Attach the .c file and the .cmd file.)
/***by. choi***/
/***main.c***/
#include <ti/devices/msp432p4xx/driverlib/driverlib.h> #include <stdio.h> volatile uint32_t var1, var2; volatile uint32_t i,j,k; // Variables defined in linker file extern int8_t text_ToSRAM_start1; // current address of func1: Flash extern int8_t text_ToSRAM_size1; // size of func1 extern int8_t text_ToSRAM_start2; // current address of func2: Flash extern int8_t text_ToSRAM_size2; // size of func2 extern int8_t SRAM_code_save1; // save address of func1: SRAM extern int8_t SRAM_code_execute1; // load address of func1: SRAM void * SRAM_code_save2; // new address of func2: SRAM void * SRAM_code_execute2; // new address of func2: SRAM // Function Pointers for RAM typedef void (*function_ptr) (void); function_ptr functionPtr1; function_ptr functionPtr2; // Function Prototype void SRAM_function1(); void SRAM_function2(); int main(void) { WDT_A->CTL = WDT_A_CTL_PW | WDT_A_CTL_HOLD; // stop watchdog timer var1=0; var2=0; // function 1 migration memcpy((void *)_symval(&SRAM_code_save1), (const void *)_symval(&text_ToSRAM_start1), _symval(&text_ToSRAM_size1)); functionPtr1 = (function_ptr)(_symval(&SRAM_code_execute1) + 1); functionPtr1(); printf("\n"); printf("var 1 = %d\n",var1); printf("var 2 = %d\n",var2); // function 2 migration SRAM_code_save2 = (void *) ((_symval(&SRAM_code_save1))+(_symval(&text_ToSRAM_size1))); SRAM_code_execute2 = (void *) ((_symval(&SRAM_code_execute1))+(_symval(&text_ToSRAM_size1))); memcpy(SRAM_code_save2, (const void *)_symval(&text_ToSRAM_start2), _symval(&text_ToSRAM_size2)); functionPtr2 = (function_ptr)(SRAM_code_execute2 + 1); functionPtr2(); printf("\n"); printf("var 1 = %d\n",var1); printf("var 2 = %d\n",var2); } // Function in SRAM #pragma RETAIN(SRAM_function1) #pragma CODE_SECTION(SRAM_function1,".text_ToSRAM1") void SRAM_function1() { var1++; } #pragma RETAIN(SRAM_function2) #pragma CODE_SECTION(SRAM_function2,".text_ToSRAM2") void SRAM_function2() { var2++; }
/***by.choi***/
/***msp432p401r.cmd***/
--retain=flashMailbox MEMORY{ FLASH (RX) : origin = 0x00000000, length = 0x00040000 INFO_FLASH (RX) : origin = 0x00200000, length = 0x00004000 SRAM_EXECUTE (RWX): origin = 0x01000000, length = 0x00010000 SRAM_SAVE (RW): origin = 0x20000000, length = 0x00010000 } SECTIONS { .intvecs: > 0x00000000 .text : > FLASH .text_ToSRAM1: load = FLASH, run = SRAM_EXECUTE, RUN_START(text_ToSRAM_start1), RUN_SIZE(text_ToSRAM_size1) .text_ToSRAM2: load = FLASH, run = SRAM_EXECUTE, RUN_START(text_ToSRAM_start2), RUN_SIZE(text_ToSRAM_size2) .const : > FLASH .cinit : > FLASH .pinit : > FLASH .init_array : > FLASH .binit : {} > FLASH .flashMailbox : > 0x00200000 .tlvTable : > 0x00201000 .bslArea : > 0x00202000 .vtable : > 0x20000000 .data : > SRAM_SAVE .bss : > SRAM_SAVE .sysmem : > SRAM_SAVE .stack : > SRAM_SAVE (HIGH) .SRAM_code_save1: RUN_START(SRAM_code_save1) > SRAM_SAVE .SRAM_code_execute1: RUN_START(SRAM_code_execute1) > SRAM_EXECUTE } WDTCTL_SYM = 0x4000480C;
Except for printf in the configured SRAM_function1(), it executes properly in the ram position without any problem, but an infinite loop error occurs when using printf or calling another function inside a function.
What is this reason?
Should I use that by combining features of the linker called UNION and copy tables.
If I use the copy table function, will the memory be copied sequentially?
In other words, is it relocated without wasting memory space, similar to the code I implemented?
Best,
Choi