↓ Skip to main content

Debugging the Local Bus Interface Between FPGA and Embedded CPU

Debugging the Local Bus Interface Between FPGA and Embedded CPU

The Local Bus, often referred to as the CPU bus, varies depending on the address line order. Historically, these are categorized into Motorola and Intel architectures. While the old CS51 microcontroller is a classic example of the Intel architecture, the PowerPC (PPC) architecture we frequently use today is derived from the Motorola 60X bus (which supports 64, 32, 16, and 8-bit widths).

In this article, I will walk through the nuances of using a PowerPC CPU to read/write FPGA internal registers or RAM, as well as handling interrupt responses.

🏗️ Hardware Architecture and Timing
#

In earlier projects, such as HINOC1.0, we used an Intel XScale PXA270 (ARM CPU) connected to an FPGA. The interface timing used there was identical to the Local Bus timing used for external asynchronous SRAM. This allowed the HINOC chip to function as an external peripheral to the ARM CPU, with configurable register or RAM access space.

The bus includes address lines, chip selects (CS), and read/write signals. A critical detail is that “asynchronous” means the CPU interface bus and the FPGA interface are not synchronized. The CPU does not send a clock signal; instead, the FPGA must sample the address and data signals using its own internal clock.

When the CPU reads from the FPGA, it provides the address and read control signal, then waits for the $t_{AA}$ (Access Time) before fetching valid data. This $t_{AA}$ value can be adjusted via registers in the PXA270.

From the FPGA side, you can see how slow these operations are. A single read/write operation can span dozens of FPGA clock cycles. Modern SoC buses like AXI are much more efficient because they support burst modes similar to DMA. However, in specialized fields like aerospace, these older Local Bus timings remain popular because they are simple, reliable, and stable.

🛠️ Debugging Environment
#

For this setup, we used the following hardware:

  • FPGA Board: AX7103
  • CPU Board: p2020
  • OS: VxWorks

Since the p2020 Local Bus 50-pin header is not directly connected to the FPGA board, we had to create a custom debugging environment. We mapped the critical Local Bus pins (37 pins: 16 addr + 16 data + 3 CS + 1 OEN + 1 WEN) and interrupt signals to the EX_IO1 and EX_IO2 headers on the AX7103.

Note: Ensure that both boards share the same voltage levels and a common ground before connecting via jumper wires.

📊 Data Read/Write Operations
#

The Local Bus is relatively straightforward: you map the CPU memory address to the hardware register/RAM address and manage the timing of the read/write enable and chip select signals.

However, signal behavior varies by processor. For example:

  • BM3803: Address and data lines are not multiplexed; it uses a 32-bit data width.
  • p2020: Data lines (LAD) are multiplexed. It uses the LALE signal to latch the high 11 bits of the address. For 16-bit addresses, LALE might not be required. It operates with a 16-bit data width.

During our initial tests, we identified that the p2020 uses CS0 and CS1 for internal NAND and NOR flash. It outputs three chip select signals (CS2, CS3, and CS4), meaning it can support up to 8 Local Bus peripherals. We discovered that the driver was originally configured to use CS4 but blocked CS2. By switching to CS2, we ensured that every read/write operation triggered the correct cpu_csn[2:0] == 3'b110 state.

🐞 The Boot Sequence Bug
#

The most significant hurdle occurred during the boot process. When we connected the data lines, the CPU failed to start. We initially suspected the cpu_oen (Output Enable) signal was interfering with the CPU’s startup.

Upon inspecting the p2020 datasheet, we found that the LGPL2 signal has dual definitions:

  1. Local Bus read enable (cpu_oen).
  2. A configuration signal for the e500 core PLL clock duty cycle.

We suspected that the FPGA’s cpu_oen level was affecting the CPU during the early boot phase. We tried setting the cpu_oen to a high-impedance state for the first 10 seconds of boot, but the CPU still wouldn’t start.

After isolating the signals one by one, we found the culprit: when the CPU reads from its internal flash during boot, it pulls cpu_oen low. Because our FPGA was connected, it would output a default value of 16'h0 onto the data bus. This effectively overrode the actual data being read from the flash.

We tried a “quick fix” by keeping the data lines in a high-impedance state for 20 seconds, but that felt like a band-aid. The proper solution was to add a logic constraint in the FPGA to ensure data is only driven when the specific chip select (CS2) is active.

Corrected FPGA Logic:

// Only output data if OEN is low AND CS2 is active. 
// Otherwise, keep the bus in high-impedance (Z).
assign cpu_data  =((cpu_oen==1'b0) && (cpu_csn[2]==1'b0)) ? cpu_rdata : 16'bz;
assign cpu_wdata = cpu_data;

This change allowed the CPU to boot successfully because the FPGA would no longer interfere with the flash memory reads during the initial boot sequence. For more information on managing hardware peripherals in real-time environments, you can refer to VxWorks documentation.

⚡ Hard Interrupts
#

The p2020 processor handles both internal and external interrupts. We utilized external interrupt 1 (irq1). In VxWorks, external interrupt vectors start at 0, so irq1 maps to vector 1.

We registered the interrupt in the BSP and bound it to the device list. However, we encountered a discrepancy: the p2022 datasheet indicated that the irq signal was active-high, but our board tests showed it was active-low.

When the driver receives an interrupt, it must clear the hardwired signal. We defined register 0x110 as the interrupt register. To reset the signal to a high state, the driver writes a 1 to bit [15] and then a 0.

Interrupt Timing Logic:

// Ensure the FPGA only drives data when the specific CS is active
assign cpu_data  =((cpu_oen==1'b0) && (cpu_csn[2]==1'b0)) ? cpu_rdata : 16'bz;
assign cpu_wdata = cpu_data;

Related