|
|||||||||||
|
Technical Support Support Resources
Product Information |
C251: Splitting Code Between Eprom and Flash MemoryQUESTIONI'm using the Keil 251 tools C and Assembly code for a project I'm designing. I need to create 2 separate code areas: one for on-chip code and one for off-chip (FLASH or ROM) code. I want to locate some functions on-chip (for speed) and some functions off-chip. What's the best way to go about this? ANSWERThere are a number of ways to solve this problem. However, the following example should be easy to implement for most developers. If you only need the two code areas and they will both be updated at the same time (new OTPs and new ROM devices) you may place the ROM(LARGE) pragma before on-chip functions and the ROM(HUGE) pragma before off-chip functions. For example:
You must determine if this is acceptable for your application. Remember to use the #pragma ROM settings before each function prototype so that the compiler generates the proper code (LCALL or ECALL) for each function. When you link your application, the L251 linker places the ROM(LARGE) functions in the CODE class and the ROM(HUGE) functions in the ECODE class. You must tell the linker where these classes reside so that they are located for your ROM/EPROM/FLASH memory arrangement. Finally, you create separate HEX files for each device using the OH251 object-HEX converter. For example:
This creates INTERNAL.HEX with code from 0xFF0000 to 0xFF1FFF and EXTERNAL.HEX with code from 0xFF2000 to 0xFF7FFF. Another method of supporting 2 code areas involves 2 program areas and a jump table. The following rules apply to this method.
In the following example, we assume that we have on-chip CODE memory from 0xFF0000 to 0xFF1FFF and off-chip memory from 0xFF2000 to 0xFF7FFF. STEP ONE:Configure the linker to locate CODE from 0xFF0000-0xFF1FFF and ECODE from 0xFF2200-0xFF7FFF using the following command line:
Note that we start ECODE at 0xFF2200 rather than 0xFF2000. The 200 bytes are saved for the jump table. You may need to adjust this number up or down. STEP TWO:Create all external functions with the prefix _ext_ and using ROM(HUGE). For example:
You may even want to save the external function in filenames that start with X_ so you can easily recognize them. STEP THREE:Create the jump table functions for each external function. The jump table is created using in-line assembly and should be created in a separate file (to avoid disabling the optimized on an important function or code block). Note that the function names in the jump table do not include the _ext_ prefix. These are the functions you will call from your main, internal program. The jump table entries are located at unique addresses using the _at_ keyword. You must be responsible for defining unique addresses for the table. For example:
Since the SRC directive is used, the C251 compiler generates FUNC1.SRC when it compiles this file. STEP FOUR:Create functions in the internal code that call functions defined as the jump table routines. For example:
Note that the func_1 function is prototyped as ROM(HUGE). This is so that the external function (_ext_func1) which is also declared as ROM(HUGE) actually returns to the main C function. STEP FIVE:Compile and Assemble and Link the files as follows:
STEP SIX:Create separate HEX files for each device. For example:
This creates INTERNAL.HEX with code from 0xFF0000 to 0xFF1FFF and EXTERNAL.HEX with code from 0xFF2000 to 0xFF7FFF. You use these files when you program your ROM/EPROM/FLASH devices. STEP SEVEN:Verify that segments and classes are located in the correct areas by viewing the MAP file created by the linker. In this case, we see that ?PR?FUNC_1... (the call table entry) and ?PR?X_FUNC1 (the external function) are located at 0xFF2000 and 0xFF2200 respectively.
DOWNLOAD251JTAB.ZIP contains the code for this example. Last Reviewed: Thursday, February 25, 2021 | ||||||||||
|
|||||||||||
Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.