Electrical – Memory-mapped IO vs Port-mapped IO in microcontrollers

addressingmemorymicrocontrollermicroprocessorperipheral

I've been reading about external peripheral mapping to microcontrollers.

I understand that memory-mapped IO means that the same address space in the microcontroller can be used for internal memory and also to map external peripherals. Therefore the same instructions we normally use can be used to communicate with external devices.

Port-mapped IO means that there is a certain address space especially used for mapping external peripherals. Sometimes specific instructions need to be used to accesss the peripherals via this address space.

Obviously we can see the advantages of memory-mapped IO here. However, I read from the link below that

"The disadvantage of memory-mapped IO method is that the entire address bus must be fully decoded for every device. For example, a machine with a 32-bit address bus would require logic gates to resolve the state of all 32 address lines to properly decode the specific address of any device. This increases the cost of adding hardware to the machine."

Can someone please explain this as I can't understand this. Why does the microcontroller need to decode the 32-bit address bus like this?

https://www.bogotobogo.com/Embedded/memory_mapped_io_vs_port_mapped_isolated_io.php

Best Answer

The statement as it stand is false or least incomplete.

Normally an I/O instruction activates some special pins on the controller to distinguish the I/O operation from a memory operation.

The statement above seems to assume that the I/O instruction then uses only part of the 32-bit address bus and thus less address decoding is needed. Without mentioning this the statement is, by itself false.

Note that, especially in the early days of the micro-controllers, whole sections of the address map would be mapped onto a few peripherals by using a few address lines to select all peripherals. e.g. address lines 15 and 14 would select one of three peripherals leaving 16K as address space.

This technique is still widely used.
These days a 32-bit processor has 2G address space but many micro-controllers have less then 1M of memory (in Flash and RAM) requiring only 20 address lines. This leaves many spare address lines for this type of sparse decoding.