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.

Use of sprintf statement multiple time gives error: program will not fit into available memory. placement with alignment fails for section ".const"

Part Number: MSP432E401Y

Hello Everyone,

I am using MSP432E401Y microcontroller for developing IoT based application. 

Use of sprintf statement multiple time (approx 80-90 times), in a project, gives me an error: program will not fit into available memory.  placement with alignment fails for section ".const"

Even though I have a plenty of free memory space available as shown below:

MEMORY CONFIGURATION

name                    origin           length           used           unused          attr     fill
---------------------- --------           ---------           --------          --------           ----      --------
FLASH                00000000    000d0000     00055556    0007aaaa     R X
USER_SEC1      000d0000    00004000     00000000    00004000     R X
USER_SEC2      000d4000    00008000     00002488    00005b78     R X
SRAM                 20000000    00040000     00036010    00009ff0       RW X
EXT_RAM          60000000    00800000     000b1d34     0074e2cc     RW X

kindly suggest me solution for the same.

  • Hi,

     I think you likely run out of stack and heap as sprintf takes a lot of runtime memory. You can increase the stack and heap and I think it should resolve the issue. 

     Most of the time, I suggest to use usprintf instead of the sprintf from the C runtime library. usprintf is a much lighter weight version of sprintf. You can find the source files of various flavors of printf in some of the SDK examples which use them. For example, if you go to C:\ti\simplelink_msp432e4_sdk_4_20_00_12\examples\nortos\MSP_EXP432E401Y\lwip\ethernet_with_lwip you will find ustdlib.c file where usprintf is defined. You can also look at enet_lwip.c on how the usprintf is referenced. 

  • Thank you for reply.

    I tried this solution but no result.

    Right now my Heap memory = 72KB and Stack memory = 16KB.

    This is the maximum size that I can allocate as I don't have enough RAM memory left in my program.

  • The message you quoted is usually accompanied by another one that says (effectively) "I needed X bytes and the largest space I could find was Y bytes". There's usually a clue there. 

    You seem to have a customized linker file. What memory region is .const  directed to go to? I think .const is where your format strings go; the .map file will tell you how big that is.

**Attention** This is a public forum