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
64from amaranth import Module
75from amaranth .lib import wiring
1513from amaranth_soc .wishbone .sram import WishboneSRAM
1614from chipflow_digital_ip .io import GPIOPeripheral , UARTPeripheral , SPIPeripheral , I2CPeripheral
1715from 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+
1922from .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
0 commit comments