Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add the Hackaday Supercon ECP5 badge #31

Merged
merged 1 commit into from
Jan 7, 2020
Merged

Conversation

pdp7
Copy link
Contributor

@pdp7 pdp7 commented Jan 6, 2020

Add the Hackaday Supercon 2019 badge which has an ECP5 FPGA.

These changes are from a fork by Michael Welling (@mwelling)

During Supercon, we tried two approaches:

  • use the built-in 16MB QSPI SRAM
  • use add-on cartiridge with 32MB SDRAM by Jacob Creedon

We were not able to get the QSPI SRAM working so I've removed those changes, and I have just added the changes that are needed to boot Linux with the 32MB SDRAM.

In addition to @mwelling, thank you to Jacob Creedon (@jcreedon), @gregdavill, Tim Ansell (@mithro), and Sean Cross (@xobs) who all helped get Linux working on this badge.

KiCad design files by @jcreedon for the SDRAM cartridge are available on GitHub.

There is also a shared project to order the SDRAM cartridge PCB.

Refer to my blog post for more information.

The Hackaday Supercon badge schematic and PCB layout are on GitHub too.

Add the Hackaday Supercon 2019 badge which has an ECP5 FPGA:
https://hackaday.io/project/167255-2019-hackaday-superconference-badge

These changes are from Michael Welling's fork:
https://github.com/mwelling/linux-on-litex-vexriscv

During Supercon, we trying two approaches:
- use the built-in 16MB QSPI SRAM
- use add-on cartiridge with 32MB SDRAM by Jacob Creedon

We were not able to get the QSPI SRAM working so I've removed
those changes, and I have just added the changes that are needed
to boot Linux with the 32MB SDRAM.

Thanks to Jacob Creedon, Greg Davill and Tim Ansell who helped debug.

KiCad design files for the SDRAM cartridge are available at:
https://github.com/jcreedon/dram-cart/

The SDRAM cartridge PCB is shared at:
https://oshpark.com/shared_projects/IQSl2lid

More information in this blog post:
https://blog.oshpark.com/2019/12/20/

The Hackaday Supercon badge PCB design is here:
https://github.com/Spritetm/hadbadge2019_pcb
@pdp7
Copy link
Contributor Author

pdp7 commented Jan 6, 2020

@enjoy-digital
Copy link
Member

Thanks, i hope you all had fun working on that! It's merged with additional cleanup/simplifications:
85c4f76
c0e4578
(sorry i need to make this to still be able to maintain things :))

Since i don't have the hardware, can you check that things are still working? (i'll merge the linux-on-litex-vexriscv PR just after writing this).

@pdp7
Copy link
Contributor Author

pdp7 commented Jan 7, 2020

@enjoy-digital thank you for merging and making the cleanups. I have tested and the badge still boots Linux correctly with lxterm and I can login OK as root:

pdp7@x1:~/dev/upstream/linux-on-litex-vexriscv$ lxterm --images=images.json /dev/ttyUSB0 --speed=1e6 --no-crc
[    0.000000] Linux version 5.0.13 (florent@lab) (gcc version 8.3.0 (Buildroot 2019.08-rc2-00011-gad9efda578)) #1 Thu Sep 12 14:20:26 CEST 2019

@enjoy-digital
Copy link
Member

Great! thanks for the feedback.

@pdp7
Copy link
Contributor Author

pdp7 commented Jan 7, 2020

@enjoy-digital fyi - I recorded an asciinema in case it it useful for reference: https://asciinema.org/a/292299

@enjoy-digital
Copy link
Member

Thanks for the asciinema record, i'll keep the link. Booting with SDRAM SoCs seems a bit slow, i'll try to identify the bottlenecks and speed things a bit.

@mithro
Copy link
Contributor

mithro commented Jan 8, 2020

From what I can see there is something misconfigured somewhere. Everything (not just booting) seems a lot slower than the OrangeCrab.

@pdp7
Copy link
Contributor Author

pdp7 commented Jan 8, 2020

I agree that is surprisingly slow. Can the DDR on the @gregdavill OrangeCrab really make that big of a difference?

@gregdavill
Copy link
Contributor

The SDRAM is running with the following specifications:

  • 8bit data bus
  • 48MHz clock
  • Raw bus throughput 384 Mbit/s (8 * 48M)

The DDR3 on the OrangeCrab:

  • 16bit data bus
  • 96MHz DDR Clock. (2:1 clock gearing)
  • Raw bus throughput 3,072Mbit/s (16 * 96M * 2)

Of course this is ignoring latency and other differences between the DDR3 and the SDRAM. But there is a pretty big difference in the raw bus speed.

@pdp7
Copy link
Contributor Author

pdp7 commented Jan 9, 2020

@gregdavill thanks for the details specs. That is good to know there is an order of magnitude difference in raw bus speed.

@enjoy-digital
Copy link
Member

From the CPU side, the maximal throughput on the wishbone bus is : 48M*32/2=768Mbit/s. (/2 since a wishbone access takes minimum 2 cycles). I need to look at how the 32-bit are down-converted to 8-bit for the SDRAM accesses, it's probably not as efficient as it could be. (not sure i ever try to optimize this case since on most designs SDRAM's controller data width >= 32). A relatively easy next thing to do to speed things with SDRAM would be to run the SDRAM at 96MHz instead of 48MHz. Then the next optimization would be to support bursts on the wishbone bus to avoid the /2 factor.

@xobs
Copy link
Member

xobs commented Jan 9, 2020 via email

@enjoy-digital
Copy link
Member

@xobs: indeed, for now it was not that critical since the CPU was mostly used to assist the hardware and do some control, but now that we are running OSes on it's becoming limiting, i'll look at the options.

@enjoy-digital
Copy link
Member

With enjoy-digital/litedram@34e6c24 and enjoy-digital/litex@fa22d6a we have a ~10% boot time speedup on designs using SDRAM:

  • De0Nano: 94.6.s to 84.6s
  • ULX3S: 75.9s to 68.2s

On Arty with DDR3 the gain is effect more limited: 8.7s to 8.4s. That would be interesting to test this on the badge.

@pdp7
Copy link
Contributor Author

pdp7 commented Jan 10, 2020

@enjoy-digital thanks! I will try it out

@pdp7
Copy link
Contributor Author

pdp7 commented Jan 10, 2020

@enjoy-digital I pulled litedram and litex but I got and error when running build:

pdp7@x1:~/dev/upstream/linux-on-litex-vexriscv$ python3 make.py --board=hadbadge --build
make: Entering directory '/home/pdp7/dev/upstream/linux-on-litex-vexriscv/build/hadbadge/software/libcompiler_rt'
make: Nothing to be done for 'all'.
make: Leaving directory '/home/pdp7/dev/upstream/linux-on-litex-vexriscv/build/hadbadge/software/libcompiler_rt'
make: Entering directory '/home/pdp7/dev/upstream/linux-on-litex-vexriscv/build/hadbadge/software/libbase'
 CC       exception.o
 CC       system.o
 CC       id.o
 CC       uart.o
 CC       time.o
 CC       spiflash.o
 CC       mdio.o
 AR       libbase.a
 AR       libbase-nofloat.a
make: Leaving directory '/home/pdp7/dev/upstream/linux-on-litex-vexriscv/build/hadbadge/software/libbase'
make: Entering directory '/home/pdp7/dev/upstream/linux-on-litex-vexriscv/build/hadbadge/software/libnet'
 CC       microudp.o
 AR       libnet.a
make: Leaving directory '/home/pdp7/dev/upstream/linux-on-litex-vexriscv/build/hadbadge/software/libnet'
make: Entering directory '/home/pdp7/dev/upstream/linux-on-litex-vexriscv/build/hadbadge/software/bios'
 CC       isr.o
 CC       sdram.o
/home/pdp7/dev/upstream/litex/litex/soc/software/bios/sdram.c: In function 'sdrrderr':
/home/pdp7/dev/upstream/litex/litex/soc/software/bios/sdram.c:225:49: warning: division by zero [-Wdiv-by-zero]
    printf("%2x", DFII_PIX_DATA_BYTES/2 - 1 - (i % (DFII_PIX_DATA_BYTES/2)));
                                                 ^
 CC       main.o
 CC       boot.o
 LD       bios.elf
chmod -x bios.elf
 OBJCOPY  bios.bin
chmod -x bios.bin
python3 -m litex.soc.software.mkmscimg bios.bin --little
make: Leaving directory '/home/pdp7/dev/upstream/linux-on-litex-vexriscv/build/hadbadge/software/bios'
Traceback (most recent call last):
  File "make.py", line 305, in <module>
    main()
  File "make.py", line 292, in main
    builder.build()
  File "/home/pdp7/dev/upstream/litex/litex/soc/integration/builder.py", line 182, in build
    toolchain_path=toolchain_path, **kwargs)
  File "/home/pdp7/dev/upstream/litex/litex/soc/integration/soc_core.py", line 461, in build
    return self.platform.build(self, *args, **kwargs)
  File "/home/pdp7/dev/upstream/litex/litex/build/lattice/platform.py", line 34, in build
    return self.toolchain.build(self, *args, **kwargs)
  File "/home/pdp7/dev/upstream/litex/litex/build/lattice/trellis.py", line 213, in build
    (family, size, speed_grade, package) = nextpnr_ecp5_parse_device(platform.device)
  File "/home/pdp7/dev/upstream/litex/litex/build/lattice/trellis.py", line 83, in nextpnr_ecp5_parse_device
    raise ValueError("Invalid speed grade {}".format(speed_grade))
ValueError: Invalid speed grade c
pdp7@x1:~/dev/upstream/linux-on-litex-vexriscv$ git log -1
commit 8ecfdcd855d42f5b373e28ecc106f8d67fdfd4be (HEAD -> master, origin/master, origin/HEAD)
Author: Florent Kermarrec <florent@enjoy-digital.fr>
Date:   Fri Jan 10 09:42:54 2020 +0100

    make.py/de0nano: increase l2_size to 2048, update comment

pdp7@x1:~/dev/upstream/litedram$ git log -1
commit 34e6c24d7296aeed6fb71ddc009b357cfc5a82ca (HEAD -> master, origin/master, origin/HEAD)
Author: Florent Kermarrec <florent@enjoy-digital.fr>
Date:   Fri Jan 10 14:27:05 2020 +0100

    frontend/wishbone: add write data buffer to avoid stalling wishbone while waiting for wdata.ready

pdp7@x1:~/dev/upstream/litex$ git log -1
commit f70dd48279cdb54e5da715d4d5f7a743ee2c370d (HEAD -> master, origin/master, origin/HEAD)
Author: Florent Kermarrec <florent@enjoy-digital.fr>
Date:   Fri Jan 10 14:25:46 2020 +0100

    bios/sdram: add memspeed

Maybe I am missing something?

@enjoy-digital
Copy link
Member

@pdp7: sorry, i introduced a typo when refactoring the CRG on the hadbage. If you use upstream litex/litedram/litex-boards and linux-on-litex-vexriscv, you should be able to build the design. (you can just use litex_setup.py update to update litex/litedram/litex-boards). Here is attached the bitstream i just generated for the hadbadge from upstream repos.

hadbadge.zip

@pdp7
Copy link
Contributor Author

pdp7 commented Jan 11, 2020

@enjoy-digital I created an issue because I didn't want to keep adding comments to a merged PR:
#34

please let me know if I should do something differently like continue to comment here or create the issue in a different repo (such as linux-on-litex-vexriscv)?

Subsignal("fmark", Pins("G1"), IOStandard("LVCMOS33")),
Subsignal("blen", Pins("P5"), IOStandard("LVCMOS33")),
),
("spiflash", 0, # clock needs to be accessed through USRMCLK
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mithro @xobs @jacobcreedon @mwelling do you remember why we had spiflash and spiflash4x for the Hackaday Badge?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on whether you're using dual/quad SPI or single SPI, either could work. Since this is a board definition, it makes sense to describe both options. For example, if you only wanted to do single SPI due to working with a fresh ROM cartridge that hasn't had its "QE" bit set.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xobs thanks. Any idea as to how to know if the QE bit set in the SDRAM cartridge that I am using?

I'm currently using spiflash for the add_spi_flash() method:
#35 (comment)

However, I can not get it to boot from flash so I'm trying to figure out what I may be doing wrong:
#35 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants