Some microcontrollers have a memory expansion function in addition to their internal ROM or RAM.
The following figure shows the relationship between the internal and external addresses.
Depending on the device and/or settings, only part of the address information is output externally.
The following describes a case where the CPU handles a 16-bit address space
and the internal ROM consists of 24KB, as shown in the CPU memory map above.
In this case, the addresses from 6000H can be used as the external expansion area.
For simplification purposes, the external expansion area is the 32KB area from 6000H to DFFFH.
(1) Case when 12-bit address output is specified (4 KB expansion)
In this case, the memory that can be expanded physically is 2
12 = 4KB.
When the CPU accesses the address 6000H,
the address 000H corresponding to the lower 12 bits of 6000H is output.
When 7000H or 8000H, 9000H are accessed, the lower 12 bits similarly become 000H.
This means that same physical address is accessed and the image of same address appears every 4KB.
Memory map during 4KB expansion :
(2) When 14-bit address output (16 KB expansion) is specified
In this case, the memory that can be physically expanded is 2
14 = 16KB.
When the CPU accesses the address 6000H, the address 2000H corresponding to the lower 14 bits is output.
Similarly, 3000H is output at 7000H, 0000H at 8000H, 1000H at 9000H, 2000H at A000H, and 3000H at B000H.
Therefore, in the case of use from 6000H, the relationship between internal addresses and the row of external addresses is inverted.
This is no problem when RAM is expanded, but caution is required when connecting PROM or flash memory.
In order to avoid this, using only the addresses from 8000H is recommended.
Moreover, since the same external address is output at multiple addresses,
when RAM has been expanded,
it is necessary to manage so that the same physical address is not accessed via different logical addresses.
Memory map during 16KB expansion :
(3) When 16-bit address output (64 KB expansion) is specified
In this case, a 64 KB space can be used externally.
However, since the CPU itself can handle only a 64 KB space,
the memory that can be expanded externally is only the area corresponding to 64 KB minus the internal memory capacity of the CPU
(depending on the device, the memory that can be externally expanded may be even smaller).
At this time, the external addresses and internal addresses are the same value.
Therefore, the part that overlaps the internal ROM (in this case, 0 to 5FFFH) may be wasted.
Memory map during 64KB expansion :
Related FAQ :
How can I allocate variables and code to other than normal memory?