Skip to content

Commit c7e842c

Browse files
author
Amanda Butler
authored
Merge pull request #308 from bulislaw/runtime_memory
Runtime memory page update
2 parents 52987c3 + 12f5c02 commit c7e842c

File tree

1 file changed

+73
-44
lines changed

1 file changed

+73
-44
lines changed

docs/reference/runtime/Memory.md

Lines changed: 73 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,80 @@
11
## Memory
22

3-
This is a basic overview of the memory model.
3+
This is a basic overview of the memory model in Mbed OS.
44

5-
Each thread of execution in the RTOS has a separate stack. When you use the RTOS, before explicitly initializing any additional thread, you will have four separate stacks:
5+
```
6+
+---------------------+ Last address of RAM
7+
| Scheduler/ISR stack |
8+
+---------------------+
9+
| ^ |
10+
| | |
11+
| |
12+
| Heap cont. |
13+
|---------------------|
14+
| User thread n stack |
15+
|---------------------|
16+
| User thread 2 stack |
17+
|---------------------|
18+
| User thread 1 stack |
19+
|---------------------|
20+
| ^ |
21+
| | |
22+
| |
23+
| Heap |
24+
+---------------------+
25+
| |
26+
| ZI: Global data |
27+
| |
28+
+---------------------+
29+
| ZI: Idle stack |
30+
+---------------------+
31+
| ZI: Timer stack |
32+
+---------------------+
33+
| ZI: Main stack |
34+
+---------------------+
35+
| |
36+
| ZI: Global data |
37+
| |
38+
+---------------------+
39+
| RW: Vector table |
40+
+=====================+ First address of RAM
41+
| | Last address of flash
42+
| |
43+
| Application |
44+
| |
45+
| |
46+
+---------------------+
47+
| |
48+
| Optional bootloader |
49+
| |
50+
+---------------------+
51+
| RO: Vector table |
52+
+---------------------+ First address of flash
653
7-
* The stack of the main thread (executing the main function).
8-
* The idle thread executed each time all the other threads are waiting for external or scheduled events. This is particularly useful for implementing energy saving strategies (like sleep).
9-
* The timer thread that executes all the time-scheduled tasks (periodic and nonperiodic).
10-
* The stack of OS scheduler itself (also used by the ISRs).
54+
```
1155

12-
Stack checking is turned on for all threads, and the kernel will error if an overflow condition is detected.
56+
There are at least two kinds of memory in the system: flash and RAM.
1357

14-
```
15-
+-------------------+ Last Address of RAM
16-
| Scheduler Stack |
17-
+-------------------+
18-
| | RAM
19-
| |
20-
| ^ |
21-
| | |
22-
| Heap Cont.. |
23-
+-------------------+
24-
| app thread n |
25-
|-------------------|
26-
| app thread 2 |
27-
|-------------------|
28-
| app thread 1 |
29-
|-------------------|
30-
| ^ |
31-
| | |
32-
| Heap |
33-
+-------------------+
34-
| ZI |
35-
+-------------------+
36-
| ZI: OS drv stack |
37-
+-------------------+
38-
| ZI: app thread 3 |
39-
+-------------------+
40-
| ZI: Idle Stack |
41-
+-------------------+
42-
| ZI: Timer Stack |
43-
+-------------------+
44-
| ZI: Main Stack |
45-
+-------------------+
46-
| RW |
47-
+===================+ First Address of RAM
48-
| |
49-
| | Flash
58+
### RAM
5059

51-
```
60+
Inside RAM, we can distinguish two logical types: static and dynamic memory. The system uses each of them in different ways:
61+
62+
- Static:
63+
- Vector table (read/write).
64+
- Global data.
65+
- Static data.
66+
- Stacks for default threads (main, timer, idle, scheduler/ISR).
67+
- Dynamic:
68+
- Heap (dynamic data).
69+
- Stacks for user threads. Mbed OS will dynamically allocate memory on heap for user thread's stacks.
70+
71+
Stack checking is turned on for all threads, and the kernel errors if it detects an overflow condition.
72+
73+
### Flash
74+
75+
Flash is a read only memory (ROM) that contains:
76+
77+
- Vector table (read only).
78+
- Application code.
79+
- Application data.
80+
- Optional bootloader.

0 commit comments

Comments
 (0)