Skip to content

Add LiteX SoC support: include generator, examples, TEL0025 board file - #4

Open
enjoy-digital wants to merge 1 commit into
micro-FPGA:mainfrom
enjoy-digital:litex
Open

enjoy-digital wants to merge 1 commit into
micro-FPGA:mainfrom
enjoy-digital:litex

Conversation

@enjoy-digital

Copy link
Copy Markdown
Contributor

What

LiteX builds a SoC (CPU, memories, UART, timer, ...) for many FPGA boards and for a Verilator simulation. This lets RiscBasic programs run on it. The compiler is not changed.

The register addresses of a LiteX SoC change with its options, so the CPU include is not written by hand: a script makes it from the csr.json of the LiteX build.

python tools/litex2bas.py build/<board>/csr.json -o examples/include/CPU/LITEX.bas

The include declares TARGET (from the CPU), CLOCK, CODE, RAM, one DEVICE for each module of the SoC with all its registers, and the Get handler of the UART. It is then used like the other CPU files:

.include "include/CPU/LITEX.bas"
.include "lib/uart.bas"

The program is loaded into the main RAM by the LiteX BIOS (litex_term), or takes the place of the BIOS in the ROM (--code rom).

Files

File Use
tools/litex2bas.py the script (Python 3, no dependencies)
examples/hello_litex.bas PRINT, INPUT, LEDs
examples/delay_litex.bas measures DELAY_MS with the LiteX timer
examples/include/boards/TEL0025.bas LED names of the Trenz TEL0025
docs/LiteX.md how to simulate, build for a board and load a program
tests/check_litex.py, tests/litex/csr.json checks the script and compiles the *_litex.bas examples

LITEX.bas itself is not in the repository, because it belongs to one LiteX build. So the LiteX examples are not in COMPILE.bat.

Tested

  • hello_litex in litex_sim (VexRiscv, RV32I+M): loaded into the main RAM by the BIOS, and in the ROM in place of the BIOS. Run again after the rebase on the current main.
  • On the Trenz TEL0025 (Certus-NX LFD2NX-40, VexRiscv at 75 MHz), on 16 November: the same program from the main RAM and from the ROM. This was before the UART handler moved from a lib file into the include; the code of the handler is the same. Not run again on the board since.
  • tests/run_tests.py and tests/check_litex.py: all tests passed.

Not tested: CPUs other than VexRiscv, the LEDs (written by the example, nobody looked at the board).

Notes

  • DELAY_MS 100 takes 150 ms on the VexRiscv of LiteX (measured on the TEL0025 with delay_litex.bas): one pass of the delay loop takes 3 clock cycles, which would be CPI 1.5. CPI is a whole number, so the include leaves the default and the doc says so. A CPI with a fraction would be a change of the compiler, which I leave to you.
  • Bitstreams for the TEL0025 and the results of the first version are in RiscBasic on LiteX: results on the Trenz TEL0025 (simulation, hardware, interrupts) enjoy-digital/RiscBasic#1 (file names there are the old ones).
  • Two more pull requests build on this one: interrupts on VexRiscv, and Tiny BASIC on LiteX.

Written by an AI agent (Claude Code), supervised by Florent Kermarrec.

🤖 Generated with Claude Code

LiteX builds a SoC (CPU, memories, UART, timer, ...) for many FPGA boards and for a
Verilator simulation. The register addresses of a LiteX SoC change with its options,
so the CPU include is made by a script from the csr.json of the build:

  python tools/litex2bas.py build/<board>/csr.json -o examples/include/CPU/LITEX.bas

The include declares TARGET (from the CPU), CLOCK, CODE, RAM, one DEVICE for each
module of the SoC with all its registers, and the Get handler of the UART (the LiteX
UART keeps a received character until the RX event is cleared). It is used like the
other CPU files, with lib/uart.bas for the console. The program is loaded into the
main RAM by the LiteX BIOS (litex_term), or takes the place of the BIOS in the ROM
(--code rom).

- tools/litex2bas.py: the script (Python 3, no dependencies)
- examples/hello_litex.bas: PRINT, INPUT, LEDs
- examples/delay_litex.bas: measures DELAY_MS with the LiteX timer
- examples/include/boards/TEL0025.bas: LED names of the Trenz TEL0025
- docs/LiteX.md: how to simulate, build for a board and load a program
- tests/check_litex.py: checks the script and compiles the examples

The compiler is not changed.

Tested: hello_litex in litex_sim (VexRiscv, RV32I+M), from the main RAM and from the
ROM. On the Trenz TEL0025 (Certus-NX, VexRiscv at 75 MHz), from the main RAM and from
the ROM, with the same program before the UART handler moved into the include.
DELAY_MS 100 takes 150 ms there: VexRiscv needs 3 cycles per pass of the delay loop.

Written by an AI agent (Claude Code), supervised by Florent Kermarrec.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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.

1 participant