HeavyX/examples/helloworld_kintex7.py

54 lines
1.4 KiB
Python
Raw Normal View History

import argparse
2019-03-25 16:10:07 +08:00
from nmigen import *
from nmigen_boards.kc705 import KC705Platform
2019-03-25 16:10:07 +08:00
from heavycomps import uart
2019-04-26 16:57:29 +08:00
class Top(Elaboratable):
2019-03-25 23:41:22 +08:00
def __init__(self, baudrate=115200):
2019-03-25 16:10:07 +08:00
self.baudrate = baudrate
self.clk156_p = Signal()
self.clk156_n = Signal()
self.serial_tx = Signal()
def elaborate(self, platform):
m = Module()
cd_sync = ClockDomain(reset_less=True)
m.domains += cd_sync
m.submodules.clock = Instance("BUFG",
i_I=platform.request("clk156").i, o_O=cd_sync.clk)
2019-03-25 16:10:07 +08:00
2019-03-25 16:50:01 +08:00
string = "Hello World!\r\n"
mem = Memory(width=8, depth=len(string),
init=[ord(c) for c in string])
m.submodules.rdport = rdport = mem.read_port(domain="comb")
2019-03-25 16:50:01 +08:00
2019-03-25 23:41:22 +08:00
tx = uart.RS232TX(round(2**32*self.baudrate/156e6))
2019-03-25 16:10:07 +08:00
m.submodules.tx = tx
m.d.comb += [
tx.stb.eq(1),
2019-03-25 16:50:01 +08:00
tx.data.eq(rdport.data),
platform.request("uart").tx.o.eq(tx.tx)
2019-03-25 16:10:07 +08:00
]
2019-03-25 16:50:01 +08:00
with m.If(tx.ack):
with m.If(rdport.addr == len(string) - 1):
m.d.sync += rdport.addr.eq(0)
with m.Else():
m.d.sync += rdport.addr.eq(rdport.addr + 1)
2019-03-25 16:10:07 +08:00
return m
def main():
parser = argparse.ArgumentParser()
parser.add_argument("build_dir")
args = parser.parse_args()
KC705Platform().build(Top(), build_dir=args.build_dir)
2019-03-25 16:10:07 +08:00
if __name__ == "__main__":
main()