cpu/gowin_emcu: Minor cosmetic cleanups, add copyright.
This commit is contained in:
parent
7286f95f55
commit
230ba5f7ba
|
@ -1,42 +1,51 @@
|
|||
#
|
||||
# This file is part of LiteX.
|
||||
#
|
||||
# Copyright (c) 2021 Ilia Sergachev <ilia.sergachev@protonmail.ch>
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
from migen import *
|
||||
|
||||
from litex.soc.interconnect import wishbone, ahb
|
||||
from litex.soc.cores.cpu import CPU
|
||||
|
||||
# AHB Flash ----------------------------------------------------------------------------------------
|
||||
|
||||
class AHBFlash(Module):
|
||||
def __init__(self, bus):
|
||||
addr = Signal(13)
|
||||
read_enable = Signal()
|
||||
read = Signal()
|
||||
self.comb += bus.resp.eq(0)
|
||||
|
||||
self.submodules.fsm = fsm = FSM()
|
||||
fsm.act("IDLE",
|
||||
bus.readyout.eq(1),
|
||||
If(bus.sel & bus.trans[1],
|
||||
NextValue(addr, bus.addr[2:]),
|
||||
NextState('READ'),
|
||||
NextState("READ"),
|
||||
)
|
||||
)
|
||||
fsm.act("READ",
|
||||
read_enable.eq(1),
|
||||
NextState('WAIT'),
|
||||
read.eq(1),
|
||||
NextState("WAIT"),
|
||||
)
|
||||
fsm.act('WAIT',
|
||||
NextState('IDLE')
|
||||
fsm.act("WAIT",
|
||||
NextState("IDLE")
|
||||
)
|
||||
self.specials += Instance(
|
||||
'FLASH256K',
|
||||
self.specials += Instance("FLASH256K",
|
||||
o_DOUT = bus.rdata,
|
||||
i_DIN = Signal(32),
|
||||
i_XADR = addr[6:],
|
||||
i_YADR = addr[:6],
|
||||
i_XE=~ResetSignal(),
|
||||
i_YE=~ResetSignal(),
|
||||
i_SE=read_enable,
|
||||
i_XE = ~ResetSignal("sys"),
|
||||
i_YE = ~ResetSignal("sys"),
|
||||
i_SE = read,
|
||||
i_PROG = 0,
|
||||
i_ERASE = 0,
|
||||
i_NVSTR = 0
|
||||
)
|
||||
|
||||
# Gowin EMCU ---------------------------------------------------------------------------------------
|
||||
|
||||
class GowinEMCU(CPU):
|
||||
variants = ["standard"]
|
||||
|
@ -46,11 +55,14 @@ class GowinEMCU(CPU):
|
|||
data_width = 32
|
||||
endianness = "little"
|
||||
gcc_triple = "arm-none-eabi"
|
||||
gcc_flags = '-mcpu=cortex-m3 -mthumb'
|
||||
gcc_flags = "-mcpu=cortex-m3 -mthumb"
|
||||
linker_output_format = "elf32-littlearm"
|
||||
nop = "nop"
|
||||
io_regions = {0x4000_0000: 0x2000_0000,
|
||||
0xA000_0000: 0x6000_0000} # Origin, Length.
|
||||
io_regions = {
|
||||
# Origin, Length.
|
||||
0x4000_0000: 0x2000_0000,
|
||||
0xa000_0000: 0x6000_0000
|
||||
}
|
||||
|
||||
@property
|
||||
def mem_map(self):
|
||||
|
@ -62,12 +74,13 @@ class GowinEMCU(CPU):
|
|||
|
||||
def __init__(self, platform, variant, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self.reset = Signal()
|
||||
self.bus_reset = Signal()
|
||||
bus_reset_n = Signal()
|
||||
self.comb += self.bus_reset.eq(~bus_reset_n)
|
||||
self.interrupt = Signal(5)
|
||||
self.reset_address = self.mem_map['rom'] + 0
|
||||
self.reset_address = self.mem_map["rom"] + 0
|
||||
|
||||
self.gpio_in = Signal(16)
|
||||
self.gpio_out = Signal(16)
|
||||
|
@ -81,7 +94,7 @@ class GowinEMCU(CPU):
|
|||
i_FLASHERR = Signal(),
|
||||
i_FLASHINT = Signal(),
|
||||
|
||||
i_FCLK=ClockSignal(),
|
||||
i_FCLK = ClockSignal("sys"),
|
||||
i_PORESETN = ~self.reset,
|
||||
i_SYSRESETN = ~self.reset,
|
||||
i_RTCSRCCLK = Signal(), # TODO - RTC clk in
|
||||
|
@ -114,12 +127,11 @@ class GowinEMCU(CPU):
|
|||
)
|
||||
|
||||
for i in range(n_srams):
|
||||
self.specials += Instance(
|
||||
'SDPB',
|
||||
self.specials += Instance("SDPB",
|
||||
p_READ_MODE = 0,
|
||||
p_BIT_WIDTH_0 = single_sram_dw,
|
||||
p_BIT_WIDTH_1 = single_sram_dw,
|
||||
p_RESET_MODE='SYNC',
|
||||
p_RESET_MODE = "SYNC",
|
||||
p_BLK_SEL_0 = 0b111,
|
||||
p_BLK_SEL_1 = 0b111,
|
||||
o_DO = Cat(sram0_rdata[i * single_sram_dw: (i + 1) * single_sram_dw], Signal(sram_dw - single_sram_dw)),
|
||||
|
@ -141,11 +153,11 @@ class GowinEMCU(CPU):
|
|||
|
||||
ahb_flash = ahb.Interface()
|
||||
for s, _ in ahb_flash.master_signals:
|
||||
if s in ['wdata', 'write', 'mastlock', 'prot']:
|
||||
if s in ["wdata", "write", "mastlock", "prot"]:
|
||||
continue
|
||||
self.cpu_params[f'o_TARGFLASH0H{s.upper()}'] = getattr(ahb_flash, s)
|
||||
self.cpu_params[f"o_TARGFLASH0H{s.upper()}"] = getattr(ahb_flash, s)
|
||||
for s, _ in ahb_flash.slave_signals:
|
||||
self.cpu_params[f'i_TARGFLASH0H{s.upper()}'] = getattr(ahb_flash, s)
|
||||
self.cpu_params[f"i_TARGFLASH0H{s.upper()}"] = getattr(ahb_flash, s)
|
||||
flash = ResetInserter()(AHBFlash(ahb_flash))
|
||||
self.comb += flash.reset.eq(self.bus_reset)
|
||||
self.submodules += flash
|
||||
|
@ -157,19 +169,19 @@ class GowinEMCU(CPU):
|
|||
ahb_targexp0 = ahb.Interface()
|
||||
for s, _ in ahb_targexp0.master_signals:
|
||||
# TODO: due to unexpected writes by the CPU bus is currently forced read-only
|
||||
if s == 'write':
|
||||
if s == "write":
|
||||
continue
|
||||
self.cpu_params[f'o_TARGEXP0H{s.upper()}'] = getattr(ahb_targexp0, s)
|
||||
self.cpu_params[f"o_TARGEXP0H{s.upper()}"] = getattr(ahb_targexp0, s)
|
||||
for s, _ in ahb_targexp0.slave_signals:
|
||||
self.cpu_params[f'i_TARGEXP0H{s.upper()}'] = getattr(ahb_targexp0, s)
|
||||
self.cpu_params[f"i_TARGEXP0H{s.upper()}"] = getattr(ahb_targexp0, s)
|
||||
self.submodules += ahb.AHB2Wishbone(ahb_targexp0, self.pbus)
|
||||
|
||||
def connect_uart(self, pads, n=0):
|
||||
assert n in (0, 1), "this CPU has 2 built-in UARTs, 0 and 1"
|
||||
self.cpu_params.update({
|
||||
f'i_UART{n}RXDI': pads.rx,
|
||||
f'o_UART{n}TXDO': pads.tx,
|
||||
f'o_UART{n}BAUDTICK': Signal()
|
||||
f"i_UART{n}RXDI": pads.rx,
|
||||
f"o_UART{n}TXDO": pads.tx,
|
||||
f"o_UART{n}BAUDTICK": Signal()
|
||||
})
|
||||
|
||||
def connect_jtag(self, pads):
|
||||
|
@ -180,7 +192,7 @@ class GowinEMCU(CPU):
|
|||
o_DAPNTDOEN = Signal(),
|
||||
i_DAPNTRST = ~self.reset,
|
||||
i_DAPSWCLKTCK = pads.tck,
|
||||
o_DAPJTAGNSW=Signal(), # indicates debug mode, JTAG or SWD
|
||||
o_DAPJTAGNSW = Signal(), # Indicates debug mode, JTAG or SWD
|
||||
)
|
||||
|
||||
def do_finalize(self):
|
||||
|
|
Loading…
Reference in New Issue