This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

mixing small and large memory models just for a few functions

Hello,

I have several projects that need to run in the faster 16 bit small memory model that I will like to add a firmware update feature to.  Most of the images are under 28K and so both current program and update image could live in under the 64K bar.

But the one program that is driving this new feature uses 36K of flash. <the MSPs I use only have 56K in lower memory>

all of the MSP's i've used have at least 96K total so I was thinking I could just download the new image in the 40K of upper memory (so far so good)

The issue I'm running into is the IAR compiler will not allow mixed memory models. Is there a way to have only a few functions use the data20 and let the rest of the code remain in small model?

I was also thinking I may be able to use the BSL to do most of the dirty work of storing the new image.  I could then write the "copy image to lower memory" RAM function as a different project and then just jump into it as a black box when  the time comes to loading the new image. I have never do either of these things so I'm looking for so advice.

Thank you.

  • Hi,

    Even though the small data model don't allow you to place variables in the upper memory, it do provide intrinsic functions for accessing it. See __data20_read_TYPE and __data20_write_TYPE.

    Note that you have to disable interrupts when using these intrinsic functions.

        -- Anders Lindgren, IAR Systems

  • Thank you Anders.

    That may be the missing key.  I've come up with a way to read and write the data to upper flash using the DMA but I could not figure out a good way to trigger the erase process. 

  • To answer the original question, even though it was the wrong one (the correct one would have been “how to do 20 bit read or write operation in small data model”):

    You can’t mix memory models. If you use large data model in a function, all ISR that could interrupt his function need to use large data model too, also any other function you might call from inside this function. Neither compiler nor linker can ensure this easily. So mixing different memory models is not supported.

    Worse for large code model: if one function is compiled for large code model, all functions calling it, as well as all functions it is calling, need to be large code model too (which propagates up to main and therefore all functions in the project, except for ‘normal’ ISRs)

     

    For 20 bit reads in small data model, the compilers offer intrinsics that take a 32 bit (long int) address and an 8/16/32 bit data value (or return one).

**Attention** This is a public forum