Skip to content

Commit 39dea88

Browse files
authored
[documentation] Fixed Program Memory Distribution - Basic.md (#5681)
* Fixed Program Memory Distribution-Basic.md * removed errors
1 parent 4562ae1 commit 39dea88

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
lines changed

documentation/basic/basic.md

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ int main(void)
174174

175175
## RT-Thread Program Memory Distribution
176176

177-
The general MCU contains storage space that includes: on-chip Flash and on-chip RAM, RAM is equivalent to memory, and Flash is equivalent to hard disk. The compiler classifies a program into several parts, which are stored in different memory areas of the MCU.
177+
The general MCU contains storage space that includes the on-chip Flash and the on-chip RAM. RAM is equivalent to memory, and Flash is comparable to a hard disk. The compiler classifies a program into several parts stored in different memory areas of the MCU.
178178

179-
After the Keil project is compiled, there will prompt information for occupied space by the corresponding program, as shown below:
179+
After the Keil project is compiled, there will be a prompt stating the occupied space by the corresponding program, for example:
180180

181181
```
182182
linking...
@@ -188,13 +188,10 @@ Build Time Elapsed: 00:00:07
188188

189189
The Program Size mentioned above contains the following sections:
190190

191-
1) Code: code segment, section of code that store the program;
192-
193-
2) RO-data: read-only data segment, stores the constants defined in the program;
194-
195-
3) RW-data: read and write data segment, stores global variables initialized to non-zero values;
196-
197-
4) ZI-data: 0 data segment, stores uninitialized global variables and initialized-to-0 variables;
191+
1. **Code**: Code Segment, section of code that stores the program
192+
2. **RO-data**: Read-Only data segment, stores the constants defined in the program
193+
3. **RW-data**: Read and Write data segment, stores global variables initialized to non-zero values
194+
4. **ZI-data**: 0 data segment, stores uninitialized global variables and initialized-to-0 variables
198195

199196
After compiling the project, there will be a generated .map file that describes the size and address of each function. The last few lines of the file also illustrate the relationship between the above fields:
200197

@@ -204,31 +201,29 @@ Total RW Size (RW Data + ZI Data) 2728 ( 2.66kB)
204201
Total ROM Size (Code + RO Data + RW Data) 53780 ( 52.52kB)
205202
```
206203

207-
1) RO Size contains Code and RO-data, indicating the size of the Flash occupied by the program;
204+
1. RO Size contains Code and RO-data, indicating the size of the Flash occupied by the program
205+
2. RW Size contains RW-data and ZI-data, indicating the size of the RAM occupied when operating
206+
3. ROM Size contains Code, RO Data, and RW Data. Indicating the size of the Flash occupied by the programming system;
208207

209-
2) RW Size contains RW-data and ZI-data, indicating the size of the RAM occupied when operating;
208+
Before the program runs, the file entity needs to be flashed into the STM32 Flash, usually a bin or hex file. The burned file is called an executable image file. The left part in the figure below shows the memory distribution after the executable image file is flashed into STM32 which includes the RO and RW segments. The RO segment stores data of Code and RO-data, and the RW segment holds the data of RW-data. Since ZI-data is 0, it is not included in the image file.
210209

211-
3) ROM Size contains Code, RO Data and RW Data, indicating the size of the Flash occupied by the programming system;
212-
213-
Before the program runs, the file entity need to be burned into STM32 Flash, usually it is bin or hex file. The burned file is called executable image file. The left figure, Figure 3-3, shows the memory distribution after the executable image file is burned to STM32 which includes two parts: the RO segment and the RW segment. The RO segment stores data of Code and RO-data and the RW segment holds the data of RW-data. Since ZI-data is 0, it is not included in the image file.
214-
215-
STM32 is launched from Flash by default after power-on. After launching, RW-data (initialized global variable) in RW segment is transferred to RAM, but RO segment is not transferred. This means execution code of CPU is read from Flash, the ZI segment is allocated according to the ZI address and size given by the compiler, and the RAM area is cleared.
210+
STM32 is launched from Flash by default after power-on. After launching, RW-data (initialized global variable) the RW segment is transferred to RAM, but the RO segment is not transferred. Meaning the execution code of the CPU is read from the Flash. The ZI segment is allocated according to the ZI address and size is given by the compiler, and the RAM area is cleared.
216211

217212
![RT-Thread Memory Distribution](figures/03Memory_distribution.png)
218213

219214
The dynamic memory heap is unused RAM space, and the memory blocks requested and released by the application come from this space.
220215

221-
As the following example:
216+
Like the following example:
222217

223218
```c
224219
rt_uint8_t* msg_ptr;
225220
msg_ptr = (rt_uint8_t*) rt_malloc (128);
226221
rt_memset(msg_ptr, 0, 128);
227222
```
228223
229-
The 128-byte memory space pointed to by the msg_ptr pointer in the code is in the dynamic memory heap space.
224+
The 128-byte memory space pointed by the `msg_ptr` pointer in the code is in the dynamic memory heap space.
230225
231-
Some global variables are stored in the RW segment and the ZI segment. The RW segment stores the global variable with the initial value (the global variable in the constant form is placed in the RO segment, which is a read-only property), and uninitialized global variable is stored in the ZI segment, as in the following example:
226+
Some global variables are stored in the RW segment and the ZI segment. The RW segment holds the global variable with the initial value (the global variable in the constant form is placed in the RO segment, which is a read-only property), and uninitialized global variable is stored in the ZI segment, as in the following example:
232227
233228
```c
234229
#include <rtthread.h>
@@ -242,11 +237,9 @@ void sensor_init()
242237
/* ... */
243238
}
244239
```
240+
The `sensor_value` is stored in the ZI segment and is automatically initialized to zero after system startup (some library functions provided by the user program or compiler are initialized to zero). The sensor_inited variable is stored in the RW segment, and the sensor_enable is stored in the RO segment.
245241

246-
The sensor_value is stored in the ZI segment and is automatically initialized to zero after system startup (some library functions provided by the user program or compiler are initialized to zero). The sensor_inited variable is stored in the RW segment, and the sensor_enable is stored in the RO segment.
247-
248-
RT-Thread Automatic Initialization Mechanism
249-
-----------------------
242+
## RT-Thread Automatic Initialization Mechanism
250243

251244
The automatic initialization mechanism means that the initialization function does not need to be called by explicit function. It only needs to be declared by macro definition at the function definition, and it will be executed during system startup.
252245

0 commit comments

Comments
 (0)