Skip to content

Commit 8a21aa3

Browse files
committed
Changes for new chipflow-lib software generator infrastructure
1 parent cc17c55 commit 8a21aa3

File tree

8 files changed

+425
-424
lines changed

8 files changed

+425
-424
lines changed

mcu_soc/chipflow.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ soc = "design.design:MySoC"
66

77
[chipflow.steps]
88
board = "design.steps.board:MyBoardStep"
9-
software = "design.steps.software:MySoftwareStep"
109

1110
[chipflow.silicon]
1211
process = "ihp_sg13g2"

mcu_soc/design/design.py

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
from pprint import pformat
21

3-
from chipflow_lib.platforms.sim import SimPlatform
4-
from chipflow_lib.software.soft_gen import SoftwareGenerator
2+
from pathlib import Path
53

64
from amaranth import Module
75
from amaranth.lib import wiring
@@ -15,7 +13,12 @@
1513
from amaranth_soc.wishbone.sram import WishboneSRAM
1614
from chipflow_digital_ip.io import GPIOPeripheral, UARTPeripheral, SPIPeripheral, I2CPeripheral
1715
from chipflow_digital_ip.processors import CV32E40P, OBIDebugModule
18-
from chipflow_lib.platforms import GPIOSignature, UARTSignature, SPISignature, I2CSignature, QSPIFlashSignature, JTAGSignature, attach_simulation_data
16+
from chipflow_lib.platforms import (
17+
GPIOSignature, UARTSignature, SPISignature, I2CSignature,
18+
QSPIFlashSignature, JTAGSignature,
19+
attach_data, SoftwareBuild
20+
)
21+
1922
from .ips.pwm import PWMPins, PWMPeripheral
2023
# from .ips.pdm import PDMPeripheral
2124

@@ -99,13 +102,6 @@ def elaborate(self, platform):
99102

100103
connect(m, wb_arbiter.bus, wb_decoder.bus)
101104

102-
# Software
103-
104-
sw = SoftwareGenerator(rom_start=self.bios_start, rom_size=0x00100000,
105-
# place BIOS data in SRAM
106-
ram_start=self.mem_sram_base, ram_size=self.sram_size)
107-
108-
109105
# CPU
110106

111107
cpu = CV32E40P(config="default", reset_vector=self.bios_start, dm_haltaddress=self.debug_base+0x800)
@@ -133,15 +129,12 @@ def elaborate(self, platform):
133129
# SPI flash
134130

135131
spiflash = QSPIFlash(addr_width=24, data_width=32)
136-
wb_decoder .add(spiflash.wb_bus, addr=self.mem_spiflash_base)
132+
wb_decoder.add(spiflash.wb_bus, name="spiflash", addr=self.mem_spiflash_base)
137133
csr_decoder.add(spiflash.csr_bus, name="spiflash", addr=self.csr_spiflash_base - self.csr_base)
138134
m.submodules.spiflash = spiflash
139135

140-
print(f"spiflash = {spiflash}")
141136
connect(m, flipped(self.flash), spiflash.pins)
142137

143-
sw.add_periph("spiflash", "SPIFLASH", self.csr_spiflash_base)
144-
145138
# SRAM
146139

147140
sram = WishboneSRAM(size=self.sram_size, data_width=32, granularity=8)
@@ -155,7 +148,6 @@ def elaborate(self, platform):
155148

156149
base_addr = self.csr_user_spi_base + i * self.periph_offset
157150
csr_decoder.add(user_spi.bus, name=f"user_spi_{i}", addr=base_addr - self.csr_base)
158-
sw.add_periph("spi", f"USER_SPI_{i}", base_addr)
159151

160152
# FIXME: These assignments will disappear once we have a relevant peripheral available
161153
pins = getattr(self, f"user_spi_{i}")
@@ -168,7 +160,6 @@ def elaborate(self, platform):
168160
gpio = GPIOPeripheral(pin_count=self.gpio_width)
169161
base_addr = self.csr_gpio_base + i * self.periph_offset
170162
csr_decoder.add(gpio.bus, name=f"gpio_{i}", addr=base_addr - self.csr_base)
171-
sw.add_periph("gpio", f"GPIO_{i}", base_addr)
172163

173164
pins = getattr(self, f"gpio_{i}")
174165
connect(m, flipped(pins), gpio.pins)
@@ -179,7 +170,6 @@ def elaborate(self, platform):
179170
uart = UARTPeripheral(init_divisor=int(25e6//115200), addr_width=5)
180171
base_addr = self.csr_uart_base + i * self.periph_offset
181172
csr_decoder.add(uart.bus, name=f"uart_{i}", addr=base_addr - self.csr_base)
182-
sw.add_periph("uart", f"UART_{i}", base_addr)
183173

184174
pins = getattr(self, f"uart_{i}")
185175
connect(m, flipped(pins), uart.pins)
@@ -192,7 +182,6 @@ def elaborate(self, platform):
192182

193183
base_addr = self.csr_i2c_base + i * self.periph_offset
194184
csr_decoder.add(i2c.bus, name=f"i2c_{i}", addr=base_addr - self.csr_base)
195-
sw.add_periph("i2c", f"I2C_{i}", base_addr)
196185

197186
i2c_pins = getattr(self, f"i2c_{i}")
198187
connect(m, flipped(i2c_pins), i2c.i2c_pins)
@@ -205,7 +194,6 @@ def elaborate(self, platform):
205194
base_addr = self.csr_motor_base + i * self.motor_offset
206195
csr_decoder.add(motor_pwm.bus, name=f"motor_pwm{i}", addr=base_addr - self.csr_base)
207196

208-
sw.add_periph("motor_pwm", f"MOTOR_PWM{i}", base_addr)
209197
setattr(m.submodules, f"motor_pwm{i}", motor_pwm)
210198

211199
# # pdm_ao
@@ -214,7 +202,6 @@ def elaborate(self, platform):
214202
# base_addr = self.csr_pdm_ao_base + i * self.pdm_ao_offset
215203
# csr_decoder.add(pdm.bus, name=f"pdm{i}", addr=base_addr - self.csr_base)
216204
#
217-
# sw.add_periph("pdm", f"PDM{i}", base_addr)
218205
# setattr(m.submodules, f"pdm{i}", pdm)
219206
# m.d.comb += getattr(self, f"pdm_ao_{i}").eq(pdm.pdm_ao)
220207

@@ -236,16 +223,12 @@ def elaborate(self, platform):
236223

237224
# m.submodules.jtag_provider = platform.providers.JTAGProvider(debug)
238225

239-
sw.add_periph("soc_id", "SOC_ID", self.csr_soc_id_base)
240-
#sw.add_periph("gpio", "BTN_GPIO", self.csr_btn_gpio_base)
226+
sw = SoftwareBuild(sources=Path('design/software').glob('*.c'),
227+
offset=self.bios_start)
241228

242-
sw.generate("build/software/generated")
243-
attach_simulation_data(self.flash, file_name="build/software/software.bin", offset=self.bios_start)
229+
# you need to attach data to both the internal and external interfaces
230+
attach_data(self.flash, m.submodules.spiflash, sw)
244231

245-
print(f"CSR resources :\n{pformat(list(csr_decoder.bus.memory_map.all_resources()), indent=2)}")
246-
print(f"CSR memory map:\n{pformat(csr_decoder.bus.memory_map._namespace._assignments, indent=2)}")
247-
print(f"CSR decoder subs:\n{pformat(csr_decoder._subs, indent=2)}")
248-
print(f"Wishbone memory map:\n{pformat(wb_decoder.bus.memory_map._namespace._assignments, indent=2)}")
249232
return m
250233

251234

File renamed without changes.

mcu_soc/design/ips/pdm.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
from amaranth.lib.wiring import In, Out, flipped, connect
66
from amaranth_soc import csr
77

8-
from chipflow_lib.platforms import OutputIOSignature
8+
from chipflow_lib.platforms import OutputIOSignature, SoftwareDriverSignature
9+
910

1011
__all__ = ["PDMPeripheral"]
1112

@@ -34,10 +35,16 @@ def __init__(self, *, bitwidth):
3435

3536
self._bridge = csr.Bridge(regs.as_memory_map())
3637

37-
super().__init__({
38-
"bus": In(csr.Signature(addr_width=addr_width, data_width=data_width)),
39-
"pdm": Out(self.WiringSignature)
40-
})
38+
super().__init__(
39+
SoftwareDriverSignature(
40+
members={
41+
"bus": In(csr.Signature(addr_width=addr_width, data_width=data_width)),
42+
"pdm": Out(self.WiringSignature)
43+
},
44+
component=self,
45+
regs_struct='pdm_regs_t',
46+
h_files=['drivers/pdm.h'])
47+
)
4148

4249
self.bus.memory_map = self._bridge.bus.memory_map
4350

@@ -48,7 +55,7 @@ def bitwidth(self):
4855
def elaborate(self, platform):
4956
m = Module()
5057
m.submodules.bridge = self._bridge
51-
maxval = Const(int((2**self._bitwidth)-1), unsigned(self._bitwidth))
58+
maxval = Const(int((2**self._bitwidth)-1), unsigned(self._bitwidth))
5259
error = Signal(unsigned(self._bitwidth), init=0x0)
5360
error_0 = Signal(unsigned(self._bitwidth), init=0x0)
5461
error_1 = Signal(unsigned(self._bitwidth), init=0x0)

mcu_soc/design/ips/pwm.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from amaranth.lib.cdc import FFSynchronizer
77
from amaranth_soc import csr
88

9-
from chipflow_lib.platforms import OutputIOSignature, InputIOSignature
9+
from chipflow_lib.platforms import OutputIOSignature, InputIOSignature, SoftwareDriverSignature
1010

1111
__all__ = ["PWMPeripheral", "PWMPins"]
1212

@@ -42,17 +42,17 @@ class Conf(csr.Register, access="rw"):
4242
"""
4343
en: csr.Field(csr.action.RW, unsigned(1))
4444
dir: csr.Field(csr.action.RW, unsigned(1))
45-
45+
4646
class Stop_int(csr.Register, access="rw"):
4747
"""Stop_int register
4848
"""
49-
stopped: csr.Field(csr.action.RW1C, unsigned(1))
50-
49+
stopped: csr.Field(csr.action.RW1C, unsigned(1))
50+
5151
class Status(csr.Register, access="r"):
5252
"""Status register
5353
"""
54-
stop_pin: csr.Field(csr.action.R, unsigned(1))
55-
54+
stop_pin: csr.Field(csr.action.R, unsigned(1))
55+
5656
"""pwm peripheral."""
5757
def __init__(self, *, pins):
5858
self.pins = pins
@@ -67,17 +67,24 @@ def __init__(self, *, pins):
6767

6868
self._bridge = csr.Bridge(regs.as_memory_map())
6969

70-
super().__init__({
71-
"bus": In(csr.Signature(addr_width=regs.addr_width, data_width=regs.data_width)),
72-
})
70+
super().__init__(
71+
SoftwareDriverSignature(
72+
members={
73+
"bus": In(csr.Signature(addr_width=regs.addr_width, data_width=regs.data_width)),
74+
},
75+
component=self,
76+
regs_struct='motor_pwm_regs_t',
77+
h_files=['drivers/motor_pwm.h'])
78+
)
79+
7380
self.bus.memory_map = self._bridge.bus.memory_map
7481

7582
def elaborate(self, platform):
7683
m = Module()
77-
m.submodules.bridge = self._bridge
84+
m.submodules.bridge = self._bridge
7885
count = Signal(unsigned(16), init=0x0)
7986
connect(m, flipped(self.bus), self._bridge.bus)
80-
87+
8188
#synchronizer
8289
stop = Signal()
8390
m.submodules += FFSynchronizer(i=self.pins.stop.i, o=stop)
@@ -87,12 +94,12 @@ def elaborate(self, platform):
8794
m.d.sync += count.eq(count+1)
8895
with m.Else():
8996
m.d.sync += count.eq(0)
90-
97+
9198
with m.If((self._numr.f.val.data > 0) & (count <= self._numr.f.val.data) & (self._conf.f.en.data == 1) & (self._stop_int.f.stopped.data == 0 )):
9299
m.d.comb += self.pins.pwm.o.eq(1)
93100
with m.Else():
94101
m.d.comb += self.pins.pwm.o.eq(0)
95-
102+
96103
with m.If(count >= self._denom.f.val.data):
97104
m.d.sync += count.eq(0)
98105

minimal/design/design.py

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from chipflow_lib.software.soft_gen import SoftwareGenerator
1+
from pathlib import Path
22

33
from amaranth import Module
44
from amaranth.lib import wiring
@@ -15,7 +15,8 @@
1515

1616
from minerva.core import Minerva
1717

18-
from chipflow_lib.platforms import Sky130DriveMode, GPIOSignature, UARTSignature, QSPIFlashSignature, attach_simulation_data
18+
from chipflow_lib.platforms import Sky130DriveMode, GPIOSignature, UARTSignature, QSPIFlashSignature, attach_data, SoftwareBuild
19+
1920

2021
__all__ = ["MySoC"]
2122

@@ -64,13 +65,6 @@ def elaborate(self, platform):
6465

6566
connect(m, wb_arbiter.bus, wb_decoder.bus)
6667

67-
# Software
68-
69-
sw = SoftwareGenerator(rom_start=self.bios_start, rom_size=0x00100000,
70-
# place BIOS data in SRAM
71-
ram_start=self.mem_sram_base, ram_size=self.sram_size)
72-
73-
7468
# CPU
7569

7670
cpu = Minerva(reset_address=self.bios_start, with_muldiv=True)
@@ -82,14 +76,12 @@ def elaborate(self, platform):
8276
# QSPI Flash
8377

8478
spiflash = QSPIFlash(addr_width=24, data_width=32)
85-
wb_decoder .add(spiflash.wb_bus, addr=self.mem_spiflash_base)
79+
wb_decoder .add(spiflash.wb_bus, name="spiflash", addr=self.mem_spiflash_base)
8680
csr_decoder.add(spiflash.csr_bus, name="spiflash", addr=self.csr_spiflash_base - self.csr_base)
8781
m.submodules.spiflash = spiflash
8882

8983
connect(m, flipped(self.flash), spiflash.pins)
9084

91-
sw.add_periph("spiflash", "SPIFLASH", self.csr_spiflash_base)
92-
9385
# SRAM
9486

9587
sram = WishboneSRAM(size=self.sram_size, data_width=32, granularity=8)
@@ -98,25 +90,22 @@ def elaborate(self, platform):
9890
m.submodules.sram = sram
9991

10092
# GPIOs
101-
m.submodules.gpio0 = gpio0 = GPIOPeripheral(pin_count=8)
102-
csr_decoder.add(gpio0.bus, name="gpio_0", addr=self.csr_gpio_base - self.csr_base)
103-
sw.add_periph("gpio", "GPIO_0", self.csr_gpio_base)
93+
m.submodules.gpio_0 = gpio_0 = GPIOPeripheral(pin_count=8)
94+
csr_decoder.add(gpio_0.bus, name="gpio_0", addr=self.csr_gpio_base - self.csr_base)
10495

105-
connect(m, flipped(self.gpio_0), gpio0.pins)
96+
connect(m, flipped(self.gpio_0), gpio_0.pins)
10697

10798
m.submodules.gpio_open_drain = gpio_open_drain = GPIOPeripheral(pin_count=4)
10899
csr_decoder.add(gpio_open_drain.bus, name="gpio_open_drain", addr=self.csr_gpio_base + self.periph_offset - self.csr_base)
109-
sw.add_periph("gpio", "GPIO_OPEN_DRAIN", self.csr_gpio_base + self.periph_offset)
110100

111101
connect(m, flipped(self.gpio_open_drain), gpio_open_drain.pins)
112102

113103

114104
# UART
115-
m.submodules.uart = uart = UARTPeripheral(init_divisor=int(25e6//115200), addr_width=5)
116-
csr_decoder.add(uart.bus, name="uart_0", addr=self.csr_uart_base - self.csr_base)
117-
sw.add_periph("uart", "UART_0", self.csr_uart_base)
105+
m.submodules.uart_0 = uart_0 = UARTPeripheral(init_divisor=int(25e6//115200), addr_width=5)
106+
csr_decoder.add(uart_0.bus, name="uart_0", addr=self.csr_uart_base - self.csr_base)
118107

119-
connect(m, flipped(self.uart_0), uart.pins)
108+
connect(m, flipped(self.uart_0), uart_0.pins)
120109

121110
# SoC ID
122111

@@ -132,10 +121,11 @@ def elaborate(self, platform):
132121

133122
m.submodules.wb_to_csr = wb_to_csr
134123

135-
sw.add_periph("soc_id", "SOC_ID", self.csr_soc_id_base)
124+
sw = SoftwareBuild(sources=Path('design/software').glob('*.c'),
125+
offset=self.bios_start)
136126

137-
sw.generate("build/software/generated")
138-
attach_simulation_data(self.flash, file_name="build/software/software.bin", offset=self.bios_start)
127+
# you need to attach data to both the internal and external interfaces
128+
attach_data(self.flash, m.submodules.spiflash, sw)
139129
return m
140130

141131

0 commit comments

Comments
 (0)