看到有人问MIF相关问题,上传几个MIF和COE文件的生成工具和方法-Anlogic-安路社区-FPGA CPLD-ChipDebug

看到有人问MIF相关问题,上传几个MIF和COE文件的生成工具和方法

该帖子部分内容已隐藏
付费阅读
10积分
此内容为付费阅读,请付费后查看
  1.  任意波形MIF生成工具,支持手绘和设定。

d2b5ca33bd105605

任意波形MIF生成工具下载

2. BIN转MIF和hex的工具

只支持MIF

同时支持MIF和HEX

也可以用python脚本实现bin转mif

#!/usr/bin/env python3

import os
import pathlib
import struct

import sys


class BinaryEOFException(Exception):
  def __init__(self):
    pass

  def __str__(self):
    return 'Premature end of file.'


class BinaryReader:

  def __init__(self, file_name):
    self.file = open(file_name, 'rb')

  def unpack(self, type_format):
    type_size = struct.calcsize(type_format)
    value = self.file.read(type_size)
    if type_size != len(value):
      raise BinaryEOFException
    return struct.unpack(type_format, value)[0]

  def __del__(self):
    self.file.close()


def header(width=8, depth=0):
  return """-- Quartus Prime generated Memory Initialization File (.mif)

WIDTH=%d;
DEPTH=%d;

ADDRESS_RADIX=HEX;
DATA_RADIX=HEX;

CONTENT BEGIN
""" % (width, depth)


def footer():
  return "END;\n"


def print_usage():
  print("Usage: %s <bin file>" % sys.argv[0])


if len(sys.argv) < 1:
  print_usage()
  exit(1)

source_filename = sys.argv[1]
binaryReader = BinaryReader(source_filename)
output_path = pathlib.Path.cwd()

try:
  width_in_bits = 8
  source_file_size = os.path.getsize(source_filename)
  if source_file_size == 0:
    print("Empty file.")
    exit(0)
  p = pathlib.Path(output_path).joinpath(source_filename + ".mif")
  os.makedirs(os.path.dirname(p), exist_ok=True)
  with p.open('w') as fh:
    fh.write(f"-- Converted from '{source_filename}'\n")
    fh.write(header(width_in_bits, source_file_size))
    pos_start = 0
    new_byte_value = binaryReader.unpack("B")
    i = 0
    try:
      while i < source_file_size - 1:
        next_byte_value = binaryReader.unpack("B")
        if new_byte_value != next_byte_value:
          fh.write(f"  {i:04X}  :   {new_byte_value:02X};\n")
        else:
          pos_start = i
          try:
            while new_byte_value == next_byte_value:
              i += 1
              next_byte_value = binaryReader.unpack("B")
          finally:
            fh.write(f"  [{pos_start:04X}..{i:04X}]  :   {new_byte_value:02X};\n")
        new_byte_value = next_byte_value
        i += 1
      else:
        fh.write(f"  {i:04X}  :   {new_byte_value:02X};\n")

    except BinaryEOFException:
      pass

    fh.write(footer())

except OSError:
  print("File error.")

 

3.图片COE和MIF文件的自动生成方法

d2b5ca33bd110000

d2b5ca33bd110017

图片转MIF生成工具下载

d2b5ca33bd110036

d2b5ca33bd110051

d2b5ca33bd110140

d2b5ca33bd110156

d2b5ca33bd110216

d2b5ca33bd110231

d2b5ca33bd110242

d2b5ca33bd110253

请登录后发表评论

    没有回复内容