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.

TMS470MF03107: The RAM space required by the program after compilation is 0x5178 bytes, which is larger than the size of a single RAM area 0x08000000-0x08003FFF. Based on the current memory space resources, how to deal with it to meet the memory requiremen

Part Number: TMS470MF03107

Tool/software:

Hi,Dear TI Engineer friends!

Here's a description of the problem I ran into:

Our system program is developed based on TMS470MF03107. After integration of this system program, the total RAM space required by RAM is 0x5178 bytes. The actual chip memory resources are shown in the following figure:

The current sys_link.cmd file is as follows:

/*----------------------------------------------------------------------------*/
/* sys_link.cmd */
/* */
/* (c) Texas Instruments 2011, All rights reserved. */
/* */

/* USER CODE BEGIN (0) */

/* USER CODE END */


/*----------------------------------------------------------------------------*/
/* Linker Settings */

-l rtsv7M3_T_be_eabi.lib

--retain="*(.intvecs)"
--retain="*(.vim_table)"

/* USER CODE END */

/*----------------------------------------------------------------------------*/
/* Memory Map */

MEMORY
{

VECTORS (X) : origin=0x00004000 length=0x00000040
VIM_TABLE (X): origin=0x00004040 length=0x000000C0
//FLASH0 (RX) : origin=0x00004100 length=0x0003BF00 //20130516
FLASH0 (RX) : origin=0x00004200 length=0x0003BDFF //0x0003BE00//20140318
//FLASH1 (RX) : origin=0x00080000 length=0x00007FFF
FLASH1 (RX) : origin=0x00080000 length=0x0000BFFF //length=0x00007FFF
STACKS (RW) : origin=0x08000000 length=0x00000A00 //800
RAM (RW) : origin=0x08000A00 length=0x00005800// length=0x00003600//length=0x00005800 //800--5800//20200409


/* USER CODE BEGIN (1) */
/* USER CODE END */
}

/* USER CODE BEGIN (2) */
/* USER CODE END */


/*----------------------------------------------------------------------------*/
/* Section Configuration */

//-----------------------KWP.obj (.text)// EBD.obj (.text)---// ------------

SECTIONS
{
.intvecs : {} > VECTORS
.vim_table : {} > VIM_TABLE
.mysec : {
EBD.obj (.text)
CAN.obj(.text)
//dirver.obj (.text)
PI.obj (.text)
GT.obj (.text)
SCI.obj (.text)
//KWP.obj (.text)
gio.obj (.text)
spi.obj (.text)
VSO.obj (.text)
M301CAN.obj (.text)
diag.obj (.text)
alldriver.obj (.text)
} >FLASH1
.text : {} > FLASH0


.const : {} > FLASH0 | FLASH1
.cinit : {} > FLASH0 | FLASH1
.pinit : {} > FLASH0 | FLASH1
.bss : {} > RAM
.data : {} > RAM
.sysmem : {} > RAM

.stack :
{
. += 0x00000500; _Stack_Table_Pointer = .; //400//20200409
. += 0x00000500; _Stack_Handler_Pointer = .; //400//20200409
} > STACKS

}

/* USER CODE BEGIN (3) */
/* USER CODE END */
//}

/* USER CODE BEGIN (4) */
/* USER CODE END */


/*----------------------------------------------------------------------------*/
/* Misc */

/* USER CODE BEGIN (5) */
/* USER CODE END */

/*----------------------------------------------------------------------------*/

Questions are as follows:

 

1) You can see that the length of RAM 0x5800 has exceeded the single RAM length 0x3FFF in the current code Settings, is it reasonable? If not, how do you configure it in memory?

 2) The system program is divided into two parts, one occupies 9000 bytes of RAM (0x2328), and the other occupies 11856 bytes (0x2E50). Considering that the program needs to generate a part of RAM occupation for dynamic data processing, combined with the above chip's own RAM resources, how to solve the problem of static memory allocation? And how to keep the dynamic running program stable? The following is the resource occupation situation of dynamic operation of part of the system program, please refer to it: When the vehicle speed data input is more than 100kph, the corresponding buffers will be consumed to store the timestamp data, one 100ms buffer and three 20ms buffers, a total of 992 bytes;

3) Having triedusing RAM memory segment 0x08080000-0x08083FFF to expand RAM storage space, the main code segment is as follows:

...

RAM0     (RW) : origin=0x08000A00 length=0x00003600//length=0x00005800 //800--5800//20200409

RAM1    (RW) : origin=0x08080000  length=0x00003FFF

...

.bss : {

        *(.bss*)

        *(.bss_ram1)

        . = ALIGN(4);

    } > RAM0 | RAM1

 

    .data : {

        *(.data*)

        *(.data_ram1)

        . = ALIGN(4);

    } > RAM0 | RAM1

 

    .sysmem : {

        *(.sysmem*)

        . = ALIGN(4);

    } > RAM0 | RAM1

 

    .bss : {

        *(.bss*)

        iTPMS_G101_NEW_1101.lib (.bss)

        . = ALIGN(4);

    } > RAM1

 

    .data : {

        *(.data*)

        iTPMS_G101_NEW_1101.lib (.data)

        . = ALIGN(4);

    } > RAM1

 

    .sysmem : {

        *(.sysmem*)

        iTPMS_G101_NEW_1101.lib (.sysmem)

        . = ALIGN(4);

    } > RAM1

...

It compiles without an error, but the program runs incorrectly (some part of the system doesn't work). Then I saw this detail in the chip manual:

4)  Does this mean that the RAM-CLR Space and RAM-SET Space cannot be used as regular random storage areas for programme running? What is the purpose of the two regions RAM-CLR Space and RAM-SET Space? Based on the resource requirements of this system program, how to apply TMS470MF03107 this chip's RAM distribution?

 5)  At present, the static occupied RAM space after compilation is 0x5180, and the configuration size of linkCMD file is 0x5800, which have exceeded the size of 0x3FFF specified in the chip manual. Why are there still CAN message? Shouldn't it be  theoretically out of memory? How to intuitively determine whether the program is overflowing? I've already used sentinel values, but they don't work well.

 

Because it is urgent, I hope to get an accurate answer from you or relevant personnel of your company, thank you!

  • 1) You can see that the length of RAM 0x5800 has exceeded the single RAM length 0x3FFF in the current code Settings, is it reasonable? If not, how do you configure it in memory?

    Hi,

      Your program requires more RAM space than what is physically available on the MCU. The only thing you can do is reduce the RAM usage. 

     2) The system program is divided into two parts, one occupies 9000 bytes of RAM (0x2328), and the other occupies 11856 bytes (0x2E50). Considering that the program needs to generate a part of RAM occupation for dynamic data processing, combined with the above chip's own RAM resources,

    Again, 9000+11856=20856 bytes. This is more than the 16kB of RAM available on the chip. There is also stack that will need to reside on the RAM.  Are these all dynamic data that must be saved on the RAM? I don't know about your application but you must figure out a way to reduce the RAM usage.  There is really not anything I can offer other than to reduce the RAM usage.

    3) Having triedusing RAM memory segment 0x08080000-0x08083FFF to expand RAM storage space, the main code segment is as follows:

    ...

    RAM0     (RW) : origin=0x08000A00 length=0x00003600//length=0x00005800 //800--5800//20200409

    RAM1    (RW) : origin=0x08080000  length=0x00003FFF

    No, you cannot do this. The 0x08080000-0x08083FFF is a alias address range for the RAM as a "SET" space. When you write to this space, it will only change from 0 to 1. Whatever value that is already a 1 cannot be changed to a 0. This is a alias space to alleviate program from doing read-modify-write operations to save cycles. This space is similar to registers where you can write a 1 to set a bit on a "SET" alias and write a 1 to clear a bit on a "CLEAR" alias address. As 

    4)  Does this mean that the RAM-CLR Space and RAM-SET Space cannot be used as regular random storage areas for programme running? What is the purpose of the two regions RAM-CLR Space and RAM-SET Space? Based on the resource requirements of this system program, how to apply TMS470MF03107 this chip's RAM distribution?

    See explanation above. 

     5)  At present, the static occupied RAM space after compilation is 0x5180, and the configuration size of linkCMD file is 0x5800, which have exceeded the size of 0x3FFF specified in the chip manual. Why are there still CAN message? Shouldn't it be  theoretically out of memory? How to intuitively determine whether the program is overflowing? I've already used sentinel values, but they don't work well.

    What is iTPMS_G101_NEW_1101.lib? Why is this mapped to RAM, not flash? 

    You can look at the map file to understand where each symbol/function is allocated in the memory;

  • Thx for your early reply!  Maybe I need further help.

     2) The system program is divided into two parts, one occupies 9000 bytes of RAM (0x2328), and the other occupies 11856 bytes (0x2E50). Considering that the program needs to generate a part of RAM occupation for dynamic data processing, combined with the above chip's own RAM resources,

    Charles Tsai said:

    Again, 9000+11856=20856 bytes. This is more than the 16kB of RAM available on the chip. There is also stack that will need to reside on the RAM.  Are these all dynamic data that must be saved on the RAM? I don't know about your application but you must figure out a way to reduce the RAM usage.  There is really not anything I can offer other than to reduce the RAM usage.

    chenyuefeng said:

    After compiling of out programme(for ABS application with TPMS function),the memory allocation is as follows,which I recognised as static Memory occupation.You can see the child items under parent"RAM"is .bss and .data,during which dynamic RAM occupation is not included yet.Once dynamic RAM is added based on the static allocation, the  real-time RAM occupation is far more than what the picture below shows for RAM? Am I put it right about the understanding about the RAM occupation after compiling and after program running,that is,static and dynamic RAM occupation?

    OR do you mean the total RAM memory for program running use is just only the space between 0x08000000-0x08003FFF?

    chenyuefeng said:

    3) Having triedusing RAM memory segment 0x08080000-0x08083FFF to expand RAM storage space, the main code segment is as follows:

    ...

    RAM0     (RW) : origin=0x08000A00 length=0x00003600//length=0x00005800 //800--5800//20200409

    RAM1    (RW) : origin=0x08080000  length=0x00003FFF

    No, you cannot do this. The 0x08080000-0x08083FFF is a alias address range for the RAM as a "SET" space. When you write to this space, it will only change from 0 to 1. Whatever value that is already a 1 cannot be changed to a 0. This is a alias space to alleviate program from doing read-modify-write operations to save cycles. This space is similar to registers where you can write a 1 to set a bit on a "SET" alias and write a 1 to clear a bit on a "CLEAR" alias address. As 

    chenyuefeng said:

    I am sorry I didn't see your answering content after "As".Anything else about your answering?

     

    chenyuefeng said:

     5)  At present, the static occupied RAM space after compilation is 0x5180, and the configuration size of linkCMD file is 0x5800, which have exceeded the size of 0x3FFF specified in the chip manual. Why are there still CAN message? Shouldn't it be  theoretically out of memory? How to intuitively determine whether the program is overflowing? I've already used sentinel values, but they don't work well.

    What is iTPMS_G101_NEW_1101.lib? Why is this mapped to RAM, not flash? 

     You can look at the map file to understand where each symbol/function is allocated in the memory;

    chenyuefeng said:

    "iTPMS_G101_NEW_1101.lib" is a .lib file which include some function APIs for use in our ABS with TPMS applications.

    It is not only  mapped into the flash,but also RAM,which you can see above:

    A s you also said,based on the memory allocation method above,no matter the total space defined for RAM in the linkCMD(22528 bytes) or the actual occupation space of the RAM(20853 bytes),  both are more than the total space 0x3FFF(address from 0x08000000 to 0x08003FFF) the chip can offer,which indicates that RAM is already out of range before program running.That means that Once program running start,  additional RAM space is needed? 

    But RAM space for program occupation is no more than 0x3FFF. So can you tell me the chip operational principle about why the program can still run without any other additional RAM space available,meanwhile with already overflowing  RAM occupation just before program run?  

  • Here it says that you use 2560bytes for stack and 20853 bytes for .bss and .data. Your .bss is 19448 bytes. This .bss section are used for statically allocated variables that are declared but have not been assigned a value yet. As far as I can tell, this is not a dynamic allocated allocated. Dynamic memory allocation are heap memory when you use malloc(). 

    Do you really need to reserve 19448 bytes of spaces in RAM? It is your application, only you can tell if this is absolutely needed. It is like you are creating a global variable as follows. 

    uint8_t My_Array[19448];

    Normally if you go to the Debug directory in your CCS workspace, you will find the .map file along with the .out file. You can read the .map file which provides more information on how symbols are allocated. 

    I am sorry I didn't see your answering content after "As".Anything else about your answering?

    There is nothing after that. I mistyped. 

  • thanks for your explanation on .bss !  I think the 'memory allocation' window display accompanied with linkcmd file is similar to the .map file you mentioned.Right?

    1、Would you please furtherly explain other questions i raised above in my last reply? e.g. since gotta some problem in memory allocation,why can the program run on ignition ,while once input wheel speed of 4 channels,the CAN message stop, meaning that the program stop running or chip stop working for self protection?  (I tested it with sentinels.The STACK didn't overflow (because the sentinelvalue didn't change at start and end addr.), but the RAM's start and end address sentinel value changed)

    2、You mention 19448 bytes of spaces in RAM for .bss.  I would say ,this is the result of compilation based on current program ,with linkcmd setting as below,which is mentioned above before RAM re-allocation into RAM0 and RAM1:

    ...

    .bss : {} > RAM

    ...

    So any problems with this code line for setting ? any optimization suggestions for flexible setting for how much RAM space for .bss and .data?

    There probably exists some drawbacks in the memory allocation aspect in the program. Do you have some suggestions in detail, as we lack some experience on this?

     

  • 1、Would you please furtherly explain other questions i raised above in my last reply? e.g. since gotta some problem in memory allocation,why can the program run on ignition ,while once input wheel speed of 4 channels,the CAN message stop, meaning that the program stop running or chip stop working for self protection?  (I tested it with sentinels.The STACK didn't overflow (because the sentinelvalue didn't change at start and end addr.), but the RAM's start and end address sentinel value changed)

    I'm not clear with your question. Are you saying you are able to load the program and the program will run fine initially and later will crash? The hardware does not know how you have built your project. If the program fits in the flash then it will run initially. Later when the program tries to access a variable that is out of the physical range of RAM then there is no such address and the program will most likely just crash. 

    2、You mention 19448 bytes of spaces in RAM for .bss.  I would say ,this is the result of compilation based on current program ,with linkcmd setting as below,which is mentioned above before RAM re-allocation into RAM0 and RAM1:

    ...

    .bss : {} > RAM

    As I mentioned, RAM0 and RAM1 are just alias address for SET and CLEAR. The physical size of onchip RAM is only 16kB. If you exceed this limit, it will not fit. You can declare in the linker file with a RAM that is equal to 100MB or whatever value you want. You are only fooling the linker into thinking there is a lot of RAM and it will just build fine. But once you run the program and the physical RAM is only 16kB and the program will just crash. 

    So any problems with this code line for setting ? any optimization suggestions for flexible setting for how much RAM space for .bss and .data?

    There probably exists some drawbacks in the memory allocation aspect in the program. Do you have some suggestions in detail, as we lack some experience on this?

    I really have nothing else to offer than for you to look at your program and determine how to reduce the RAM usage. Which part of your code is reserving a large area of RAM? Can you show?

  • Thanks for replying!
    1、Would you please furtherly explain other questions i raised above in my last reply? e.g. since gotta some problem in memory allocation,why can the program run on ignition ,while once input wheel speed of 4 channels,the CAN message stop, meaning that the program stop running or chip stop working for self protection?  (I tested it with sentinels.The STACK didn't overflow (because the sentinelvalue didn't change at start and end addr.), but the RAM's start and end address sentinel value changed)

    I'm not clear with your question. Are you saying you are able to load the program and the program will run fine initially and later will crash? The hardware does not know how you have built your project. If the program fits in the flash then it will run initially. Later when the program tries to access a variable that is out of the physical range of RAM then there is no such address and the program will most likely just crash. 

    chenyuefeng:

    Yes,I am able to load the program and the program will run fine initially without other input signals(here is 4 Wheel speed).But once the wheel speed signals are input, with speed value up to about 100kph or above, the ECU just stop working with CAN messages stopping transmission. The CAN message can only recover after stopping wheel speed signals input meanwhile ignition OFF and then ON. Once ignition ON and program starts to run again,if the wheel speeds input again up to about 100kph or above, the problem re-occurred(means program crash like you said).

    3、So any problems with this code line for setting ? any optimization suggestions for flexible setting for how much RAM space for .bss and .data?

    There probably exists some drawbacks in the memory allocation aspect in the program. Do you have some suggestions in detail, as we lack some experience on this?

    Charles Tsai:

    I really have nothing else to offer than for you to look at your program and determine how to reduce the RAM usage. Which part of your code is reserving a large area of RAM? Can you show?

    Here is the .map file main content for MEMORY CONFIGURATION、SEGMENT ALLOCATION MAP、 RAM SECTION ALLOCATION MAP,maybe you can see which part of the code is reserving a large area of RAM:

    As you can see above, most of .data region is already out of range. 

    Here are another questions below:

    4、But as I mentioned before, Why can the program run initially once ignition ON,but when the wheel speed up to 100kph or so (basically wheel pulses) input to the ECU, the CAN message stops transmission meanwhile ECU stop working?? 

     5、Since the RAM for .data is out of RAM physical range,why does the ECU still work initially??    Shouldn't the ECU fail to start initially?? What is the principle?

    6、As I know.current program may be hard to reduce the usage of RAM,if possible from your experience,any other method for reducing the RAM use?

    7、All in all,   based on current memory allocation method 、target hardware resources requirement、real hardware RAM resources(16K bytes) in combination ,do you have any suggestions for our program integration optimization?

  • 4、But as I mentioned before, Why can the program run initially once ignition ON,but when the wheel speed up to 100kph or so (basically wheel pulses) input to the ECU, the CAN message stops transmission meanwhile ECU stop working?? 

     5、Since the RAM for .data is out of RAM physical range,why does the ECU still work initially??    Shouldn't the ECU fail to start initially?? What is the principle?

    6、As I know.current program may be hard to reduce the usage of RAM,if possible from your experience,any other method for reducing the RAM use?

    7、All in all,   based on current memory allocation method 、target hardware resources requirement、real hardware RAM resources(16K bytes) in combination ,do you have any suggestions for our program integration optimization?

    Hi,

      As I have explained, the code may run initially after the program is loaded because it has not used some variables that are out of range yet. During runtime, when your program tries to access a location that is out of range, it may be fetching a mirror/wraparound address or even get trapped in a fault exception. For example, the program during runtime tries to access a location at 16k+0x100. The program may base on the data on this location to jump to a different area of the program or do whatever with it based on your program intention. Since there is no physical memory at 16k+0x100 then the value returned may be just junk or could be the data at location 0x100 which is a wrap-around address. The decoder may just ignore the upper address bits beyond 16kB. It is also very possible the the address decoder generate a bus fault because this is an invalid address. You need to check when your program crashes, where is the CPU program counter. The program counter will give some idea what happens to the CPU. You can also look at the link register to trace back your code what caused the exception.

  • Thanks again,Sir!

    What do you mean by "CPU program counter" and "link register" ??

    Would you please show them in the datasheet or user manual or some other ways?

  • Hi,

      Every CPU will have a PC (program counter) and LR (link register). You can find them in the register browser.

    Please also refer to this app note for diagnosing faults if you find out that your code crashes due to a fault exception. This app note was written for a different MCU. However, they use a very similar CPU architecture. Both of them are based on Cortex-M3/M4F. 

    Diagnosing Software Faults in Stellaris® Microcontrollers

  • Hi,

         I have tried your suggestions about getting the LR and PC value while program crash shown as the picture below. Can you help explain the meaning of the value displayed?

  • Hi,

      As expected, you are getting a bus fault from the address decoder. This is why you are trapped in the _Bus_Fault() ISR. The SP register on your screenshot shows 0x7FFFFFA8. This is an illegal address. As I mentioned several times, your program is trying to access RAM that is not physically available. You can also refer to Cortex-M3 TRM and look for Bus Fault Address Register and the Fault Status register and various other fault related registers. These registers will provide information as to which address caused the fault exception. As I provided last time, this app note is also helpful. Diagnosing Software Faults in Stellaris® Microcontrollers. At the end of day, you need to make sure you do not use more RAM than is available to really solve your problem. 

  • Sorry,sir,I cannot find the 'Bus Fault Address Register' and its address '0xEEE0ED38' in the doc. 'TMS470M Series Technical Reference Manual (TRM)' and doc. under the download link you shared,in which I also cannot find the Page 8-32 you mentioned in the screenshot you posted. Below is the screenshot of the doc.s you shared both in diagnosing software faults in stellaris microcontrollers and CortexTm -M3 Revision r2p0 Technical Reference Manual:

    Can you show?

  • Hi,

    Sorry,sir,I cannot find the 'Bus Fault Address Register' and its address '0xEEE0ED38' in the doc. 'TMS470M Series Technical Reference Manual (TRM)' and doc. 

      The TMS470M TRM does not cover the details for Arm Cortex-M3 core. The Arm Cortex-M3 TRM is provided by Arm which I referred the link. I use an older version of the Arm Cortex-M3 TRM while Arm website has the latest version. Not sure why the latest Arm Cortex-M3 TRM does not have the details for Bus Fault Address register. However, you can the details in ARMv7-M Architecture Reference Manual

  • Hi 

    I have tried detect the register Bus Fault Address register:

    So is this the problem showing that the fault accuring address?But I can not see the  BFSR register in my debug window,can you show ?

  • Hi,

      If you look at the CFSR (Configurable Fault Status Register), it consists three subregisters and they are MMFSR, BFSR and UFSR. Refer to the ARMv7-M Architecture Reference Manual I sent last time and also see below. BFSR resides on bit 15:8 of CFSR register. 

    You can check if the fault is precise or imprecise. If the fault is imprecise then you cannot rely on the bus fault address register value. A imprecise fault normally are due to a write operation. Normally, the address decode logic has a write buffer in order to improve CPU performance. With the write buffer, the CPU does not have to wait until the write operation is complete before executing the next instruction. In another word, the CPU could be executing several instructions while the write operation is going on in parallel. However, if there is a fault due to that write operation (e.g. writing to an illegal address), the fault becomes imprecise and the CPU cannot remember which instruction caused the write to fault as it has already advanced in its instruction pipeline for new instructions. 

    As I mentioned several, I strongly suggest you first resolve your program image issue where it requires more RAM than available. If you can resolve this issue then I hope whatever bus fault issue you have right now or other problem down the road will resolve by itself. For your current issue, I will also suggest you increase the stack size. As I see you r screenshot that your SP is at 0x7FFFFFA8. Your stack should reside from 0x08000000 to 0x08000A00. When I see 0x7FFFFFA8, this is an illegal address. This can lead to a bus fault as this address does not exist in the device's memory map. 

  • Thanks sir again as usual!

    As I am in the debug process,I have notice the register  CFSR you mentioned,in which the bit 15-8 are bus fault status. I saw the bits' value for CFSR are all zeros.   Compared with the value of BFAR, it is strange why they are all zeros within register CFSR.  Then I believe in the registers below I mentioned at last reply:

    So they seems to show what happened the same time the program crashes or the CAN message stopped running,that is ,some memory access event unexpectedly happened at the illegal address out of range of physical ???

  • some memory access event unexpectedly happened at the illegal address out of range of physical ???

    I think so. As I just mentioned, increase the stack size and see if that changes the behavior.