STM32 program distribution memory

References: https://www.rt-thread.org/document/site/programming-manual/basic/basic/

MCU memory contains general are: Flash chip within the chip RAM, RAM memory corresponds, Flash corresponds to the hard disk. The compiler will be classified as a program in several parts of MCU are stored in different storage areas.

After compiling the project Keil, there will be a corresponding program space occupied by the message, as follows:

linking...
Program Size: Code=48008 RO-data=5660 RW-data=604 ZI-data=2124
After Build - User command \#1: fromelf --bin.\\build\\rtthread-stm32.axf--output rtthread.bin
".\\build\\rtthread-stm32.axf" - 0 Error(s), 0 Warning(s).
Build Time Elapsed: 00:00:07

Program Size mentioned above includes the following sections:

    1) Code: code portion code segment, stored procedures

    2) RO-data: read-only data segment, defined in the program stored constants;

    3) RW-data: read and write data segment, initialize the global variables stored non-zero value

    4) ZI-data: zero data segments, to store global variables and uninitialized variables initialized to 0;

Completion Cheng Huisheng compiled into a map file, the file shows the size and address of each function occupied in the last few lines of the file also shows the relationship between several fields above:

Total RO Size (Code + RO Data) 53668 ( 52.41kB)
Total RW Size (RW Data + ZI Data) 2728 ( 2.66kB)
Total ROM Size (Code + RO Data + RW Data) 53780 ( 52.52kB)

    1) RO Size Code contains and RO-data, the program represents the size of the space occupied by Flash

    2) RW Size contains RW-data and ZI-data, the size of the RAM occupied by the representation of the runtime

    3) ROM Size contains Code, RO Data and RW Data, it represents the magnitude of the programming process space occupied by Flash

       Before the program is running, the need for physical file is burned to the STM32 Flash, typically bin or hex file, burn the file is called an executable image file. 3-3 shown in the left, the image file is an executable programmed into memory after the STM32 distribution, which comprises two portions RO and RW group: wherein RO segment saved in the Code, RO-data data, by RW RW-data storage data, since ZI-data is 0, it is not included in the image file.

       STM32 After the power-up default startup from Flash, RW-data (initialized global variables) will be in the period after the start RW conveyed to RAM, but does not transport RO slot, i.e., the CPU reads the execution code from Flash , ZI additionally allocated according to the size of the address and the compiler analysis ZI section, and the RAM is cleared this area

 

 

 Wherein the dynamic heap of unused RAM space, applications and freeing memory blocks from the space.

As in the following example:

rt_uint8_t* msg_ptr;
msg_ptr = (rt_uint8_t*) rt_malloc (128);
rt_memset(msg_ptr, 0, 128);

msg_ptr code pointer points to the memory space is 128 bytes of dynamic memory heap space.

And global variables are stored in segments RW and ZI section, RW segment is stored in global variables with initial values ​​(and global variables as constants are placed in RO segment, the attribute is read-only), storage section ZI uninitialized global system variables, such as the following example:

#include <rtthread.h>

const static rt_uint32_t sensor_enable = 0x000000FE;
rt_uint32_t sensor_value;
rt_bool_t sensor_inited = RT_FALSE;

void sensor_init()
{
     /* ... */
}

sensor_value stored in the ZI section it is automatically initialized to zero after the system starts (number of library functions provided by the user program or compiler initialized to zero). sensor_inited variable is stored in the RW segment and stored in the RO sensor_enable section.

 

 

 

Guess you like

Origin www.cnblogs.com/linux-37ge/p/11964434.html