WF_XXX Internal Pin Aliases (and @MAP_IO Help)

Intro

First, I want to clarify that there are two sets of pins when discussing the main FPGA device.

  1. EXTERNAL The physical pins that run along the perimeter of the FPGA device’s PCB.
  2. INTERNAL The small pins that surround the FPGA QFN chip itself.

The synthesis engine expects that all pins referenced are INTERNAL, as in, they are part of the FPGA chip itself. It has no knowledge of the outside world (the rest of the PCB).

However, for our use cases, it’s nice to be able to look at the FPGA device and say "I want to blink an LED using pin 1" and see that it toggles the pin at that physical location (instead of merely pin 1 on the FPGA chip).

When using @MAP_IO, our backend replaces the EXTERNAL pins with their corresponding INTERNAL pin. I’ll will post the full lookup table at the end of this post. You won’t need this table unless you decide to write your own .pcf files when using IceStorm or Lattice’s iCECube.

Automated Aliases

There are certain FPGA chip pins that are wired directly to certain peripherals. For example, the LED is always wired to FPGA pin 31.

If you are using an external toolchain (IceStorm or iCECube), you might want to set these in your pinmap.pcf.

Name         FPGA pin
---------------------
WF_LED       31
WF_CLK       35
WF_BUTTON    42
WF_NEO       32
WF_CPU1      11
WF_CPU2      12
WF_CPU3      13
WF_CPU4      10

@MAP_IO Usage

The syntax is // @MAP_IO <name> <pin_number>, where pin_number is denoted by the silk-screen EXTERNAL pin number on the main FPGA board.

For example,

// @MAP_IO EXTERNAL_LED 5
module top(output wire EXTERNAL_LED);
    assign EXTERNAL_LED = 1;
endmodule

EXTERNAL to INTERNAL Pin Lookup

# Given an EXTERNAL pin number, return the INTERNAL pin
# number that is wired to it.
def internal_pin_map(external_pin)
    map = []
    map[0]  = 17

    map[1]  = 16
    map[2]  = 14
    map[3]  = 23
    map[4]  = 20
    map[5]  = 19
    map[6]  = 18
    map[7]  = 21
    map[8]  = 25
    map[9]  = 26
    map[10] = 28
    map[11] = 27
    map[12] = 34
    map[13] = 35
    map[14] = 36

    map[15] = 37
    map[16] = 40
    map[17] = 44
    map[18] = 46
    map[19] = 47
    map[20] = 45
    map[21] = 48
    map[22] = 2

    map[23] = 3
    map[24] = 4
    map[25] = 9
    map[26] = 6
    map[27] = 43
    map[28] = 41
    map[29] = 39
    map[30] = 38
    map[31] = 15

    return map[external_pin]
end