This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Change the execution address of a library

Hello

I am working with a C161U micro on an EASY UTAH target.

Well I have two projects, startup and application, that I load on Flash with the Flash Tool.

At the target reset, what it is on flash begins to run: the startup project.
The startup project copies the application project from flash to RAM, and its last instruction is to jump to the beginning of the RAM, and then the application project is executed from RAM. To accomplish this, I must avoid absolute call to functions by converting the calls in relative calls thanks to the key word near before each function.
For example the function void near config (void) is at address 0x20100 (this is the load address in Flash), so if the RAM start address is 0x110000, then this function is copied at address 0x110100. When this function is called, this is not with a CALLS CC_US, 0x20100 but with a CALLA CC_US, 0x00100 thanks to near. The call is then relative and the function is executed from RAM.

Well, I have a problem with the library functions used in my program C_PCASTS or MEMCPY, because they are executed in Flash. I don't know how to specify that they must be called with relative calls since I can't put the near word before their declarations.

How to obtain their execution in RAM and not in Flash?

Thanks for your help
Best regards
Carmen

Parents
  • Hello,

    Thanks Mike for your response.

    I use the large memory model. This is for that I need to specify that all functions are near when executing.

    Yes, this is what I do. I generate two HEX files (one for startup project and one for application project). The startup project copies the application project from flash 0x20000 to RAM 0x110000.
    But I observe that for doing a multiplication, for example, the call to the library function is CALLS ?C_FPMUL(0x20204) and not CALLA ?C_FPMUL(0x00204) as I expect (this is what happened for functions declared with near).

    The first command implies that execution is really done at address 0x20204, that is to say in Flash, and the second command implies that the execution is done at a relative address of 0x204 starting from the RAM base address, that is to say from 0x110000, that is to say at the address 0x110204, where the FPMUL library function is copied.

    I know how to have relative calls for functions I defined and wrote on my program, but not for library functions already defined. Do someone know how to do this?

    Thanks for help.
    Regards

Reply
  • Hello,

    Thanks Mike for your response.

    I use the large memory model. This is for that I need to specify that all functions are near when executing.

    Yes, this is what I do. I generate two HEX files (one for startup project and one for application project). The startup project copies the application project from flash 0x20000 to RAM 0x110000.
    But I observe that for doing a multiplication, for example, the call to the library function is CALLS ?C_FPMUL(0x20204) and not CALLA ?C_FPMUL(0x00204) as I expect (this is what happened for functions declared with near).

    The first command implies that execution is really done at address 0x20204, that is to say in Flash, and the second command implies that the execution is done at a relative address of 0x204 starting from the RAM base address, that is to say from 0x110000, that is to say at the address 0x110204, where the FPMUL library function is copied.

    I know how to have relative calls for functions I defined and wrote on my program, but not for library functions already defined. Do someone know how to do this?

    Thanks for help.
    Regards

Children
  • Hello Carmen,

    the call to the library function is CALLS ?C_FPMUL(0x20204) and not CALLA ?C_FPMUL(0x00204) as I expect (this is what happened for functions declared with near)

    In large memory model all library functions are far and they are called with the CALLS instruction. From your observation I can also see that code address range for your application was specified to be in flash:
    ROM: start 0x20000, size 0x20000
    RAM: start 0x110000, size 0x20000
    (or something like that in the target options)
    If you want your code to reside in your board's RAM, however, your memory ranges have to look like that:
    ROM: start 0x110000, size 0x10000
    RAM: start 0x120000, size 0x10000
    (I don't know the sizes, so correct that)
    because during build all the code goes to the 'ROM' range. But the 'ROM' range doesn't have to be in physical ROM, it can be your board's RAM just as well.
    So after you've changed your target options, you'll see that all calls to library functions will look like this:
    CALLS ?C_FPMUL(0x110204) // or whatever
    Of course, the HEX file will start at 0x110000, so it's not suitable for burning into flash directly. But it's a minor problem, you can solve it easily (see my previous message).
    - Mike