Electrical – How does a CPU interface with GPIO pins

cpufpgagpioxilinx

I am trying to implement a simple mips1 clone in Verilog at the moment, works all fine in simulators but I also want to run it on an actual FPGA.

Basically I would like to send/receive characters to the running CPU via UART, also I would like to read values from buttons/switches on the FPGA. Now I'm wondering what is the best way to interface GPIO pins and UART.

The only idea I could come up with is to just have separate chips running on the FPGA, directly connected to the GPIO pins and to the UART interface. These chips would just read from/write to specific memory locations and do their job based on that data.

I could also imagine that I will need some kind of interrupt controller for this so the CPU could run some snippet of code when a button is pressed. But I can only imagine this to be useful for input from something, not when I want to make an LED light up.

How does a microcontroller or a Raspberry get an LED to light up?

Best Answer

What you want is a "memory mapped peripheral". You add some logic to the address bus so that, if the address matches a specific pattern, instead of read/write being routed to the memory they are routed to a peripheral.

The peripheral then contains one or more registers, which can be directly connected to pieces of the peripheral. So for example when reading from address 0x1234 you might read directly from the GPIO.

Interrupts are useful but not essential.

You might find it convenient to implement "AXI" or "AMBA" bus protocols, especially if you want to connect to pre-existing IP blocks for peripherals.

(I learned this from Micro Interfacing Circuits by RA Penfold, but that's an extremely old book)