Hi, I have an application with von neumann memory. I have hardware support to load this memory from a serial flash. I would like to be able to load function sets to a specific location in this memory and run them. To that end I have downloaded the C51: IN-SYSTEM FLASH PROGRAMMING (PART 2) example and it runs OK. I then modified this by adding another function set identical to the first pflash one. How do I get the tools to overlap the execution area for the two sets?
These are the LX51 locate user class settings: This does not work and I would like it to: SROM ( C:0x1000-C:0x1FFF), CODE_FLASHMEM(C:0x2000-C:0x2020) [ ], CODE_FLASHMEM1(C:0x2000-C:0x2020) [ ],
This does work: SROM ( C:0x1000-C:0x1FFF), CODE_FLASHMEM(C:0x2000-C:0x2020) [ ], CODE_FLASHMEM1(C:0x2000-C:0x2040) [ ],
I attach the files I modified from the example. This is the srom.c file
#include <string.h> #include <intrins.h> #include "srom.h" // SROM Handling definitions extern void flash ( void ); // first function to be executed in RAM. extern void flash1 ( void ); // first function to be executed in RAM. SROM_MC (CODE_FLASHMEM) // define SROM program segment SROM_MC (CODE_FLASHMEM1) // define SROM program segment /*------------------------------------------------ The main C function. ------------------------------------------------*/ void main (void) { memcpy (SROM_MC_TRG(CODE_FLASHMEM), // copy flash function from ROM to RAM SROM_MC_SRC(CODE_FLASHMEM), SROM_MC_LEN(CODE_FLASHMEM)); flash(); // calls flash function in RAM memcpy (SROM_MC_TRG(CODE_FLASHMEM1), // copy flash function from ROM to RAM SROM_MC_SRC(CODE_FLASHMEM1), SROM_MC_LEN(CODE_FLASHMEM1)); flash1(); // calls flash function in RAM while (1); }
This is the srom.c file
This is the pflash1.c file which needs to be added to the example project.
#include <intrins.h> #pragma USERCLASS(CODE = FLASHMEM1) // user class CODE_FLASHMEM /*------------------------------------------------ Module stored in ROM and will be executed in RAM. ----------------------------------------------*/ /*------------------------------------------------ Delay function FUN ------------------------------------------------*/ void delay1 ( unsigned int i ) { while (i--); } /*------------------------------------------------ This function should handle your Flash Memory FUN ------------------------------------------------*/ void flash1 ( void ) { unsigned int i= 0x0FFF; delay1(i); _nop_(); }
This is the other file in the project. Pflash.c which is unmodified from the example.
/*------------------------------------------------------------------------------ PFLASH.C Copyright 1995-2002 Keil Software, Inc. ------------------------------------------------------------------------------*/ #include <intrins.h> #pragma USERCLASS(CODE = FLASHMEM) // user class CODE_FLASHMEM /*------------------------------------------------ Module stored in ROM and will be executed in RAM. ------------------------------------------------*/ /*------------------------------------------------ Delay function ------------------------------------------------*/ void delay ( unsigned int i ) { while (i--); } /*------------------------------------------------ This function should handle your Flash Memory ------------------------------------------------*/ void flash ( void ) { unsigned int i= 0xFFFF; delay(i); _nop_(); }
Thanks for any help!
OK thanks for the hint on RESERVE. Although it seems like my problem is more in line with getting the linker to not reserve the memory.
Do you know if there a way to use the SEGMENTS directive to link several functions together in the manner that the CLASS directive did?
I have tried this type approach: SEGMENTS (?PR?*?PFLASH1 (0x2000) [!]) but this compiles bad code since all the functions execute at 0x2000.
Anyway it does not seem like the tools support reusing code space except for at best one function at a time.
Thanks