When learning MCU, C language, etc., the bus address, ROM, RAM, flash, special registers, etc. are only superficial understanding. Suddenly I want to summarize my understanding over the past few years.
RAM:
First of all, RAM is the operating memory that we ordinary people understand. The content stored in it will be gone after a power failure, and it will start again when it is clicked again.
So when we think about writing MCU programs, what things will disappear after power failure.
Naturally, it is our variable, but if it is only a variable that can be read and written, if it is a read-only variable, that is, the constant is stored in RAM space.
Then let's divide the variables that can be read and written again;
it may be different for different keyword modifications.
Commonly used static variables, global variables, and local variables are all in RAM, but RAM can be divided into three areas. Heap, stack, static storage area;
1. The heap is automatically allocated (malloc) and released by the programmer. The release here is very important, and the memory must be released after the use is completed (free)! ! !
2. The stack compiler automatically allocates our local variables and some formal parameters of the function in this area.
3. Static storage area: initialized global variables and static modified variables are stored here. Note that as long as it is static modified The variables are stored in the static storage area.
ROM/FLASH
Regarding ROM and flash, flash is a kind of ROM;
all constants, read-only variables, and codes are stored in flash.
Problems encountered by Master Hung:
Some time ago, I was using a domestically-made MCU, and the RAM space was relatively small. The big brother encountered a situation where the space was not enough when working on an encryption algorithm.
By calculating the RAM occupancy of the code, it should be enough, but the result is not enough.
It is because the original factory divides the flash into two areas, and the compiler cannot automatically allocate these two address pools. You need to add the keyword bank to modify, and the programmer will assign it by himself.
And because the compiler is not doing well, there are many more convenient ways of writing in the case of C language, but it involves the relationship between direct addressing and indirect addressing. It needs to be more verbose. Write separately, and the efficiency will be more high. I was impressed by the fact that we should not pass parameters multiple times, because they are restricted by their stack levels.
So we have to refer to some indicative routines they gave to write. Improve efficiency and rational use.
Domestic MCU or chips still need to refuel. . . .