Skip to content

Commit

Permalink
Be able to use spi flash from LiteSPI.
Browse files Browse the repository at this point in the history
Signed-off-by: Fin Maaß <[email protected]>
  • Loading branch information
maass-hamburg committed Jun 19, 2024
1 parent 5e63d20 commit aa807e2
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
[submodule "third_party/litex-boards"]
path = third_party/litex-boards
url = https://github.com/litex-hub/litex-boards.git
[submodule "third_party/litespi"]
path = third_party/litespi
url = https://github.com/litex-hub/litespi.git
[submodule "third_party/liteiclink"]
path = third_party/liteiclink
url = https://github.com/enjoy-digital/liteiclink.git
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ Build options
| --with_i2s | Enable i2s |
| --sys-clk-freq | System clock frequency |
| --with_spi | Enable SPI |
| --with_spi_flash | Enable SPI flash |
| --with_i2c | Enable i2c |
| --with_pwm | Enable PWM |
| --spi-data-width | SPI data width |
| --spi-clk-freq | SPI clock frequency |
| --spi_flash_rate | SPI flash rate |
| --with_mmcm | Enable MMCM |
| --local-ip | local IP address |
| --remote-ip | remote IP address |
Expand Down
2 changes: 1 addition & 1 deletion init
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export PATH="${PWD}/third_party/litex/litex/tools:$PATH"
export PATH="${PWD}/tools/conda/bin:$PATH"

directories=(litedram liteeth liteiclink litepcie litesata litescope litevideo litex litex-boards litex-renode migen nmigen pythondata-cpu-vexriscv pythondata-software-compiler_rt pythondata-software-picolibc)
directories=(litedram liteeth liteiclink litepcie litespi litesata litescope litevideo litex litex-boards litex-renode migen nmigen pythondata-cpu-vexriscv pythondata-software-compiler_rt pythondata-software-picolibc)

for directory in "${directories[@]}";
do
Expand Down
7 changes: 7 additions & 0 deletions make.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,12 @@ def main():
parser.add_argument("--with_i2s", action="store_true", help="Enable i2s (Arty target only)")
parser.add_argument("--sys-clk-freq", default=100e6, help="System clock frequency.")
parser.add_argument("--with_spi", action="store_true", help="Enable spi (Arty target only)")
parser.add_argument("--with_spi_flash", action="store_true", help="Enable spi flash (Arty target only)")
parser.add_argument("--with_i2c", action="store_true", help="Enable i2c (Arty target only)")
parser.add_argument("--with_pwm", action="store_true", help="Enable pwm (Arty target only)")
parser.add_argument("--spi-data-width", type=int, default=8, help="SPI data width (maximum transfered bits per xfer, Arty target only)")
parser.add_argument("--spi-clk-freq", type=int, default=1e6, help="SPI clock frequency (Arty target only)")
parser.add_argument("--spi_flash_rate", default="1:1", help="SPI flash rate, can be 1:1 or 1:2 (Arty target only)")
parser.add_argument("--with_mmcm", action="store_true", help="Enable mmcm (Arty target only)")
parser.add_argument("--local-ip", default="192.168.1.50", help="local IP address (Arty target only)")
parser.add_argument("--remote-ip", default="192.168.1.100", help="remote IP address of TFTP server (Arty target only)")
Expand Down Expand Up @@ -117,6 +119,11 @@ def main():
soc.add_rgb_led()
if args.with_spi:
soc.add_spi(args.spi_data_width, args.spi_clk_freq)
if args.with_spi_flash:
from litespi.modules import S25FL128L
from litespi.opcodes import SpiNorFlashOpCodes as Codes
assert args.spi_flash_rate in ["1:1", "1:2"]
soc.add_spi_flash(mode="4x", module=S25FL128L(Codes.READ_1_1_4), rate=args.spi_flash_rate, with_master=True)
if args.with_i2c:
soc.add_i2c()
if args.with_i2s:
Expand Down
3 changes: 3 additions & 0 deletions soc_zephyr.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class _SoCZephyr(soc_cls):
"i2s_rx": 21, # addr: 0xe000a800
"i2s_tx": 22, # addr: 0xe000b000
"ddrphy": 23, # addr: 0xe000b800
"spiflash_core": 24, # addr: 0xe000c000
"spiflash_phy": 25, # addr: 0xe000c800
}}

interrupt_map = {**soc_cls.interrupt_map, **{
Expand All @@ -63,6 +65,7 @@ class _SoCZephyr(soc_cls):
"rom": 0x00000000,
"sram": 0x01000000,
"main_ram": 0x40000000,
"spiflash": 0x60000000,
"ethmac": 0xb0000000,
"i2s_rx": 0xb1000000,
"i2s_tx": 0xb2000000,
Expand Down
1 change: 1 addition & 0 deletions third_party/litespi
Submodule litespi added at 3a0651

0 comments on commit aa807e2

Please sign in to comment.