Memory management

The storage and memory system of microcontrollers consists out of multiple components. There is a section of read-only-memory (ROM) that is only written to once when the chip is programmed, but which cannot normally be altered by the MCU itself, as we saw in the previous section.

The MCU may also have a bit of persistent storage, in the form of EEPROM or equivalent. Finally, there are CPU registers and the random-access memory (RAM). This results in the following exemplary memory layout:

The use of a modified Harvard architecture (split program and data memory at some architectural level, generally with the data buses) is common with MCUs. With the AVR architecture, for example, the program memory is found in the ROM, which for the ATmega2560 is connected using its own bus with the CPU core, as one can seen on the block diagram for this MCU, which we looked at previously in Chapter 1, What Are Embedded Systems?

A major advantage of having separate buses for these memory spaces is that one can address each of them separately, which makes better use of the limited addressing space available to an 8-bit processor (1 and 2 byte wide address). It also allows for concurrent accesses while the CPU is busy with the other memory space, further optimizing the available resources.

For the data memory in the SRAM, we are then free to use it as we want. Here, we do need at least a stack to be able to run a program. Depending on how much SRAM is left in the MCU, we can then also add a heap. Applications of moderate complexity can be realized with only stack and statically allocated memory though, not involving higher-level language features that produce code with heap allocations.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.33.107