Abstract: IoT embedded chip, storage is one of the data cores, this is relatively unfamiliar to programmers and design people. Today, let’s talk about the memory structure in MCU.

This article is shared from Huawei Cloud Community " Talking about Embedded System Memory ", author: o0龙龙0o.

Preface

In the embedded chip of the Internet of Things, storage is one of the cores of data. This is relatively unfamiliar to programmers and designers. Today, let’s talk about the memory structure in MCU.

1. Memory format

MCU memory is divided into volatile memory, non-volatile memory, Volatile memory and Non-volatile memory in terms of storage characteristics.

Random Access Memory: 1. DRAM (Dynamic Random Access Memory), 2. SRAM (Static Random Access Memory) Generally, MCU memory is mostly composed of SRAM, mainly because of its fast speed and simple structure.

(Non-volatile memory) means that even if the power supply is interrupted, the data stored in the memory will not disappear, and the data in the memory can be read after the power is re-powered. The main types are as follows:

 Read only memory (ROM)
 Programmable read-only memory (PROM)
 Erasable programmable read-only memory (EPROM)
 Electronically erasable rewritable read-only memory (EEPROM)
 Flash ROM
 Magnetic storage, hard disk, floppy disk, tape, 3D XPoint, solid state hard disk, optical storage, optical disk

Among them, PROM and Flash are generally used as MCU data program memory, but there are also many MCUs with embedded EEPROM, which is convenient for users to write temporary data.

Erasable Programmable Read Only Memory

It is a computer memory chip that can retain data even after power is off. It is a group of floating gate transistors that are programmed separately by an electronic device that provides a higher voltage than the voltage commonly used in electronic circuits. Once the data is written, EPROM can only be erased with strong ultraviolet radiation. The 24C chip we often say is this kind of memory chip. It can erase shoe data according to Byte, which is much better than flash erased according to sector.

2. Data storage

Memory data can generally be divided into heap, stack, program code, data code, global variable code

Generally distributed as follows:
image.png

The starting address of the heap memory (also called the memory pool) and the total size of the heap area are LiteOS' interpretation of the program heap, which is the size of the memory occupied by a section of AP program. These sizes are composed of a linked list or a binary tree and are used for the memory of the program segment. Of occupation.

Stack-Stack (:stack), also known as stack or stack, is an abstract data type in computer science. It is only allowed to add data ( : Push) and remove data (: pop) operations. Therefore, it operates according to the principle of LIFO (Last In First Out). In the MCU, the system LiteOS allocates the remaining memory for the use of the program's local variables and the data malloc to generate newly allocated memory.

Bss segment: (bss segment) usually refers to a memory area used to store uninitialized global variables in the program. bss is the abbreviation of English Block Started by Symbol. The bss segment belongs to static memory allocation.

Data segment: The data segment usually refers to a memory area used to store initialized global variables in the program. The data segment belongs to static memory allocation.

Text segment: Code segment/text segment usually refers to a memory area used to store program execution code, generally stored in ROM. The size of this area is determined before the program runs, and the memory area is usually read-only (some architectures also allow the code segment to be writable, that is, the program is allowed to be modified). In the code segment, there may also be some read-only constant variables, such as string constants.

We rarely design these designs when programming, and they are often done automatically by the system LiteOS or by a compiler.

3. How to use the program to design memory?

Macro command:

#pragma alloc_text( "textsection", function1, ... )

Name the code segment where the specially defined function resides. The pragma must appear between the function specifier and the function definition.

#pragma code_seg( ["section-name"[,"section-class"] ] )

Specify the code segment of the allocation function. The code_seg pragma specifies the default segment for the function. You can also specify an optional class name like a section name. Using #pragma code_seg without a segment name string will restore the state assigned to the start of compilation.

#pragma const_seg( "MY_DATA" )

Cause the constant data after the #pragma statement to be allocated in a section called MY_DATA.

#pragma const_seg( ["section-name"[, "section-class"] ] )

Specify the default segment used for constant data. The data_seg pragma has the same effect except that it can work on all data. You can use this pragma to save your constant data in a read-only section.

Click to follow, and learn about Huawei Cloud's fresh technology for the first time~


华为云开发者联盟
1.4k 声望1.8k 粉丝

生于云,长于云,让开发者成为决定性力量