Skip to content

Commit ba5a142

Browse files
committed
cleanup + litex
1 parent 1edf91f commit ba5a142

File tree

290 files changed

+61918
-3581
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

290 files changed

+61918
-3581
lines changed

Diff for: .gitignore

+10-2
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,13 @@ tmp
4242
rtl
4343
attic
4444

45-
totesim/obj_dir
46-
45+
*.o
46+
*.su
47+
*.d
48+
*.map
49+
*.elf
50+
*.bin
51+
*.asm
52+
csr.csv
53+
sim.gtkw
54+
venv

Diff for: .gitmodules

-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
11
[submodule "src/main/resources/rtl/Booth_Multipliers"]
22
path = hardware/main/resources/rtl/Booth_Multipliers
33
url = https://github.com/dlobato/Booth_Multipliers
4-
[submodule "libs/ELFIO"]
5-
path = totesim/libs/ELFIO
6-
url = https://github.com/serge1/ELFIO.git
7-
[submodule "libs/tensorflow"]
8-
path = software/libs/tensorflow
9-
url = https://github.com/dlobato/tensorflow.git

Diff for: README.md

-116
Original file line numberDiff line numberDiff line change
@@ -20,119 +20,3 @@ The project depends on several tools, check the requirements on each project to
2020
3. RISC-V GNU Embedded Toolchain to build the software targetted to riscv. YOu can build it yourself (https://github.com/riscv/riscv-gnu-toolchain) or get a pre-built one from https://www.sifive.com or https://github.com/gnu-mcu-eclipse/riscv-none-gcc/releases
2121
4. [Tensorflow](www.tensorflow.org): To train and do inference.
2222

23-
### Generate core HDL
24-
To generate verilog for a core run:
25-
```
26-
$> cd neuralFPGA
27-
$> sbt "runMain neuralfpga.core.Tote rtl"
28-
```
29-
This will generate the file _rtl/Tote.v_ and _cpu0.yaml_ (used on openocd session)
30-
31-
### Run simulation
32-
First we need to build the simulator for our core:
33-
```
34-
$> cd neuralFPGA/sim/tote
35-
$> make
36-
```
37-
Then we need a program to run on our simulated core. You can use the [hello world example](software/helloworld). Build it with:
38-
```
39-
$> cd neuralFPGA/software/helloworld
40-
$> make
41-
```
42-
Run it on the simulator:
43-
```
44-
$> cd neuralFPGA/sim/tote
45-
$> obj_dir/VTote_tb --program ../../software/helloworld/build/helloworld.elf
46-
Loading program: ../../software/helloworld/build/helloworld.elf
47-
LOAD [0] 0x5 0x80000000 0x22f4 0x22f4
48-
LOAD [1] 0x6 0x80002300 0x70 0x80
49-
LOAD [2] 0x6 0x80002370 0x0 0x10
50-
LOAD [3] 0x6 0x80002370 0x0 0x800
51-
LOAD [4] 0x6 0x80002370 0x0 0x4000
52-
_exit at 800000b4
53-
Simulation start
54-
586: Hello World!
55-
_exit with code=0
56-
```
57-
58-
### Debug simulation
59-
The simulated core can be debugged with gdb attached to openocd.
60-
Start the simulator:
61-
```
62-
$> cd neuralFPGA/sim/tote
63-
$> obj_dir/VTote_tb --jtag-enabled
64-
Simulation start
65-
This emulator compiled with JTAG Remote Bitbang client.
66-
Listening on port 9090
67-
Attempting to accept client socket
68-
```
69-
70-
On a different terminal start openocd:
71-
```
72-
$> cd neuralFPGA
73-
$> openocd -c "set VEXRISCV_YAML cpu0.yaml" -f sim/openocd/tote_remote_bitbang.tcl
74-
Open On-Chip Debugger 0.10.0+dev-01214-g0ace94f7 (2019-08-27-18:21)
75-
Licensed under GNU GPL v2
76-
For bug reports, read
77-
http://openocd.org/doc/doxygen/bugs.html
78-
cpu0.yaml
79-
Warn : Adapter driver 'remote_bitbang' did not declare which transports it allows; assuming legacy JTAG-only
80-
Info : only one transport option; autoselect 'jtag'
81-
Info : set servers polling period to 50ms
82-
Info : Initializing remote_bitbang driver
83-
Info : Connecting to localhost:9090
84-
Info : remote_bitbang driver initialized
85-
Info : This adapter doesn't support configurable speed
86-
Info : JTAG tap: fpga_spinal.bridge tap/device found: 0x10001fff (mfg: 0x7ff (<invalid>), part: 0x0001, ver: 0x1)
87-
Info : Listening on port 3333 for gdb connections
88-
requesting target halt and executing a soft reset
89-
Info : Listening on port 6666 for tcl connections
90-
Info : Listening on port 4444 for telnet connections
91-
```
92-
93-
And last on another terminal start gdb:
94-
```
95-
$> cd neuralFPGA
96-
$> riscv64-unknown-elf-gdb software/helloworld/build/helloworld.elf
97-
GNU gdb (SiFive GDB 8.3.0-2019.05.3) 8.3
98-
Copyright (C) 2019 Free Software Foundation, Inc.
99-
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
100-
This is free software: you are free to change and redistribute it.
101-
There is NO WARRANTY, to the extent permitted by law.
102-
Type "show copying" and "show warranty" for details.
103-
This GDB was configured as "--host=x86_64-linux-gnu --target=riscv64-unknown-elf".
104-
Type "show configuration" for configuration details.
105-
For bug reporting instructions, please see:
106-
<https://github.com/sifive/freedom-tools/issues>.
107-
Find the GDB manual and other documentation resources online at:
108-
<http://www.gnu.org/software/gdb/documentation/>.
109-
110-
For help, type "help".
111-
Type "apropos word" to search for commands related to "word"...
112-
Reading symbols from software/helloworld/build/helloworld.elf...
113-
(gdb)
114-
```
115-
116-
Now we need to connect our gdb to the target:
117-
```
118-
(gdb) target remote localhost:3333
119-
Remote debugging using localhost:3333
120-
_start ()
121-
at /home/dlobato/workspace-roboclub/neuralFPGA/software/tote/riscv/start.S:7
122-
7 la gp, __global_pointer$
123-
(gdb) monitor reset halt
124-
JTAG tap: fpga_spinal.bridge tap/device found: 0x10001fff (mfg: 0x7ff (<invalid>), part: 0x0001, ver: 0x1)
125-
(gdb) load
126-
Loading section .text, size 0x22f0 lma 0x80000000
127-
Loading section .sdata2._global_impure_ptr, size 0x4 lma 0x800022f0
128-
Loading section .sdata, size 0x10 lma 0x80002300
129-
Loading section .data, size 0x60 lma 0x80002310
130-
Start address 0x80000000, load size 9060
131-
Transfer rate: 1474 KB/sec, 2265 bytes/write.
132-
(gdb) continue
133-
Continuing.
134-
```
135-
136-
On the simulator terminal (the one running obj_dir/VTote_tb --jtag-enabled) we should see the message "9611126: Hello World!" (the timestamp might be different). You can stop the program execution on the gdb terminal with Ctrl + C.
137-
138-
Instead of continue we can set a breakpoint and debbug our code, print variable data, see registers, ...

Diff for: firmware/common.mk

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
2+
LITEX_BUILD_DIR ?= $(realpath $(ROOT_DIR)/../build/sim)
3+
include $(LITEX_BUILD_DIR)/software/include/generated/variables.mak
4+
5+
TARGET_TOOLCHAIN_PREFIX ?= riscv-none-embed-
6+
7+
CXX := $(TARGET_TOOLCHAIN_PREFIX)g++
8+
CC := $(TARGET_TOOLCHAIN_PREFIX)gcc
9+
AS := $(TARGET_TOOLCHAIN_PREFIX)as
10+
AR := $(TARGET_TOOLCHAIN_PREFIX)ar
11+
LD := $(TARGET_TOOLCHAIN_PREFIX)ld
12+
NM := $(TARGET_TOOLCHAIN_PREFIX)nm
13+
OBJDUMP := $(TARGET_TOOLCHAIN_PREFIX)objdump
14+
OBJCOPY := $(TARGET_TOOLCHAIN_PREFIX)objcopy
15+
SIZE := $(TARGET_TOOLCHAIN_PREFIX)size
16+
17+
INCLUDES := -I$(SOC_DIRECTORY)/software/include \
18+
-I$(BUILDINC_DIRECTORY) \
19+
-I$(CPU_DIRECTORY) \
20+
-I$(ROOT_DIR)/include
21+
22+
LDSCRIPT := linker.ld
23+
MAP_NAME := fw.map
24+
COMMON_FLAGS := $(CPUFLAGS) -MD -MP -ffunction-sections -fdata-sections -fstack-usage -ffreestanding -Wall
25+
ifeq ($(DEBUG),yes)
26+
COMMON_FLAGS += -g -Og
27+
else
28+
COMMON_FLAGS += -DNDEBUG -Os
29+
endif
30+
31+
CFLAGS = $(CFLAGS_ARGS) \
32+
$(COMMON_FLAGS) \
33+
-std=gnu11
34+
35+
CXXFLAGS = $(CXXFLAGS_ARGS) \
36+
$(COMMON_FLAGS) \
37+
-std=gnu++11 \
38+
-fno-exceptions \
39+
-fno-rtti \
40+
-fno-unwind-tables \
41+
-fcheck-new \
42+
-fno-use-cxa-atexit
43+
44+
LDFLAGS = -L$(BUILDINC_DIRECTORY) \
45+
-nostartfiles --specs=nano.specs \
46+
-Wl,--gc-sections,-Bstatic,-T,$(LDSCRIPT),-Map,$(MAP_NAME),--print-memory-usage
47+
48+
%.o: %.c
49+
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
50+
51+
%.o: %.cc
52+
$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@
53+
54+
%.o: %.cpp
55+
$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@
56+
57+
%.o: %.S
58+
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
59+
60+
%.hex: %.elf
61+
$(OBJCOPY) -O ihex $^ $@
62+
63+
%.bin: %.elf
64+
$(OBJCOPY) -O binary $^ $@
65+
66+
%.v: %.elf
67+
$(OBJCOPY) -O verilog $^ $@
68+
69+
%.asm: %.elf
70+
$(OBJDUMP) -S -d $^ > $@

Diff for: firmware/get_tflite_dep.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
!#/bin/bash
2+
3+
set -euo pipefail
4+
5+
TENSORFLOW_DIR=$1
6+
7+
make -f $(TENSORFLOW_DIR)/tensorflow/lite/micro/tools/make/Makefile TARGET=esp generate_hello_world_esp_project
8+
cp -r $(TENSORFLOW_DIR)/tensorflow/lite/micro/tools/make/gen/esp_xtensa-esp32_default/prj/hello_world/esp-idf/components/tfmicro .
9+
rm -r tfmicro/CMakeLists.txt
10+
11+
git -C $(TENSORFLOW_DIR)/src/tensorflow rev-parse --short HEAD > tfmicro/version

Diff for: firmware/helloworld/Makefile

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
PROJ_NAME := helloworld
2+
include ../common.mk
3+
4+
LDSCRIPT := linker.ld
5+
6+
SRCS += isr.c main.c
7+
8+
OBJS := $(SRCS:.c=.o)
9+
OBJS := $(ROOT_DIR)/rt/crt0.o \
10+
$(ROOT_DIR)/rt/init.o \
11+
uart.o \
12+
$(OBJS)
13+
14+
all: $(PROJ_NAME).elf $(PROJ_NAME).asm $(PROJ_NAME).bin
15+
16+
$(PROJ_NAME).elf: $(OBJS)
17+
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS)
18+
19+
uart.o: $(LIBBASE_DIRECTORY)/uart.c
20+
$(CC) $(CFLAGS) -I$(SOC_DIRECTORY)/software/include/base $(INCLUDES) -c $< -o $@
21+
22+
-include $(OBJS:.o=.d)
23+
24+
.PHONY : clean
25+
clean:
26+
-rm -f $(OBJS) $(OBJS:.o=.d) $(OBJS:.o=.su) $(PROJ_NAME).elf $(PROJ_NAME).asm $(PROJ_NAME).bin $(MAP_NAME)
27+
28+
.SECONDARY: $(OBJS)

Diff for: firmware/helloworld/isr.c

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// This file is Copyright (c) 2020 Florent Kermarrec <[email protected]>
2+
// License: BSD
3+
4+
#include <generated/csr.h>
5+
#include <generated/soc.h>
6+
#include <irq.h>
7+
#include <base/uart.h>
8+
9+
void isr(void);
10+
11+
#ifdef CONFIG_CPU_HAS_INTERRUPT
12+
13+
void isr(void)
14+
{
15+
__attribute__((unused)) unsigned int irqs;
16+
17+
irqs = irq_pending() & irq_getmask();
18+
19+
#ifndef UART_POLLING
20+
if(irqs & (1 << UART_INTERRUPT))
21+
uart_isr();
22+
#endif
23+
}
24+
25+
#else
26+
27+
void isr(void){};
28+
29+
#endif

Diff for: firmware/helloworld/linker.ld

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/* adapted from https://raw.githubusercontent.com/RISCV-on-Microsemi-FPGA/SoftConsole/master/riscv-simple-baremetal-bootloader/riscv_hal/microsemi-riscv-ram.ld */
2+
3+
INCLUDE generated/output_format.ld
4+
ENTRY(_start)
5+
INCLUDE generated/regions.ld
6+
7+
__stack_size = DEFINED(__stack_size) ? __stack_size : 2K;
8+
9+
SECTIONS
10+
{
11+
.text :
12+
{
13+
KEEP (*(SORT_NONE(.text.entry)))
14+
. = ALIGN(4);
15+
*(.text .text.* .gnu.linkonce.t.*)
16+
*(.plt)
17+
. = ALIGN(4);
18+
19+
KEEP (*crtbegin.o(.ctors))
20+
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
21+
KEEP (*(SORT(.ctors.*)))
22+
KEEP (*crtend.o(.ctors))
23+
KEEP (*crtbegin.o(.dtors))
24+
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
25+
KEEP (*(SORT(.dtors.*)))
26+
KEEP (*crtend.o(.dtors))
27+
28+
*(.rodata .rodata.* .gnu.linkonce.r.*)
29+
*(.gcc_except_table)
30+
*(.eh_frame_hdr)
31+
*(.eh_frame)
32+
33+
KEEP (*(.init))
34+
KEEP (*(.fini))
35+
36+
PROVIDE_HIDDEN (__preinit_array_start = .);
37+
KEEP (*(.preinit_array))
38+
PROVIDE_HIDDEN (__preinit_array_end = .);
39+
PROVIDE_HIDDEN (__init_array_start = .);
40+
KEEP (*(SORT(.init_array.*)))
41+
KEEP (*(.init_array))
42+
PROVIDE_HIDDEN (__init_array_end = .);
43+
PROVIDE_HIDDEN (__fini_array_start = .);
44+
KEEP (*(.fini_array))
45+
KEEP (*(SORT(.fini_array.*)))
46+
PROVIDE_HIDDEN (__fini_array_end = .);
47+
. = ALIGN(4);
48+
49+
} > main_ram
50+
51+
/* short/global data section */
52+
.sdata : ALIGN(4)
53+
{
54+
__sdata_load = LOADADDR(.sdata);
55+
__sdata_start = .;
56+
PROVIDE( __global_pointer$ = . + 0x800);
57+
*(.srodata.cst16) *(.srodata.cst8) *(.srodata.cst4) *(.srodata.cst2)
58+
*(.srodata*)
59+
*(.sdata .sdata.* .gnu.linkonce.s.*)
60+
. = ALIGN(4);
61+
__sdata_end = .;
62+
} > main_ram
63+
64+
/* data section */
65+
.data : ALIGN(4)
66+
{
67+
__data_load = LOADADDR(.data);
68+
__data_start = .;
69+
*(.got.plt) *(.got)
70+
*(.shdata)
71+
*(.data .data.* .gnu.linkonce.d.*)
72+
. = ALIGN(4);
73+
__data_end = .;
74+
} > main_ram
75+
76+
/* sbss section */
77+
.sbss : ALIGN(4)
78+
{
79+
__sbss_start = .;
80+
*(.sbss .sbss.* .gnu.linkonce.sb.*)
81+
*(.scommon)
82+
. = ALIGN(0x10);
83+
__sbss_end = .;
84+
} > sram
85+
86+
/* sbss section */
87+
.bss : ALIGN(4)
88+
{
89+
__bss_start = .;
90+
*(.shbss)
91+
*(.bss .bss.* .gnu.linkonce.b.*)
92+
*(COMMON)
93+
. = ALIGN(4);
94+
__bss_end = .;
95+
} > sram
96+
}
97+
98+
PROVIDE(__stack_top = ORIGIN(sram) + LENGTH(sram));
99+
100+
PROVIDE(_heap_start = __data_end);
101+
PROVIDE(_heap_end = ORIGIN(main_ram) + LENGTH(main_ram));

0 commit comments

Comments
 (0)