Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
a168a7d
set up basic freertos project
Barabas5532 Aug 21, 2024
62fb2b2
add demo freertos app
Barabas5532 Aug 21, 2024
2bb3153
fix obvious errors
Barabas5532 Aug 21, 2024
253e955
WIP settings up build
Barabas5532 Aug 24, 2024
ab3f6f4
WIP
Barabas5532 Aug 24, 2024
eebd0d3
Update config
Barabas5532 Aug 24, 2024
4593739
fix build for the most part
Barabas5532 Aug 25, 2024
583b131
set up IRQ stack
Barabas5532 Aug 25, 2024
5abb95e
add TODO for setting up interrupts
Barabas5532 Aug 25, 2024
83c6aa7
Configure FreeRTOS to use mtime, mtimecmp for system tick
Barabas5532 Aug 25, 2024
35db764
Update python dependencies for Python 3.12 support
Barabas5532 Aug 25, 2024
14c456b
Update to latest riscv-arch-test
Barabas5532 Aug 25, 2024
04b94a7
Update notes
Barabas5532 Aug 25, 2024
c578c86
start implementing timer
Barabas5532 Aug 26, 2024
0db7967
extract wishbone write to task
Barabas5532 Aug 27, 2024
c5d8d8c
complete mtimer
Barabas5532 Aug 27, 2024
040c68d
WIP implement interrupts
Barabas5532 Sep 2, 2024
3cc8e22
update linker script
Barabas5532 Sep 2, 2024
715d76f
set up simulation for freertos
Barabas5532 Sep 2, 2024
e8a4224
run program from flash
Barabas5532 Sep 4, 2024
823354e
Fix errors in string.c
Barabas5532 Sep 4, 2024
30b23ed
Fix recursive standard library functions
Barabas5532 Sep 4, 2024
0ca5ca7
Fix C runtime initialisation
Barabas5532 Sep 4, 2024
9d0bb45
Update simulation timings
Barabas5532 Sep 4, 2024
eba277c
connect interrupt signals to mtimer
Barabas5532 Sep 5, 2024
101ebe9
configure trap handler address
Barabas5532 Sep 5, 2024
8079c3c
WIP
Barabas5532 Sep 6, 2024
67c8cb6
Set up test for CSR instructions
Barabas5532 Sep 23, 2024
ce8848b
Implement csrrw
Barabas5532 Sep 23, 2024
548fc32
Implement csrrs
Barabas5532 Sep 23, 2024
a5e9625
Implement csrrc
Barabas5532 Sep 23, 2024
77e4512
Implement immediate csrs
Barabas5532 Sep 23, 2024
0c51e99
implement exception stack management
Barabas5532 Sep 23, 2024
bf30291
Implement mret
Barabas5532 Sep 23, 2024
bad5d4a
WIP
Barabas5532 Sep 25, 2024
ffa61e0
fix ecall
Barabas5532 Sep 25, 2024
b8915cf
create flash
Barabas5532 Sep 26, 2024
3106e6a
WIP set up flash bootloader ROM
Barabas5532 Oct 1, 2024
eb3c0b8
fix linker script
Barabas5532 Oct 1, 2024
7759a01
WIP set up flash loading
Barabas5532 Oct 1, 2024
c2cd6c9
prepare for merge
Barabas5532 Oct 2, 2024
7376d8c
Merge remote-tracking branch 'origin/master' into machine-mode
Barabas5532 Oct 2, 2024
9466d5b
fix bootloader build
Barabas5532 Oct 2, 2024
dd14a1f
start implementing top level for freertos demo
Barabas5532 Oct 2, 2024
cfe9e5c
WIP integrate SPI boot loading
Barabas5532 Oct 2, 2024
395220d
clean up some lints
Barabas5532 Oct 2, 2024
49ddfa2
Replace hardware SPI with a soft SPI
Barabas5532 Jan 22, 2025
17691dd
clean up SPI bootloader
Barabas5532 Jan 23, 2025
f47b214
fix iceprog hints
Barabas5532 Jan 23, 2025
5a56d59
remove debug script
Barabas5532 Jan 23, 2025
a265463
clean up freertos config
Barabas5532 Jan 23, 2025
811108b
fix hint
Barabas5532 Jan 23, 2025
90c4bd8
remove unused file
Barabas5532 Jan 23, 2025
28037a5
remove commented code
Barabas5532 Jan 23, 2025
c824899
add new simulations to CI
Barabas5532 Jan 23, 2025
04f363b
WIP set up build option to include machine mode
Barabas5532 Jan 23, 2025
852a5b5
WIP
Barabas5532 Jan 23, 2025
3792d31
Merge remote-tracking branch 'origin/master' into machine-mode
Barabas5532 Jan 24, 2025
b86226d
fix
Barabas5532 Jan 24, 2025
c2f849b
fix ci
Barabas5532 Jan 24, 2025
33f10b1
fix
Barabas5532 Jan 24, 2025
8730e97
fix
Barabas5532 Jan 24, 2025
11f4da3
fix fw for freertos demo
Barabas5532 Jan 24, 2025
10ce7ed
Udpate core file
Barabas5532 Jan 24, 2025
e08dfa4
fix machine mode parameter
Barabas5532 Jan 24, 2025
c4f90be
fix
Barabas5532 Jan 24, 2025
b46ae13
remove file left by mistake
Barabas5532 Jan 24, 2025
581528a
fix mtimer test
Barabas5532 Jan 24, 2025
7794112
remove unnesessary parameter
Barabas5532 Jan 24, 2025
c970b8f
fix MACHINE_MODE parameter not exported
Barabas5532 Jan 24, 2025
f91ab82
fix up build system
Barabas5532 Jan 24, 2025
dbc2f81
fix tb
Barabas5532 Jan 24, 2025
f727725
fix spi
Barabas5532 Jan 24, 2025
0c41c31
fix typo
Barabas5532 Jan 24, 2025
efa9154
Increase test timeout
Barabas5532 Feb 6, 2025
b8406d6
fix a lint
Barabas5532 Feb 6, 2025
fec3358
fix a lint
Barabas5532 Feb 6, 2025
87185fa
fix lints
Barabas5532 Feb 6, 2025
b48f1ba
add comment
Barabas5532 Feb 6, 2025
04f635f
Update waiver
Barabas5532 Feb 6, 2025
50e6f40
Update lint config
Barabas5532 Feb 6, 2025
26e02eb
fix lints
Barabas5532 Feb 6, 2025
feba36e
fix all lints
Barabas5532 Feb 6, 2025
ebe5957
fix ci
Barabas5532 Feb 6, 2025
988d03e
fix misplaced code
Barabas5532 Feb 6, 2025
c46f32a
update CI
Barabas5532 Feb 6, 2025
d97e0b5
Fix CI
Barabas5532 Feb 6, 2025
57c051d
Update docs
Barabas5532 Feb 6, 2025
69e8f13
try fix for freertos linking
Barabas5532 Feb 6, 2025
0d4683f
Revert "try fix for freertos linking"
Barabas5532 Feb 13, 2025
c831534
Merge branch 'master' into machine-mode
Barabas5532 Feb 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
- sim_alu
- sim_inst_immediate_decode
- sim_load_store
- sim_csr
- sim_mtimer
# sim_cpu is not a testbench, but a target for RISCOF testing, so it
# is not included here
uses: ./.github/workflows/simulate.yml
Expand All @@ -21,19 +23,29 @@ jobs:
strategy:
matrix:
target:
- sim_memory
- sim_top
uses: ./.github/workflows/simulate.yml
with:
project: crush_example
target: ${{ matrix.target }}
verilog-sim-crush-example-freertos-cpu:
uses: ./.github/workflows/simulate.yml
with:
project: crush_example_freertos
target: sim_cpu
verilog-sim-crush-example-freertos-top:
uses: ./.github/workflows/simulate.yml
with:
project: crush_example_freertos
target: sim_top
timeout-minutes: 10
verilog-lint:
runs-on: ubuntu-22.04
container:
image: barabas5532/crush-ci:5
strategy:
matrix:
project: [crush, crush_example]
project: [crush, crush_example, crush_example_freertos]
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -77,6 +89,9 @@ jobs:
runs-on: ubuntu-22.04
container:
image: barabas5532/crush-ci:5
strategy:
matrix:
project: [crush_example, crush_example_freertos]
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -94,24 +109,23 @@ jobs:
timeout-minutes: 1
run: |
. script/init.sh
fusesoc --verbose run crush_example
fusesoc --verbose run ${{ matrix.project }}
firmware:
runs-on: ubuntu-22.04
strategy:
matrix:
path:
- crush_example/fw
- crush_example_freertos/fw/spi_bootloader
- crush_example_freertos/fw/app
container:
image: barabas5532/crush-ci:5
defaults:
run:
working-directory: crush_example/fw
working-directory: ${{ matrix.path }}
steps:
- uses: actions/checkout@v4
- name: Configure
run: cmake -B build -G Ninja -DCMAKE_TOOLCHAIN_FILE=TC-crush.cmake
- name: Build
run: cmake --build build
- uses: actions/upload-artifact@v4
with:
name: firmware-elf
path: |
fw/build/crush-blinky
fw/build/crush-blinky.bin
fw/build/crush-blinky.data
6 changes: 5 additions & 1 deletion .github/workflows/simulate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ on:
target:
required: true
type: string
timeout-minutes:
default: 1
required: false
type: number

jobs:
simulate:
Expand All @@ -29,7 +33,7 @@ jobs:
# also use the venv.
echo PATH=$PATH >> $GITHUB_ENV
- name: Run simulation
timeout-minutes: 1
timeout-minutes: ${{ inputs.timeout-minutes }}
run: |
. script/init.sh
fusesoc run --target ${{ inputs.target }} --resolve-env-vars-early ${{ inputs.project }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
build

fusesoc.conf
fusesoc_libraries
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,64 @@ Goals:
| [verible](https://github.com/chipsalliance/verible) | Standard LSP linter that can integrate with most text editors. |
| [FuseSoC](https://github.com/olofk/fusesoc) | Build tool that simplifies running the testbenches and synthesis tools. |
| [RISCOF, a RISC-V Architectural Test Framework](https://github.com/riscv-software-src/riscof) | The design passes all tests provided by RISCOF. See the `tools/compliance` folder. |

## Demo SoCs

### Basic Configuration (module top)

#### Boot process

All firmware executes directly from configurable block RAM. There is no support
for booting from flash. The block RAM stores both the executable code and the
system RAM.

#### Vectors

| Vector | Address |
|--------|-------------|
| Reset | 0x1000_0000 |


#### Memory Map

| Address | Size (bytes) | Description |
|-------------|--------------|-------------|
| 0x1000_0000 | 8192 | Block RAM |
| 0x4000_0000 | | GPIO |

### RTOS configuration (module top_freertos)

#### Boot process

The first stage bootloader stored in block RAM copies program data from flash to
RAM, then jumps to the "Boot entry" vector at the top of RAM (0x1000_0000).
After the bootloader completes, the application runs from SPRAM and the flash is
not used any more.

#### Vectors

| Vector | Address |
|----------------------|-------------|
| Reset | 0x0000_0000 |
| Bootloader app entry | 0x1000_0000 |
| Interrupt | 0x1000_0100 |

#### Memory Map

| Address | Size (bytes) | Description |
|-------------|--------------|----------------|
| 0x0000_0000 | 1024 | Boot block RAM |
| 0x1000_0000 | 65536 | SPRAM |
| 0x3000_0000 | | mtimer |
| 0x4000_0000 | | GPIO |
| 0x5000_0000 | | SPI |

## References

The SPI flash bootloader is based on the following open source libraries:

https://github.com/no2fpga/no2bootloader

https://github.com/chipsalliance/VeeRwolf

https://github.com/olofk/simple_spi
42 changes: 39 additions & 3 deletions crush/crush.core
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ filesets:
- rtl/inst_decode_registers.v
- rtl/inst_immediate_decode.v
- rtl/memory_infer.v: {file_type: systemVerilogSource}
- rtl/mtimer.v
- rtl/params.vh: {is_include_file: true}
- rtl/program_counter.v
- rtl/registers.v
Expand All @@ -20,26 +21,38 @@ filesets:
files:
- sim/inst_immediate_decode_tb.v
file_type: systemVerilogSource
depend: [crush_support]
depend: [crush_testing]

sim_alu:
files:
- sim/alu_tb.v
file_type: systemVerilogSource
depend: [crush_support]
depend: [crush_testing]

sim_load_store:
files:
- sim/load_store_tb.v
file_type: systemVerilogSource
depend: [crush_support]
depend: [crush_testing]

sim_cpu:
files:
- sim/control.v
- sim/cpu_tb.v
file_type: systemVerilogSource

sim_csr:
files:
- sim/csr_tb.v
file_type: systemVerilogSource
depend: [crush_testing]

sim_mtimer:
files:
- sim/mtimer_tb.v
file_type: systemVerilogSource
depend: [crush_testing]

verilator_waiver:
files:
- ../data/verilator_waiver.vlt
Expand All @@ -55,6 +68,8 @@ targets:
iverilog_options:
- "-g2012"
- "-gassertions"
parameters:
- MACHINE_MODE

lint:
default_tool : verilator
Expand Down Expand Up @@ -102,3 +117,24 @@ targets:
toplevel: cpu_tb
default_tool: icarus

sim_csr:
<<: *default
filesets_append:
- sim_csr
toplevel: csr_tb
default_tool: icarus
parameters:
- MACHINE_MODE=true

sim_mtimer:
<<: *default
filesets_append:
- sim_mtimer
toplevel: mtimer_tb
default_tool: icarus

parameters:
MACHINE_MODE:
datatype : bool
description: Enables machine privilege mode features
paramtype : vlogdefine
18 changes: 17 additions & 1 deletion crush/rtl/alu.v
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@ module alu (
wire [31:0] B_immediate;
wire [31:0] U_immediate;
wire [31:0] J_immediate;
// False positive, because only used in machine mode
// verilator lint_off UNUSEDSIGNAL
wire [31:0] CSR_immediate;
// verilator lint_on UNUSEDSIGNAL

inst_immediate_decode immediate_decode (
.inst(instruction),
.I_immediate(I_immediate),
.S_immediate(S_immediate),
.B_immediate(B_immediate),
.U_immediate(U_immediate),
.J_immediate(J_immediate)
.J_immediate(J_immediate),
.CSR_immediate(CSR_immediate)
);

wire [6:0] opcode = instruction[6:0];
Expand Down Expand Up @@ -78,6 +83,17 @@ module alu (
OPCODE_STORE: out = op_a + S_immediate;
OPCODE_JAL: out = pc + J_immediate;
OPCODE_JALR: out = (op_a + I_immediate) & ~1;
`ifdef MACHINE_MODE
OPCODE_SYSTEM: case(funct3)
FUNCT3_CSRRW: out = op_a;
FUNCT3_CSRRWI: out = CSR_immediate;
FUNCT3_CSRRC: out = op_a & ~op_b;
FUNCT3_CSRRCI: out = op_a & ~CSR_immediate;
FUNCT3_CSRRS: out = op_a | op_b;
FUNCT3_CSRRSI: out = op_a | CSR_immediate;
default: ;
endcase
`endif
default: ;
endcase
end
Expand Down
Loading