Beaglebone GPMC Framebuffer Project with FPGA

Overview

This project implements a Framebuffer on an FPGA board (GeminiBoard) connected to Beaglebone via GPMC (General-Purpose Memory Controller). The Beaglebone sends pixel data to the FPGA, which stores it in the on-board SDRAM. The FPGA then generates HDMI signals to output the display onto a monitor.

graph TD subgraph "Beaglebone" B1[GPMC] end subgraph "GeminiBoard" subgraph "FPGA" F1[GPMC Slave] F2[HDMI TX] end G1[SDRAM] end B1 -- Pixel Data --> F1 F1 -- Write --> G1 F2 -- Read --> G1 F2 --> Monitor

In operation, Beaglebone writes image data via GPMC to the FPGA, which acts as a Slave device. The FPGA buffers the data in a FIFO and writes it to SDRAM. Simultaneously, the HDMI controller in the FPGA continuously reads data from the SDRAM to generate video signals for the HDMI monitor output.


Development Steps

1. FPGA Design

The FPGA logic has three main responsibilities: GPMC interfacing, SDRAM management, and HDMI video signal generation.

graph TD subgraph "FPGA" F1[GPMC controller] F1_1[write FIFO] F2[SDRAM controller] F2_1[read FIFO] F3[HDMI controller] end S1[SDRAM] GPMC -- pixel data --> F1 F1 --> F1_1 --> F2 -- write pixel data --> S1 S1 -- read pixel data (@30Hz) --> F2 --> F2_1 --> F3 --> Monitor
  • GPMC Controller: Acts as a Slave device to receive pixel data from Beaglebone.
  • FIFO Buffers: A Write FIFO is used to buffer incoming pixel data line-by-line (line buffer) before writing to SDRAM to optimize memory access efficiency. A Read FIFO is used to buffer data before feeding it to the HDMI controller.
  • SDRAM Controller: Manages reading and writing data to external SDRAM, which serves as the Framebuffer memory space.
  • HDMI Controller: Continuously reads Framebuffer data from SDRAM at the desired refresh rate (e.g., 30Hz) and generates TMDS signals to output to the HDMI monitor.

VHDL Modules

The FPGA project structure is divided into the following VHDL files:

  • PRJ_TOP.vhd: Top-level file that connects all modules together.
  • GPMC_IF.vhd: GPMC slave interface for communicating with Beaglebone.
  • FRAME_BUF.vhd: Main Framebuffer controller, managing data flow from GPMC to SDRAM, and from SDRAM to the HDMI controller.
  • vga_syncgen.vhd: Generates basic VGA timing signals (HSYNC, VSYNC, DE) based on the target display resolution.
  • tmds_encoder.vhd: Encodes 8-bit color data into 10-bit TMDS (Transition-Minimized Differential Signaling) according to the DVI/HDMI standard.
  • dvi_tx_pdiff.vhd: Main DVI transmitter module, which receives image data and timing signals, encodes them using tmds_encoder, and serializes the data for transmission.
  • pdiff_transmitter.vhd: Sends serialized data out as pseudo-differential signals, utilizing the Double Data Rate I/O pin capabilities of the FPGA.

Example code from FRAME_BUF.vhd showing the SDRAM read and write interface via the Avalon Bus:

u0 : component MyQsys
    port map (
        -- Avalon Master signals for writing/reading SDRAM
        AvalonSimpleMaster_0_avm_m0_address     => AvalonSimpleMaster_0_avm_m0_address,
        AvalonSimpleMaster_0_avm_m0_read        => AvalonSimpleMaster_0_avm_m0_read,
        AvalonSimpleMaster_0_avm_m0_readdata    => AvalonSimpleMaster_0_avm_m0_readdata,
        AvalonSimpleMaster_0_avm_m0_readdatavalid => AvalonSimpleMaster_0_avm_m0_readdatavalid,
        AvalonSimpleMaster_0_avm_m0_write       => AvalonSimpleMaster_0_avm_m0_write,
        AvalonSimpleMaster_0_avm_m0_writedata   => AvalonSimpleMaster_0_avm_m0_writedata,
        AvalonSimpleMaster_0_avm_m0_waitrequest => AvalonSimpleMaster_0_avm_m0_waitrequest,
        -- SDRAM physical interface
        new_sdram_controller_0_wire_addr        => SDRAM_ADDR(11 downto 0),
        -- ... other SDRAM signals
        clk_clk                                 => CLK,
        reset_reset_n                           => RST_L
    );

-- Process to handle WRITE requests to SDRAM (from GPMC FIFO)
process( CLK , RST_L )
begin
    if ( RST_L = '0' ) then
        AvalonSimpleMaster_0_avm_m0_write   <=  '0';
    elsif ( CLK'event and CLK = '1' ) then
        -- A write is requested when data is available from GPMC
        if(wAvalonWrReq = '1')then 
            AvalonSimpleMaster_0_avm_m0_write   <=  '1';
        -- De-assert write when transaction is accepted
        elsif(AvalonSimpleMaster_0_avm_m0_waitrequest = '0')then
            AvalonSimpleMaster_0_avm_m0_write   <=  '0';
        end if;
    end if;
end process;

-- Process to handle READ requests from SDRAM (for VGA output)
process( CLK , RST_L )
begin
    if ( RST_L = '0' ) then
        AvalonSimpleMaster_0_avm_m0_read    <=  '0';
    elsif ( CLK'event and CLK = '1' ) then
        -- Stop reading at the end of a line
        if(wRdCnt = k480p_COL_NUM-1)then
            AvalonSimpleMaster_0_avm_m0_read    <=  '0';
        -- Start reading when triggered by VGA timing (start of a line)
        elsif(wpAvalonRdReq = '1')then
            AvalonSimpleMaster_0_avm_m0_read    <=  '1';
        end if;
    end if;
end process;

2. Software Development

The software running on Beaglebone's Linux must be configured to communicate with the FPGA. This consists of two main parts: GPMC pin configuration and Framebuffer driver implementation.

2.1 GPMC Pin Configuration

The pins of the AM335x processor can be configured in various ways. We need to configure Pin Multiplexing to enable GPMC functionality on the correct pins. This is typically done in the kernel's Board Support Package (BSP) file, which in this case is board-am335xevm.c.

The code below shows the pinmux configuration for the GPMC signals connected to the FPGA. This configures the data pins (gpmc_ad0 to gpmc_ad15) and various control signal pins (gpmc_csn1, gpmc_advn_ale, etc.) to operate in GPMC mode.

/* From D:\hong\obsidian\hong\Myblog\board-am335xevm.c */

static struct pinmux_config fpga_gpmc_pin_mux[] = {
    {"gpmc_ad0.gpmc_ad0",     OMAP_MUX_MODE0 | AM33XX_PIN_INPUT_PULLUP},
    {"gpmc_ad1.gpmc_ad1",     OMAP_MUX_MODE0 | AM33XX_PIN_INPUT_PULLUP},
    {"gpmc_ad2.gpmc_ad2",     OMAP_MUX_MODE0 | AM33XX_PIN_INPUT_PULLUP},
    {"gpmc_ad3.gpmc_ad3",     OMAP_MUX_MODE0 | AM33XX_PIN_INPUT_PULLUP},
    {"gpmc_ad4.gpmc_ad4",     OMAP_MUX_MODE0 | AM33XX_PIN_INPUT_PULLUP},
    {"gpmc_ad5.gpmc_ad5",     OMAP_MUX_MODE0 | AM33XX_PIN_INPUT_PULLUP},
    {"gpmc_ad6.gpmc_ad6",     OMAP_MUX_MODE0 | AM33XX_PIN_INPUT_PULLUP},
    {"gpmc_ad7.gpmc_ad7",     OMAP_MUX_MODE0 | AM33XX_PIN_INPUT_PULLUP},
    {"gpmc_ad8.gpmc_ad8",     OMAP_MUX_MODE0 | AM33XX_PIN_INPUT_PULLUP},
    {"gpmc_ad9.gpmc_ad9",     OMAP_MUX_MODE0 | AM33XX_PIN_INPUT_PULLUP},
    {"gpmc_ad10.gpmc_ad10",   OMAP_MUX_MODE0 | AM33XX_PIN_INPUT_PULLUP},
    {"gpmc_ad11.gpmc_ad11",   OMAP_MUX_MODE0 | AM33XX_PIN_INPUT_PULLUP},
    {"gpmc_ad12.gpmc_ad12",   OMAP_MUX_MODE0 | AM33XX_PIN_INPUT_PULLUP},
    {"gpmc_ad13.gpmc_ad13",   OMAP_MUX_MODE0 | AM33XX_PIN_INPUT_PULLUP},
    {"gpmc_ad14.gpmc_ad14",   OMAP_MUX_MODE0 | AM33XX_PIN_INPUT_PULLUP},
    {"gpmc_ad15.gpmc_ad15",   OMAP_MUX_MODE0 | AM33XX_PIN_INPUT_PULLUP},
    {"gpmc_csn1.gpmc_csn1",   OMAP_MUX_MODE0 | AM33XX_PULL_DISA},//
    {"gpmc_advn_ale.gpmc_advn_ale",  OMAP_MUX_MODE0 | AM33XX_PULL_DISA},//
    {"gpmc_oen_ren.gpmc_oen_ren",    OMAP_MUX_MODE0 | AM33XX_PULL_DISA},//
    {"gpmc_wen.gpmc_wen",     OMAP_MUX_MODE0 | AM33XX_PULL_DISA},//
    {"gpmc_ben0_cle.gpmc_ben0_cle",  OMAP_MUX_MODE0 | AM33XX_PULL_DISA},//
    {"gpmc_ben1.gpmc_ben1", OMAP_MUX_MODE0 | AM33XX_PULL_DISA},
    {"gpmc_clk.gpmc_clk",    OMAP_MUX_MODE0 | AM33XX_PIN_INPUT},//
    {NULL, 0},
};

2.2 Framebuffer Driver (Simple Framebuffer Driver)

We will create a Framebuffer driver (gpmcfb) for Linux so that the OS and user applications can use our custom Framebuffer via standard device files (/dev/fbX). This allows applications to draw on the screen without needing to know the low-level hardware details.

The header file gpmcfb.h defines the main parameters of the driver:

/* From D:\hong\obsidian\hong\Myblog\gpmcfb.h */

#define DRVNAME     "gpmcfb"
#define WIDTH       720
#define HEIGHT      480
#define BPP     16

struct gpmcfb_par {
    struct device *dev;
    struct fb_info *info;
    unsigned long gpmc_adr;
};
  • DRVNAME: Name of the driver
  • WIDTH, HEIGHT, BPP: Specifies the screen resolution (720x480) and color depth (16 bits per pixel).
  • gpmcfb_par: Structure for storing device-specific information, including the GPMC address (gpmc_adr) mapped for the Framebuffer.

The driver needs to implement key file_operations, most importantly write, which receives data from user-space and writes it to the hardware. For other operations (currently only fb_write is implemented), the gpmcfb_write function takes the received pixel data and writes it directly to the GPMC address mapped to the FPGA. The FPGA then forwards the data to SDRAM.

/* From gpmcfb.c (conceptual) */
static struct fb_ops gpmcfb_ops = {
    .owner      = THIS_MODULE,
    //.fb_read  = fb_sys_read,
    .fb_write   = gpmcfb_write,
    .fb_fillrect    = cfb_fillrect,
    .fb_copyarea    = cfb_copyarea,
    .fb_imageblit   = cfb_imageblit,
};

Note

The example code for this project can be downloaded at: https://github.com/wichayen/geminiboard/tree/main/FPGA/BEAGLEBONE_HDMI_FB_8bit