Home

Awesome

AXI-4 RAM Tester

Github: https://github.com/ultraembedded/core_ram_tester

This core can be used to test read/write performance of a 32-bit AXI-4 memory.
It can also be used to validate read data.
Accesses are performed as pipelined AXI-4 burst operations.

Example Usage

##################################################################
# run_ram_test: Write pattern to RAM array
##################################################################
def run_ram_test(bus_if, base, size, pattern, clock_ns, burst_len=32):

    # Configure
    bus_if.write32(RAM_TEST_BASE,  base)
    bus_if.write32(RAM_TEST_END,   base + size)

    if pattern != None:
        bus_if.write32(RAM_TEST_WRITE, pattern)

    # Burst length
    cfg = ((burst_len/4)-1) << RAM_TEST_CFG_BURST_LEN_SHIFT

    # Type
    if pattern != None:
        cfg |= (1 << RAM_TEST_CFG_USER_SHIFT)
    else:
        cfg |= (1 << RAM_TEST_CFG_INCR_SHIFT)

    if pattern != None:
        print "# Write RAM to 0x%08x" % pattern
    else:
        print "# Write RAM to INCR"

    bus_if.write32(RAM_TEST_CFG, cfg)
    while True:
        status = bus_if.read32(RAM_TEST_STS)
        if (status & (1 << RAM_TEST_STS_BUSY_SHIFT)) == 0:
            break

    cycles   = bus_if.read32(RAM_TEST_TIME)
    time_ns  = clock_ns * cycles
    bw       = (1000000000.0 / time_ns) * size
    print "|- %d bytes written in %d cycles (%dMB/s)" % (size, cycles, bw / 1000000)

    print "# Read RAM and compare"
    bus_if.write32(RAM_TEST_CFG, cfg | (1 << RAM_TEST_CFG_READ_SHIFT))
    while True:
        status = bus_if.read32(RAM_TEST_STS)
        if (status & (1 << RAM_TEST_STS_BUSY_SHIFT)) == 0:
            break

    errors   = bus_if.read32(RAM_TEST_ERRORS)
    cycles   = bus_if.read32(RAM_TEST_TIME)
    time_ns  = clock_ns * cycles
    bw       = (1000000000.0 / time_ns) * size
    print "|- %d bytes read in %d cycles (%dMB/s)" % (size, cycles, bw / 1000000)
    print "|- Errors: %d" % errors
    if errors > 0:
        print "ERROR: RAM read errors encountered"
        sys.exit(1)

##################################################################
# Test sequence
##################################################################
    clock_ns  = 20
    burst_len = 64
    print "# User clock: %fns (%fMHz)" % (clock_ns, 1000/clock_ns)
    print "# Burst Length: %d bytes" % (burst_len)

    base = 0x80000000
    size = (1 * 1024 * 1024)

    run_ram_test(bus_if, base, size, 0x00000000, clock_ns, burst_len)
    run_ram_test(bus_if, base, size, 0xFFFFFFFF, clock_ns, burst_len)
    run_ram_test(bus_if, base, size, 0x5555aaaa, clock_ns, burst_len)
    run_ram_test(bus_if, base, size, None,       clock_ns, burst_len)
Register Map
OffsetNameDescription
0x00RAM_TEST_CFG[RW] Configuration Register
0x04RAM_TEST_BASE[RW] Buffer Base Address
0x08RAM_TEST_END[RW] Buffer End Address
0x0cRAM_TEST_STS[R] Status Register
0x10RAM_TEST_CURRENT[R] Buffer Current address
0x14RAM_TEST_WRITE[RW] User specified write pattern
0x18RAM_TEST_TIME[R] Operation completion cycles
0x1cRAM_TEST_ERRORS[R] Operation errors
0x20RAM_TEST_LAST[R] Last read data
Register: RAM_TEST_CFG
BitsNameDescription
31:28BURST_LENBurst length - 1 (0 = singles, 1 = 8 bytes, 3 = 16 bytes)
8READPerform read operation (with error checking)
7RND_DELAYEnable short psuedo random delay between accesses
3USERExecute - write/compare user data word to RAM (RAM_TEST_WRITE_PATTERN)
2INCRExecute - incrementing pattern 0x33221100, 0x77665544, ...
1ONESExecute - all ones pattern
0ZEROExecute - all zeros pattern
Register: RAM_TEST_BASE
BitsNameDescription
31:0ADDRBase address (should be 4 byte aligned)
Register: RAM_TEST_END
BitsNameDescription
31:0ADDREnd address (size of test = RAM_TEST_END - RAM_TEST_BASE)
Register: RAM_TEST_STS
BitsNameDescription
0BUSYBusy executing operation
Register: RAM_TEST_CURRENT
BitsNameDescription
31:0ADDRCurrent read / write pointer
Register: RAM_TEST_WRITE
BitsNameDescription
31:0PATTERNData word to be written on RAM_TEST_CFG.USER
Register: RAM_TEST_TIME
BitsNameDescription
31:0CYCLESNumber of cycles operation took
Register: RAM_TEST_ERRORS
BitsNameDescription
31:0COUNTFor READ tests, number of data mismatches
Register: RAM_TEST_LAST
BitsNameDescription
31:0RD_DATAFor READ tests, last word read from RAM