├── .gitignore ├── Attic ├── CSR_file.v ├── aligned_memory_access.v ├── branch_predicates.v ├── decoder.v ├── femtorv32_2CPI_linear_flow.v ├── femtorv32_fast_quark_95MHz.v ├── femtorv32_single_file.v.alu_state ├── large_alu.v ├── mini_femtorv32.v ├── register_file.v └── small_alu.v ├── Basic ├── ARTY │ └── ARTY_blink │ │ ├── arty.xdc │ │ ├── blinky.v │ │ └── makeit.sh ├── FOMU │ ├── FOMU_VGA │ │ ├── Images │ │ │ ├── FOMU_VGA.gif │ │ │ ├── FOMU_in_USB.jpg │ │ │ ├── FrankenFOMU.png │ │ │ ├── VGA.jpg │ │ │ └── vga_mode.png │ │ ├── README.md │ │ ├── fomu-pvt.pcf │ │ ├── makeit.sh │ │ └── vga.v │ └── FOMU_blink │ │ ├── blink.v │ │ ├── fomu-pvt.pcf │ │ └── makeit.sh ├── ICESTICK │ ├── Blinker │ │ ├── blink.pcf │ │ ├── blink.v │ │ └── makeit.sh │ ├── LedMatrix │ │ ├── led_matrix.pcf │ │ ├── led_matrix.v │ │ ├── makeit.sh │ │ └── notes.txt │ ├── LedTerminal │ │ ├── led_terminal.pcf │ │ ├── led_terminal.pcf.LedMatrixOnPMod │ │ ├── led_terminal.pcf.LedMatrixOnTheSide │ │ ├── led_terminal.timings │ │ ├── led_terminal.v │ │ ├── led_terminal.v.line_edit │ │ ├── led_terminal.v.show_car │ │ ├── makeit.sh │ │ ├── notes.txt │ │ └── start.sh │ ├── Libs │ │ ├── MAX7219.v │ │ ├── SSD1351.v │ │ ├── font_rom.v │ │ ├── scroller.v │ │ ├── uart.v │ │ └── vga.v │ ├── Oled │ │ ├── makeit.sh │ │ ├── notes.txt │ │ ├── oled.pcf │ │ └── oled.v │ └── Serial │ │ ├── makeit.sh │ │ ├── serial.pcf │ │ ├── serial.v │ │ ├── start.sh │ │ └── uart.v ├── Tools │ └── Font │ │ ├── font8x8.xpm │ │ └── makefont.c └── ULX3S │ ├── ULX3S_SDRAM_hdmi │ ├── HDMI_clock.v │ ├── README.md │ ├── SDRAM_HDMI_test.v │ ├── TMDS_encoder.v │ ├── makeit.sh │ └── ulx3s.lpf │ └── ULX3S_hdmi │ ├── HDMI_clock.v │ ├── HDMI_test_DDR.v │ ├── HDMI_test_hires.v │ ├── README.md │ ├── TMDS_encoder.v │ ├── makeit.sh │ └── ulx3s.lpf ├── FemtoRV ├── BOARDS │ ├── arty.xdc │ ├── arty35_symbiflow.mk │ ├── arty35_yosys_nextpnr.mk │ ├── arty_defs.v │ ├── bench.mk │ ├── cmod_a7.xdc │ ├── cmod_a7_yosys_nextpnr.mk │ ├── ecp5-evn.cfg │ ├── ecp5_evn.lpf │ ├── ecp5_evn.mk │ ├── fomu-pvt.pcf │ ├── fomu.mk │ ├── ice4pi.mk │ ├── ice4pi.pcf │ ├── icebreaker.mk │ ├── icebreaker.pcf │ ├── icefeather.mk │ ├── icefeather.pcf │ ├── icestick.mk │ ├── icestick.pcf │ ├── icestick_mecrisp_quintus.mk │ ├── icestick_mecrisp_quintus.pcf │ ├── icesugar.mk │ ├── icesugar.pcf │ ├── icesugar_nano.mk │ ├── icesugar_nano.pcf │ ├── ulx3s.lpf │ └── ulx3s.mk ├── FIRMWARE │ ├── ASM_EXAMPLES │ │ ├── Makefile │ │ ├── bench_count_15.S │ │ ├── blinker_loop.S │ │ ├── blinker_shift.S │ │ ├── blinker_shift_fast.S │ │ ├── blinker_wait.S │ │ ├── hello.S │ │ ├── mandelbrot_OLED.S │ │ ├── mandelbrot_terminal.S │ │ ├── test_OLED.S │ │ ├── test_led_matrix.S │ │ ├── test_serial.S │ │ └── tinyblinky.S │ ├── CPP_EXAMPLES │ │ ├── Makefile │ │ ├── cpp_test.cpp │ │ ├── geometry.h │ │ └── tinyrt_cpp.cpp │ ├── CRT │ │ ├── Makefile │ │ ├── baremetal.ld │ │ ├── crt0_baremetal.S │ │ ├── crt0_spiflash.S │ │ ├── spiflash.ld │ │ ├── spiflash_fomu.ld │ │ ├── spiflash_icebreaker.ld │ │ ├── spiflash_icebreaker_run_from_flash.ld │ │ ├── spiflash_icestick.ld │ │ ├── spiflash_icesugar_nano.ld │ │ └── syscalls.c │ ├── DHRYSTONE │ │ ├── Makefile │ │ ├── README │ │ ├── dhry.h │ │ ├── dhry_1.c │ │ ├── dhry_2.c │ │ └── stubs.c │ ├── EXAMPLES │ │ ├── DATA │ │ │ ├── notes.txt │ │ │ ├── scene1.dat │ │ │ ├── scene_description.txt │ │ │ └── test_ST_NICCC.c │ │ ├── FGA_test.c │ │ ├── Makefile │ │ ├── ST_NICCC.c │ │ ├── ST_NICCC_spi_flash.c │ │ ├── TOOLS │ │ │ ├── make_sintab.c │ │ │ └── tiny_riscv_logo.xpm │ │ ├── cube.c │ │ ├── donut.c │ │ ├── errno_fix.h │ │ ├── gfx_demo.c │ │ ├── gfx_test.c │ │ ├── hello.c │ │ ├── hello_LED.c │ │ ├── hello_bench.c │ │ ├── imgui_cup.c │ │ ├── imgui_disco.c │ │ ├── imgui_doom.c │ │ ├── imgui_emul.h │ │ ├── imgui_road.c │ │ ├── imgui_tunnel.c │ │ ├── julia.c │ │ ├── life_led_matrix.c │ │ ├── malloc_test.c │ │ ├── mandel_float.c │ │ ├── mandelbrot.c │ │ ├── pi.c │ │ ├── riscv_logo.c │ │ ├── riscv_logo_2.c │ │ ├── sieve.c │ │ ├── spirograph.c │ │ ├── sysconfig.c │ │ ├── test_buttons.c │ │ ├── test_font_OLED.c │ │ ├── test_ir_remote.c │ │ ├── test_ir_sensor.c │ │ ├── test_spi_flash.c │ │ ├── test_spi_sdcard.c │ │ ├── tinyraytracer.c │ │ └── tty_OLED.c │ ├── FEMTOS │ │ ├── Makefile │ │ └── commander.c │ ├── LIBFEMTOC │ │ ├── Makefile │ │ ├── femtostdlib.h │ │ ├── missing │ │ │ ├── clz.c │ │ │ ├── div.S │ │ │ ├── memcpy.c │ │ │ ├── memset.c │ │ │ ├── mul.S │ │ │ ├── random.c │ │ │ ├── strcmp.c │ │ │ ├── strcpy.c │ │ │ ├── strlen.c │ │ │ ├── strncmp.c │ │ │ └── strncpy.c │ │ ├── print.c │ │ └── printf.c │ ├── LIBFEMTOGL │ │ ├── FGA.c │ │ ├── FGA.h │ │ ├── FGA_mode.c │ │ ├── Makefile │ │ ├── femtoGL.c │ │ ├── femtoGL.h │ │ ├── femtoGLfill_poly.c │ │ ├── femtoGLfill_rect.c │ │ ├── femtoGLline.c │ │ ├── femtoGLsetpixel.c │ │ ├── femtoGLtext.c │ │ ├── femto_GUI.c │ │ ├── font_3x5.S │ │ ├── font_5x6.S │ │ ├── font_8x16.S │ │ ├── font_8x8.S │ │ ├── max7219_text.c │ │ └── tty_init.c │ ├── LIBFEMTORV32 │ │ ├── HardwareConfig_bits.h │ │ ├── HardwareConfig_bits.inc │ │ ├── Makefile │ │ ├── cycles_32.c │ │ ├── cycles_64.S │ │ ├── exec.c │ │ ├── fat_io_lib │ │ │ ├── fat_access.c │ │ │ ├── fat_access.h │ │ │ ├── fat_cache.c │ │ │ ├── fat_cache.h │ │ │ ├── fat_defs.h │ │ │ ├── fat_filelib.c │ │ │ ├── fat_filelib.h │ │ │ ├── fat_format.c │ │ │ ├── fat_format.h │ │ │ ├── fat_list.h │ │ │ ├── fat_misc.c │ │ │ ├── fat_misc.h │ │ │ ├── fat_opts.h │ │ │ ├── fat_string.c │ │ │ ├── fat_string.h │ │ │ ├── fat_table.c │ │ │ ├── fat_table.h │ │ │ ├── fat_types.h │ │ │ ├── fat_write.c │ │ │ └── fat_write.h │ │ ├── femto_elf.c │ │ ├── femto_elf.h │ │ ├── femtorv32.S │ │ ├── femtorv32.h │ │ ├── femtorv32.inc │ │ ├── filesystem.c │ │ ├── gen_hardwareconfig_bits.sh │ │ ├── keyboard.c │ │ ├── keyboard.h │ │ ├── max7219.S │ │ ├── microwait.c │ │ ├── milliseconds.c │ │ ├── milliwait.c │ │ ├── spi_sd.c │ │ ├── ssd1351_1331.S │ │ ├── ssd1351_1331.inc │ │ ├── ssd1351_1331_init.S │ │ ├── uart.S │ │ ├── virtual_io.c │ │ └── wait_cycles.c │ ├── MECRISP_QUINTUS │ │ ├── README.md │ │ ├── mecrisp-quintus-hx1k-with-disassembler.bin │ │ └── mecrisp-quintus-hx1k.bin │ ├── Makefile │ ├── NOTES.txt │ ├── README.txt │ ├── TOOLS │ │ ├── FIRMWARE_WORDS_SRC │ │ │ └── firmware_words.cpp │ │ └── FONT │ │ │ ├── font8x16.xpm │ │ │ ├── font8x8.xpm │ │ │ ├── make_font3x5.c │ │ │ ├── make_font5x6.c │ │ │ ├── make_font8x16.c │ │ │ ├── make_font8x8.c │ │ │ ├── pico8_font3x5.xpm │ │ │ └── pico8_font5x6.xpm │ └── makefile.inc ├── LICENSE.md ├── Makefile ├── NOTES.txt ├── README.md ├── RTL │ ├── Attic │ │ ├── mini_decoder.v │ │ └── mini_femtorv32.v │ ├── CONFIGS │ │ ├── arty_config.v │ │ ├── bench_config.v │ │ ├── cmod_a7_config.v │ │ ├── ecp5evn_config.v │ │ ├── generic_config.v │ │ ├── icebreaker_config.v │ │ ├── icestick_config.v │ │ ├── icesugarnano_config.v │ │ └── ulx3s_config.v │ ├── DEVICES │ │ ├── Buttons.v │ │ ├── FGA.v │ │ ├── GFX_hdmi.v │ │ ├── GFX_modes.v │ │ ├── HardwareConfig.v │ │ ├── HardwareConfig_bits.v │ │ ├── LEDs.v │ │ ├── MAX7219.v │ │ ├── MappedSPIFlash.v │ │ ├── SDCard.v │ │ ├── SSD1351_1331.v │ │ ├── TMDS_encoder.v │ │ ├── ice40up5k_spram.v │ │ ├── uart.v │ │ ├── uart_picosoc.v.orig │ │ └── uart_picosoc_shrunk.v │ ├── PLL │ │ ├── femtopll.v │ │ ├── frequencies.txt │ │ ├── gen_pll.sh │ │ ├── gen_plls.sh │ │ ├── pll_arty.v │ │ ├── pll_cmod_a7.v │ │ ├── pll_ecp5_evn.v │ │ ├── pll_fomu.v │ │ ├── pll_icebreaker.v │ │ ├── pll_icefeather.v │ │ ├── pll_icestick.v │ │ ├── pll_icesugar.v │ │ └── pll_ulx3s.v │ ├── PROCESSOR │ │ ├── README.md │ │ ├── TESTDRIVE │ │ │ ├── README.md │ │ │ ├── femtorv32_testdrive_RV32IM.v │ │ │ ├── femtorv32_testdrive_RV32IMF.v │ │ │ └── femtorv32_testdrive_RV32IM_simF.v │ │ ├── femtorv32_electron.v │ │ ├── femtorv32_gracilis.v │ │ ├── femtorv32_individua.v │ │ ├── femtorv32_intermissum.v │ │ ├── femtorv32_petitbateau.v │ │ ├── femtorv32_quark.v │ │ ├── femtorv32_quark_bicycle.v │ │ ├── femtorv32_tachyon.v │ │ ├── femtorv32_testdrive.v │ │ ├── petitbateau.v │ │ └── utils.v │ ├── SDRAM │ │ ├── muchtoremember.v │ │ └── simulation │ │ │ ├── mt48lc16m16a2.v │ │ │ ├── run-icarus │ │ │ ├── test_sdram.v │ │ │ └── tidyup-icarus │ ├── femtosoc.v │ ├── femtosoc_bench.v │ ├── femtosoc_config.v │ ├── femtosoc_icestick_mecrisp_quintus.v │ └── get_config.v ├── SIM │ ├── FPU_funcs.cpp │ ├── FPU_funcs.h │ ├── SSD1351.cpp │ ├── SSD1351.h │ └── sim_main.cpp ├── TOOLS │ ├── get_symbiflow.sh │ ├── ice4pi_prog │ └── make_config.sh └── TUTORIALS │ ├── DESIGN │ ├── FemtoRV32.md │ ├── FemtoRV32_I.md │ ├── FemtoRV32_II.md │ ├── FemtoRV32_III.md │ ├── FemtoRV32_IV.md │ ├── FemtoRV32_IX.md │ ├── FemtoRV32_V.md │ ├── FemtoRV32_VI.md │ ├── FemtoRV32_VII.md │ ├── FemtoRV32_VIII.md │ ├── FemtoRV32_X.md │ └── Images │ │ ├── 6502.jpg │ │ ├── FemtoRV32_design.jpg │ │ ├── FemtoRV32_design_1.jpg │ │ ├── FemtoRV32_design_2.jpg │ │ ├── FemtoRV32_design_3.jpg │ │ ├── FemtoRV32_design_4.jpg │ │ └── FemtoRV32_design_addradd.jpg │ ├── DSP.md │ ├── ECP5_EVN.md │ ├── FOMU.md │ ├── FPU.md │ ├── FROM_BLINKER_TO_RISCV │ ├── BOARDS │ │ ├── arty.xdc │ │ ├── cmod_a7.xdc │ │ ├── ecp5_evn.lpf │ │ ├── icebreaker.pcf │ │ ├── icestick.pcf │ │ ├── run_arty.sh │ │ ├── run_cmod_a7.sh │ │ ├── run_ecp5evn.sh │ │ ├── run_icebreaker.sh │ │ ├── run_icestick.sh │ │ ├── run_icestick_show.sh │ │ ├── run_ulx3s.sh │ │ └── ulx3s.lpf │ ├── FIRMWARE │ │ ├── COREMARK │ │ │ ├── core_list_join.c │ │ │ ├── core_main.c │ │ │ ├── core_matrix.c │ │ │ ├── core_portme.c │ │ │ ├── core_portme.h │ │ │ ├── core_state.c │ │ │ ├── core_util.c │ │ │ ├── coremark.h │ │ │ └── ee_printf.c │ │ ├── DHRYSTONE │ │ │ ├── dhry.h │ │ │ ├── dhry_1.c │ │ │ ├── dhry_2.c │ │ │ └── stubs.c │ │ ├── GL_tty.h │ │ ├── Makefile │ │ ├── PRECOMPILED │ │ │ ├── RV32I │ │ │ │ ├── COREMARK │ │ │ │ │ ├── DATARAM.hex │ │ │ │ │ └── PROGROM.hex │ │ │ │ ├── DHRYSTONES │ │ │ │ │ ├── DATARAM.hex │ │ │ │ │ └── PROGROM.hex │ │ │ │ └── RAYSTONES │ │ │ │ │ ├── DATARAM.hex │ │ │ │ │ └── PROGROM.hex │ │ │ └── RV32IM │ │ │ │ ├── COREMARK │ │ │ │ ├── DATARAM.hex │ │ │ │ └── PROGROM.hex │ │ │ │ ├── DHRYSTONES │ │ │ │ ├── DATARAM.hex │ │ │ │ └── PROGROM.hex │ │ │ │ └── RAYSTONES │ │ │ │ ├── DATARAM.hex │ │ │ │ └── PROGROM.hex │ │ ├── ST_NICCC.c │ │ ├── blinker.S │ │ ├── bram.ld │ │ ├── dhrystones.c │ │ ├── donut.c │ │ ├── donut2.c │ │ ├── errno.c │ │ ├── hello.S │ │ ├── humanshader.c │ │ ├── io.h │ │ ├── mandel_C.c │ │ ├── mandelbrot.S │ │ ├── memcpy.c │ │ ├── notes.txt │ │ ├── perf.S │ │ ├── perf.h │ │ ├── pi.c │ │ ├── pipeline.ld │ │ ├── print.c │ │ ├── putchar.S │ │ ├── raystones.c │ │ ├── read_spiflash.c │ │ ├── riscv_logo.c │ │ ├── sieve.c │ │ ├── spiflash0.ld │ │ ├── spiflash1.ld │ │ ├── spiflash2.ld │ │ ├── spiflash3.ld │ │ ├── start.S │ │ ├── start_pipeline.S │ │ ├── start_spiflash1.S │ │ ├── test_rdcycle.c │ │ ├── test_spi_flash.c │ │ ├── tinyraytracer.c │ │ ├── tty_graphics.h │ │ ├── tty_graphics_demo.c │ │ └── wait.S │ ├── INTERRUPTS.md │ ├── IceStick_RESET.jpg │ ├── IceStick_SPIFLASH.jpg │ ├── PIPELINE.md │ ├── README.md │ ├── ST_NICCC_tty.png │ ├── bench_iverilog.v │ ├── clockworks.v │ ├── emitter_uart.v │ ├── labels.sh │ ├── mandel_and_riscvlogo.png │ ├── pipeline1.v │ ├── pipeline10.v │ ├── pipeline2.v │ ├── pipeline3.v │ ├── pipeline4.v │ ├── pipeline5.v │ ├── pipeline5_bis.v │ ├── pipeline6.v │ ├── pipeline7.v │ ├── pipeline8.v │ ├── pipeline9.v │ ├── pipelineX.v │ ├── pipelineY.v │ ├── pipelineZ.v │ ├── riscv_assembly.v │ ├── riscv_disassembly.v │ ├── run.sh │ ├── run_verilator.sh │ ├── sim_main.cpp │ ├── spi_flash.v │ ├── step1.v │ ├── step10.v │ ├── step11.v │ ├── step12.v │ ├── step13.v │ ├── step14.v │ ├── step15.v │ ├── step16.v │ ├── step17.v │ ├── step18.v │ ├── step2.v │ ├── step20.v │ ├── step22.v │ ├── step23.v │ ├── step24.v │ ├── step3.v │ ├── step4.v │ ├── step5.v │ ├── step6.v │ ├── step7.v │ ├── step7_with_disasm.v │ ├── step8.v │ ├── step9.v │ ├── terminal.sh │ ├── tinyraytracer_tty.png │ └── verilog_riscv_debugger.png │ ├── HDMI.md │ ├── Ice4Pi.md │ ├── IceBreaker.md │ ├── IceStick.md │ ├── Images │ ├── HDMI.jpg │ ├── ICE40HX1K_and_ECP5.png │ ├── IceBreaker.jpg │ ├── IceStick.jpg │ ├── IceStick_J2.jpg │ ├── IceStick_graphics.jpg │ ├── IceStick_hello.gif │ ├── LedMatrix.jpg │ ├── LedMatrix_connector.jpg │ ├── LedMatrix_on_IceStick.jpg │ ├── OysterPMOD.jpg │ ├── OysterPMOD_1.jpg │ ├── OysterPMOD_2.jpg │ ├── OysterPMOD_3.jpg │ ├── OysterPMOD_4.jpg │ ├── OysterPMOD_demo.gif │ ├── SSD1331_on_ULX3S.jpg │ ├── SSD1351_on_ECP5_EVN.jpg │ ├── SSD1351_on_IceStick.jpg │ ├── SSD1351_on_ULX3S.jpg │ ├── ST_NICCC_on_IceStick.gif │ ├── ULX3S.jpg │ ├── ULX3S_demos.jpg │ ├── arty.jpg │ ├── ecp5_evn.jpg │ ├── iCESugar.jpg │ ├── ice40_Feather.jpg │ ├── ice40_Feather_led_blank.jpg │ ├── ice40_Feather_led_femto.jpg │ ├── ice40_Feather_led_lit.jpg │ ├── ice4pi.jpg │ └── mandelbrot_terminal.gif │ ├── Linux_on_IceStick.v │ ├── Morph.md │ ├── OysterPMOD.md │ ├── README.md │ ├── SDRAM.md │ ├── ULX3S.md │ ├── WSL.md │ ├── arty.md │ ├── beyond_hello_world.md │ ├── iCE_40_Feather.md │ ├── newboard.md │ ├── priviledged.md │ ├── software.md │ ├── spi_flash.md │ ├── toolchain.md │ └── toolchain_arty.md ├── LICENSE ├── LiteX ├── Images │ └── ULX3S_SDRAM.jpg ├── README.md ├── ULX3S.md ├── boards │ ├── README.md │ └── radiona_ulx3s_ex.py ├── litex-boards.md ├── makeit_ulx3s.sh ├── orange_crab.md └── software │ ├── DemoBundle │ ├── Makefile │ ├── README.md │ ├── commands.c │ ├── demos │ │ ├── demos.h │ │ ├── mandelbrot.c │ │ ├── oled_julia.c │ │ ├── oled_riscv_logo.c │ │ ├── oled_test.c │ │ ├── pi.c │ │ └── tinyraytracer.c │ ├── isr.c │ ├── linker.ld │ ├── main.c │ └── raystones_tty.gif │ ├── Doom │ ├── Doom.gif │ ├── Makefile │ ├── README.md │ ├── crt0.S │ ├── doom_oled.gif │ ├── exit.c │ ├── linker.ld │ ├── mc1-doom │ │ ├── README.md │ │ ├── iddoc │ │ │ ├── ChangeLog │ │ │ ├── DOOMLIC.TXT │ │ │ ├── FILES │ │ │ ├── FILES2 │ │ │ ├── README.TXT │ │ │ ├── README.asm │ │ │ ├── README.b │ │ │ ├── README.book │ │ │ ├── README.gl │ │ │ ├── README.sound │ │ │ └── TODO │ │ ├── logo │ │ │ └── mc1-doom-logo.png │ │ └── src │ │ │ ├── .clang-format │ │ │ ├── .gitignore │ │ │ ├── CMakeLists.txt │ │ │ ├── am_map.c │ │ │ ├── am_map.h │ │ │ ├── d_englsh.h │ │ │ ├── d_event.h │ │ │ ├── d_french.h │ │ │ ├── d_items.c │ │ │ ├── d_items.h │ │ │ ├── d_main.c │ │ │ ├── d_main.h │ │ │ ├── d_net.c │ │ │ ├── d_net.h │ │ │ ├── d_player.h │ │ │ ├── d_textur.h │ │ │ ├── d_think.h │ │ │ ├── d_ticcmd.h │ │ │ ├── doomdata.h │ │ │ ├── doomdef.c │ │ │ ├── doomdef.h │ │ │ ├── doomstat.c │ │ │ ├── doomstat.h │ │ │ ├── doomtype.h │ │ │ ├── dstrings.c │ │ │ ├── dstrings.h │ │ │ ├── f_finale.c │ │ │ ├── f_finale.h │ │ │ ├── f_wipe.c │ │ │ ├── f_wipe.h │ │ │ ├── g_game.c │ │ │ ├── g_game.h │ │ │ ├── hu_lib.c │ │ │ ├── hu_lib.h │ │ │ ├── hu_stuff.c │ │ │ ├── hu_stuff.h │ │ │ ├── i_main.c │ │ │ ├── i_net.c │ │ │ ├── i_net.h │ │ │ ├── i_net_dummy.c │ │ │ ├── i_sound.h │ │ │ ├── i_sound_alsa.c │ │ │ ├── i_sound_dummy.c │ │ │ ├── i_system.c │ │ │ ├── i_system.h │ │ │ ├── i_video.h │ │ │ ├── i_video_dummy.c │ │ │ ├── i_video_fb.c │ │ │ ├── i_video_mc1.c │ │ │ ├── i_video_ncurses.c │ │ │ ├── i_video_oled.c │ │ │ ├── i_video_sdl2.c │ │ │ ├── info.c │ │ │ ├── info.h │ │ │ ├── list │ │ │ ├── m_argv.c │ │ │ ├── m_argv.h │ │ │ ├── m_bbox.c │ │ │ ├── m_bbox.h │ │ │ ├── m_cheat.c │ │ │ ├── m_cheat.h │ │ │ ├── m_fixed.c │ │ │ ├── m_fixed.h │ │ │ ├── m_menu.c │ │ │ ├── m_menu.h │ │ │ ├── m_misc.c │ │ │ ├── m_misc.h │ │ │ ├── m_random.c │ │ │ ├── m_random.h │ │ │ ├── m_swap.c │ │ │ ├── m_swap.h │ │ │ ├── mc1-toolchain.cmake │ │ │ ├── mc1.h │ │ │ ├── p_ceilng.c │ │ │ ├── p_doors.c │ │ │ ├── p_enemy.c │ │ │ ├── p_floor.c │ │ │ ├── p_inter.c │ │ │ ├── p_inter.h │ │ │ ├── p_lights.c │ │ │ ├── p_local.h │ │ │ ├── p_map.c │ │ │ ├── p_maputl.c │ │ │ ├── p_mobj.c │ │ │ ├── p_mobj.h │ │ │ ├── p_plats.c │ │ │ ├── p_pspr.c │ │ │ ├── p_pspr.h │ │ │ ├── p_saveg.c │ │ │ ├── p_saveg.h │ │ │ ├── p_setup.c │ │ │ ├── p_setup.h │ │ │ ├── p_sight.c │ │ │ ├── p_spec.c │ │ │ ├── p_spec.h │ │ │ ├── p_switch.c │ │ │ ├── p_telept.c │ │ │ ├── p_tick.c │ │ │ ├── p_tick.h │ │ │ ├── p_user.c │ │ │ ├── r_bsp.c │ │ │ ├── r_bsp.h │ │ │ ├── r_data.c │ │ │ ├── r_data.h │ │ │ ├── r_defs.h │ │ │ ├── r_draw.c │ │ │ ├── r_draw.h │ │ │ ├── r_local.h │ │ │ ├── r_main.c │ │ │ ├── r_main.h │ │ │ ├── r_plane.c │ │ │ ├── r_plane.h │ │ │ ├── r_segs.c │ │ │ ├── r_segs.h │ │ │ ├── r_sky.c │ │ │ ├── r_sky.h │ │ │ ├── r_state.h │ │ │ ├── r_things.c │ │ │ ├── r_things.h │ │ │ ├── run.bat │ │ │ ├── run.sh │ │ │ ├── s_sound.c │ │ │ ├── s_sound.h │ │ │ ├── sounds.c │ │ │ ├── sounds.h │ │ │ ├── st_lib.c │ │ │ ├── st_lib.h │ │ │ ├── st_stuff.c │ │ │ ├── st_stuff.h │ │ │ ├── tables.c │ │ │ ├── tables.h │ │ │ ├── v_video.c │ │ │ ├── v_video.h │ │ │ ├── w_wad.c │ │ │ ├── w_wad.h │ │ │ ├── wi_stuff.c │ │ │ ├── wi_stuff.h │ │ │ ├── z_zone.c │ │ │ └── z_zone.h │ ├── regions.ld │ └── sbrk.c │ ├── Libs │ ├── README.md │ ├── imgui │ │ ├── LICENSE.txt │ │ ├── imconfig.h │ │ ├── imgui.cpp │ │ ├── imgui.h │ │ ├── imgui_demo.cpp │ │ ├── imgui_draw.cpp │ │ ├── imgui_internal.h │ │ ├── imgui_sw.cpp │ │ ├── imgui_sw.h │ │ ├── imgui_tables.cpp │ │ ├── imgui_widgets.cpp │ │ ├── imstb_rectpack.h │ │ ├── imstb_textedit.h │ │ └── imstb_truetype.h │ ├── lite_elf.c │ ├── lite_elf.h │ ├── lite_fb.c │ ├── lite_fb.h │ ├── lite_oled.c │ ├── lite_oled.h │ ├── lite_stdio.c │ └── lite_stdio.h │ ├── LiteOS │ ├── Makefile │ ├── README.md │ ├── builtins.c │ ├── isr.c │ ├── linker.ld │ └── main.c │ ├── Programs │ ├── Makefile │ ├── README.md │ ├── ST_NICCC.c │ ├── crt0.S │ ├── hello.c │ ├── imgui_test.cpp │ ├── linker.ld │ ├── regions.ld │ ├── sbrk.c │ ├── scene1.dat │ ├── spirograph.c │ └── tinyraytracer.c │ ├── README.md │ ├── Tagl │ ├── Lib │ │ ├── LinG.cc │ │ ├── LinG.h │ │ ├── LiteXgport.cc │ │ ├── LiteXgport.h │ │ ├── Makefile │ │ ├── Xgport.cc │ │ ├── Xgport.h │ │ ├── Xpeng.cc │ │ ├── Xpeng.h │ │ ├── Xpeng.ih │ │ ├── ccell.h │ │ ├── ccell.ih │ │ ├── dld.h │ │ ├── dldlinker.cc │ │ ├── dldlinker.h │ │ ├── flags.h │ │ ├── flags.ih │ │ ├── g_20.h │ │ ├── gcomp.cc │ │ ├── gcomp.h │ │ ├── gcomp.ih │ │ ├── gdefs.h │ │ ├── gendraw.h │ │ ├── genfill.h │ │ ├── genpeng.h │ │ ├── gman.cc │ │ ├── gman.h │ │ ├── gman.ih │ │ ├── gmath.h │ │ ├── gmatrix.h │ │ ├── gmatrix.ih │ │ ├── gnum.h │ │ ├── gnum.ih │ │ ├── gport.cc │ │ ├── gport.h │ │ ├── gport.ih │ │ ├── gproc.cc │ │ ├── gproc.h │ │ ├── gproc.ih │ │ ├── gproject.ih │ │ ├── gray0.bm │ │ ├── gray1.bm │ │ ├── gray2.bm │ │ ├── gray3.bm │ │ ├── gray4.bm │ │ ├── gray5.bm │ │ ├── gray6.bm │ │ ├── gray7.bm │ │ ├── gtrans.ih │ │ ├── gvector.h │ │ ├── gvector.ih │ │ ├── gview.ih │ │ ├── list │ │ ├── locgman.cc │ │ ├── locgman.h │ │ ├── locgman.ih │ │ ├── machine.h │ │ ├── peng_24.cc │ │ ├── peng_32x.cc │ │ ├── peng_32xi.cc │ │ ├── peng_555.cc │ │ ├── peng_565.cc │ │ ├── peng_8.cc │ │ ├── peng_x32.cc │ │ ├── polyeng.cc │ │ ├── polyeng.h │ │ ├── polyeng.ih │ │ ├── polygon.h │ │ ├── polygon.ih │ │ ├── rect.h │ │ ├── rect.ih │ │ ├── sintab.cc │ │ ├── sintab.h │ │ ├── stdmok.h │ │ ├── vpool.h │ │ └── vpool.ih │ ├── Makefile │ ├── Objects │ │ ├── 1.tga │ │ ├── 2.tga │ │ ├── 3.tga │ │ ├── apple_logo.geom │ │ ├── apple_logo.ipcol │ │ ├── babem.geom │ │ ├── beethoven.geom │ │ ├── cldsmap.tga │ │ ├── cow.geom │ │ ├── cube.geom │ │ ├── dragon.geom │ │ ├── evrgreen.tga │ │ ├── foot_bones.geom │ │ ├── foot_bones.ipcol │ │ ├── glass4.geom │ │ ├── head.geom │ │ ├── king.geom │ │ ├── meditdn.tga │ │ ├── pear.geom │ │ ├── raytrace.tga │ │ ├── refmap.tga │ │ ├── sticks.geom │ │ ├── sunset2.tga │ │ ├── tagl.geom │ │ ├── teapot.geom │ │ ├── torus.geom │ │ ├── tref.geom │ │ ├── vw.geom │ │ ├── vw.ipcol │ │ ├── x29.geom │ │ └── x29.ipcol │ ├── README.md │ ├── Rotate │ │ ├── bezier.cc │ │ ├── bezier.h │ │ ├── bezier.ih │ │ ├── cmdline.cc │ │ ├── cmdline.h │ │ ├── gobj.cc │ │ ├── gobj.h │ │ ├── gobj.ih │ │ ├── mesh.cc │ │ ├── mesh.h │ │ ├── mesh.ih │ │ ├── rotate.cc │ │ ├── smmesh.cc │ │ ├── smmesh.h │ │ ├── smtri.cc │ │ ├── smtri.h │ │ ├── texture.cc │ │ ├── texture.h │ │ ├── trimesh.cc │ │ ├── trimesh.h │ │ ├── trimesh.ih │ │ ├── vectorf.h │ │ └── vectorf.ih │ ├── crt0.S │ ├── linker.ld │ ├── regions.ld │ ├── sbrk.c │ └── tagl.png │ └── makefile.inc ├── Notes ├── NOTES.txt ├── NOTES_ARTY.txt ├── NOTES_ECP5.txt ├── NOTES_ICEBreaker.txt ├── NOTES_ICEStick.txt └── NOTES_OrangeCrab.txt ├── README.md └── Tools └── install_ice40_toolchain.sh /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.o 3 | *.a 4 | *.exe 5 | *.elf 6 | *.asc 7 | *.bin 8 | *.bit 9 | *.json 10 | *.svf 11 | *.timings 12 | *_out.config 13 | *.000 14 | *.hex 15 | *.vvp 16 | *.dfu 17 | *.rpt 18 | *.blif 19 | *.list 20 | FemtoRV/FIRMWARE/firmware.txt 21 | FemtoRV/FIRMWARE/TOOLCHAIN/ 22 | FemtoRV/FIRMWARE/TOOLS/firmware_words 23 | FemtoRV/RTL/CONFIGS/my_config.v 24 | FemtoRV/femtosoc.txt 25 | FemtoRV/FIRMWARE/config.mk 26 | FemtoRV/TOOLS/environment.yml 27 | FemtoRV/TOOLS/requirements.txt 28 | -------------------------------------------------------------------------------- /Basic/ARTY/ARTY_blink/blinky.v: -------------------------------------------------------------------------------- 1 | module top (input clk_i, input [3:0] sw, output [11:0] led); 2 | 3 | //assign led = {&sw, |sw, ^sw, ~^sw}; 4 | 5 | wire clk; 6 | BUFGCTRL bufg_i ( 7 | .I0(clk_i), 8 | .CE0(1'b1), 9 | .S0(1'b1), 10 | .O(clk) 11 | ); 12 | 13 | 14 | // wire clk = clk_i; 15 | 16 | reg clkdiv; 17 | reg [22:0] ctr; 18 | 19 | always @(posedge clk) {clkdiv, ctr} <= ctr + 1'b1; 20 | 21 | reg [5:0] led_r = 4'b0000; 22 | 23 | always @(posedge clk) begin 24 | if (clkdiv) 25 | led_r <= led_r + 1'b1; 26 | end 27 | 28 | wire [11:0] led_s = led_r[3:0] << (4 * led_r[5:4]); 29 | 30 | assign led = &(led_r[5:4]) ? {3{led_r[3:0]}} : led_s; 31 | 32 | endmodule -------------------------------------------------------------------------------- /Basic/ARTY/ARTY_blink/makeit.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | PROJECT_NAME=blinky 3 | DB_DIR=/usr/share/nextpnr/prjxray-db 4 | CHIPDB_DIR=/usr/share/nextpnr/xilinx-chipdb 5 | PART=xc7a35tcsg324-1 6 | 7 | set -ex 8 | yosys -p "synth_xilinx -flatten -abc9 -nobram -arch xc7 -top top; write_json ${PROJECT_NAME}.json" ${PROJECT_NAME}.v 9 | nextpnr-xilinx --chipdb ${CHIPDB_DIR}/xc7a35t.bin --xdc arty.xdc --json ${PROJECT_NAME}.json --write ${PROJECT_NAME}_routed.json --fasm ${PROJECT_NAME}.fasm 10 | fasm2frames.py --part ${PART} --db-root ${DB_DIR}/artix7 ${PROJECT_NAME}.fasm > ${PROJECT_NAME}.frames 11 | xc7frames2bit --part_file ${DB_DIR}/artix7/${PART}/part.yaml --part_name ${PART} --frm_file ${PROJECT_NAME}.frames --output_file ${PROJECT_NAME}.bit 12 | #To send to SRAM: 13 | openFPGALoader --board arty ${PROJECT_NAME}.bit 14 | #To send to FLASH: 15 | #openFPGALoader --board arty -f ${PROJECT_NAME}.bit -------------------------------------------------------------------------------- /Basic/FOMU/FOMU_VGA/Images/FOMU_VGA.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/Basic/FOMU/FOMU_VGA/Images/FOMU_VGA.gif -------------------------------------------------------------------------------- /Basic/FOMU/FOMU_VGA/Images/FOMU_in_USB.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/Basic/FOMU/FOMU_VGA/Images/FOMU_in_USB.jpg -------------------------------------------------------------------------------- /Basic/FOMU/FOMU_VGA/Images/FrankenFOMU.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/Basic/FOMU/FOMU_VGA/Images/FrankenFOMU.png -------------------------------------------------------------------------------- /Basic/FOMU/FOMU_VGA/Images/VGA.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/Basic/FOMU/FOMU_VGA/Images/VGA.jpg -------------------------------------------------------------------------------- /Basic/FOMU/FOMU_VGA/Images/vga_mode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/Basic/FOMU/FOMU_VGA/Images/vga_mode.png -------------------------------------------------------------------------------- /Basic/FOMU/FOMU_VGA/fomu-pvt.pcf: -------------------------------------------------------------------------------- 1 | set_io rgb0 A5 2 | set_io rgb1 B5 3 | set_io rgb2 C5 4 | set_io clki F4 5 | set_io user_1 E4 6 | set_io user_2 D5 7 | set_io user_3 E5 8 | set_io user_4 F5 9 | set_io spi_mosi F1 10 | set_io spi_miso E1 11 | set_io spi_clk D1 12 | set_io spi_io2 F2 13 | set_io spi_io3 B1 14 | set_io spi_cs C1 15 | set_io usb_dn A2 16 | set_io usb_dp A1 17 | set_io usb_dp_pu A4 18 | -------------------------------------------------------------------------------- /Basic/FOMU/FOMU_VGA/makeit.sh: -------------------------------------------------------------------------------- 1 | rm -fr vga.bit vga.dfu vga.asc vga.json 2 | yosys -DPVT -q -p 'synth_ice40 -dsp -top vga -json vga.json' vga.v 3 | nextpnr-ice40 --up5k --package uwg30 --pcf fomu-pvt.pcf --json vga.json --asc vga.asc 4 | icepack vga.asc vga.bit 5 | cp vga.bit vga.dfu 6 | dfu-suffix -v 1209 -p 70b1 -a vga.dfu 7 | dfu-util -D vga.dfu 8 | 9 | -------------------------------------------------------------------------------- /Basic/FOMU/FOMU_blink/fomu-pvt.pcf: -------------------------------------------------------------------------------- 1 | set_io rgb0 A5 2 | set_io rgb1 B5 3 | set_io rgb2 C5 4 | set_io pmod_1 E4 5 | set_io pmod_2 D5 6 | set_io pmod_3 E5 7 | set_io pmod_4 F5 8 | set_io pmoda_1 E4 9 | set_io pmoda_2 D5 10 | set_io pmoda_3 E5 11 | set_io pmoda_4 F5 12 | set_io clki F4 13 | set_io user_1 E4 14 | set_io user_2 D5 15 | set_io user_3 E5 16 | set_io user_4 F5 17 | set_io touch_1 E4 18 | set_io touch_2 D5 19 | set_io touch_3 E5 20 | set_io touch_4 F5 21 | set_io spi_mosi F1 22 | set_io spi_miso E1 23 | set_io spi_clk D1 24 | set_io spi_io2 F2 25 | set_io spi_io3 B1 26 | set_io spi_cs C1 27 | set_io usb_dn A2 28 | set_io usb_dp A1 29 | set_io usb_dp_pu A4 30 | -------------------------------------------------------------------------------- /Basic/FOMU/FOMU_blink/makeit.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -o nounset 3 | set -o errexit 4 | 5 | yosys -DPVT -p 'synth_ice40 -top top -json blink.json' blink.v 6 | nextpnr-ice40 --up5k --package uwg30 --pcf fomu-pvt.pcf --json blink.json --asc blink.asc 7 | icepack blink.asc blink.bit 8 | cp blink.bit blink.dfu 9 | dfu-suffix -v 1209 -p 70b1 -a blink.dfu 10 | dfu-util -D blink.dfu 11 | -------------------------------------------------------------------------------- /Basic/ICESTICK/Blinker/blink.pcf: -------------------------------------------------------------------------------- 1 | set_io clock 21 2 | set_io led1 99 3 | set_io led2 98 4 | set_io led3 97 5 | set_io led4 96 6 | set_io led5 95 7 | 8 | -------------------------------------------------------------------------------- /Basic/ICESTICK/Blinker/blink.v: -------------------------------------------------------------------------------- 1 | module blink ( 2 | input clock, 3 | output led1, led2, led3, led4, led5 4 | ); 5 | 6 | localparam BITS = 25; 7 | reg [BITS-1:0] counter; 8 | 9 | always@(posedge clock) begin 10 | counter <= counter + 1; 11 | end 12 | 13 | assign {led1, led2, led3, led4, led5} = counter[BITS-1 : BITS-5]; 14 | 15 | endmodule -------------------------------------------------------------------------------- /Basic/ICESTICK/Blinker/makeit.sh: -------------------------------------------------------------------------------- 1 | PROJECTNAME=blink 2 | VERILOGS="$PROJECTNAME.v" 3 | yosys -q -p "synth_ice40 -top $PROJECTNAME -json $PROJECTNAME.json" $VERILOGS || exit 4 | nextpnr-ice40 --force --json $PROJECTNAME.json --pcf $PROJECTNAME.pcf --asc $PROJECTNAME.asc --freq 12 --hx1k --package tq144 $1 || exit 5 | icetime -p $PROJECTNAME.pcf -P tq144 -r $PROJECTNAME.timings -d hx1k -t $PROJECTNAME.asc 6 | icepack $PROJECTNAME.asc $PROJECTNAME.bin || exit 7 | iceprog $PROJECTNAME.bin || exit 8 | echo DONE. 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Basic/ICESTICK/LedMatrix/led_matrix.pcf: -------------------------------------------------------------------------------- 1 | set_io pclk 21 2 | 3 | set_io leds_din 60 4 | set_io leds_cs 56 5 | set_io leds_clk 48 6 | 7 | set_io D1 99 8 | set_io D2 98 9 | set_io D3 97 10 | set_io D4 96 11 | set_io D5 95 12 | -------------------------------------------------------------------------------- /Basic/ICESTICK/LedMatrix/makeit.sh: -------------------------------------------------------------------------------- 1 | PROJECTNAME=led_matrix 2 | VERILOGS="$PROJECTNAME.v ../Libs/MAX7219.v ../Libs/font_rom.v ../Libs/scroller.v" 3 | yosys -q -p "synth_ice40 -top $PROJECTNAME -json $PROJECTNAME.json" $VERILOGS || exit 4 | nextpnr-ice40 --force --json $PROJECTNAME.json --pcf $PROJECTNAME.pcf --asc $PROJECTNAME.asc --freq 12 --hx1k --package tq144 $1 || exit 5 | icetime -p $PROJECTNAME.pcf -P tq144 -r $PROJECTNAME.timings -d hx1k -t $PROJECTNAME.asc 6 | icepack $PROJECTNAME.asc $PROJECTNAME.bin || exit 7 | iceprog $PROJECTNAME.bin || exit 8 | echo DONE. 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Basic/ICESTICK/LedMatrix/notes.txt: -------------------------------------------------------------------------------- 1 | envoyer un octet: 2 | Pour chaque bit de 7 à 0 3 | clock <- 0 4 | data <- bit 5 | clock <- 1 6 | 7 | envoyer une commande: 8 | cs <- 0 9 | envoyer l'adresse (1 octet) 10 | envoyer la donnée 11 | cs <- 1 12 | clk <- 0 13 | 14 | sequence d'initialisation: 15 | 0x09, 0x00 -> Decode-Mode: 00 = no decode 16 | 0x0a, 0x01 -> Intensity: (00 .. 0f) 17 | 0x0b, 0x07 -> Scan limit: 0x07 = show all lines 18 | 0x0c, 0x01 -> Shut down: 0x01 = normal operation 19 | 0x0f, 0x00 -> Display Test: 0x00 = normal operation 20 | 21 | allumer une rangée de leds: 22 | envoyer row (in 1..8), data 23 | 24 | clock: 10 MHz 25 | 26 | -------------------------------------------------------------------------------- /Basic/ICESTICK/LedTerminal/led_terminal.pcf: -------------------------------------------------------------------------------- 1 | set_io pclk 21 2 | 3 | set_io leds_din 60 4 | set_io leds_cs 56 5 | set_io leds_clk 48 6 | 7 | set_io D1 99 8 | set_io D2 98 9 | set_io D3 97 10 | set_io D4 96 11 | set_io D5 95 12 | 13 | set_io TXD 8 14 | set_io RXD 9 15 | -------------------------------------------------------------------------------- /Basic/ICESTICK/LedTerminal/led_terminal.pcf.LedMatrixOnPMod: -------------------------------------------------------------------------------- 1 | set_io pclk 21 2 | 3 | set_io leds_din 91 4 | set_io leds_cs 90 5 | set_io leds_clk 88 6 | 7 | set_io D1 99 8 | set_io D2 98 9 | set_io D3 97 10 | set_io D4 96 11 | set_io D5 95 12 | 13 | set_io TXD 8 14 | set_io RXD 9 15 | -------------------------------------------------------------------------------- /Basic/ICESTICK/LedTerminal/led_terminal.pcf.LedMatrixOnTheSide: -------------------------------------------------------------------------------- 1 | set_io pclk 21 2 | 3 | set_io leds_din 60 4 | set_io leds_cs 56 5 | set_io leds_clk 48 6 | 7 | set_io D1 99 8 | set_io D2 98 9 | set_io D3 97 10 | set_io D4 96 11 | set_io D5 95 12 | 13 | set_io TXD 8 14 | set_io RXD 9 15 | -------------------------------------------------------------------------------- /Basic/ICESTICK/LedTerminal/makeit.sh: -------------------------------------------------------------------------------- 1 | PROJECTNAME=led_terminal 2 | VERILOGS="$PROJECTNAME.v ../Libs/uart.v ../Libs/font_rom.v ../Libs/MAX7219.v ../Libs/scroller.v" 3 | yosys -q -p "synth_ice40 -top $PROJECTNAME -json $PROJECTNAME.json" $VERILOGS || exit 4 | nextpnr-ice40 --force --json $PROJECTNAME.json --pcf $PROJECTNAME.pcf --asc $PROJECTNAME.asc --freq 12 --hx1k --package tq144 $1 || exit 5 | icetime -p $PROJECTNAME.pcf -P tq144 -r $PROJECTNAME.timings -d hx1k -t $PROJECTNAME.asc 6 | icepack $PROJECTNAME.asc $PROJECTNAME.bin || exit 7 | iceprog $PROJECTNAME.bin || exit 8 | echo DONE. 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Basic/ICESTICK/LedTerminal/notes.txt: -------------------------------------------------------------------------------- 1 | screen /dev/ttyUSB1 115200 2 | -------------------------------------------------------------------------------- /Basic/ICESTICK/LedTerminal/start.sh: -------------------------------------------------------------------------------- 1 | miniterm.py --dtr=0 /dev/ttyUSB1 115200 2 | # or screen /dev/ttyUSB1 112000 (<ctrl> a \ to exit) 3 | 4 | 5 | -------------------------------------------------------------------------------- /Basic/ICESTICK/Libs/MAX7219.v: -------------------------------------------------------------------------------- 1 | // Simple driver for MAX7219 led matrix 2 | // Bruno Levy, May 2020 3 | 4 | module MAX7219 ( 5 | input wire clk, // Max 10 MHz 6 | input wire reset, 7 | input wire [15:0] address_data, // a7...a0 d7...d0 8 | input wire wr, // raise to send data 9 | output wire d_out, // MAX7219 D pin 10 | output wire cs_out, // MAX7219 CS pin 11 | output wire clk_out, // MAX7219 CLK pin 12 | output wire busy // 1 if currently sending data 13 | ); 14 | 15 | reg[4:0] bitcount; // 0 means idle 16 | reg[15:0] shifter; 17 | 18 | assign d_out = shifter[15]; 19 | wire sending = |bitcount; 20 | assign cs_out = !sending; 21 | assign busy = sending; 22 | assign clk_out = sending && clk; 23 | 24 | always @(posedge clk) 25 | begin 26 | if(reset) begin 27 | shifter <= 0; 28 | bitcount <= 0; 29 | end else begin 30 | if(wr) begin 31 | shifter <= address_data; 32 | bitcount <= 16; 33 | end else if(sending) begin 34 | bitcount <= bitcount - 5'd1; 35 | shifter <= { shifter[14:0], 1'b0 }; 36 | end 37 | end 38 | end 39 | 40 | endmodule 41 | 42 | -------------------------------------------------------------------------------- /Basic/ICESTICK/Oled/makeit.sh: -------------------------------------------------------------------------------- 1 | PROJECTNAME=oled 2 | VERILOGS="$PROJECTNAME.v ../Libs/SSD1351.v" 3 | yosys -q -p "synth_ice40 -top $PROJECTNAME -json $PROJECTNAME.json" $VERILOGS || exit 4 | nextpnr-ice40 --force --json $PROJECTNAME.json --pcf $PROJECTNAME.pcf --asc $PROJECTNAME.asc --freq 12 --hx1k --package tq144 $1 || exit 5 | icetime -p $PROJECTNAME.pcf -P tq144 -r $PROJECTNAME.timings -d hx1k -t $PROJECTNAME.asc 6 | icepack $PROJECTNAME.asc $PROJECTNAME.bin || exit 7 | iceprog $PROJECTNAME.bin || exit 8 | echo DONE. 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Basic/ICESTICK/Oled/oled.pcf: -------------------------------------------------------------------------------- 1 | set_io pclk 21 2 | 3 | set_io oled_DIN 91 4 | set_io oled_CLK 90 5 | set_io oled_CS 88 6 | set_io oled_DC 87 7 | set_io oled_RST 78 8 | 9 | set_io D1 99 10 | set_io D2 98 11 | set_io D3 97 12 | set_io D4 96 13 | set_io D5 95 14 | -------------------------------------------------------------------------------- /Basic/ICESTICK/Serial/makeit.sh: -------------------------------------------------------------------------------- 1 | PROJECTNAME=serial 2 | VERILOGS="$PROJECTNAME.v uart.v" 3 | yosys -q -p "synth_ice40 -top $PROJECTNAME -json $PROJECTNAME.json" $VERILOGS || exit 4 | nextpnr-ice40 --json $PROJECTNAME.json --pcf $PROJECTNAME.pcf --asc $PROJECTNAME.asc --freq 12 --hx1k --package tq144 || exit 5 | icepack $PROJECTNAME.asc $PROJECTNAME.bin || exit 6 | iceprog $PROJECTNAME.bin || exit 7 | echo DONE. 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Basic/ICESTICK/Serial/serial.pcf: -------------------------------------------------------------------------------- 1 | set_io resetq 3 2 | set_io pclk 21 3 | set_io led1 99 4 | set_io led2 98 5 | set_io led3 97 6 | set_io led4 96 7 | set_io led5 95 8 | set_io TXD 8 9 | set_io RXD 9 10 | -------------------------------------------------------------------------------- /Basic/ICESTICK/Serial/start.sh: -------------------------------------------------------------------------------- 1 | miniterm.py --dtr=0 /dev/ttyUSB1 115200 2 | 3 | 4 | -------------------------------------------------------------------------------- /Basic/ULX3S/ULX3S_SDRAM_hdmi/README.md: -------------------------------------------------------------------------------- 1 | SDRAM framebuffer Test 2 | ====================== 3 | 4 | _WIP_ 5 | 6 | My experiments to learn how to talk to an SDRAM chip and display a 7 | framebuffer stored on it to HDMI. 8 | 9 | More notes and information: 10 | - [SDRAM](https://github.com/BrunoLevy/learn-fpga/blob/master/FemtoRV/TUTORIALS/SDRAM.md). 11 | - [HDMI](https://github.com/BrunoLevy/learn-fpga/blob/master/FemtoRV/TUTORIALS/HDMI.md). 12 | 13 | -------------------------------------------------------------------------------- /Basic/ULX3S/ULX3S_SDRAM_hdmi/makeit.sh: -------------------------------------------------------------------------------- 1 | PROJECTNAME=SDRAM_HDMI_test 2 | VERILOGS="$PROJECTNAME.v HDMI_clock.v TMDS_encoder.v" 3 | 4 | if [ $1 == "clean" ]; then 5 | rm -f *.bit *.json *.config *.svf *~ 6 | exit 7 | fi 8 | 9 | yosys -p "synth_ecp5 -abc9 -top $PROJECTNAME -json $PROJECTNAME.json" $VERILOGS || exit 10 | nextpnr-ecp5 --json $PROJECTNAME.json --lpf ulx3s.lpf --textcfg $PROJECTNAME.config --85k --freq 25 --package CABGA381 || exit 11 | ecppack --compress --svf-rowsize 100000 --svf $PROJECTNAME.svf $PROJECTNAME.config $PROJECTNAME.bit || exit 12 | ujprog $PROJECTNAME.bit || exit 13 | # To flash permanently, use instead: 14 | # Use ujprog -j FLASH $PROJECTNAME.bit -------------------------------------------------------------------------------- /Basic/ULX3S/ULX3S_hdmi/README.md: -------------------------------------------------------------------------------- 1 | HDMI Test 2 | ========= 3 | 4 | My experiments to learn how to display stuff on HDMI. 5 | More information [here](https://github.com/BrunoLevy/learn-fpga/blob/master/FemtoRV/TUTORIALS/HDMI.md). 6 | 7 | -------------------------------------------------------------------------------- /Basic/ULX3S/ULX3S_hdmi/makeit.sh: -------------------------------------------------------------------------------- 1 | PROJECTNAME=HDMI_test_hires 2 | #PROJECTNAME=HDMI_test 3 | #PROJECTNAME=HDMI_test_DDR # This one uses DDR primitives for higher freq, ready for higher res (to be tested) 4 | VERILOGS="$PROJECTNAME.v HDMI_clock.v TMDS_encoder.v" 5 | 6 | if [ $1 == "clean" ]; then 7 | rm -f *.bit *.json *.config *.svf *~ 8 | exit 9 | fi 10 | 11 | yosys -p "synth_ecp5 -abc9 -top $PROJECTNAME -json $PROJECTNAME.json" $VERILOGS || exit 12 | nextpnr-ecp5 --force --timing-allow-fail --json $PROJECTNAME.json --lpf ulx3s.lpf --textcfg $PROJECTNAME.config --85k --freq 25 --package CABGA381 || exit 13 | ecppack --compress --svf-rowsize 100000 --svf $PROJECTNAME.svf $PROJECTNAME.config $PROJECTNAME.bit || exit 14 | ujprog $PROJECTNAME.bit || exit 15 | # To flash permanently, use instead: 16 | # Use ujprog -j FLASH $PROJECTNAME.bit -------------------------------------------------------------------------------- /Basic/ULX3S/ULX3S_hdmi/ulx3s.lpf: -------------------------------------------------------------------------------- 1 | # See https://github.com/emard/ulx3s/blob/master/doc/constraints/ulx3s_v20.lpf 2 | 3 | ## Clock 4 | 5 | LOCATE COMP "pclk" SITE "G2"; 6 | IOBUF PORT "pclk" PULLMODE=NONE IO_TYPE=LVCMOS33; 7 | FREQUENCY PORT "pclk" 25 MHZ; 8 | 9 | ## HDMI 10 | # Note: if using IO_TYPE=LVCMOS33D, it automatically 11 | # generates the negative (_dn[]) pins from the 12 | # positive ones. 13 | LOCATE COMP "gpdi_dp[0]" SITE "A16"; # Blue + 14 | LOCATE COMP "gpdi_dn[0]" SITE "B16"; # Blue - 15 | LOCATE COMP "gpdi_dp[1]" SITE "A14"; # Green + 16 | LOCATE COMP "gpdi_dn[1]" SITE "C14"; # Green - 17 | LOCATE COMP "gpdi_dp[2]" SITE "A12"; # Red + 18 | LOCATE COMP "gpdi_dn[2]" SITE "A13"; # Red - 19 | LOCATE COMP "gpdi_dp[3]" SITE "A17"; # Clock + 20 | LOCATE COMP "gpdi_dn[3]" SITE "B18"; # Clock - 21 | IOBUF PORT "gpdi_dp[0]" IO_TYPE=LVCMOS33D DRIVE=4; 22 | IOBUF PORT "gpdi_dn[0]" IO_TYPE=LVCMOS33D DRIVE=4; 23 | IOBUF PORT "gpdi_dp[1]" IO_TYPE=LVCMOS33D DRIVE=4; 24 | IOBUF PORT "gpdi_dn[1]" IO_TYPE=LVCMOS33D DRIVE=4; 25 | IOBUF PORT "gpdi_dp[2]" IO_TYPE=LVCMOS33D DRIVE=4; 26 | IOBUF PORT "gpdi_dn[2]" IO_TYPE=LVCMOS33D DRIVE=4; 27 | IOBUF PORT "gpdi_dp[3]" IO_TYPE=LVCMOS33D DRIVE=4; 28 | IOBUF PORT "gpdi_dn[3]" IO_TYPE=LVCMOS33D DRIVE=4; 29 | 30 | 31 | -------------------------------------------------------------------------------- /FemtoRV/BOARDS/arty_defs.v: -------------------------------------------------------------------------------- 1 | `define ARTY 2 | -------------------------------------------------------------------------------- /FemtoRV/BOARDS/bench.mk: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # testbench pseudo-board 3 | ################################################################################ 4 | 5 | BENCH: BENCH.verilator 6 | 7 | BENCH.firmware_config: 8 | BOARD=testbench TOOLS/make_config.sh -DBENCH_VERILATOR 9 | (cd FIRMWARE; make libs) 10 | 11 | BENCH.icarus: 12 | (cd RTL; iverilog -IPROCESSOR -IDEVICES femtosoc_bench.v \ 13 | -o ../femtosoc_bench.vvp) 14 | vvp femtosoc_bench.vvp 15 | 16 | BENCH.verilator: 17 | verilator -DBENCH_VERILATOR --top-module femtoRV32_bench \ 18 | -IRTL -IRTL/PROCESSOR -IRTL/DEVICES -IRTL/PLL \ 19 | -CFLAGS '-I../SIM' -LDFLAGS '-lglfw -lGL' \ 20 | -FI FPU_funcs.h \ 21 | --cc --exe SIM/sim_main.cpp SIM/FPU_funcs.cpp SIM/SSD1351.cpp RTL/femtosoc_bench.v 22 | (cd obj_dir; make -f VfemtoRV32_bench.mk) 23 | obj_dir/VfemtoRV32_bench 24 | 25 | BENCH.lint: 26 | verilator -DBENCH --lint-only --top-module femtoRV32_bench \ 27 | -IRTL -IRTL/PROCESSOR -IRTL/DEVICES -IRTL/PLL femtosoc_bench.v 28 | ################################################################################ 29 | -------------------------------------------------------------------------------- /FemtoRV/BOARDS/ecp5-evn.cfg: -------------------------------------------------------------------------------- 1 | # this supports ECP5 Evaluation Board 2 | 3 | interface ftdi 4 | ftdi_device_desc "Lattice ECP5 Evaluation Board" 5 | ftdi_vid_pid 0x0403 0x6010 6 | # channel 1 does not have any functionality 7 | ftdi_channel 0 8 | # just TCK TDI TDO TMS, no reset 9 | ftdi_layout_init 0xfff8 0xfffb 10 | reset_config none 11 | 12 | # default speed 13 | adapter_khz 5000 14 | 15 | # ECP5 device - LFE5UM5G-85F 16 | jtag newtap ecp5 tap -irlen 8 -expected-id 0x81113043 17 | -------------------------------------------------------------------------------- /FemtoRV/BOARDS/ecp5_evn.lpf: -------------------------------------------------------------------------------- 1 | LOCATE COMP "pclk" SITE "A10"; 2 | IOBUF PORT "pclk" IO_TYPE=LVCMOS33; 3 | FREQUENCY PORT "pclk" 12 MHZ; 4 | 5 | LOCATE COMP "RESET" SITE "P4"; 6 | IOBUF PORT "RESET" IO_TYPE=LVCMOS33; 7 | 8 | LOCATE COMP "oled_DIN" SITE "D11"; 9 | LOCATE COMP "oled_CLK" SITE "D12"; 10 | LOCATE COMP "oled_CS" SITE "D13"; 11 | LOCATE COMP "oled_DC" SITE "E12"; 12 | LOCATE COMP "oled_RST" SITE "E13"; 13 | 14 | IOBUF PORT "oled_DIN" IO_TYPE=LVCMOS33; 15 | IOBUF PORT "oled_CLK" IO_TYPE=LVCMOS33; 16 | IOBUF PORT "oled_CS" IO_TYPE=LVCMOS33; 17 | IOBUF PORT "oled_DC" IO_TYPE=LVCMOS33; 18 | IOBUF PORT "oled_RST" IO_TYPE=LVCMOS33; 19 | 20 | LOCATE COMP "D1" SITE "B17"; 21 | LOCATE COMP "D2" SITE "A17"; 22 | LOCATE COMP "D3" SITE "C17"; 23 | LOCATE COMP "D4" SITE "B18"; 24 | LOCATE COMP "D5" SITE "A18"; 25 | 26 | IOBUF PORT "D1" IO_TYPE=LVCMOS33; 27 | IOBUF PORT "D2" IO_TYPE=LVCMOS33; 28 | IOBUF PORT "D3" IO_TYPE=LVCMOS33; 29 | IOBUF PORT "D4" IO_TYPE=LVCMOS33; 30 | IOBUF PORT "D5" IO_TYPE=LVCMOS33; 31 | 32 | -------------------------------------------------------------------------------- /FemtoRV/BOARDS/ecp5_evn.mk: -------------------------------------------------------------------------------- 1 | YOSYS_ECP5_EVN_OPT=-DECP5_EVN -q -p "synth_ecp5 -top $(PROJECTNAME) -json $(PROJECTNAME).json" 2 | NEXTPNR_ECP5_EVN_OPT=--force --json $(PROJECTNAME).json --lpf BOARDS/ecp5_evn.lpf \ 3 | --textcfg $(PROJECTNAME)_out.config --um5g-85k --freq 50 --package CABGA381 4 | 5 | ####################################################################################################################### 6 | 7 | ECP5_EVN: ECP5_EVN.firmware_config ECP5_EVN.synth ECP5_EVN.prog 8 | 9 | ECP5_EVN.synth: FIRMWARE/firmware.hex 10 | TOOLS/make_config.sh -DECP5_EVN 11 | yosys $(YOSYS_ECP5_EVN_OPT) $(VERILOGS) 12 | nextpnr-ecp5 $(NEXTPNR_ECP5_EVN_OPT) 13 | ecppack --compress --svf-rowsize 100000 --svf $(PROJECTNAME).svf $(PROJECTNAME)_out.config $(PROJECTNAME).bit 14 | 15 | ECP5_EVN.prog: 16 | ujprog $(PROJECTNAME).bit 17 | # openocd -f BOARDS/ecp5-evn.cfg -c "transport select jtag; init; svf $(PROJECTNAME).svf; exit" 18 | 19 | ECP5_EVN.prog_flash: 20 | ujprog -j flash $(PROJECTNAME).bit 21 | 22 | ECP5_EVN.firmware_config: 23 | BOARD=ecp5_evn TOOLS/make_config.sh -DECP5_EVN 24 | (cd FIRMWARE; make libs) -------------------------------------------------------------------------------- /FemtoRV/BOARDS/fomu-pvt.pcf: -------------------------------------------------------------------------------- 1 | set_io rgb0 A5 2 | set_io rgb1 B5 3 | set_io rgb2 C5 4 | set_io pmod_1 E4 5 | set_io pmod_2 D5 6 | set_io pmod_3 E5 7 | set_io pmod_4 F5 8 | set_io pmoda_1 E4 9 | set_io pmoda_2 D5 10 | set_io pmoda_3 E5 11 | set_io pmoda_4 F5 12 | set_io pclk F4 13 | set_io user_1 E4 14 | set_io user_2 D5 15 | set_io user_3 E5 16 | set_io user_4 F5 17 | set_io touch_1 E4 18 | set_io touch_2 D5 19 | set_io touch_3 E5 20 | set_io touch_4 F5 21 | set_io spi_mosi F1 22 | set_io spi_miso E1 23 | set_io spi_clk D1 24 | set_io spi_io2 F2 25 | set_io spi_io3 B1 26 | set_io spi_cs C1 27 | set_io usb_dn A2 28 | set_io usb_dp A1 29 | set_io usb_dp_pu A4 30 | set_io RESET E4 31 | -------------------------------------------------------------------------------- /FemtoRV/BOARDS/fomu.mk: -------------------------------------------------------------------------------- 1 | YOSYS_FOMU_OPT=-DFOMU -q -p "synth_ice40 -dsp -top $(PROJECTNAME) -json $(PROJECTNAME).json" 2 | NEXTPNR_FOMU_OPT=--json $(PROJECTNAME).json --pcf BOARDS/fomu-pvt.pcf --asc $(PROJECTNAME).asc \ 3 | --freq 12 --up5k --package uwg30 4 | 5 | ####################################################################################################################### 6 | 7 | FOMU: FOMU.firmware_config FOMU.synth FOMU.prog 8 | 9 | FOMU.synth: FIRMWARE/firmware.hex 10 | TOOLS/make_config.sh -DFOMU 11 | yosys $(YOSYS_FOMU_OPT) $(VERILOGS) 12 | nextpnr-ice40 $(NEXTPNR_FOMU_OPT) 13 | icetime -p BOARDS/fomu-pvt.pcf -P uwg30 -r $(PROJECTNAME).timings -d up5k -t $(PROJECTNAME).asc 14 | icepack -s $(PROJECTNAME).asc $(PROJECTNAME).bin 15 | mv $(PROJECTNAME).bin $(PROJECTNAME).dfu 16 | dfu-suffix -v 1209 -p 70b1 -a $(PROJECTNAME).dfu 17 | 18 | FOMU.show: FIRMWARE/firmware.hex 19 | yosys $(YOSYS_FOMU_OPT) $(VERILOGS) 20 | nextpnr-ice40 $(NEXTPNR_FOMU_OPT) --pcf-allow-unconstrained --gui 21 | 22 | FOMU.prog: 23 | dfu-util -D $(PROJECTNAME).dfu 24 | 25 | FOMU.firmware_config: 26 | BOARD=fomu TOOLS/make_config.sh -DFOMU 27 | (cd FIRMWARE; make libs) 28 | ####################################################################################################################### 29 | -------------------------------------------------------------------------------- /FemtoRV/BOARDS/ice4pi.pcf: -------------------------------------------------------------------------------- 1 | icestick.pcf -------------------------------------------------------------------------------- /FemtoRV/BOARDS/icebreaker.pcf: -------------------------------------------------------------------------------- 1 | set_io pclk 35 2 | 3 | set_io D1 27 4 | set_io D2 21 5 | set_io D3 25 6 | set_io D4 23 7 | set_io D5 26 8 | 9 | set_io TXD 9 10 | set_io RXD 6 11 | 12 | set_io RESET 10 13 | 14 | # wired to PMOD 1A 15 | set_io ledmtx_DIN 45 16 | set_io ledmtx_CS 47 17 | set_io ledmtx_CLK 2 18 | 19 | # wired to PMOD 1A 20 | set_io oled_DIN 44 21 | set_io oled_CLK 46 22 | set_io oled_CS 48 23 | set_io oled_DC 3 24 | set_io oled_RST 4 25 | 26 | set_io spi_cs_n 16 27 | set_io spi_miso 17 28 | set_io spi_mosi 14 29 | set_io spi_clk 15 30 | 31 | set_io spi_io0 14 32 | set_io spi_io1 17 33 | set_io spi_io2 12 34 | set_io spi_io3 13 35 | -------------------------------------------------------------------------------- /FemtoRV/BOARDS/icefeather.mk: -------------------------------------------------------------------------------- 1 | YOSYS_ICEFEATHER_OPT=-DICE_FEATHER -q -p "synth_ice40 -relut -top $(PROJECTNAME) -json $(PROJECTNAME).json" 2 | NEXTPNR_ICEFEATHER_OPT=--force --json $(PROJECTNAME).json --pcf BOARDS/icefeather.pcf --asc $(PROJECTNAME).asc \ 3 | --freq 12 --up5k --package sg48 4 | 5 | ####################################################################################################################### 6 | 7 | ICEFEATHER: ICEFEATHER.firmware_config ICEFEATHER.synth ICEFEATHER.prog 8 | 9 | ICEFEATHER.synth: FIRMWARE/firmware.hex 10 | TOOLS/make_config.sh -DICE_FEATHER 11 | yosys $(YOSYS_ICEFEATHER_OPT) $(VERILOGS) 12 | nextpnr-ice40 $(NEXTPNR_ICEFEATHER_OPT) 13 | icetime -p BOARDS/icefeather.pcf -P sg48 -r $(PROJECTNAME).timings -d up5k -t $(PROJECTNAME).asc 14 | icepack -s $(PROJECTNAME).asc $(PROJECTNAME).bin 15 | 16 | ICEFEATHER.show: FIRMWARE/firmware.hex 17 | yosys $(YOSYS_ICEFEATHER_OPT) $(VERILOGS) 18 | nextpnr-ice40 $(NEXTPNR_ICEFEATHER_OPT) --gui 19 | 20 | ICEFEATHER.prog: 21 | iceprog $(PROJECTNAME).bin 22 | 23 | ICEFEATHER.firmware_config: 24 | BOARD=icefeather TOOLS/make_config.sh -DICE_FEATHER 25 | (cd FIRMWARE; make libs) -------------------------------------------------------------------------------- /FemtoRV/BOARDS/icefeather.pcf: -------------------------------------------------------------------------------- 1 | # 12 MHz clock 2 | set_io pclk 35 3 | 4 | # User LED 5 | set_io nLED 47 6 | 7 | # RGB LED 8 | set_io rgb0 41 9 | set_io rgb1 40 10 | set_io rgb2 39 11 | 12 | # LED Matrix RGB LED 13 | set_io rgb0_fw 6 14 | set_io rgb1_fw 4 15 | set_io rgb2_fw 3 16 | 17 | # LED Wing Buttons 18 | set_io buttons[0] 43 19 | set_io buttons[1] 44 20 | set_io buttons[2] 2 21 | set_io buttons[3] 48 22 | 23 | # LED Matrix Pins 24 | set_io row[0] 38 25 | set_io row[1] 37 26 | set_io row[2] 32 27 | set_io row[3] 26 28 | set_io row[4] 27 29 | set_io row[5] 25 30 | 31 | set_io col[0] 12 32 | set_io col[1] 11 33 | set_io col[2] 10 34 | set_io col[3] 9 35 | set_io col[4] 36 36 | set_io col[5] 28 37 | 38 | # GPIO (x2 RGB LED's are lumped D1-D6) 39 | set_io D1 41 40 | set_io D2 40 41 | set_io D3 39 42 | set_io D4 6 43 | set_io D5 4 44 | set_io D6 3 45 | set_io D7 31 46 | set_io D8 3 47 | set_io D9 4 48 | set_io D10 6 49 | set_io D11 9 50 | set_io D12 10 51 | set_io D13 11 52 | set_io D14 12 53 | set_io D15 46 54 | set_io D16 13 55 | set_io D17 42 56 | set_io D18 45 57 | 58 | # UART 59 | set_io RXD 23 60 | set_io TXD 21 61 | 62 | # SPI Flash 63 | set_io spi_clk 15 64 | set_io spi_cs_n 16 65 | set_io spi_mosi 14 66 | set_io spi_miso 17 67 | 68 | # Use D0 as RESET 69 | set_io RESET 25 -------------------------------------------------------------------------------- /FemtoRV/BOARDS/icestick.mk: -------------------------------------------------------------------------------- 1 | YOSYS_ICESTICK_OPT=-DICE_STICK -q -p "synth_ice40 -relut -top $(PROJECTNAME) -json $(PROJECTNAME).json" 2 | NEXTPNR_ICESTICK_OPT=--force --json $(PROJECTNAME).json --pcf BOARDS/icestick.pcf --asc $(PROJECTNAME).asc \ 3 | --freq 12 --hx1k --package tq144 --opt-timing 4 | 5 | 6 | ####################################################################################################################### 7 | 8 | ICESTICK: ICESTICK.firmware_config ICESTICK.synth ICESTICK.prog 9 | 10 | ICESTICK.synth: 11 | yosys $(YOSYS_ICESTICK_OPT) $(VERILOGS) 12 | nextpnr-ice40 $(NEXTPNR_ICESTICK_OPT) 13 | icetime -p BOARDS/icestick.pcf -P tq144 -r $(PROJECTNAME).timings -d hx1k -t $(PROJECTNAME).asc 14 | icepack -s $(PROJECTNAME).asc $(PROJECTNAME).bin 15 | 16 | ICESTICK.show: 17 | yosys $(YOSYS_ICESTICK_OPT) $(VERILOGS) 18 | nextpnr-ice40 $(NEXTPNR_ICESTICK_OPT) --gui 19 | 20 | ICESTICK.prog: 21 | iceprog $(PROJECTNAME).bin 22 | 23 | ICESTICK.firmware_config: 24 | BOARD=icestick TOOLS/make_config.sh -DICE_STICK 25 | (cd FIRMWARE; make libs) 26 | 27 | ICESTICK.lint: 28 | verilator -DICE_STICK -DBENCH --lint-only --top-module $(PROJECTNAME) \ 29 | -IRTL -IRTL/PROCESSOR -IRTL/DEVICES -IRTL/PLL $(VERILOGS) 30 | 31 | ####################################################################################################################### 32 | -------------------------------------------------------------------------------- /FemtoRV/BOARDS/icestick.pcf: -------------------------------------------------------------------------------- 1 | set_io pclk 21 2 | 3 | set_io oled_DIN 91 4 | set_io oled_CLK 90 5 | set_io oled_CS 88 6 | set_io oled_DC 87 7 | set_io oled_RST 78 8 | 9 | set_io D1 99 10 | set_io D2 98 11 | set_io D3 97 12 | set_io D4 96 13 | set_io D5 95 14 | 15 | set_io TXD 8 16 | set_io RXD 9 17 | 18 | set_io ledmtx_DIN 81 19 | set_io ledmtx_CS 80 20 | set_io ledmtx_CLK 79 21 | 22 | set_io spi_cs_n 71 23 | set_io spi_miso 68 24 | set_io spi_mosi 67 25 | set_io spi_clk 70 26 | 27 | set_io RESET 47 28 | 29 | set_io irda_TXD 105 30 | set_io irda_RXD 106 31 | set_io irda_SD 107 -------------------------------------------------------------------------------- /FemtoRV/BOARDS/icestick_mecrisp_quintus.pcf: -------------------------------------------------------------------------------- 1 | set_io D1 99 2 | set_io D2 98 3 | set_io D3 97 4 | set_io D4 96 5 | set_io D5 95 6 | 7 | set_io CTS 4 8 | set_io RTS 7 9 | 10 | set_io TXD 8 11 | set_io RXD 9 12 | 13 | set_io oscillator 21 14 | set_io reset_button 3 15 | 16 | set_io spi_cs_n 71 17 | set_io spi_miso 68 18 | set_io spi_mosi 67 19 | set_io spi_clk 70 20 | 21 | set_io IR_TXD 105 22 | set_io IR_RXD 106 23 | set_io IR_SD 107 24 | 25 | set_io PIO1_02 78 26 | set_io PIO1_03 79 27 | set_io PIO1_04 80 28 | set_io PIO1_05 81 29 | set_io PIO1_06 87 30 | set_io PIO1_07 88 31 | set_io PIO1_08 90 32 | set_io PIO1_09 91 33 | 34 | set_io PIO0_02 112 35 | set_io PIO0_03 113 36 | set_io PIO0_04 114 37 | set_io PIO0_05 115 38 | set_io PIO0_06 116 39 | set_io PIO0_07 117 40 | set_io PIO0_08 118 41 | set_io PIO0_09 119 42 | 43 | set_io PIO2_10 44 44 | set_io PIO2_11 45 45 | set_io PIO2_12 47 46 | set_io PIO2_13 48 47 | set_io PIO2_14 56 48 | set_io PIO2_15 60 49 | set_io PIO2_16 61 50 | set_io PIO2_17 62 51 | 52 | -------------------------------------------------------------------------------- /FemtoRV/BOARDS/icesugar.mk: -------------------------------------------------------------------------------- 1 | YOSYS_ICESUGAR_OPT=-DICE_SUGAR -q -p "synth_ice40 -relut -top $(PROJECTNAME) -json $(PROJECTNAME).json" 2 | NEXTPNR_ICESUGAR_OPT=--force --json $(PROJECTNAME).json --pcf BOARDS/icesugar.pcf --asc $(PROJECTNAME).asc \ 3 | --freq 12 --up5k --package sg48 4 | 5 | ####################################################################################################################### 6 | 7 | ICESUGAR: ICESUGAR.firmware_config ICESUGAR.synth ICESUGAR.prog 8 | 9 | ICESUGAR.synth: FIRMWARE/firmware.hex 10 | TOOLS/make_config.sh -DICE_SUGAR 11 | yosys $(YOSYS_ICESUGAR_OPT) $(VERILOGS) 12 | nextpnr-ice40 $(NEXTPNR_ICESUGAR_OPT) 13 | icetime -p BOARDS/icesugar.pcf -P sg48 -r $(PROJECTNAME).timings -d up5k -t $(PROJECTNAME).asc 14 | icepack -s $(PROJECTNAME).asc $(PROJECTNAME).bin 15 | 16 | ICESUGAR.show: FIRMWARE/firmware.hex 17 | yosys $(YOSYS_ICESUGAR_OPT) $(VERILOGS) 18 | nextpnr-ice40 $(NEXTPNR_ICESUGAR_OPT) --gui 19 | 20 | ICESUGAR.prog: 21 | icesprog $(PROJECTNAME).bin 22 | 23 | ICESUGAR.firmware_config: 24 | BOARD=icesugar TOOLS/make_config.sh -DICE_SUGAR 25 | (cd FIRMWARE; make libs) -------------------------------------------------------------------------------- /FemtoRV/BOARDS/icesugar.pcf: -------------------------------------------------------------------------------- 1 | set_io pclk 35 2 | 3 | set_io TXD 6 4 | set_io RXD 4 5 | 6 | set_io spi_cs_n 16 7 | set_io spi_miso 14 8 | set_io spi_mosi 17 9 | set_io spi_clk 15 10 | 11 | set_io oled_DIN 46 12 | set_io oled_CLK 44 13 | set_io oled_CS 42 14 | set_io oled_DC 37 15 | set_io oled_RST 36 16 | 17 | set_io D1 38 18 | set_io D2 43 19 | set_io D3 45 20 | set_io D4 34 21 | set_io D5 31 22 | 23 | 24 | set_io ledmtx_DIN 27 25 | set_io ledmtx_CS 25 26 | set_io ledmtx_CLK 23 27 | 28 | 29 | set_io RESET 18 30 | -------------------------------------------------------------------------------- /FemtoRV/BOARDS/icesugar_nano.mk: -------------------------------------------------------------------------------- 1 | YOSYS_ICESUGAR_NANO_OPT=-DICE_SUGAR_NANO -q -p "synth_ice40 -relut -top $(PROJECTNAME) -json $(PROJECTNAME).json" 2 | NEXTPNR_ICESUGAR_NANO_OPT=--force --json $(PROJECTNAME).json --pcf BOARDS/icesugar_nano.pcf --asc $(PROJECTNAME).asc \ 3 | --freq 12 --lp1k --package cm36 4 | 5 | ####################################################################################################################### 6 | 7 | ICESUGAR_NANO: ICESUGAR_NANO.firmware_config ICESUGAR_NANO.synth ICESUGAR_NANO.prog 8 | 9 | ICESUGAR_NANO.synth: 10 | yosys $(YOSYS_ICESUGAR_NANO_OPT) $(VERILOGS) 11 | nextpnr-ice40 $(NEXTPNR_ICESUGAR_NANO_OPT) 12 | icetime -p BOARDS/icesugar_nano.pcf -P cm36 -r $(PROJECTNAME).timings -d lp1k -t $(PROJECTNAME).asc 13 | icepack -s $(PROJECTNAME).asc $(PROJECTNAME).bin 14 | 15 | ICESUGAR_NANO.show: 16 | yosys $(YOSYS_ICESUGAR_NANO_OPT) $(VERILOGS) 17 | nextpnr-ice40 $(NEXTPNR_ICESUGAR_NANO_OPT) --gui 18 | 19 | ICESUGAR_NANO.prog: 20 | icesprog $(PROJECTNAME).bin 21 | 22 | ICESUGAR_NANO.firmware_config: 23 | BOARD=icesugar_nano TOOLS/make_config.sh -DICE_SUGAR_NANO 24 | (cd FIRMWARE; make libs) 25 | 26 | -------------------------------------------------------------------------------- /FemtoRV/BOARDS/icesugar_nano.pcf: -------------------------------------------------------------------------------- 1 | set_io pclk D1 2 | 3 | set_io TXD B3 4 | set_io RXD A3 5 | 6 | set_io spi_cs_n D5 7 | set_io spi_miso F5 8 | set_io spi_mosi E4 9 | set_io spi_clk E5 10 | 11 | # 12 | #set_io oled_DIN 46 13 | #set_io oled_CLK 44 14 | #set_io oled_CS 42 15 | #set_io oled_DC 37 16 | #set_io oled_RST 36 17 | # 18 | 19 | # B6 is the in-board LED 20 | set_io D1 B6 21 | set_io D2 C6 22 | set_io D3 B5 23 | set_io D4 E3 24 | set_io D5 E1 25 | # 26 | # 27 | #set_io ledmtx_DIN 27 28 | #set_io ledmtx_CS 25 29 | #set_io ledmtx_CLK 23 30 | 31 | 32 | set_io RESET C5 33 | 34 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/ASM_EXAMPLES/Makefile: -------------------------------------------------------------------------------- 1 | include ../makefile.inc 2 | 3 | 4 | all: 5 | @echo "Please specify target (progname.elf or progname.hex or progname.prog) or 'everything'" 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/ASM_EXAMPLES/bench_count_15.S: -------------------------------------------------------------------------------- 1 | # A simple program to be displayed on the test bench 2 | # Counts from 0 to 15, outputs each number to the LEDs, 3 | # outputs return value 5 at the end. 4 | # (you won't see anything if you run it on the device, 5 | # it is meant to be used with the iverilog testbench) 6 | 7 | .include "femtorv32.inc" 8 | 9 | .globl main 10 | .type main, @function 11 | 12 | main: add sp,sp,-4 13 | sw ra, 0(sp) 14 | 15 | # output amount of RAM on LEDs 16 | lw t1,IO_RAM(gp) 17 | sw t1,IO_LEDS(gp) 18 | 19 | li t1,0 20 | li t2,16 21 | 22 | loop: sw t1,IO_LEDS(gp) 23 | addi t1,t1,1 24 | bne t1,t2,loop 25 | 26 | li a0, 5 # main() return value 27 | lw ra, 0(sp) 28 | add sp,sp,4 29 | ret 30 | 31 | 32 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/ASM_EXAMPLES/blinker_loop.S: -------------------------------------------------------------------------------- 1 | # Blinker example, using a delay loop. 2 | 3 | .include "femtorv32.inc" 4 | 5 | .globl main 6 | .type main, @function 7 | 8 | main: add sp,sp,-4 9 | sw ra, 0(sp) 10 | loop0: li t1,0 11 | li t2,15 12 | loop: addi t1,t1,1 13 | call mywait 14 | call show 15 | bne t1,t2,loop 16 | j end 17 | end: j loop0 18 | lw ra,0(sp) 19 | add sp,sp,4 20 | ret 21 | 22 | mywait: li t3,0 23 | li t4,0x100000 24 | mwaitl: addi t3,t3,1 25 | bne t3,t4,mwaitl 26 | ret 27 | 28 | show: addi t0,t1,0 29 | sw t0,IO_LEDS(gp) 30 | ret 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/ASM_EXAMPLES/blinker_shift.S: -------------------------------------------------------------------------------- 1 | # Blinker example, using the shift instruction 2 | .include "femtorv32.inc" 3 | 4 | .globl main 5 | .type main, @function 6 | 7 | main: add sp,sp,-4 8 | sw ra, 0(sp) 9 | li t1,0 10 | li t2,15 11 | loop: addi t1,t1,1 12 | call show 13 | bne t0,t2,loop 14 | j end 15 | end: li a0, 15 # main() return value, all leds lit 16 | lw ra, 0(sp) 17 | add sp,sp,4 18 | ret 19 | 20 | show: srli t0,t1,18 21 | sw t0,IO_LEDS(gp) 22 | ret 23 | 24 | 25 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/ASM_EXAMPLES/blinker_shift_fast.S: -------------------------------------------------------------------------------- 1 | # Blinker example, using the shift instruction 2 | # Fast version, to be run from the SPI flash (that slows down everything) 3 | .include "femtorv32.inc" 4 | 5 | .globl main 6 | .type main, @function 7 | 8 | main: li t1,0 9 | li t2,15 10 | loop: addi t1,t1,1 11 | call show 12 | bne t0,t2,loop 13 | j end 14 | end: j main 15 | 16 | show: srli t0,t1,14 17 | sw t0,IO_LEDS(gp) 18 | ret 19 | 20 | 21 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/ASM_EXAMPLES/blinker_wait.S: -------------------------------------------------------------------------------- 1 | # Blinker example, using a delay loop. 2 | 3 | .include "femtorv32.inc" 4 | 5 | .globl main 6 | .type main, @function 7 | 8 | main: add sp,sp,-4 9 | sw ra, 0(sp) 10 | li t1,0 11 | li t2,15 12 | loop: addi t1,t1,1 13 | call mywait 14 | call show 15 | bne t1,t2,loop 16 | j end 17 | end: li a0,15 # main() return value, let all leds lit 18 | lw ra,0(sp) 19 | add sp,sp,4 20 | ret 21 | 22 | mywait: li t3,0 23 | li t4,0x100000 24 | mwaitl: addi t3,t3,1 25 | bne t3,t4,mwaitl 26 | ret 27 | 28 | show: addi t0,t1,0 29 | sw t0,IO_LEDS(gp) 30 | ret 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/ASM_EXAMPLES/hello.S: -------------------------------------------------------------------------------- 1 | # Testing the serial interface. Echoes typed characters, 2 | # and displays 4 LSBs using the LEDs. 3 | .include "femtorv32.inc" 4 | 5 | # Needs both NRV_IO_UART_RX and NRV_IO_UART_TX to be 6 | # enabled. 7 | # 8 | # To access it, use: 9 | # miniterm.py --dtr=0 /dev/ttyUSB1 115200 10 | # or screen /dev/ttyUSB1 115200 (<ctrl> a \ to exit) 11 | 12 | .globl main 13 | .type main, @function 14 | 15 | main: add sp,sp,-4 16 | sw ra, 0(sp) 17 | call femtosoc_tty_init # redirect IO to configured device 18 | loop: li t0, 15 19 | sw t0, IO_LEDS(gp) 20 | # call getchar # wait for a char from the UART 21 | la a0, hello 22 | call print_string 23 | j loop 24 | li a0,0 25 | lw ra,0(sp) 26 | add sp,sp,4 27 | ret 28 | 29 | hello: 30 | .asciz "Hello, world !!\n" 31 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/ASM_EXAMPLES/test_OLED.S: -------------------------------------------------------------------------------- 1 | # Testing the OLED screen, displaying an animated pattern with 2 | # all the 65K colors. 3 | 4 | .include "femtorv32.inc" 5 | .include "ssd1351_1331.inc" 6 | 7 | # On the IceStick, install the code in BRAM (much faster) 8 | .ifdef ICE_STICK 9 | .section .fastcode 10 | .endif 11 | 12 | .globl main 13 | .type main, @function 14 | 15 | main: add sp,sp,-4 16 | sw ra, 0(sp) 17 | 18 | call GL_init 19 | 20 | # anim 21 | # s0 = X, s1 = Y, s2 = bound, s3 = frame 22 | li s2,128 23 | li s3,0 24 | anim: 25 | OLED2 0x15,0x00,0x7f # column address 26 | OLED2 0x75,0x00,0x7f # row address 27 | OLED0 0x5c # write RAM 28 | li s1,0 29 | loop_y: li s0,0 30 | loop_x: add s0,s0,1 31 | 32 | # compute pixel color: RRRRR GGGGG 0 BBBBB 33 | # (or an additional G LSB instead of 0) 34 | # RRRRR = X+frame 35 | # GGGGG = X >> 3 36 | # BBBBB = Y+frame 37 | 38 | add t0,s0,s3 39 | sll t0,t0,3 40 | 41 | srl t1,s0,5 42 | and t1,t1,7 43 | or t0,t0,t1 44 | sw t0, IO_SSD1351_DAT(gp) 45 | add t0,s1,s3 46 | andi t0,t0,31 47 | sll t1,s0,3 48 | and t1,t1,192 49 | or t0,t0,t1 50 | sw t0, IO_SSD1351_DAT(gp) 51 | 52 | bne s0,s2,loop_x 53 | add s1,s1,1 54 | bne s1,s0,loop_y 55 | add s3,s3,1 56 | 57 | sw s3, 0(gp) 58 | j anim 59 | 60 | li a0,0 61 | lw ra, 0(sp) 62 | add sp,sp,4 63 | ret 64 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/ASM_EXAMPLES/test_led_matrix.S: -------------------------------------------------------------------------------- 1 | .include "femtorv32.inc" 2 | 3 | .globl main 4 | .type main, @function 5 | 6 | main: add sp,sp,-4 7 | sw ra, 0(sp) 8 | call MAX7219_init 9 | anim: la a0,face1data 10 | call MAX7219_image 11 | li a0, 500 12 | call milliwait 13 | la a0,face2data 14 | call MAX7219_image 15 | li a0,500 16 | call milliwait 17 | j anim 18 | li a0,0 19 | lw ra, 0(sp) 20 | add sp,sp,4 21 | ret 22 | 23 | MAX7219_image: 24 | add sp,sp,-4 25 | sw ra, 0(sp) 26 | li s0,1 27 | mv s1,a0 28 | li s2,9 29 | MAXil: mv a0,s0 30 | lbu a1,0(s1) 31 | call MAX7219 32 | add s0,s0,1 33 | add s1,s1,1 34 | bne s0,s2,MAXil 35 | lw ra, 0(sp) 36 | add sp,sp,4 37 | ret 38 | 39 | 40 | face1data: 41 | .byte 0b00111100, 0b01000010, 0b10001001, 0b10100001 42 | .byte 0b10100001, 0b10001001, 0b01000010, 0b00111100 43 | 44 | face2data: 45 | .byte 0b00000000, 0b00001000, 0b00010100, 0b00101000 46 | .byte 0b00101000, 0b00010100, 0b00001000, 0b00000000 47 | 48 | 49 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/ASM_EXAMPLES/test_serial.S: -------------------------------------------------------------------------------- 1 | # Testing the serial interface. Echoes typed characters, 2 | # and displays 4 LSBs using the LEDs. 3 | 4 | # Needs both NRV_IO_UART_RX and NRV_IO_UART_TX to be 5 | # enabled. 6 | # 7 | # To access it, use: 8 | # miniterm.py --dtr=0 /dev/ttyUSB1 115200 9 | # or screen /dev/ttyUSB1 115200 (<ctrl> a \ to exit) 10 | 11 | .include "femtorv32.inc" 12 | 13 | .globl main 14 | .type main, @function 15 | 16 | main: add sp,sp,-4 17 | sw ra, 0(sp) 18 | loop: call getchar 19 | sw a0,IO_LEDS(gp) 20 | call putchar 21 | j loop 22 | li a0,0 23 | lw ra,0(sp) 24 | add sp,sp,4 25 | ret 26 | 27 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/CPP_EXAMPLES/Makefile: -------------------------------------------------------------------------------- 1 | include ../makefile.inc 2 | 3 | everything: cpp_test.elf tinyrt_cpp.elf 4 | 5 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/CPP_EXAMPLES/cpp_test.cpp: -------------------------------------------------------------------------------- 1 | // http://www.pixelbeat.org/programming/gcc/supc++/ 2 | // This one works on the IceStick (but IceStick does 3 | // not support much more !! 6kB is really too small to 4 | // do C++ it seems...) 5 | 6 | #include <vector> 7 | #include <algorithm> 8 | 9 | extern "C" { 10 | #include <femtorv32.h> 11 | void femtosoc_tty_init(); 12 | } 13 | 14 | int main() { 15 | femtosoc_tty_init(); 16 | std::vector<int> V; 17 | V.push_back(8); 18 | V.push_back(11); 19 | V.push_back(3); 20 | V.push_back(100); 21 | V.push_back(53); 22 | V.push_back(5); 23 | std::sort(V.begin(), V.end()); 24 | for(int i=0; i<V.size(); ++i) { 25 | printf("%d\n",V[i]); 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/CRT/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: $(RVGCC) crt0_baremetal.o crt0_spiflash.o syscalls.o 3 | 4 | include ../makefile.inc 5 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/CRT/baremetal.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * linker control script for 'bare metal' executables. 3 | * Ensures that _start defined in LIB/crt0.S is put at address 0 4 | * Uses the first 64 kB of BRAM. It can be used for instance by 5 | * an OS. Standard ELF executables are implanted at address 0x10000, 6 | * so this ensures they won't collide. 7 | */ 8 | MEMORY 9 | { 10 | BRAM (RWX) : ORIGIN = 0x0000, LENGTH = 0x10000 11 | } 12 | SECTIONS 13 | { 14 | .text : 15 | { 16 | crt0_baremetal.o (.text) 17 | *(.text) 18 | _end = .; /* as expected by syscalls.c */ 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/CRT/crt0_baremetal.S: -------------------------------------------------------------------------------- 1 | .include "femtorv32.inc" 2 | 3 | .text 4 | .global _start 5 | .type _start, @function 6 | 7 | _start: 8 | .option push 9 | .option norelax 10 | li gp,IO_BASE # Base address of memory-mapped IO 11 | .option pop 12 | 13 | li t0,IO_HW_CONFIG_RAM # Can't use IO_HW_CONFIG_RAM(gp) (too far away !) 14 | add t0,t0,gp # Read RAM size in hw config register and 15 | lw sp,0(t0) # initialize SP at end of RAM 16 | li t0,0 # reset t0 to 0 17 | 18 | # TODO: clear BSS (for this we need a linker script that declares _edata) 19 | # la t1,_edata 20 | #.L1: sw zero,0(t1) 21 | # addi t1,t1,4 22 | # bne t1,sp,.L1 23 | 24 | call main 25 | tail exit 26 | 27 | 28 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/CRT/crt0_spiflash.S: -------------------------------------------------------------------------------- 1 | .include "femtorv32.inc" 2 | 3 | .text 4 | .global _start 5 | .type _start, @function 6 | 7 | _start: 8 | .option push 9 | .option norelax 10 | li gp,IO_BASE # Base address of memory-mapped IO 11 | .option pop 12 | 13 | li t0,IO_HW_CONFIG_RAM # Can't use IO_HW_CONFIG_RAM(gp) (too far away !) 14 | add t0,t0,gp # Read RAM size in hw config register and 15 | lw sp,0(t0) # initialize SP at end of RAM 16 | li t0,0 # reset t0 to 0 17 | 18 | # zero-init bss section: 19 | # clears from _sbss to _ebss 20 | # _sbss and _ebss are defined by linker script (spi_flash.ld) 21 | la a0, _sbss 22 | la a1, _ebss 23 | bge a0, a1, end_init_bss 24 | loop_init_bss: 25 | sw zero, 0(a0) 26 | addi a0, a0, 4 27 | blt a0, a1, loop_init_bss 28 | end_init_bss: 29 | 30 | # copy data section from SPI Flash to BRAM: 31 | # copies from _sidata (in flash) to _sdata ... _edata (in BRAM) 32 | # _sidata, _sdata and _edata are defined by linker script (spi_flash.ld) 33 | la a0, _sidata 34 | la a1, _sdata 35 | la a2, _edata 36 | bge a1, a2, end_init_data 37 | loop_init_data: 38 | lw a3, 0(a0) 39 | sw a3, 0(a1) 40 | addi a0, a0, 4 41 | addi a1, a1, 4 42 | blt a1, a2, loop_init_data 43 | end_init_data: 44 | 45 | call main 46 | tail exit 47 | 48 | 49 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/DHRYSTONE/Makefile: -------------------------------------------------------------------------------- 1 | include ../makefile.inc 2 | 3 | RVUSERCFLAGS=-w -DRISCV -DTIME -DUSE_MYSTDLIB -fno-pic 4 | OBJECTS=dhry_1.o dhry_2.o stubs.o 5 | 6 | all: dhrystone.elf 7 | 8 | # Generate a "femtOS elf executable", to be loaded from address 0x10000 (rule for conversion to .bin file in makefile.inc) 9 | dhrystone.elf: $(OBJECTS) 10 | $(RVGCC) $(RVCFLAGS) $(OBJECTS) -o $@ -L$(FIRMWARE_DIR)/CRT_BAREMETAL -L$(FIRMWARE_DIR)/LIBFEMTOGL -L$(FIRMWARE_DIR)/LIBFEMTORV32 -L$(FIRMWARE_DIR)/LIBFEMTOC -lfemtoGL -lfemtorv32 -lfemtoc -lm 11 | 12 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/DHRYSTONE/README: -------------------------------------------------------------------------------- 1 | The Dhrystone benchmark, with some modifications by Claire Wolf. 2 | Added redirection to OLED display. 3 | Needs 128K of RAM and counters (does not fit on the ICEStick). 4 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/DHRYSTONE/stubs.c: -------------------------------------------------------------------------------- 1 | #include <femtorv32.h> 2 | 3 | long time() { 4 | int cycles; 5 | asm volatile ("rdcycle %0" : "=r"(cycles)); 6 | return cycles; 7 | } 8 | 9 | long insn() { 10 | int insns; 11 | asm volatile ("rdinstret %0" : "=r"(insns)); 12 | return insns; 13 | } 14 | 15 | int has_counters() { 16 | return 1; 17 | } 18 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/EXAMPLES/DATA/notes.txt: -------------------------------------------------------------------------------- 1 | the ST-NICCC Demo 2 | http://leonard.oxg.free.fr/stniccc/stniccc.html 3 | http://www.pouet.net/topic.php?which=11559&page=1 4 | 5 | Data file and information: 6 | http://arsantica-online.com/st-niccc-competition/ 7 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/EXAMPLES/DATA/scene1.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/FIRMWARE/EXAMPLES/DATA/scene1.dat -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/EXAMPLES/FGA_test.c: -------------------------------------------------------------------------------- 1 | #include <femtoGL.h> 2 | 3 | int main() { 4 | int frame=0; 5 | FGA_setmode(FGA_MODE_320x200x16bpp); 6 | for(;;) { 7 | uint16_t* graph_ptr = (uint16_t*)FGA_BASEMEM; 8 | for(int y=0; y<200; ++y) { 9 | for(int x=0; x<320; ++x) { 10 | uint32_t R = (x+frame) & 63; 11 | uint32_t G = (x >> 3) & 63; 12 | uint32_t B = (y+frame) & 63; 13 | *graph_ptr = GL_RGB(R<<3,G<<3,B<<3); 14 | graph_ptr++; 15 | } 16 | } 17 | ++frame; 18 | } 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/EXAMPLES/Makefile: -------------------------------------------------------------------------------- 1 | include ../makefile.inc 2 | 3 | ALL_PROGRAMS= cube.elf FGA_test.elf gfx_demo.elf gfx_test.elf hello.elf imgui_cup.elf \ 4 | imgui_doom.elf imgui_road.elf imgui_tunnel.elf life_led_matrix.elf \ 5 | malloc_test.elf mandelbrot.elf mandel_float.elf riscv_logo_2.elf \ 6 | riscv_logo.elf sieve.elf spirograph.elf ST_NICCC.elf ST_NICCC_spi_flash.elf \ 7 | sysconfig.elf test_buttons.elf test_font_OLED.elf \ 8 | test_spi_flash.elf test_spi_sdcard.elf tinyraytracer.elf tty_OLED.elf 9 | 10 | 11 | all: 12 | @echo "Please specify target (progname.elf, progname.bin, progname.hex) or 'everything'" 13 | 14 | everything: $(ALL_PROGRAMS) 15 | 16 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/EXAMPLES/TOOLS/make_sintab.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Generates a sinus table. 3 | * Do not try compiling this one on the femtoRV ! 4 | */ 5 | 6 | #include <math.h> 7 | #include <stdio.h> 8 | #include <stdlib.h> 9 | 10 | void main(int argc, char** argv) { 11 | int NB = 64; 12 | int factor = 256; 13 | 14 | if(argc == 2) { 15 | factor = atoi(argv[1]); 16 | } 17 | 18 | printf("int sintab[%d] = {",NB); 19 | for(int i=0; i<NB; ++i) { 20 | double alpha = 2.0*M_PI*(double)i/(double)NB; 21 | printf("%d",(int)(factor*sin(alpha))); 22 | if(i != NB-1) { 23 | printf(","); 24 | } 25 | } 26 | printf("};\n"); 27 | } 28 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/EXAMPLES/TOOLS/tiny_riscv_logo.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static char * tiny_riscv_logo_xpm[] = { 3 | "16 16 8 1", 4 | " c #283374", 5 | ". c #7B809B", 6 | "+ c #AAACBC", 7 | "@ c #F9B115", 8 | "# c #F9BE65", 9 | "$ c #F9C782", 10 | "% c #FCD8B0", 11 | "& c #FAFBF8", 12 | "&&&&&&$@@@@@@@@&", 13 | "&&&&&&&$@@@@@@@&", 14 | "....+&&&@@@@@@@&", 15 | " .&&$@@@@@@&", 16 | " &&%@@@@@%&", 17 | " &&$@@@@#&&", 18 | " +&&#@@@@&&&", 19 | " +++&&&%@@@@%&&&", 20 | " &&&&&%@@@@amp;&+&", 21 | " .&&&#@@@@@&&& &", 22 | " +&&%@@@@%&&. &", 23 | " +&&$@@amp;&+ &", 24 | " &&&$#&&+ &", 25 | " &&&&&& &", 26 | " .&&&&. &", 27 | "&&&&&&&&&&&&&&&&"}; 28 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/EXAMPLES/errno_fix.h: -------------------------------------------------------------------------------- 1 | 2 | // Sometimes __errno is not linked, here is a dummy replacement. 3 | // Note that __errno is a function that returns a pointer to the 4 | // actual __errno (this is for multithreading). Made me bang my 5 | // head to the wall (and made tinyraytracer crash because powf() 6 | // was *calling* __errno). 7 | 8 | int* __errno() { 9 | static int val = 0; 10 | return &val; 11 | } 12 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/EXAMPLES/gfx_test.c: -------------------------------------------------------------------------------- 1 | // Testing the OLED screen, displaying an animated pattern with 2 | // all the 65K colors. 3 | 4 | #include <femtoGL.h> 5 | 6 | int main() RV32_FASTCODE; 7 | int main() { 8 | GL_init(GL_MODE_CHOOSE_RGB); 9 | GL_clear(); 10 | int frame = 0; 11 | for(;;) { 12 | GL_write_window(0,0,GL_width-1,GL_height-1); 13 | for(uint32_t y=0; y<GL_height; ++y) { 14 | for(uint32_t x=0; x<GL_width; ++x) { 15 | uint32_t R = (x+frame) & 63; 16 | uint32_t G = (x >> 3) & 63; 17 | uint32_t B = (y+frame) & 63; 18 | // pixel color: RRRRR GGGGG 0 BBBBB 19 | GL_WRITE_DATA_UINT16(B | (G << 6) | (R << 11)); 20 | } 21 | } 22 | ++frame; 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/EXAMPLES/hello.c: -------------------------------------------------------------------------------- 1 | #include <femtorv32.h> 2 | #include <femtoGL.h> 3 | 4 | int main() { 5 | int i = 0; 6 | /* 7 | * redirects display to UART (default), OLED display 8 | * or led matrix, based on configured devices (in femtosoc.v). 9 | * Note: pulls the two fonts (eats up a subsequent part of the 10 | * available 6 Kbs). 11 | * To save code size, on the IceStick, you can use 12 | * instead MAX7219_tty_init() if you know you are 13 | * using the led matrix, or GL_tty_init() if you know you are 14 | * using the small OLED display. 15 | */ 16 | GL_set_font(&Font8x16); 17 | 18 | for(;;) { 19 | /* Using: "LIBFEMTORV32/HardwareConfig_bits.h" (derived from "HardwareConfig_bits.v") 20 | * IO_XXX = 1 << (IO_XXX_bit + 2); IO_LEDS_bit=0; --> (1<<(0+2))=4 --> 0x400004 21 | */ 22 | *(volatile uint32_t*)(0x400004) = (~*(volatile uint32_t*)(0x400004)) & 0x1; // read and invert D1 LED/Pin 23 | 24 | delay(500); 25 | printf("Hello world !!\n Let me introduce myself, I am FemtoRV32, one of the smallest RISC-V cores\n"); 26 | delay(500); 27 | i++; 28 | printf("Freq: %d MHz ; loop=%d ; LED D1=%d\n\n", FEMTORV32_FREQ, i, *(volatile uint32_t*)(0x400004)); 29 | } 30 | 31 | return 0; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/EXAMPLES/hello_LED.c: -------------------------------------------------------------------------------- 1 | #include <femtorv32.h> 2 | 3 | // é = 130 4 | // smileys = 1,2 5 | 6 | int main() { 7 | MAX7219_tty_init(); // redirect printf() to led matrix scroller 8 | for(;;) { 9 | printf("Hello, RISC-V world \001 \002 \001 \002 "); 10 | } 11 | return 0; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/EXAMPLES/hello_bench.c: -------------------------------------------------------------------------------- 1 | #include <femtorv32.h> 2 | #include <femtoGL.h> 3 | 4 | // Demo program for 'make testbench' 5 | 6 | int main() { 7 | femtosoc_tty_init(); 8 | printf("Hello world !!\n Let me introduce myself, I am FemtoRV32, one of the smallest RISC-V cores\n"); 9 | putchar(4); // EOT 10 | return 0; 11 | } 12 | 13 | 14 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/EXAMPLES/malloc_test.c: -------------------------------------------------------------------------------- 1 | #include <stdlib.h> 2 | 3 | extern int femtosoc_tty_init(); 4 | 5 | int main() { 6 | femtosoc_tty_init(); 7 | void* p1 = malloc(10); 8 | void* p2 = malloc(100); 9 | printf("p1=0x%x\n",p1); 10 | printf("p2=0x%x\n",p2); 11 | free(p2); 12 | free(p1); 13 | void* p3 = malloc(50); 14 | printf("p1=0x%x\n",p3); 15 | exit(0); 16 | } 17 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/EXAMPLES/test_buttons.c: -------------------------------------------------------------------------------- 1 | #include <femtorv32.h> 2 | 3 | int main() { 4 | femtosoc_tty_init(); 5 | printf("Btn test\n"); 6 | uint32_t btn_state = IO_IN(IO_BUTTONS); 7 | for(;;) { 8 | uint32_t new_state = IO_IN(IO_BUTTONS); 9 | if(new_state != btn_state) { 10 | printf("state=%d\n", new_state); 11 | for(int i=0; i<6; ++i) { 12 | if(((btn_state & (1 << i)) != (new_state & (1 << i)))) { 13 | printf("button %d: %s\n", i, (new_state & (1 << i)) ? "press" : "release"); 14 | } 15 | } 16 | } 17 | 18 | btn_state = new_state; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/EXAMPLES/test_font_OLED.c: -------------------------------------------------------------------------------- 1 | // Testing the OLED screen, displaying the font map. 2 | 3 | #include <femtoGL.h> 4 | 5 | extern int GL_putchar(int); 6 | 7 | int main() RV32_FASTCODE; 8 | int main() { 9 | 10 | GL_init(GL_MODE_OLED); 11 | GL_clear(); 12 | 13 | int frame=0; 14 | 15 | for(;;) { 16 | GL_write_window(0,0,GL_width-1,GL_height-1); 17 | for(uint32_t y=0; y<GL_height; ++y) { 18 | for(uint32_t x=0; x<GL_width; ++x) { 19 | uint32_t car_x = (x + frame)/8; 20 | uint32_t car_y = (y + frame)/8; 21 | uint32_t car = (car_y * (128/8) + car_x) & 127; 22 | 23 | uint32_t col = (x + frame)%8; 24 | uint32_t row = (y + frame)%8; 25 | 26 | uint32_t BW = (font_8x8[car*8+col] & (1 << row)) ? 255 : 0; 27 | 28 | uint32_t R = ((y+frame) & 63); 29 | uint32_t G = (y >> 3) & 63; 30 | uint32_t B = (-y+frame) & 63; 31 | 32 | GL_WRITE_DATA_UINT16(BW ? (B | (G << 6) | (R << 11)) : 0); 33 | } 34 | } 35 | ++frame; 36 | } 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/EXAMPLES/test_ir_sensor.c: -------------------------------------------------------------------------------- 1 | #include <femtorv32.h> 2 | 3 | static inline int ir_status() { 4 | return !(IO_IN(IO_LEDS) & 64); 5 | } 6 | 7 | void test_irda() RV32_FASTCODE; 8 | void test_irda() { 9 | for(;;) { 10 | printf("%c",ir_status() ? '*' : ' '); 11 | } 12 | } 13 | 14 | int main() { 15 | femtosoc_tty_init(); 16 | test_irda(); 17 | } 18 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/EXAMPLES/test_spi_sdcard.c: -------------------------------------------------------------------------------- 1 | 2 | #include <femtorv32.h> 3 | #include <fat_io_lib/fat_filelib.h> 4 | 5 | int main() { 6 | femtosoc_tty_init(); 7 | 8 | if(sd_init()) { 9 | printf("Could not initialize SDCard\n"); 10 | return 1; 11 | } 12 | printf("SDCard OK\n"); 13 | fl_init(); 14 | if(fl_attach_media((fn_diskio_read)sd_readsector, (fn_diskio_write)sd_writesector) != FAT_INIT_OK) { 15 | printf("ERROR: Failed to init file system\n"); 16 | return -1; 17 | } 18 | printf("FileSystem OK\n"); 19 | fl_listdirectory("/"); 20 | printf("done.\n"); 21 | 22 | 23 | /* 24 | 25 | if(sd_init()) { 26 | printf("Could not initialize SDCard\n"); 27 | return 1; 28 | } 29 | 30 | if(!sd_readsector(4152, buffer, 1)) { 31 | printf("Could not read sector from SDCard\n"); 32 | return 1; 33 | } 34 | 35 | for(int i=0; i<128; ++i) { 36 | print_hex_digits(buffer[i], 2); 37 | if(!i%16) { 38 | printf("\n"); 39 | } 40 | } 41 | printf("\n"); 42 | */ 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/EXAMPLES/tty_OLED.c: -------------------------------------------------------------------------------- 1 | #include <femtorv32.h> 2 | #include <femtoGL.h> 3 | 4 | int main() { 5 | GL_tty_init(GL_MODE_OLED); 6 | printf("femtorv32 TTY\n"); 7 | for(;;) { 8 | int c = getchar(); 9 | if(c != 10 && c !=13) { 10 | putchar(c); 11 | // printf("char=%d\n", (int)c); 12 | } else { 13 | putchar('\n'); 14 | putchar(']'); 15 | } 16 | 17 | } 18 | return 0; 19 | } 20 | 21 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/FEMTOS/Makefile: -------------------------------------------------------------------------------- 1 | include ../makefile.inc 2 | 3 | all: commander.hex 4 | 5 | 6 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTOC/Makefile: -------------------------------------------------------------------------------- 1 | #Uncomment if not linking with riscv-gcc's libraries 2 | # 3 | #MISSING_OBJECTS=missing/mul.o missing/div.o \ 4 | # memset.o memcpy.o random.o \ 5 | # strcpy.o strncpy.o strcmp.o strncmp.o strlen.o\ 6 | # clz.o 7 | # 8 | #MISSING_OBJECTS_WITH_DIR=missing/mul.o missing/div.o \ 9 | # missing/memset.o missing/memcpy.o missing/random.o \ 10 | # missing/strcpy.o missing/strncpy.o missing/strcmp.o missing/strncmp.o \ 11 | # missing/strlen.o missing/clz.o 12 | 13 | OBJECTS=print.o printf.o 14 | 15 | all: $(RVGCC) libfemtoc.a 16 | 17 | libfemtoc.a: $(OBJECTS) $(MISSING_OBJECTS_WITH_DIR) 18 | $(RVAR) cq libfemtoc.a $(OBJECTS) $(MISSING_OBJECTS) 19 | $(RVRANLIB) libfemtoc.a 20 | 21 | include ../makefile.inc 22 | 23 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTOC/femtostdlib.h: -------------------------------------------------------------------------------- 1 | #ifndef H__FEMTOSTDLIB__H 2 | #define H__FEMTOSTDLIB__H 3 | 4 | #include <femtorv32.h> 5 | 6 | /* My light weight replacement function for printf() */ 7 | extern int printf(const char *fmt,...); /* supports %s, %d, %x */ 8 | 9 | /* Uncomment if using functions in 'missing' subdirectory 10 | void* memset(void *s, int c, size_t n); 11 | void* memcpy(void *dest, const void *src, size_t n); 12 | char* strcpy(char *dest, const char *src); 13 | char* strncpy(char *dest, const char *src, size_t n); 14 | int strcmp(const char *p1, const char *p2); 15 | size_t strlen(const char* p); 16 | extern int random(); 17 | */ 18 | 19 | /* Specialized print functions (but one can use printf() instead) */ 20 | extern void print_string(const char* s); 21 | extern void print_dec(int val); 22 | extern void print_hex_digits(unsigned int val, int digits); 23 | extern void print_hex(unsigned int val); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTOC/missing/clz.c: -------------------------------------------------------------------------------- 1 | #include "../femtostdlib.h" 2 | 3 | // Number of leading zero bits 4 | // (I do not know where the source of this function is, did not find 5 | // it in riscv-glibc) 6 | int __clzsi2(unsigned int x) { 7 | unsigned int mask = (1 << 31); 8 | for(int i=0; i<32; ++i) { 9 | if(x & mask) { 10 | return i; 11 | } 12 | mask = mask >> 1; 13 | } 14 | return 32; 15 | } 16 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTOC/missing/memcpy.c: -------------------------------------------------------------------------------- 1 | #include "../femtostdlib.h" 2 | 3 | /* 4 | * Needed to prevent the compiler from recognizing memcpy in the 5 | * body of memcpy and replacing it with a call to memcpy 6 | * (infinite recursion) 7 | */ 8 | #pragma GCC optimize ("no-tree-loop-distribute-patterns") 9 | 10 | void* memcpy(void * dst, void const * src, size_t len) { 11 | uint32_t * plDst = (uint32_t *) dst; 12 | uint32_t const * plSrc = (uint32_t const *) src; 13 | 14 | // If source and destination are aligned, 15 | // copy 32s bit by 32 bits. 16 | if (!((uint32_t)src & 3) && !((uint32_t)dst & 3)) { 17 | while (len >= 4) { 18 | *plDst++ = *plSrc++; 19 | len -= 4; 20 | } 21 | } 22 | 23 | uint8_t* pcDst = (uint8_t *) plDst; 24 | uint8_t const* pcSrc = (uint8_t const *) plSrc; 25 | 26 | while (len--) { 27 | *pcDst++ = *pcSrc++; 28 | } 29 | 30 | return dst; 31 | } 32 | 33 | 34 | /* 35 | * Equivalent (slower) version 36 | void* memcpy(void* dest, const void* src, size_t n) { 37 | char *csrc = (char *)src; 38 | char *cdest = (char *)dest; 39 | for (size_t i=0; i<n; i++) { 40 | cdest[i] = csrc[i]; 41 | } 42 | } 43 | */ 44 | 45 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTOC/missing/memset.c: -------------------------------------------------------------------------------- 1 | #include "../femtostdlib.h" 2 | 3 | /* 4 | * Needed to prevent the compiler from recognizing memset in the 5 | * body of memset and replacing it with a call to memset 6 | * (infinite recursion) 7 | */ 8 | #pragma GCC optimize ("no-tree-loop-distribute-patterns") 9 | 10 | /* 11 | * Super-slow memset function. 12 | * TODO: write word by word. 13 | */ 14 | void* memset(void* s, int c, size_t n) { 15 | uint8_t* p = (uint8_t*)s; 16 | for(size_t i=0; i<n; ++i) { 17 | *p = (uint8_t)c; 18 | p++; 19 | } 20 | return s; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTOC/missing/mul.S: -------------------------------------------------------------------------------- 1 | .include "femtorv32.inc" 2 | 3 | ################################################################################# 4 | # multiplication, source in a0 and a1, result in a0 5 | 6 | .global __mulsi3 7 | .type __mulsi3, @function 8 | 9 | __mulsi3: 10 | mv a2, a0 11 | li a0, 0 12 | .L1: 13 | andi a3, a1, 1 14 | beqz a3, .L2 15 | add a0, a0, a2 16 | .L2: 17 | srli a1, a1, 1 18 | slli a2, a2, 1 19 | bnez a1, .L1 20 | ret 21 | 22 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTOC/missing/random.c: -------------------------------------------------------------------------------- 1 | #include "../femtostdlib.h" 2 | 3 | static int randomseed = 1; 4 | 5 | int random() { 6 | randomseed = (randomseed * 1366l + 150889l) % 714025l; 7 | return randomseed; 8 | } 9 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTOC/missing/strcmp.c: -------------------------------------------------------------------------------- 1 | #include "../femtostdlib.h" 2 | 3 | int strcmp (const char *p1, const char *p2) { 4 | const unsigned char *s1 = (const unsigned char *) p1; 5 | const unsigned char *s2 = (const unsigned char *) p2; 6 | unsigned char c1, c2; 7 | do { 8 | c1 = (unsigned char) *s1++; 9 | c2 = (unsigned char) *s2++; 10 | if (c1 == '\0') { 11 | return c1 - c2; 12 | } 13 | } 14 | while (c1 == c2); 15 | return c1 - c2; 16 | } 17 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTOC/missing/strcpy.c: -------------------------------------------------------------------------------- 1 | #include "../femtostdlib.h" 2 | 3 | char *strcpy(char *dest, const char *src) { 4 | char* result = dest; 5 | while(*dest++=*src++); 6 | return result; 7 | } 8 | 9 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTOC/missing/strlen.c: -------------------------------------------------------------------------------- 1 | #include "../femtostdlib.h" 2 | 3 | size_t strlen(const char *str) { 4 | for (size_t len = 0;;++len) if (str[len]==0) return len; 5 | } 6 | 7 | 8 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTOC/missing/strncmp.c: -------------------------------------------------------------------------------- 1 | #include <femtorv32.h> 2 | 3 | int strncmp( const char * s1, const char * s2, size_t n ) { 4 | while ( n && *s1 && ( *s1 == *s2 ) ) { 5 | ++s1; 6 | ++s2; 7 | --n; 8 | } 9 | if (n == 0) { 10 | return 0; 11 | } else { 12 | return ( *(unsigned char *)s1 - *(unsigned char *)s2 ); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTOC/missing/strncpy.c: -------------------------------------------------------------------------------- 1 | #include "../femtostdlib.h" 2 | 3 | char* strncpy(char *dest, const char *src, size_t n) { 4 | size_t i; 5 | for (i = 0; i < n && src[i] != '\0'; i++) { 6 | dest[i] = src[i]; 7 | } 8 | for ( ; i < n; i++) { 9 | dest[i] = '\0'; 10 | } 11 | return dest; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTOC/print.c: -------------------------------------------------------------------------------- 1 | #include <femtostdlib.h> 2 | 3 | /* print_dec, print_hex taken from picorv32 */ 4 | 5 | void print_string(const char* s) { 6 | for(const char* p = s; *p; ++p) { 7 | putchar(*p); 8 | } 9 | } 10 | 11 | int puts(const char* s) { 12 | print_string(s); 13 | putchar('\n'); 14 | return 1; 15 | } 16 | 17 | void print_dec(int val) { 18 | char buffer[255]; 19 | char *p = buffer; 20 | if(val < 0) { 21 | putchar('-'); 22 | print_dec(-val); 23 | return; 24 | } 25 | while (val || p == buffer) { 26 | *(p++) = val % 10; 27 | val = val / 10; 28 | } 29 | while (p != buffer) { 30 | putchar('0' + *(--p)); 31 | } 32 | } 33 | 34 | void print_hex(unsigned int val) { 35 | print_hex_digits(val, 8); 36 | } 37 | 38 | void print_hex_digits(unsigned int val, int nbdigits) { 39 | for (int i = (4*nbdigits)-4; i >= 0; i -= 4) { 40 | putchar("0123456789ABCDEF"[(val >> i) % 16]); 41 | } 42 | } 43 | 44 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTOC/printf.c: -------------------------------------------------------------------------------- 1 | #include <femtostdlib.h> 2 | #include <stdarg.h> 3 | 4 | int printf(const char *fmt,...) 5 | { 6 | va_list ap; 7 | 8 | for(va_start(ap, fmt);*fmt;fmt++) 9 | { 10 | if(*fmt=='%') 11 | { 12 | fmt++; 13 | if(*fmt=='s') print_string(va_arg(ap,char *)); 14 | else if(*fmt=='x') print_hex(va_arg(ap,int)); 15 | else if(*fmt=='d') print_dec(va_arg(ap,int)); 16 | else if(*fmt=='c') putchar(va_arg(ap,int)); 17 | else putchar(*fmt); 18 | } 19 | else putchar(*fmt); 20 | } 21 | 22 | va_end(ap); 23 | 24 | return 0; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTOGL/Makefile: -------------------------------------------------------------------------------- 1 | include ../makefile.inc 2 | 3 | OBJECTS= font_8x16.o font_8x8.o font_5x6.o font_3x5.o \ 4 | femtoGL.o femtoGLtext.o femtoGLfill_rect.o\ 5 | femtoGLsetpixel.o femtoGLline.o femtoGLfill_poly.o \ 6 | tty_init.o max7219_text.o \ 7 | FGA_mode.o FGA.o \ 8 | femto_GUI.o 9 | 10 | all: $(RVGCC) libfemtoGL.a 11 | 12 | libfemtoGL.a: $(OBJECTS) 13 | $(RVAR) cq libfemtoGL.a $(OBJECTS) 14 | $(RVRANLIB) libfemtoGL.a 15 | 16 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTOGL/femtoGLfill_rect.c: -------------------------------------------------------------------------------- 1 | #include <femtoGL.h> 2 | 3 | void GL_fill_rect( 4 | uint32_t x1, uint32_t y1, uint32_t x2, uint32_t y2, uint16_t color 5 | ) { 6 | #ifdef FGA 7 | if(FGA_mode == -1) { 8 | GL_write_window(x1,y1,x2,y2); 9 | for(int y=y1; y<=y2; ++y) { 10 | for(int x=x1; x<=x2; ++x) { 11 | GL_WRITE_DATA_UINT16(color); 12 | } 13 | } 14 | } else { 15 | FGA_fill_rect(x1,y1,x2,y2,color); 16 | } 17 | #else 18 | GL_write_window(x1,y1,x2,y2); 19 | for(int y=y1; y<=y2; ++y) { 20 | for(int x=x1; x<=x2; ++x) { 21 | GL_WRITE_DATA_UINT16(color); 22 | } 23 | } 24 | #endif 25 | } 26 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTOGL/femtoGLsetpixel.c: -------------------------------------------------------------------------------- 1 | #include <femtoGL.h> 2 | 3 | void GL_setpixel(int x, int y, uint16_t color) { 4 | GL_write_window(x,y,x,y); 5 | GL_WRITE_DATA_UINT16(color); 6 | } 7 | 8 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTOGL/max7219_text.c: -------------------------------------------------------------------------------- 1 | #include <femtoGL.h> 2 | 3 | static uint8_t buff[16] = { 4 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 5 | }; 6 | 7 | void MAX7219_shift() { 8 | for(int i=0; i<15; ++i) { 9 | if(i<8) { 10 | MAX7219(i+1, buff[i]); 11 | } 12 | buff[i] = buff[i+1]; 13 | } 14 | delay(60); 15 | } 16 | 17 | 18 | int MAX7219_putchar(int c) { 19 | int i; 20 | if(c == 10) { 21 | MAX7219_putchar(' '); 22 | MAX7219_putchar(' '); 23 | return c; 24 | } 25 | if(c == 13) { 26 | MAX7219_putchar(' '); 27 | MAX7219_putchar(' '); 28 | return c; 29 | } 30 | 31 | for(i=0; i<8; ++i) { 32 | buff[8+i] = font_8x8[8*c+i]; 33 | } 34 | for(i=0; i<8; ++i) { 35 | MAX7219_shift(); 36 | } 37 | 38 | return c; 39 | } 40 | 41 | void MAX7219_tty_init() { 42 | MAX7219_init(); 43 | for(int i=0; i<8; ++i) { 44 | MAX7219(i+1, 0); 45 | } 46 | set_putcharfunc(MAX7219_putchar); 47 | } 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTOGL/tty_init.c: -------------------------------------------------------------------------------- 1 | #include <femtoGL.h> 2 | 3 | void femtosoc_tty_init() { 4 | 5 | /* default mode is UART */ 6 | if(FEMTOSOC_HAS_DEVICE(IO_SSD1351_CNTL_bit)) { 7 | /* If OLED screen is configured, redirect output to it */ 8 | GL_tty_init(GL_MODE_OLED); 9 | } else if(FEMTOSOC_HAS_DEVICE(IO_MAX7219_DAT_bit)) { 10 | /* else if LED matrix is configured, redirect output to it */ 11 | MAX7219_tty_init(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTORV32/HardwareConfig_bits.h: -------------------------------------------------------------------------------- 1 | /* Constants for memory-mapped IO registers. */ 2 | /* Automatically extracted from RTL/DEVICES/HardwareConfig_bits.v */ 3 | 4 | #define IO_LEDS_bit 0 5 | #define IO_UART_DAT_bit 1 6 | #define IO_UART_CNTL_bit 2 7 | #define IO_SSD1351_CNTL_bit 3 8 | #define IO_SSD1351_CMD_bit 4 9 | #define IO_SSD1351_DAT_bit 5 10 | #define IO_SSD1351_DAT16_bit 6 11 | #define IO_MAX7219_DAT_bit 7 12 | #define IO_SDCARD_bit 8 13 | #define IO_BUTTONS_bit 9 14 | #define IO_FGA_CNTL_bit 10 15 | #define IO_FGA_DAT_bit 11 16 | #define IO_HW_CONFIG_RAM_bit 17 17 | #define IO_HW_CONFIG_DEVICES_bit 18 18 | #define IO_HW_CONFIG_CPUINFO_bit 19 19 | #define IO_MAPPED_SPI_FLASH_bit 20 20 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTORV32/HardwareConfig_bits.inc: -------------------------------------------------------------------------------- 1 | 2 | # Constants for memory-mapped IO registers. 3 | # Automatically extracted from RTL/DEVICES/HardwareConfig_bits.v 4 | 5 | .equ IO_LEDS_bit, 0 6 | .equ IO_UART_DAT_bit, 1 7 | .equ IO_UART_CNTL_bit, 2 8 | .equ IO_SSD1351_CNTL_bit, 3 9 | .equ IO_SSD1351_CMD_bit, 4 10 | .equ IO_SSD1351_DAT_bit, 5 11 | .equ IO_SSD1351_DAT16_bit, 6 12 | .equ IO_MAX7219_DAT_bit, 7 13 | .equ IO_SDCARD_bit, 8 14 | .equ IO_BUTTONS_bit, 9 15 | .equ IO_FGA_CNTL_bit, 10 16 | .equ IO_FGA_DAT_bit, 11 17 | .equ IO_HW_CONFIG_RAM_bit, 17 18 | .equ IO_HW_CONFIG_DEVICES_bit, 18 19 | .equ IO_HW_CONFIG_CPUINFO_bit, 19 20 | .equ IO_MAPPED_SPI_FLASH_bit, 20 21 | 22 | ################################################################# 23 | # IO_XXX = 1 << (IO_XXX_bit + 2) 24 | 25 | .equ IO_LEDS, 4 26 | .equ IO_UART_DAT, 8 27 | .equ IO_UART_CNTL, 16 28 | .equ IO_SSD1351_CNTL, 32 29 | .equ IO_SSD1351_CMD, 64 30 | .equ IO_SSD1351_DAT, 128 31 | .equ IO_SSD1351_DAT16, 256 32 | .equ IO_MAX7219_DAT, 512 33 | .equ IO_SDCARD, 1024 34 | .equ IO_BUTTONS, 2048 35 | .equ IO_FGA_CNTL, 4096 36 | .equ IO_FGA_DAT, 8192 37 | .equ IO_HW_CONFIG_RAM, 524288 38 | .equ IO_HW_CONFIG_DEVICES, 1048576 39 | .equ IO_HW_CONFIG_CPUINFO, 2097152 40 | .equ IO_MAPPED_SPI_FLASH, 4194304 41 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTORV32/Makefile: -------------------------------------------------------------------------------- 1 | include ../makefile.inc 2 | 3 | FAT_IO_OBJS_WITH_DIR=fat_io_lib/fat_access.o fat_io_lib/fat_cache.o \ 4 | fat_io_lib/fat_filelib.o fat_io_lib/fat_format.o fat_io_lib/fat_misc.o \ 5 | fat_io_lib/fat_string.o fat_io_lib/fat_table.o fat_io_lib/fat_write.o 6 | 7 | FAT_IO_OBJS=fat_access.o fat_cache.o fat_filelib.o fat_format.o fat_misc.o \ 8 | fat_string.o fat_table.o fat_write.o 9 | 10 | OBJECTS= femtorv32.o max7219.o ssd1351_1331.o ssd1351_1331_init.o uart.o keyboard.o \ 11 | virtual_io.o \ 12 | wait_cycles.o microwait.o milliwait.o milliseconds.o\ 13 | spi_sd.o cycles_32.o cycles_64.o \ 14 | filesystem.o exec.o femto_elf.o 15 | 16 | all: $(RVGCC) libfemtorv32.a 17 | 18 | libfemtorv32.a: $(OBJECTS) $(FAT_IO_OBJS_WITH_DIR) 19 | $(RVAR) cq libfemtorv32.a $(OBJECTS) $(FAT_IO_OBJS) 20 | $(RVRANLIB) libfemtorv32.a 21 | 22 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTORV32/cycles_32.c: -------------------------------------------------------------------------------- 1 | #include <femtorv32.h> 2 | 3 | // Gets the number of cycles elapsed from device startup. 4 | // This version for processors that do not have 64-bits 5 | // tick counter. 6 | 7 | #ifndef CYCLES_64 8 | uint64_t cycles() RV32_FASTCODE; 9 | uint64_t cycles() { 10 | static uint32_t cycles_lap_=0; 11 | static uint64_t cycles_=0; 12 | static uint32_t last_cycles32_=0; 13 | uint32_t cycles32_; 14 | 15 | if(cycles_lap_ == 0) { 16 | cycles_lap_ = FEMTORV32_COUNTER_BITS; 17 | if(cycles_lap_ == 32) { 18 | cycles_lap_ = ~0u; 19 | } else { 20 | cycles_lap_ = 1u << cycles_lap_; 21 | } 22 | } 23 | 24 | 25 | asm volatile ("rdcycle %0" : "=r"(cycles32_)); 26 | // Detect counter overflow 27 | if(cycles32_ < last_cycles32_) { 28 | cycles_ += cycles_lap_; 29 | } 30 | cycles_ += cycles32_; 31 | cycles_ -= last_cycles32_; 32 | last_cycles32_ = cycles32_; 33 | return cycles_; 34 | } 35 | #endif 36 | 37 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTORV32/cycles_64.S: -------------------------------------------------------------------------------- 1 | .include "femtorv32.inc" 2 | 3 | # This version for processors that have a 64-bits ticks counter. 4 | 5 | .ifdef CYCLES_64 6 | .global cycles 7 | .type cycles, @function 8 | 9 | cycles: 10 | rdcycleh a1 11 | rdcycle a0 12 | rdcycleh t0 13 | bne t0, a1, cycles 14 | ret 15 | .endif 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTORV32/fat_io_lib/fat_cache.h: -------------------------------------------------------------------------------- 1 | #ifndef __FAT_CACHE_H__ 2 | #define __FAT_CACHE_H__ 3 | 4 | #include "fat_filelib.h" 5 | 6 | //----------------------------------------------------------------------------- 7 | // Prototypes 8 | //----------------------------------------------------------------------------- 9 | int fatfs_cache_init(struct fatfs *fs, FL_FILE *file); 10 | int fatfs_cache_get_next_cluster(struct fatfs *fs, FL_FILE *file, uint32 clusterIdx, uint32 *pNextCluster); 11 | int fatfs_cache_set_next_cluster(struct fatfs *fs, FL_FILE *file, uint32 clusterIdx, uint32 nextCluster); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTORV32/fat_io_lib/fat_format.h: -------------------------------------------------------------------------------- 1 | #ifndef __FAT_FORMAT_H__ 2 | #define __FAT_FORMAT_H__ 3 | 4 | #include "fat_defs.h" 5 | #include "fat_opts.h" 6 | #include "fat_access.h" 7 | 8 | //----------------------------------------------------------------------------- 9 | // Prototypes 10 | //----------------------------------------------------------------------------- 11 | int fatfs_format(struct fatfs *fs, uint32 volume_sectors, const char *name); 12 | int fatfs_format_fat16(struct fatfs *fs, uint32 volume_sectors, const char *name); 13 | int fatfs_format_fat32(struct fatfs *fs, uint32 volume_sectors, const char *name); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTORV32/fat_io_lib/fat_string.h: -------------------------------------------------------------------------------- 1 | #ifndef __FILESTRING_H__ 2 | #define __FILESTRING_H__ 3 | 4 | //----------------------------------------------------------------------------- 5 | // Prototypes 6 | //----------------------------------------------------------------------------- 7 | int fatfs_total_path_levels(char *path); 8 | int fatfs_get_substring(char *Path, int levelreq, char *output, int max_len); 9 | int fatfs_split_path(char *FullPath, char *Path, int max_path, char *FileName, int max_filename); 10 | int fatfs_compare_names(char* strA, char* strB); 11 | int fatfs_string_ends_with_slash(char *path); 12 | int fatfs_get_sfn_display_name(char* out, char* in); 13 | int fatfs_get_extension(char* filename, char* out, int maxlen); 14 | int fatfs_create_path_string(char* path, char *filename, char* out, int maxlen); 15 | 16 | #ifndef NULL 17 | #define NULL 0 18 | #endif 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTORV32/fat_io_lib/fat_table.h: -------------------------------------------------------------------------------- 1 | #ifndef __FAT_TABLE_H__ 2 | #define __FAT_TABLE_H__ 3 | 4 | #include "fat_opts.h" 5 | #include "fat_misc.h" 6 | 7 | //----------------------------------------------------------------------------- 8 | // Prototypes 9 | //----------------------------------------------------------------------------- 10 | void fatfs_fat_init(struct fatfs *fs); 11 | int fatfs_fat_purge(struct fatfs *fs); 12 | uint32 fatfs_find_next_cluster(struct fatfs *fs, uint32 current_cluster); 13 | void fatfs_set_fs_info_next_free_cluster(struct fatfs *fs, uint32 newValue); 14 | int fatfs_find_blank_cluster(struct fatfs *fs, uint32 start_cluster, uint32 *free_cluster); 15 | int fatfs_fat_set_cluster(struct fatfs *fs, uint32 cluster, uint32 next_cluster); 16 | int fatfs_fat_add_cluster_to_chain(struct fatfs *fs, uint32 start_cluster, uint32 newEntry); 17 | int fatfs_free_cluster_chain(struct fatfs *fs, uint32 start_cluster); 18 | uint32 fatfs_count_free_clusters(struct fatfs *fs); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTORV32/fat_io_lib/fat_write.h: -------------------------------------------------------------------------------- 1 | #ifndef __FAT_WRITE_H__ 2 | #define __FAT_WRITE_H__ 3 | 4 | #include "fat_defs.h" 5 | #include "fat_opts.h" 6 | 7 | //----------------------------------------------------------------------------- 8 | // Prototypes 9 | //----------------------------------------------------------------------------- 10 | int fatfs_add_file_entry(struct fatfs *fs, uint32 dirCluster, char *filename, char *shortfilename, uint32 startCluster, uint32 size, int dir); 11 | int fatfs_add_free_space(struct fatfs *fs, uint32 *startCluster, uint32 clusters); 12 | int fatfs_allocate_free_space(struct fatfs *fs, int newFile, uint32 *startCluster, uint32 size); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTORV32/femtorv32.S: -------------------------------------------------------------------------------- 1 | .include "femtorv32.inc" 2 | 3 | ################################################################################# 4 | 5 | # FemtoRV32 support library 6 | 7 | # exit function: display exit code 8 | # on LEDS, or spinning wheel if exit 9 | # code is zero. 10 | .global exit 11 | .type exit, @function 12 | exit: 13 | sw a0, IO_LEDS(gp) # display exit code 14 | exitl1: 15 | bnez a0, exitl1 # if exit code is non-0, loop. 16 | exitl: 17 | li t0, 1 18 | sw t0, IO_LEDS(gp) 19 | li a0, 100 20 | call milliwait 21 | li t0, 2 22 | sw t0, IO_LEDS(gp) 23 | li a0, 100 24 | call milliwait 25 | li t0, 4 26 | sw t0, IO_LEDS(gp) 27 | li a0, 100 28 | call milliwait 29 | li t0, 8 30 | sw t0, IO_LEDS(gp) 31 | li a0, 100 32 | call milliwait 33 | j exitl 34 | 35 | .global abort 36 | .type abort, @function 37 | abort: ebreak 38 | ret 39 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTORV32/femtorv32.inc: -------------------------------------------------------------------------------- 1 | ################################################################################# 2 | 3 | # Mapped IO constants 4 | 5 | .equ IO_BASE, 0x400000 # Base address of memory-mapped IO 6 | 7 | .include "HardwareConfig_bits.inc" # generated from RTL/DEVICES/HardwareConfig_bits.v 8 | 9 | ################################################################################ 10 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTORV32/filesystem.c: -------------------------------------------------------------------------------- 1 | #include <femtorv32.h> 2 | 3 | int filesystem_init() { 4 | LEDS(1); 5 | if(sd_init()) { 6 | printf("ERROR:\nCould not init\n SDCard\n"); 7 | return -1; 8 | } 9 | fl_init(); 10 | LEDS(2); 11 | if(fl_attach_media( 12 | (fn_diskio_read)sd_readsector, 13 | (fn_diskio_write)sd_writesector) != FAT_INIT_OK 14 | ) { 15 | printf("ERROR:\nCould not init\nfile system\n"); 16 | return -1; 17 | } 18 | LEDS(4); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTORV32/keyboard.c: -------------------------------------------------------------------------------- 1 | #include "femtorv32.h" 2 | #include "keyboard.h" 3 | 4 | int UART_pollkey() { 5 | uint64_t t0; 6 | int k1,k2; 7 | k1 = IO_IN(IO_UART_DAT); 8 | if(!(k1 & 256)) { 9 | return 0; // Bit 8 = 0: no data ready 10 | } 11 | 12 | k1 &= 255; 13 | if(k1 != 27) { 14 | return k1; 15 | } 16 | 17 | // Two-character escape sequence 18 | t0 = milliseconds(); 19 | while(milliseconds()-t0 < 10); 20 | while(milliseconds()-t0 < 100) { 21 | k2 = IO_IN(IO_UART_DAT); 22 | if(k2 & 256) { 23 | k2 &= 255; 24 | return (27 << 8) | k2; 25 | } 26 | } 27 | 28 | // If no other character appears in 29 | // 100 ms, then it is just the escape key 30 | return 27; 31 | } 32 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTORV32/keyboard.h: -------------------------------------------------------------------------------- 1 | 2 | #define KEY_ESCAPE 27 3 | #define KEY_UP ((27 << 8) | 65) 4 | #define KEY_DOWN ((27 << 8) | 66) 5 | #define KEY_RIGHT ((27 << 8) | 67) 6 | #define KEY_LEFT ((27 << 8) | 68) 7 | #define KEY_BACKSPACE 8 8 | #define KEY_ENTER 13 9 | 10 | int UART_pollkey(); 11 | 12 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTORV32/max7219.S: -------------------------------------------------------------------------------- 1 | .include "femtorv32.inc" 2 | 3 | 4 | ################################################################################# 5 | # femtorv led matrix support 6 | ################################################################################# 7 | 8 | .global MAX7219 9 | .type MAX7219, @function 10 | MAX7219: # a0: register a1: value 11 | slli t0, a0, 8 12 | or t0, t0, a1 13 | sw t0, IO_MAX7219_DAT(gp) 14 | ret 15 | 16 | .global MAX7219_init 17 | .type MAX7219_init, @function 18 | MAX7219_init: 19 | add sp,sp,-4 20 | sw ra, 0(sp) 21 | li a0, 0x09 # decode mode 22 | li a1, 0x00 23 | call MAX7219 24 | li a0, 0x0a # intensity 25 | li a1, 0x0f 26 | call MAX7219 27 | li a0, 0x0b # scan limit 28 | li a1, 0x07 29 | call MAX7219 30 | li a0, 0x0c # shutdown 31 | li a1, 0x01 32 | call MAX7219 33 | li a0, 0x0f # display test 34 | li a1, 0x00 35 | call MAX7219 36 | lw ra, 0(sp) 37 | add sp,sp,4 38 | ret 39 | 40 | 41 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTORV32/microwait.c: -------------------------------------------------------------------------------- 1 | #include <femtorv32.h> 2 | 3 | void microwait(int time) { 4 | if(time) { 5 | wait_cycles(time * FEMTORV32_FREQ); 6 | } 7 | } 8 | 9 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTORV32/milliseconds.c: -------------------------------------------------------------------------------- 1 | #include <femtorv32.h> 2 | 3 | uint64_t milliseconds() { 4 | uint64_t freq = (uint64_t)FEMTORV32_FREQ; 5 | uint64_t cyc = (uint64_t)cycles(); 6 | return cyc / (freq * 1000); 7 | } 8 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTORV32/milliwait.c: -------------------------------------------------------------------------------- 1 | #include <femtorv32.h> 2 | 3 | void milliwait(int time) { 4 | wait_cycles(time * 1000 * FEMTORV32_FREQ); 5 | } 6 | 7 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTORV32/uart.S: -------------------------------------------------------------------------------- 1 | .include "femtorv32.inc" 2 | 3 | ################################################################################# 4 | # NanoRv UART support 5 | ################################################################################# 6 | 7 | .global UART_putchar 8 | .type UART_putchar, @function 9 | UART_putchar: 10 | sw a0,IO_UART_DAT(gp) 11 | pcrx: lw t0,IO_UART_DAT(gp) 12 | andi t0,t0,512 # bit 9 = busy 13 | bnez t0,pcrx 14 | ret 15 | 16 | .global UART_getchar 17 | .type UART_getchar, @function 18 | UART_getchar: 19 | lw a0,IO_UART_DAT(gp) 20 | andi t0,a0,256 # bit 8 = data ready 21 | beqz t0,UART_getchar 22 | andi a0, a0, 255 23 | li t0, 10 # <enter> generates CR/LF, we ignore LF. 24 | beq a0, t0, UART_getchar 25 | ret 26 | 27 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTORV32/virtual_io.c: -------------------------------------------------------------------------------- 1 | #include <femtorv32.h> 2 | 3 | extern int UART_putchar(int); 4 | extern int UART_getchar(); 5 | 6 | static putcharfunc_t putcharfunc = UART_putchar; 7 | static getcharfunc_t getcharfunc = UART_getchar; 8 | 9 | void set_putcharfunc(putcharfunc_t f) { 10 | putcharfunc = f; 11 | } 12 | 13 | void set_getcharfunc(getcharfunc_t f) { 14 | getcharfunc = f; 15 | } 16 | 17 | int putchar(int c) { 18 | return (*putcharfunc)(c); 19 | } 20 | 21 | int getchar() { 22 | return (*getcharfunc)(); 23 | } 24 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/LIBFEMTORV32/wait_cycles.c: -------------------------------------------------------------------------------- 1 | #include <femtorv32.h> 2 | 3 | void wait_cycles(int nb_cycles) { 4 | uint64_t lim = cycles() + (uint64_t)nb_cycles; 5 | while(cycles()<lim); 6 | } 7 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/MECRISP_QUINTUS/mecrisp-quintus-hx1k-with-disassembler.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/FIRMWARE/MECRISP_QUINTUS/mecrisp-quintus-hx1k-with-disassembler.bin -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/MECRISP_QUINTUS/mecrisp-quintus-hx1k.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/FIRMWARE/MECRISP_QUINTUS/mecrisp-quintus-hx1k.bin -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/Makefile: -------------------------------------------------------------------------------- 1 | libs: 2 | (cd LIBFEMTOGL; make clean all) # Compile graphic library 3 | (cd LIBFEMTORV32; make clean all) # Compile hardware support lib 4 | (cd LIBFEMTOC; make clean all) # Compile lib with printf() replacement function 5 | (cd CRT; make clean all) # Compile C runtime for baremetal 6 | @echo ==== Generated femtorv32 libs. 7 | -------------------------------------------------------------------------------- /FemtoRV/FIRMWARE/README.txt: -------------------------------------------------------------------------------- 1 | See comments in config.sh 2 | 3 | 4 | 5 | REFERENCES 6 | ========== 7 | 8 | Coding style recommendations: https://docs.opentitan.org/doc/rm/asm_coding_style/ 9 | ABI, pseudo-instructions: page 109 of https://content.riscv.org/wp-content/uploads/2017/05/riscv-spec-v2.2.pdf 10 | -------------------------------------------------------------------------------- /FemtoRV/RTL/CONFIGS/bench_config.v: -------------------------------------------------------------------------------- 1 | 2 | `define NRV_IO_LEDS 3 | `define NRV_IO_UART 4 | `define NRV_IO_SSD1351 5 | `define NRV_FREQ 1 6 | 7 | 8 | //`define NRV_FEMTORV32_QUARK // RV32I (the most elementary femtorv) 9 | //`define NRV_FEMTORV32_ELECTRON // RV32IM 10 | //`define NRV_FEMTORV32_INTERMISSUM // RV32IMzCSR 11 | //`define NRV_FEMTORV32_GRACILIS // RV32IMCzCSR 12 | `define NRV_FEMTORV32_PETITBATEAU // WIP RF32F !! 13 | //`define NRV_FEMTORV32_TESTDRIVE 14 | 15 | `define NRV_RESET_ADDR 0 16 | `define NRV_RAM 65536 17 | `define NRV_IO_HARDWARE_CONFIG 18 | `define NRV_CONFIGURED 19 | 20 | -------------------------------------------------------------------------------- /FemtoRV/RTL/DEVICES/Buttons.v: -------------------------------------------------------------------------------- 1 | // femtorv32, a minimalistic RISC-V RV32I core 2 | // Bruno Levy, 2020-2021 3 | // 4 | // This file: driver for the buttons (does nearly nothing, 5 | // could include some filtering here). 6 | 7 | module Buttons( 8 | input wire sel, // select (read/write ignored if low) 9 | output wire [31:0] rdata, // read data 10 | 11 | input wire[5:0] BUTTONS // the six pins wired to the buttons 12 | ); 13 | 14 | assign rdata = (sel ? {26'b0, BUTTONS} : 32'b0); 15 | 16 | endmodule 17 | -------------------------------------------------------------------------------- /FemtoRV/RTL/DEVICES/SDCard.v: -------------------------------------------------------------------------------- 1 | // femtorv32, a minimalistic RISC-V RV32I core 2 | // Bruno Levy, 2020-2021 3 | // 4 | // This file: driver for SDCard (does nearly nothing, 5 | // for now it is just an interface for software bitbanging, 6 | // see FIRMWARE/LIBFEMTORV32/spi_sd.c) 7 | // 8 | 9 | module SDCard( 10 | input wire clk, // system clock 11 | input wire rstrb, // read strobe 12 | input wire wstrb, // write strobe 13 | input wire sel, // select (read/write ignored if low) 14 | input wire [31:0] wdata, // data to be written 15 | output wire [31:0] rdata, // read data 16 | 17 | output wire MOSI, 18 | input wire MISO, 19 | output wire CS_N, 20 | output wire CLK 21 | ); 22 | reg [2:0] state; // CS_N,CLK,MOSI 23 | 24 | assign CS_N = state[2]; 25 | assign CLK = state[1]; 26 | assign MOSI = state[0]; 27 | 28 | initial begin 29 | state = 3'b100; 30 | end 31 | 32 | assign rdata = (sel ? {31'b0, MISO} : 32'b0); 33 | 34 | always @(posedge clk) begin 35 | if(sel && wstrb) begin 36 | state <= wdata[2:0]; 37 | end 38 | end 39 | 40 | endmodule 41 | -------------------------------------------------------------------------------- /FemtoRV/RTL/PLL/femtopll.v: -------------------------------------------------------------------------------- 1 | /* 2 | * The PLL, that generates the internal clock (high freq) from the 3 | * external one (lower freq). 4 | * Trying to make something that is portable between different boards 5 | * For now, ICEStick, ULX3S, ECP5 evaluation boards, FOMU supported. 6 | * WIP: IceFeather 7 | */ 8 | 9 | `ifdef BENCH_OR_LINT 10 | `define PASSTHROUGH_PLL 11 | `endif 12 | 13 | /**********************************************************************/ 14 | 15 | `ifdef PASSTHROUGH_PLL 16 | module femtoPLL #( 17 | parameter freq = 60 18 | ) ( 19 | input pclk, 20 | output clk 21 | ); 22 | assign clk = pclk; 23 | endmodule 24 | `else 25 | `ifdef ICE_STICK 26 | `include "pll_icestick.v" 27 | `elsif ICE_BREAKER 28 | `include "pll_icebreaker.v" 29 | `elsif ICE_FEATHER 30 | `include "pll_icefeather.v" 31 | `elsif ICE_SUGAR 32 | `include "pll_icesugar.v" 33 | `elsif ULX3S 34 | `include "pll_ulx3s.v" 35 | `elsif ECP5_EVN 36 | `include "pll_ecp5_evn.v" 37 | `elsif FOMU 38 | `include "pll_fomu.v" 39 | `elsif ARTY 40 | `include "pll_arty.v" 41 | `elsif CMODA7 42 | `include "pll_cmod_a7.v" 43 | `endif 44 | `endif 45 | 46 | -------------------------------------------------------------------------------- /FemtoRV/RTL/PLL/frequencies.txt: -------------------------------------------------------------------------------- 1 | 16 2 | 20 3 | 24 4 | 25 5 | 30 6 | 35 7 | 40 8 | 45 9 | 48 10 | 50 11 | 55 12 | 60 13 | 65 14 | 66 15 | 70 16 | 75 17 | 80 18 | 85 19 | 90 20 | 95 21 | 100 22 | 105 23 | 110 24 | 115 25 | 120 26 | 125 27 | 130 28 | 135 29 | 140 30 | 150 31 | 160 32 | 170 33 | 180 34 | 190 35 | 200 -------------------------------------------------------------------------------- /FemtoRV/RTL/PLL/gen_plls.sh: -------------------------------------------------------------------------------- 1 | 2 | echo Generating PLL for FOMU 3 | ./gen_pll.sh ICE40 48 > pll_fomu.v 4 | 5 | echo Generating PLL for IceFeather 6 | ./gen_pll.sh ICE40 12 > pll_icefeather.v 7 | 8 | echo Generating PLL for IceStick 9 | ./gen_pll.sh ICE40 12 > pll_icestick.v 10 | 11 | echo Generating PLL for IceSugar 12 | ./gen_pll.sh ICE40 12 > pll_icesugar.v 13 | 14 | echo Generating PLL for ULX3S 15 | ./gen_pll.sh ECP5 25 > pll_ulx3s.v 16 | 17 | echo Generating PLL for ECP5 evaluation board 18 | ./gen_pll.sh ECP5 12 > pll_ecp5_evn.v -------------------------------------------------------------------------------- /FemtoRV/RTL/PLL/pll_arty.v: -------------------------------------------------------------------------------- 1 | module femtoPLL #( 2 | parameter freq = 50 3 | ) ( 4 | input wire pclk, 5 | output wire clk 6 | ); 7 | 8 | wire clk_feedback; 9 | wire clk_internal; 10 | 11 | // .CLKFBOUT_MULT(8) 12 | // .CLKOUT0_DIVIDE(8*100/freq) 13 | 14 | PLLE2_ADV #( 15 | .BANDWIDTH("OPTIMIZED"), // OPTIMIZED, HIGH, LOW 16 | .CLKFBOUT_MULT(freq/5), // Multiply value for all CLKOUT (2-64) 17 | .CLKFBOUT_PHASE("0.0"), // Phase offset in degrees of CLKFB, (-360-360) 18 | .CLKIN1_PERIOD("10.0"), // Input clock period in ns to ps resolution 19 | .CLKOUT0_DIVIDE(20), 20 | .CLKOUT0_DUTY_CYCLE("0.5"), 21 | .CLKOUT0_PHASE("0.0"), 22 | .DIVCLK_DIVIDE(1), // Master division value , (1-56) 23 | .REF_JITTER1("0.0"), // Reference input jitter in UI (0.000-0.999) 24 | .STARTUP_WAIT("FALSE") // Delayu DONE until PLL Locks, ("TRUE"/"FALSE") 25 | ) genclock( 26 | .CLKOUT0(clk_internal), 27 | .CLKFBOUT(clk_feedback), // 1-bit output, feedback clock 28 | .CLKIN1(pclk), 29 | .PWRDWN(1'b0), 30 | .RST(1'b0), 31 | .CLKFBIN(clk_feedback) // 1-bit input, feedback clock 32 | ); 33 | 34 | BUFG bufg( 35 | .I(clk_internal), 36 | .O(clk) 37 | ); 38 | 39 | endmodule 40 | -------------------------------------------------------------------------------- /FemtoRV/RTL/PLL/pll_cmod_a7.v: -------------------------------------------------------------------------------- 1 | module femtoPLL #( 2 | parameter freq = 50 3 | ) ( 4 | input wire pclk, 5 | output wire clk 6 | ); 7 | 8 | wire clk_feedback; 9 | wire clk_internal; 10 | 11 | // .CLKFBOUT_MULT(8) 12 | // .CLKOUT0_DIVIDE(8*100/freq) 13 | 14 | PLLE2_ADV #( 15 | .BANDWIDTH("OPTIMIZED"), // OPTIMIZED, HIGH, LOW 16 | .CLKFBOUT_MULT(freq/5), // Multiply value for all CLKOUT (2-64) 17 | .CLKFBOUT_PHASE("0.0"), // Phase offset in degrees of CLKFB, (-360-360) 18 | .CLKIN1_PERIOD("10.0"), // Input clock period in ns to ps resolution 19 | .CLKOUT0_DIVIDE(20), 20 | .CLKOUT0_DUTY_CYCLE("0.5"), 21 | .CLKOUT0_PHASE("0.0"), 22 | .DIVCLK_DIVIDE(1), // Master division value , (1-56) 23 | .REF_JITTER1("0.0"), // Reference input jitter in UI (0.000-0.999) 24 | .STARTUP_WAIT("FALSE") // Delayu DONE until PLL Locks, ("TRUE"/"FALSE") 25 | ) genclock( 26 | .CLKOUT0(clk_internal), 27 | .CLKFBOUT(clk_feedback), // 1-bit output, feedback clock 28 | .CLKIN1(pclk), 29 | .PWRDWN(1'b0), 30 | .RST(1'b0), 31 | .CLKFBIN(clk_feedback) // 1-bit input, feedback clock 32 | ); 33 | 34 | BUFG bufg( 35 | .I(clk_internal), 36 | .O(clk) 37 | ); 38 | 39 | endmodule 40 | -------------------------------------------------------------------------------- /FemtoRV/RTL/PROCESSOR/TESTDRIVE/README.md: -------------------------------------------------------------------------------- 1 | This directory contains several versions of femtorv32, that I'm using 2 | for testing different features and influence on timings: 3 | - testdrive_RV32IM: tachyon core (with two execute cycles) with M extension 4 | - testdrive_RV32IM_simF: M extension, F decoder and simulated FPU (works only with Verilator) 5 | - testdrive_RV32IMF: M and F extensions 6 | 7 | I recommend using the other cores instead. 8 | -------------------------------------------------------------------------------- /FemtoRV/RTL/PROCESSOR/utils.v: -------------------------------------------------------------------------------- 1 | /********************* Utilities, macros for debugging *************/ 2 | 3 | `ifdef VERBOSE 4 | `define verbose(command) command 5 | `else 6 | `define verbose(command) 7 | `endif 8 | 9 | `ifdef BENCH 10 | `define BENCH_OR_LINT 11 | `ifdef QUIET 12 | `define bench(command) 13 | `else 14 | `define bench(command) command 15 | `endif 16 | `else 17 | `define bench(command) 18 | `endif 19 | 20 | `ifdef verilator 21 | `define BENCH_OR_LINT 22 | `endif 23 | -------------------------------------------------------------------------------- /FemtoRV/RTL/SDRAM/simulation/mt48lc16m16a2.v: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/RTL/SDRAM/simulation/mt48lc16m16a2.v -------------------------------------------------------------------------------- /FemtoRV/RTL/SDRAM/simulation/run-icarus: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | iverilog -o test_sdram.vvp -s test_sdram test_sdram.v ../muchtoremember.v mt48lc16m16a2.v 4 | vvp *.vvp 5 | 6 | 7 | -------------------------------------------------------------------------------- /FemtoRV/RTL/SDRAM/simulation/tidyup-icarus: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | rm -f *.vvp 4 | rm -f *.vcd 5 | 6 | 7 | -------------------------------------------------------------------------------- /FemtoRV/SIM/SSD1351.h: -------------------------------------------------------------------------------- 1 | /*****************************************************************/ 2 | #include "verilated.h" 3 | #include <GLFW/glfw3.h> 4 | 5 | // Emulates the 128x128 OLED display 6 | class SSD1351 { 7 | public: 8 | SSD1351( 9 | CData& DIN, CData& CLK, CData& CS, CData& DC, CData& RST 10 | ); 11 | 12 | void eval(); 13 | 14 | private: 15 | void redraw(); 16 | unsigned int flip(unsigned int x, unsigned int nb) { 17 | unsigned int result=0; 18 | for(unsigned int bit=0; bit<nb; ++bit) { 19 | if(x & (1 << bit)) { 20 | result |= (1 << (nb-1-bit)); 21 | } 22 | } 23 | return result; 24 | } 25 | 26 | private: 27 | CData& DIN_; 28 | CData& CLK_; 29 | CData& CS_; 30 | CData& DC_; 31 | CData& RST_; 32 | 33 | CData prev_CLK_; 34 | CData prev_CS_; 35 | unsigned int prev_word_; 36 | unsigned int cur_word_; 37 | unsigned int cur_bit_; 38 | unsigned int cur_command_; 39 | unsigned int cur_arg_[2]; 40 | unsigned int cur_arg_index_; 41 | 42 | GLFWwindow* window_; 43 | 44 | unsigned short framebuffer_[128*128]; 45 | 46 | unsigned int x_, x1_, x2_; 47 | unsigned int y_, y1_, y2_; 48 | unsigned int start_line_; 49 | 50 | bool fetch_next_half_; 51 | }; 52 | -------------------------------------------------------------------------------- /FemtoRV/SIM/sim_main.cpp: -------------------------------------------------------------------------------- 1 | #include "VfemtoRV32_bench.h" 2 | #include "verilated.h" 3 | #include "FPU_funcs.h" 4 | #include "SSD1351.h" 5 | #include <memory> 6 | #include <fenv.h> 7 | #include <xmmintrin.h> 8 | 9 | int main(int argc, char** argv, char** env) { 10 | 11 | // simplest rounding = ignore LSBs 12 | fesetround(FE_TOWARDZERO); 13 | 14 | // for now, flush denormalized result to zero. 15 | _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON); 16 | 17 | VfemtoRV32_bench top; 18 | SSD1351 oled( 19 | top.oled_DIN, top.oled_CLK, top.oled_CS, top.oled_DC, top.oled_RST 20 | ); 21 | top.pclk = 0; 22 | while(!Verilated::gotFinish()) { 23 | top.pclk = !top.pclk; 24 | top.eval(); 25 | oled.eval(); 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /FemtoRV/TOOLS/ice4pi_prog: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Usage: 4 | # ice4pi_prog fpga-bitstream.bin <firmware.bin> 5 | 6 | # Example1: 7 | # ice4pi_prog rot.bin 8 | 9 | 10 | # Example2: 11 | # ice4pi_prog femtosoc.bin hello.spiflash.bin 12 | 13 | 14 | #assert CRESET 15 | 16 | echo 24 > /sys/class/gpio/export || true 17 | echo out > /sys/class/gpio/gpio24/direction 18 | echo 1 >/sys/class/gpio/gpio24/value 19 | 20 | echo 0 >/sys/class/gpio/gpio24/value 21 | 22 | tr '\0' '\377' < /dev/zero | dd bs=1M count=4 of=image iflag=fullblock 23 | dd if=${1} conv=notrunc of=image 24 | if [[ $# -eq 2 ]] ; then 25 | dd if=${2} bs=128K seek=1 conv=notrunc of=image 26 | flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=20000 -w image 27 | fi 28 | 29 | #release CRESET 30 | 31 | echo 1 >/sys/class/gpio/gpio24/value 32 | -------------------------------------------------------------------------------- /FemtoRV/TOOLS/make_config.sh: -------------------------------------------------------------------------------- 1 | # Extracts compilation flags from selected board, and 2 | # write them to FIRMWARE/config.mk 3 | cd RTL 4 | iverilog -I PROCESSOR $1 -o tmp.vvp get_config.v 5 | vvp tmp.vvp > ../FIRMWARE/config.mk 6 | rm -f tmp.vvp 7 | echo BOARD=$BOARD >> ../FIRMWARE/config.mk 8 | cat ../FIRMWARE/config.mk 9 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/DESIGN/FemtoRV32.md: -------------------------------------------------------------------------------- 1 | FemtoRV32 Design: from zero to I,II,III,IV ... RISC-V 2 | ===================================================== 3 | 4 |  5 | 6 | _During the first confinement in March 2020, I grabbed an IceStick 7 | just before getting stuck at home, with the idea in mind to learn 8 | verilog and processor design. I came out with FemtoRV32, a super-simple design. 9 | It is too basic (no pipeline), but it may be useful to somebody who 10 | wants to quickly understand the general principles. This document 11 | is written from my curated notes, keeping the order in which I 12 | understood different things and how they mesh together._ 13 | 14 | - [Episode I](FemtoRV32_I.md) 15 | - [Episode II](FemtoRV32_II.md) 16 | - [Episode III](FemtoRV32_III.md) 17 | - [Episode IV](FemtoRV32_IV.md) 18 | - [Episode V](FemtoRV32_V.md) 19 | - [Episode VI](FemtoRV32_VI.md) 20 | - [Episode VII](FemtoRV32_VII.md) 21 | - [Episode VIII](FemtoRV32_VIII.md) 22 | - [Episode IX](FemtoRV32_IX.md) 23 | - [Episode X](FemtoRV32_X.md) 24 | 25 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/DESIGN/FemtoRV32_VII.md: -------------------------------------------------------------------------------- 1 | Episode VII: Linear execution flow, adding `reg <- reg OP imm` ALU instructions 2 | ---------------------------------------------------------------------------- 3 |  4 | 5 | Let us now introduce the ALU operations that take immediate values. To 6 | do that, as shown in the schematic, we insert a mux before the 7 | second ALU input. This mux selects either the second output register 8 | from the register file or the decoded immediate value. It is driven by 9 | an additional signal generated by the instruction decoder. 10 | 11 | We have implemented 2 out of 7 instructions, let us continue... 12 | 13 | [Next](FemtoRV32_VIII.md) -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/DESIGN/Images/6502.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/DESIGN/Images/6502.jpg -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/DESIGN/Images/FemtoRV32_design.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/DESIGN/Images/FemtoRV32_design.jpg -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/DESIGN/Images/FemtoRV32_design_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/DESIGN/Images/FemtoRV32_design_1.jpg -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/DESIGN/Images/FemtoRV32_design_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/DESIGN/Images/FemtoRV32_design_2.jpg -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/DESIGN/Images/FemtoRV32_design_3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/DESIGN/Images/FemtoRV32_design_3.jpg -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/DESIGN/Images/FemtoRV32_design_4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/DESIGN/Images/FemtoRV32_design_4.jpg -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/DESIGN/Images/FemtoRV32_design_addradd.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/DESIGN/Images/FemtoRV32_design_addradd.jpg -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/BOARDS/arty.xdc: -------------------------------------------------------------------------------- 1 | # Clock pin 2 | set_property PACKAGE_PIN E3 [get_ports CLK] 3 | set_property IOSTANDARD LVCMOS33 [get_ports CLK] 4 | 5 | # LEDs 6 | set_property PACKAGE_PIN H5 [get_ports LEDS[0]] 7 | set_property PACKAGE_PIN J5 [get_ports LEDS[1]] 8 | set_property PACKAGE_PIN T9 [get_ports LEDS[2]] 9 | set_property PACKAGE_PIN T10 [get_ports LEDS[3]] 10 | set_property IOSTANDARD LVCMOS33 [get_ports LEDS[0]] 11 | set_property IOSTANDARD LVCMOS33 [get_ports LEDS[1]] 12 | set_property IOSTANDARD LVCMOS33 [get_ports LEDS[2]] 13 | set_property IOSTANDARD LVCMOS33 [get_ports LEDS[3]] 14 | 15 | # Clock constraints 16 | create_clock -period 10.0 [get_ports CLK] 17 | 18 | # UART 19 | set_property LOC D10 [get_ports TXD] 20 | set_property LOC A9 [get_ports RXD] 21 | set_property IOSTANDARD LVCMOS33 [get_ports RXD] 22 | set_property IOSTANDARD LVCMOS33 [get_ports TXD] 23 | 24 | # reset button 25 | set_property LOC C2 [get_ports RESET] 26 | set_property IOSTANDARD LVCMOS33 [get_ports RESET] 27 | 28 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/BOARDS/cmod_a7.xdc: -------------------------------------------------------------------------------- 1 | # Clock pin 2 | set_property PACKAGE_PIN L17 [get_ports CLK] 3 | set_property IOSTANDARD LVCMOS33 [get_ports CLK] 4 | 5 | # LEDs 6 | set_property PACKAGE_PIN A17 [get_ports LEDS[0]] 7 | set_property PACKAGE_PIN C16 [get_ports LEDS[1]] 8 | set_property PACKAGE_PIN B17 [get_ports LEDS[2]] 9 | set_property PACKAGE_PIN B16 [get_ports LEDS[3]] 10 | set_property PACKAGE_PIN C17 [get_ports LEDS[4]] 11 | set_property IOSTANDARD LVCMOS33 [get_ports LEDS[0]] 12 | set_property IOSTANDARD LVCMOS33 [get_ports LEDS[1]] 13 | set_property IOSTANDARD LVCMOS33 [get_ports LEDS[2]] 14 | set_property IOSTANDARD LVCMOS33 [get_ports LEDS[3]] 15 | set_property IOSTANDARD LVCMOS33 [get_ports LEDS[4]] 16 | 17 | # Clock constraints 18 | create_clock -period 83.33 [get_ports CLK] 19 | 20 | # UART 21 | set_property LOC G17 [get_ports TXD] 22 | set_property LOC G19 [get_ports RXD] 23 | set_property IOSTANDARD LVCMOS33 [get_ports RXD] 24 | set_property IOSTANDARD LVCMOS33 [get_ports TXD] 25 | 26 | # reset button 27 | set_property LOC A18 [get_ports RESET] 28 | set_property IOSTANDARD LVCMOS33 [get_ports RESET] 29 | 30 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/BOARDS/ecp5_evn.lpf: -------------------------------------------------------------------------------- 1 | # See https://github.com/emard/ulx3s/blob/master/doc/constraints/ulx3s_v20.lpf 2 | 3 | ## Clock ######################################### 4 | 5 | LOCATE COMP "CLK" SITE "A10"; 6 | IOBUF PORT "CLK" IO_TYPE=LVCMOS33; 7 | FREQUENCY PORT "CLK" 12 MHZ; 8 | 9 | ## RESET button ################################## 10 | 11 | LOCATE COMP "RESET" SITE "P4"; 12 | IOBUF PORT "RESET" IO_TYPE=LVCMOS33; 13 | 14 | ## LEDs ########################################## 15 | 16 | LOCATE COMP "LEDS[0]" SITE "B17"; 17 | LOCATE COMP "LEDS[1]" SITE "A17"; 18 | LOCATE COMP "LEDS[2]" SITE "C17"; 19 | LOCATE COMP "LEDS[3]" SITE "B18"; 20 | LOCATE COMP "LEDS[4]" SITE "A18"; 21 | 22 | IOBUF PORT "LEDS[0]" IO_TYPE=LVCMOS33; 23 | IOBUF PORT "LEDS[1]" IO_TYPE=LVCMOS33; 24 | IOBUF PORT "LEDS[2]" IO_TYPE=LVCMOS33; 25 | IOBUF PORT "LEDS[3]" IO_TYPE=LVCMOS33; 26 | IOBUF PORT "LEDS[4]" IO_TYPE=LVCMOS33; 27 | 28 | ## UART ###################################################### 29 | 30 | LOCATE COMP "TXD" SITE "D11"; 31 | LOCATE COMP "RXD" SITE "D12"; 32 | 33 | IOBUF PORT "TXD" PULLMODE=UP IO_TYPE=LVCMOS33 DRIVE=4; 34 | IOBUF PORT "RXD" PULLMODE=UP IO_TYPE=LVCMOS33; 35 | 36 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/BOARDS/icebreaker.pcf: -------------------------------------------------------------------------------- 1 | set_io CLK 35 2 | 3 | set_io LEDS[0] 27 4 | set_io LEDS[1] 21 5 | set_io LEDS[2] 25 6 | set_io LEDS[3] 23 7 | set_io LEDS[4] 26 8 | 9 | set_io TXD 9 10 | set_io RXD 6 11 | 12 | set_io RESET 10 13 | 14 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/BOARDS/icestick.pcf: -------------------------------------------------------------------------------- 1 | set_io CLK 21 2 | 3 | set_io LEDS[0] 99 4 | set_io LEDS[1] 98 5 | set_io LEDS[2] 97 6 | set_io LEDS[3] 96 7 | set_io LEDS[4] 95 8 | 9 | set_io TXD 8 10 | set_io RXD 9 11 | 12 | set_io SPIFLASH_CLK 70 13 | set_io SPIFLASH_CS_N 71 14 | 15 | set_io SPIFLASH_MOSI 67 16 | set_io SPIFLASH_MISO 68 17 | 18 | set_io SPIFLASH_IO[0] 67 19 | set_io SPIFLASH_IO[1] 68 20 | 21 | set_io RESET 47 22 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/BOARDS/run_arty.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | PROJECT_NAME=SOC 3 | DB_DIR=/usr/share/nextpnr/prjxray-db 4 | CHIPDB_DIR=/usr/share/nextpnr/xilinx-chipdb 5 | PART=xc7a35tcsg324-1 6 | VERILOGS=$1 7 | BOARD_FREQ=100 8 | CPU_FREQ=100 9 | 10 | set -ex 11 | yosys -DARTY -DBOARD_FREQ=$BOARD_FREQ -DCPU_FREQ=$CPU_FREQ -p "scratchpad -set xilinx_dsp.multonly 1" -p "synth_xilinx -nowidelut -flatten -abc9 -arch xc7 -top SOC; write_json ${PROJECT_NAME}.json" ${VERILOGS} 12 | nextpnr-xilinx --chipdb ${CHIPDB_DIR}/xc7a35t.bin --xdc BOARDS/arty.xdc --json ${PROJECT_NAME}.json --write ${PROJECT_NAME}_routed.json --fasm ${PROJECT_NAME}.fasm 13 | fasm2frames --part ${PART} --db-root ${DB_DIR}/artix7 ${PROJECT_NAME}.fasm > ${PROJECT_NAME}.frames 14 | xc7frames2bit --part_file ${DB_DIR}/artix7/${PART}/part.yaml --part_name ${PART} --frm_file ${PROJECT_NAME}.frames --output_file ${PROJECT_NAME}.bit 15 | #To send to SRAM: 16 | openFPGALoader --board arty ${PROJECT_NAME}.bit 17 | #To send to FLASH: 18 | #openFPGALoader --board arty -f ${PROJECT_NAME}.bit 19 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/BOARDS/run_cmod_a7.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | PROJECT_NAME=SOC 3 | DB_DIR=/usr/share/nextpnr/prjxray-db 4 | CHIPDB_DIR=/usr/share/nextpnr/xilinx-chipdb 5 | PART=xc7a35tcpg236-1 6 | VERILOGS=$1 7 | BOARD_FREQ=100 8 | CPU_FREQ=100 9 | 10 | set -ex 11 | yosys -DCMODA7 -DBOARD_FREQ=$BOARD_FREQ -DCPU_FREQ=$CPU_FREQ -p "scratchpad -set xilinx_dsp.multonly 1" -p "synth_xilinx -nowidelut -flatten -abc9 -arch xc7 -top SOC; write_json ${PROJECT_NAME}.json" ${VERILOGS} 12 | nextpnr-xilinx --chipdb ${CHIPDB_DIR}/xc7a35tcpg236-1.bin --xdc BOARDS/cmod_a7.xdc --json ${PROJECT_NAME}.json --write ${PROJECT_NAME}_routed.json --fasm ${PROJECT_NAME}.fasm 13 | fasm2frames --part ${PART} --db-root ${DB_DIR}/artix7 ${PROJECT_NAME}.fasm > ${PROJECT_NAME}.frames 14 | xc7frames2bit --part_file ${DB_DIR}/artix7/${PART}/part.yaml --part_name ${PART} --frm_file ${PROJECT_NAME}.frames --output_file ${PROJECT_NAME}.bit 15 | #To send to SRAM: 16 | openFPGALoader --freq 30e6 -c digilent --fpga-part xc7a35 femtosoc.bit 17 | #To send to FLASH: 18 | # openFPGALoader --freq 30e6 -c digilent --fpga-part xc7a35tcpg236 -f femtosoc.bit 19 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/BOARDS/run_ecp5evn.sh: -------------------------------------------------------------------------------- 1 | PROJECTNAME=SOC 2 | BOARD=ecp5_evn 3 | BOARD_FREQ=12 4 | CPU_FREQ=100 5 | FPGA_VARIANT=um5g-85k 6 | FPGA_PACKAGE=CABGA381 7 | VERILOGS=$1 8 | 9 | yosys -q -DECP5_EVN -DBOARD_FREQ=$BOARD_FREQ -DCPU_FREQ=$CPU_FREQ -p "synth_ecp5 -abc9 -top $PROJECTNAME -json $PROJECTNAME.json" $VERILOGS || exit 10 | nextpnr-ecp5 --force --timing-allow-fail --json $PROJECTNAME.json --lpf BOARDS/$BOARD.lpf --textcfg $PROJECTNAME"_out".config --freq $BOARD_FREQ --$FPGA_VARIANT --package $FPGA_PACKAGE || exit 11 | ecppack --compress --svf-rowsize 100000 --svf $PROJECTNAME".svf" $PROJECTNAME"_out.config" $PROJECTNAME".bit" || exit 12 | ujprog -j FLASH $PROJECTNAME".bit" || exit 13 | 14 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/BOARDS/run_icebreaker.sh: -------------------------------------------------------------------------------- 1 | PROJECTNAME=SOC 2 | BOARD=icebreaker 3 | BOARD_FREQ=12 4 | CPU_FREQ=20 5 | FPGA_VARIANT=up5k 6 | FPGA_PACKAGE=sg48 7 | VERILOGS=$1 8 | yosys -q -DICE_BREAKER -DNEGATIVE_RESET -DBOARD_FREQ=$BOARD_FREQ -DCPU_FREQ=$CPU_FREQ -p "synth_ice40 -abc9 -device u -dsp -top $PROJECTNAME -json $PROJECTNAME.json" $VERILOGS || exit 9 | nextpnr-ice40 --force --json $PROJECTNAME.json --pcf BOARDS/$BOARD.pcf --asc $PROJECTNAME.asc --freq $BOARD_FREQ --$FPGA_VARIANT --package $FPGA_PACKAGE --pcf-allow-unconstrained || exit 10 | icetime -p BOARDS/$BOARD.pcf -P $FPGA_PACKAGE -r $PROJECTNAME.timings -d up5k -t $PROJECTNAME.asc 11 | icepack $PROJECTNAME.asc $PROJECTNAME.bin || exit 12 | iceprog $PROJECTNAME.bin || exit 13 | echo DONE. 14 | 15 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/BOARDS/run_icestick.sh: -------------------------------------------------------------------------------- 1 | PROJECTNAME=SOC 2 | BOARD=icestick 3 | BOARD_FREQ=12 4 | CPU_FREQ=45 5 | FPGA_VARIANT=hx1k 6 | FPGA_PACKAGE=tq144 7 | VERILOGS=$1 8 | yosys -q -DICE_STICK -DBOARD_FREQ=$BOARD_FREQ -DCPU_FREQ=$CPU_FREQ -p "synth_ice40 -relut -top $PROJECTNAME -json $PROJECTNAME.json" $VERILOGS || exit 9 | nextpnr-ice40 --force --timing-allow-fail --json $PROJECTNAME.json --pcf BOARDS/$BOARD.pcf --asc $PROJECTNAME.asc --freq $CPU_FREQ --$FPGA_VARIANT --package $FPGA_PACKAGE --pcf-allow-unconstrained --opt-timing || exit 10 | icetime -p BOARDS/$BOARD.pcf -P $FPGA_PACKAGE -r $PROJECTNAME.timings -d hx1k -t $PROJECTNAME.asc 11 | icepack $PROJECTNAME.asc $PROJECTNAME.bin || exit 12 | iceprog $PROJECTNAME.bin || exit 13 | echo DONE. 14 | 15 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/BOARDS/run_icestick_show.sh: -------------------------------------------------------------------------------- 1 | PROJECTNAME=SOC 2 | BOARD=icestick 3 | BOARD_FREQ=12 4 | CPU_FREQ=45 5 | FPGA_VARIANT=hx1k 6 | FPGA_PACKAGE=tq144 7 | VERILOGS=$1 8 | yosys -q -DICE_STICK -DBOARD_FREQ=$BOARD_FREQ -DCPU_FREQ=$CPU_FREQ -p "synth_ice40 -relut -top $PROJECTNAME -json $PROJECTNAME.json" $VERILOGS || exit 9 | nextpnr-ice40 --gui --force --timing-allow-fail --json $PROJECTNAME.json --pcf BOARDS/$BOARD.pcf --asc $PROJECTNAME.asc --freq $CPU_FREQ --$FPGA_VARIANT --package $FPGA_PACKAGE --pcf-allow-unconstrained --opt-timing || exit 10 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/BOARDS/run_ulx3s.sh: -------------------------------------------------------------------------------- 1 | PROJECTNAME=SOC 2 | BOARD=ulx3s 3 | BOARD_FREQ=25 4 | CPU_FREQ=100 5 | FPGA_VARIANT=85k 6 | FPGA_PACKAGE=CABGA381 7 | VERILOGS=$1 8 | 9 | yosys -q -DULX3S -DBOARD_FREQ=$BOARD_FREQ -DCPU_FREQ=$CPU_FREQ -p "synth_ecp5 -abc9 -top $PROJECTNAME -json $PROJECTNAME.json" $VERILOGS || exit 10 | nextpnr-ecp5 --force --timing-allow-fail --json $PROJECTNAME.json --lpf BOARDS/$BOARD.lpf --textcfg $PROJECTNAME"_out".config --freq $BOARD_FREQ --$FPGA_VARIANT --package $FPGA_PACKAGE || exit 11 | ecppack --compress --svf-rowsize 100000 --svf $PROJECTNAME".svf" $PROJECTNAME"_out.config" $PROJECTNAME".bit" || exit 12 | ujprog -j FLASH $PROJECTNAME".bit" || exit 13 | 14 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/BOARDS/ulx3s.lpf: -------------------------------------------------------------------------------- 1 | # See https://github.com/emard/ulx3s/blob/master/doc/constraints/ulx3s_v20.lpf 2 | 3 | ## Clock ######################################### 4 | 5 | LOCATE COMP "CLK" SITE "G2"; 6 | IOBUF PORT "CLK" PULLMODE=NONE IO_TYPE=LVCMOS33; 7 | FREQUENCY PORT "CLK" 25 MHZ; 8 | 9 | ## RESET button ################################## 10 | 11 | LOCATE COMP "RESET" SITE "T1"; # fire 2 12 | IOBUF PORT "RESET" IO_TYPE=LVCMOS33; 13 | 14 | ## LEDs ########################################## 15 | 16 | LOCATE COMP "LEDS[0]" SITE "B2"; 17 | LOCATE COMP "LEDS[1]" SITE "C2"; 18 | LOCATE COMP "LEDS[2]" SITE "C1"; 19 | LOCATE COMP "LEDS[3]" SITE "D2"; 20 | LOCATE COMP "LEDS[4]" SITE "D1"; 21 | 22 | IOBUF PORT "LEDS[0]" IO_TYPE=LVCMOS33; 23 | IOBUF PORT "LEDS[1]" IO_TYPE=LVCMOS33; 24 | IOBUF PORT "LEDS[2]" IO_TYPE=LVCMOS33; 25 | IOBUF PORT "LEDS[3]" IO_TYPE=LVCMOS33; 26 | IOBUF PORT "LEDS[4]" IO_TYPE=LVCMOS33; 27 | 28 | ## UART ###################################################### 29 | 30 | LOCATE COMP "TXD" SITE "L4"; # FPGA transmits to ftdi 31 | LOCATE COMP "RXD" SITE "M1"; # FPGA receives from ftdi 32 | 33 | IOBUF PORT "TXD" PULLMODE=UP IO_TYPE=LVCMOS33 DRIVE=4; 34 | IOBUF PORT "RXD" PULLMODE=UP IO_TYPE=LVCMOS33; 35 | 36 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/FIRMWARE/blinker.S: -------------------------------------------------------------------------------- 1 | # Simple blinker 2 | 3 | .equ IO_BASE, 0x400000 4 | .equ IO_LEDS, 4 5 | 6 | .section .text 7 | 8 | .globl main 9 | 10 | main: 11 | .L0: 12 | 13 | li t0, 5 14 | sw t0, IO_LEDS(gp) 15 | call wait 16 | li t0, 10 17 | sw t0, IO_LEDS(gp) 18 | call wait 19 | j .L0 20 | 21 | 22 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/FIRMWARE/bram.ld: -------------------------------------------------------------------------------- 1 | MEMORY 2 | { 3 | BRAM (RWX) : ORIGIN = 0x0000, LENGTH = 0x1800 /* 6kB RAM */ 4 | } 5 | SECTIONS 6 | { 7 | everything : 8 | { 9 | . = ALIGN(4); 10 | start.o (.text) 11 | *(.*) 12 | } >BRAM 13 | } 14 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/FIRMWARE/dhrystones.c: -------------------------------------------------------------------------------- 1 | #define RISCV 2 | #define TIME 3 | #define USE_MYSTDLIB 4 | 5 | #include "DHRYSTONE/dhry_1.c" 6 | #include "DHRYSTONE/dhry_2.c" 7 | #include "DHRYSTONE/stubs.c" -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/FIRMWARE/errno.c: -------------------------------------------------------------------------------- 1 | 2 | // Sometimes __errno is not linked, here is a dummy replacement. 3 | // Note that __errno is a function that returns a pointer to the 4 | // actual __errno (this is for multithreading). Made me bang my 5 | // head to the wall (and made tinyraytracer crash because powf() 6 | // was *calling* __errno). 7 | 8 | int* __errno() { 9 | static int val = 0; 10 | return &val; 11 | } 12 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/FIRMWARE/hello.S: -------------------------------------------------------------------------------- 1 | # Hello world ! 2 | 3 | .section .text 4 | .globl main 5 | 6 | main: 7 | .L0: 8 | la a0, hello 9 | call putstring 10 | j .L0 11 | 12 | putstring: 13 | addi sp,sp,-4 # save ra on the stack 14 | sw ra,0(sp) # (need to do that for functions that call functions) 15 | mv t2,a0 16 | .L1: lbu a0,0(t2) 17 | beqz a0,.L2 18 | call putchar 19 | addi t2,t2,1 20 | j .L1 21 | .L2: lw ra,0(sp) # restore ra 22 | addi sp,sp,4 # restore sp 23 | ret 24 | 25 | .section .data 26 | hello: 27 | .asciz "Hello, world !\n" 28 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/FIRMWARE/io.h: -------------------------------------------------------------------------------- 1 | #include <stdint.h> 2 | 3 | #define IO_BASE 0x400000 4 | #define IO_LEDS 4 5 | #define IO_UART_DAT 8 6 | #define IO_UART_CNTL 16 7 | 8 | #define IO_IN(port) *(volatile uint32_t*)(IO_BASE + port) 9 | #define IO_OUT(port,val) *(volatile uint32_t*)(IO_BASE + port)=(val) 10 | 11 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/FIRMWARE/memcpy.c: -------------------------------------------------------------------------------- 1 | #include <stddef.h> 2 | #include <stdint.h> 3 | 4 | #pragma GCC optimize ("no-tree-loop-distribute-patterns") 5 | 6 | void* memcpy(void * dst, void const * src, size_t len) { 7 | uint32_t * plDst = (uint32_t *) dst; 8 | uint32_t const * plSrc = (uint32_t const *) src; 9 | 10 | // If source and destination are aligned, 11 | // copy 32s bit by 32 bits. 12 | if (!((uint32_t)src & 3) && !((uint32_t)dst & 3)) { 13 | while (len >= 4) { 14 | *plDst++ = *plSrc++; 15 | len -= 4; 16 | } 17 | } 18 | 19 | uint8_t* pcDst = (uint8_t *) plDst; 20 | uint8_t const* pcSrc = (uint8_t const *) plSrc; 21 | 22 | while (len--) { 23 | *pcDst++ = *pcSrc++; 24 | } 25 | 26 | return dst; 27 | } 28 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/FIRMWARE/notes.txt: -------------------------------------------------------------------------------- 1 | # https://blog.thea.codes/the-most-thoroughly-commented-linker-script/ 2 | # https://interrupt.memfault.com/blog/how-to-write-linker-scripts-for-firmware 3 | 4 | bin/riscv64-unknown-elf-as -march=rv32i -mabi=ilp32 -mno-relax mandelbrot_terminal.S -o mandelbrot_terminal.o 5 | riscv64-unknown-elf-ld mandelbrot_terminal.o -T baremetal.ld -m elf32lriscv -nostdlib -norelax 6 | /home/blevy/Programming/learn-fpga/FemtoRV/FIRMWARE/TOOLS/firmware_words a.elf -ram 6144 -hex a.hex 7 | 8 | 9 | FTDI 2232H 10 | 11 | Rx > 12 | Tx < 13 | RTSn > Request to send 14 | CTSn < Clear to send 15 | DTRn > Data Terminal Ready 16 | DSRn < Data Set Ready 17 | DCDn > Data Carrier Detect 18 | 19 | 20 | #set_io DCDn 1 21 | #set_io DSRn 2 22 | #set_io DTRn 3 23 | #set_io CTSn 4 24 | #set_io RTSn 7 25 | set_io RS232_Tx_TTL 8 26 | set_io RS232_Rx_TTL 9 27 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/FIRMWARE/perf.S: -------------------------------------------------------------------------------- 1 | .section .text 2 | .globl rdcycle 3 | .globl rdinstret 4 | 5 | rdcycle: 6 | .L0: 7 | rdcycleh a1 8 | rdcycle a0 9 | rdcycleh t0 10 | bne a1,t0,.L0 11 | ret 12 | 13 | rdinstret: 14 | .L1: 15 | rdinstreth a1 16 | rdinstret a0 17 | rdinstreth t0 18 | bne a1,t0,.L1 19 | ret 20 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/FIRMWARE/perf.h: -------------------------------------------------------------------------------- 1 | #include <stdint.h> 2 | 3 | extern uint64_t rdcycle(); 4 | extern uint64_t rdinstret(); 5 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/FIRMWARE/pipeline.ld: -------------------------------------------------------------------------------- 1 | MEMORY { 2 | PROGROM (RX) : ORIGIN = 0x00000, LENGTH = 0x10000 /* 64kB ROM */ 3 | DATARAM (RW) : ORIGIN = 0x10000, LENGTH = 0x10000 /* 64kB RAM */ 4 | } 5 | 6 | SECTIONS { 7 | 8 | .text : { 9 | . = ALIGN(4); 10 | start_pipeline.o (.text) 11 | *(.text*) 12 | } > PROGROM 13 | 14 | .data : { 15 | . = ALIGN(4); 16 | *(.data*) 17 | *(.sdata*) 18 | *(.rodata*) 19 | *(.srodata*) 20 | *(.bss*) 21 | *(.sbss*) 22 | 23 | *(COMMON) 24 | *(.eh_frame) 25 | *(.eh_frame_hdr) 26 | *(.init_array*) 27 | *(.gcc_except_table*) 28 | } > DATARAM 29 | } 30 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/FIRMWARE/putchar.S: -------------------------------------------------------------------------------- 1 | # Base address of memory-mapped IO, 2 | # Loaded into gp at startup 3 | .equ IO_BASE, 0x400000 4 | 5 | # IO-reg offsets. To read or write one of them, 6 | # use IO_XXX(gp) 7 | .equ IO_LEDS, 4 8 | .equ IO_UART_DAT, 8 9 | .equ IO_UART_CNTL, 16 10 | 11 | .section .text 12 | .globl putchar 13 | 14 | putchar: 15 | sw a0, IO_UART_DAT(gp) 16 | li t0, 1<<9 17 | .L0: 18 | lw t1, IO_UART_CNTL(gp) 19 | and t1, t1, t0 20 | bnez t1, .L0 21 | ret 22 | 23 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/FIRMWARE/read_spiflash.c: -------------------------------------------------------------------------------- 1 | #include "io.h" 2 | 3 | #define SPI_FLASH_BASE ((char*)(1 << 23)) 4 | 5 | int main() { 6 | for(int i=0; i<16; ++i) { 7 | IO_OUT(IO_LEDS,i); 8 | int lo = (int)SPI_FLASH_BASE[2*i ]; 9 | int hi = (int)SPI_FLASH_BASE[2*i+1]; 10 | print_hex_digits((hi << 8) | lo,4); // print four hexadecimal digits 11 | printf(" "); 12 | } 13 | printf("\n"); 14 | } 15 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/FIRMWARE/spiflash0.ld: -------------------------------------------------------------------------------- 1 | MEMORY { 2 | FLASH (RX) : ORIGIN = 0x00820000, LENGTH = 0x100000 /* 4 MB in flash */ 3 | } 4 | SECTIONS { 5 | everything : { 6 | . = ALIGN(4); 7 | start.o (.text) 8 | *(.*) 9 | } >FLASH 10 | } 11 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/FIRMWARE/start.S: -------------------------------------------------------------------------------- 1 | .equ IO_BASE, 0x400000 2 | .section .text 3 | .globl start 4 | start: 5 | li gp,IO_BASE 6 | li sp,0x1800 7 | call main 8 | ebreak 9 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/FIRMWARE/start_pipeline.S: -------------------------------------------------------------------------------- 1 | .equ IO_BASE, 0x400000 2 | .section .text 3 | .globl start 4 | start: 5 | li gp,IO_BASE 6 | li sp,0x20000 7 | call main 8 | ebreak 9 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/FIRMWARE/start_spiflash1.S: -------------------------------------------------------------------------------- 1 | .equ IO_BASE, 0x400000 2 | 3 | .text 4 | .global _start 5 | .type _start, @function 6 | 7 | _start: 8 | .option push 9 | .option norelax 10 | li gp,IO_BASE 11 | .option pop 12 | 13 | li sp,0x1800 14 | 15 | # zero-init bss section: 16 | # clears from _sbss to _ebss 17 | # _sbss and _ebss are defined by linker script (spiflash.ld) 18 | la a0, _sbss 19 | la a1, _ebss 20 | bge a0, a1, end_init_bss 21 | loop_init_bss: 22 | sw zero, 0(a0) 23 | addi a0, a0, 4 24 | blt a0, a1, loop_init_bss 25 | end_init_bss: 26 | 27 | # copy data section from SPI Flash to BRAM: 28 | # copies from _sidata (in flash) to _sdata ... _edata (in BRAM) 29 | # _sidata, _sdata and _edata are defined by linker script (spiflash.ld) 30 | la a0, _sidata 31 | la a1, _sdata 32 | la a2, _edata 33 | bge a1, a2, end_init_data 34 | loop_init_data: 35 | lw a3, 0(a0) 36 | sw a3, 0(a1) 37 | addi a0, a0, 4 38 | addi a1, a1, 4 39 | blt a1, a2, loop_init_data 40 | end_init_data: 41 | 42 | call main 43 | ebreak 44 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/FIRMWARE/test_rdcycle.c: -------------------------------------------------------------------------------- 1 | #include "perf.h" 2 | 3 | int main() { 4 | for(int i=0; i<100; ++i) { 5 | uint64_t cycles = rdcycle(); 6 | uint64_t instret = rdinstret(); 7 | printf("i=%d cycles=%d instret=%d\n", i, (int)cycles, (int)instret); 8 | } 9 | uint64_t instret = rdinstret(); 10 | uint64_t cycles = rdcycle(); 11 | printf("cycles=%d instret=%d 100CPI=%d\n", (int)cycles, (int)instret, (int)(100*cycles/instret)); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/FIRMWARE/test_spi_flash.c: -------------------------------------------------------------------------------- 1 | #include <stdio.h> 2 | #include <stdint.h> 3 | 4 | #define SPI_FLASH_BASE ((uint32_t*)(1 << 23)) 5 | 6 | int main() { 7 | for(;;) { 8 | for(int i=0; i<40; ++i) { 9 | uint32_t word = SPI_FLASH_BASE[i]; 10 | char* c = (char*)&word; 11 | printf("%d 0x%x %c%c%c%c\n", i, word, c[0],c[1],c[2],c[3]); 12 | } 13 | printf("\n"); 14 | printf("\n"); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/FIRMWARE/tty_graphics_demo.c: -------------------------------------------------------------------------------- 1 | #include "tty_graphics.h" 2 | #include <math.h> 3 | 4 | #ifdef __linux__ 5 | #include <stdlib.h> 6 | #include <unistd.h> 7 | #endif 8 | 9 | // Size of the screen 10 | // Replace with your own variables or values 11 | #define graphics_width 80 12 | #define graphics_height 40 13 | 14 | int frame = 0; 15 | float f = 0.0; 16 | 17 | void do_pixel(int i, int j, float* R, float* G, float* B) { 18 | float x = (float)i; 19 | float y = (float)j; 20 | *R = 0.5f*(sin(x*0.1+f)+1.0); 21 | *G = 0.5f*(sin(y*0.1+2.0*f)+1.0); 22 | *B = 0.5f*(sin((x+y)*0.05-3.0*f)+1.0); 23 | } 24 | 25 | int main() { 26 | tty_graphics_init(); 27 | for(;;) { 28 | tty_graphics_fscan(graphics_width, graphics_height, do_pixel); 29 | f += 0.1; 30 | ++frame; 31 | tty_graphics_reset_colors(); 32 | printf("frame = %d\n",frame); 33 | #ifdef __linux__ 34 | usleep(40000); 35 | #endif 36 | } 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/FIRMWARE/wait.S: -------------------------------------------------------------------------------- 1 | .section .text 2 | .globl wait 3 | 4 | wait: 5 | li t0,1 6 | slli t0, t0,17 7 | .L0: 8 | addi t0,t0,-1 9 | bnez t0, .L0 10 | ret 11 | 12 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/IceStick_RESET.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/IceStick_RESET.jpg -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/IceStick_SPIFLASH.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/IceStick_SPIFLASH.jpg -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/ST_NICCC_tty.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/ST_NICCC_tty.png -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/bench_iverilog.v: -------------------------------------------------------------------------------- 1 | module bench(); 2 | reg CLK; 3 | wire RESET = 0; 4 | wire [4:0] LEDS; 5 | reg RXD = 1'b0; 6 | wire TXD; 7 | 8 | SOC uut( 9 | .CLK(CLK), 10 | .RESET(RESET), 11 | .LEDS(LEDS), 12 | .RXD(RXD), 13 | .TXD(TXD) 14 | ); 15 | 16 | reg[4:0] prev_LEDS = 0; 17 | initial begin 18 | CLK = 0; 19 | forever begin 20 | #1 CLK = ~CLK; 21 | if(LEDS != prev_LEDS) begin 22 | $display("LEDS = %b",LEDS); 23 | end 24 | prev_LEDS <= LEDS; 25 | end 26 | end 27 | endmodule 28 | 29 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/emitter_uart.v: -------------------------------------------------------------------------------- 1 | module corescore_emitter_uart 2 | #( 3 | parameter clk_freq_hz = 0, 4 | parameter baud_rate = 1000000) 5 | ( 6 | input wire i_clk, 7 | input wire i_rst, 8 | input wire [7:0] i_data, 9 | input wire i_valid, 10 | output reg o_ready, 11 | output wire o_uart_tx 12 | ); 13 | 14 | localparam START_VALUE = clk_freq_hz/baud_rate; 15 | 16 | localparam WIDTH = $clog2(START_VALUE); 17 | 18 | reg [WIDTH:0] cnt = 0; 19 | 20 | reg [9:0] data; 21 | 22 | assign o_uart_tx = data[0] | !(|data); 23 | 24 | always @(posedge i_clk) begin 25 | if (cnt[WIDTH] & !(|data)) begin 26 | o_ready <= 1'b1; 27 | end else if (i_valid & o_ready) begin 28 | o_ready <= 1'b0; 29 | end 30 | 31 | if (o_ready | cnt[WIDTH]) 32 | cnt <= {1'b0,START_VALUE[WIDTH-1:0]}; 33 | else 34 | cnt <= cnt-1; 35 | 36 | if (cnt[WIDTH]) 37 | data <= {1'b0, data[9:1]}; 38 | else if (i_valid & o_ready) 39 | data <= {1'b1, i_data, 1'b0}; 40 | end 41 | 42 | endmodule 43 | 44 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/labels.sh: -------------------------------------------------------------------------------- 1 | ./run.sh $1 -DGET_ASM_LABELS | grep 'Label:' | sed -e 's|Label:|=|g' -e 's|$|;|g' > values.txt 2 | cat $1 | grep 'Label(' | sed -e 's|Label(|integer |g' -e 's|)||g' -e's|;||g' > labels.txt 3 | paste labels.txt values.txt 4 | rm -f labels.txt values.txt 5 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/mandel_and_riscvlogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/mandel_and_riscvlogo.png -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/run.sh: -------------------------------------------------------------------------------- 1 | rm -f a.out 2 | iverilog -DBENCH -DSIM -DPASSTHROUGH_PLL -DBOARD_FREQ=10 -DCPU_FREQ=10 bench_iverilog.v $1 $2 3 | vvp a.out 4 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/run_verilator.sh: -------------------------------------------------------------------------------- 1 | (cd obj_dir; rm -f *.cpp *.o *.a VSOC) 2 | verilator -CFLAGS '-I../../../FIRMWARE/LIBFEMTORV32 -DSTANDALONE_FEMTOELF' -DBENCH -DBOARD_FREQ=10 -DCPU_FREQ=10 -DPASSTHROUGH_PLL -Wno-fatal \ 3 | --top-module SOC -cc -exe sim_main.cpp ../../FIRMWARE/LIBFEMTORV32/femto_elf.c $1 4 | (cd obj_dir; make -f VSOC.mk) 5 | obj_dir/VSOC $2 6 | 7 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/step1.v: -------------------------------------------------------------------------------- 1 | /** 2 | * Step 1: Blinker 3 | * DONE 4 | */ 5 | 6 | `default_nettype none 7 | 8 | module SOC ( 9 | input CLK, // system clock 10 | input RESET, // reset button 11 | output [4:0] LEDS, // system LEDs 12 | input RXD, // UART receive 13 | output TXD // UART transmit 14 | ); 15 | 16 | 17 | // A blinker that counts on 5 bits, wired to the 5 LEDs 18 | reg [4:0] count = 0; 19 | always @(posedge CLK) begin 20 | count <= count + 1; 21 | end 22 | assign LEDS = count; 23 | assign TXD = 1'b0; // not used for now 24 | endmodule 25 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/step2.v: -------------------------------------------------------------------------------- 1 | /** 2 | * Step 2: Blinker (slower version) 3 | * DONE* 4 | */ 5 | 6 | `default_nettype none 7 | `include "clockworks.v" 8 | 9 | module SOC ( 10 | input CLK, // system clock 11 | input RESET, // reset button 12 | output [4:0] LEDS, // system LEDs 13 | input RXD, // UART receive 14 | output TXD // UART transmit 15 | ); 16 | 17 | wire clk; // internal clock 18 | wire resetn; // internal reset signal, goes low on reset 19 | 20 | // A blinker that counts on 5 bits, wired to the 5 LEDs 21 | reg [4:0] count = 0; 22 | always @(posedge clk) begin 23 | count <= !resetn ? 0 : count + 1; 24 | end 25 | 26 | // Clock gearbox (to let you see what happens) 27 | // and reset circuitry (to workaround an 28 | // initialization problem with Ice40) 29 | Clockworks #( 30 | .SLOW(21) // Divide clock frequency by 2^21 31 | )CW( 32 | .CLK(CLK), 33 | .RESET(RESET), 34 | .clk(clk), 35 | .resetn(resetn) 36 | ); 37 | 38 | assign LEDS = count; 39 | assign TXD = 1'b0; // not used for now 40 | endmodule 41 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/terminal.sh: -------------------------------------------------------------------------------- 1 | DEVICE=/dev/ttyUSB1 # replace by the terminal used by your device 2 | BAUDS=1000000 3 | 4 | 5 | # MINITERM exit: <ctrl> ] package: sudo apt-get install python3-serial 6 | #miniterm --dtr=0 $DEVICE $BAUDS 7 | 8 | # SCREEN exit: <ctrl> a \ package: sudo apt-get install screen 9 | #screen $DEVICE $BAUDS 10 | 11 | # PICOCOM exit: <ctrl> a <ctrl> x package: sudo apt-get install picocom 12 | picocom -b $BAUDS $DEVICE --imap lfcrlf,crcrlf --omap delbs,crlf --send-cmd "ascii-xfr -s -l 30 -n" 13 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/tinyraytracer_tty.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/tinyraytracer_tty.png -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/verilog_riscv_debugger.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV/verilog_riscv_debugger.png -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/Images/HDMI.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/Images/HDMI.jpg -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/Images/ICE40HX1K_and_ECP5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/Images/ICE40HX1K_and_ECP5.png -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/Images/IceBreaker.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/Images/IceBreaker.jpg -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/Images/IceStick.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/Images/IceStick.jpg -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/Images/IceStick_J2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/Images/IceStick_J2.jpg -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/Images/IceStick_graphics.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/Images/IceStick_graphics.jpg -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/Images/IceStick_hello.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/Images/IceStick_hello.gif -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/Images/LedMatrix.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/Images/LedMatrix.jpg -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/Images/LedMatrix_connector.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/Images/LedMatrix_connector.jpg -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/Images/LedMatrix_on_IceStick.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/Images/LedMatrix_on_IceStick.jpg -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/Images/OysterPMOD.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/Images/OysterPMOD.jpg -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/Images/OysterPMOD_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/Images/OysterPMOD_1.jpg -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/Images/OysterPMOD_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/Images/OysterPMOD_2.jpg -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/Images/OysterPMOD_3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/Images/OysterPMOD_3.jpg -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/Images/OysterPMOD_4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/Images/OysterPMOD_4.jpg -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/Images/OysterPMOD_demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/Images/OysterPMOD_demo.gif -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/Images/SSD1331_on_ULX3S.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/Images/SSD1331_on_ULX3S.jpg -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/Images/SSD1351_on_ECP5_EVN.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/Images/SSD1351_on_ECP5_EVN.jpg -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/Images/SSD1351_on_IceStick.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/Images/SSD1351_on_IceStick.jpg -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/Images/SSD1351_on_ULX3S.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/Images/SSD1351_on_ULX3S.jpg -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/Images/ST_NICCC_on_IceStick.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/Images/ST_NICCC_on_IceStick.gif -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/Images/ULX3S.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/Images/ULX3S.jpg -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/Images/ULX3S_demos.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/Images/ULX3S_demos.jpg -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/Images/arty.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/Images/arty.jpg -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/Images/ecp5_evn.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/Images/ecp5_evn.jpg -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/Images/iCESugar.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/Images/iCESugar.jpg -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/Images/ice40_Feather.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/Images/ice40_Feather.jpg -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/Images/ice40_Feather_led_blank.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/Images/ice40_Feather_led_blank.jpg -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/Images/ice40_Feather_led_femto.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/Images/ice40_Feather_led_femto.jpg -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/Images/ice40_Feather_led_lit.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/Images/ice40_Feather_led_lit.jpg -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/Images/ice4pi.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/Images/ice4pi.jpg -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/Images/mandelbrot_terminal.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/FemtoRV/TUTORIALS/Images/mandelbrot_terminal.gif -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/Linux_on_IceStick.v: -------------------------------------------------------------------------------- 1 | |\ \ \ \ \ \ \ \ __ 2 | | \ \ \ \ \ \ \ \ | O~-_ 3 | | >----|-|-|-|-|-|-|--| __/ 4 | | / / / / / / / / |__\ 5 | |/ / / / / / / / 6 | 7 | 8 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/README.md: -------------------------------------------------------------------------------- 1 | FemtoRV32 Tutorials 2 | =================== 3 | 4 | - [IceSTICK tutorial](IceStick.md) 5 | - [IceBreaker tutorial](IceBreaker.md) 6 | - [Ice4Pi tutorial](Ice4Pi.md) 7 | - [ULX3S tutorial](ULX3S.md) 8 | - [ECP5 evaluation board tutorial](ECP5_EVN.md) _(WIP)_ 9 | - [FOMU tutorial](FOMU.md) _(WIP) 10 | - [Oyster PMOD](OysterPMOD.md) 11 | - [Adding a new board](newboard.md) 12 | - [Mecrisp-quintus on the IceStick (Forth)](https://github.com/BrunoLevy/learn-fpga/blob/master/FemtoRV/FIRMWARE/MECRISP_QUINTUS/README.md) 13 | 14 | FemtoRV32 Notes 15 | =============== 16 | 17 | - [Notes on FemtoRV32 design](DESIGN/FemtoRV32.md) 18 | - [Notes on RISC-V software compilation and runtime](software.md) 19 | - [Notes on HDMI](HDMI.md) 20 | - [Notes on SPI Flash](spi_flash.md) 21 | - [Notes on priviledged instruction set](priviledged.md) _(WIP)_ 22 | - [Notes on SDRAM](SDRAM.md) _(WIP)_ 23 | - [Notes on DSPs](DSP.md) _(WIP)_ 24 | -------------------------------------------------------------------------------- /FemtoRV/TUTORIALS/WSL.md: -------------------------------------------------------------------------------- 1 | Windows/WSL Tutorial (WIP) 2 | ========================== 3 | 4 | My tutorials are mainly adapted to Linux users (I'm using Ubuntu). It 5 | is possible to make everything work under Windows using WSL, however, 6 | USB under Windows is tricky ! 7 | 8 | Some precompiled binaries and instructions (including about how to make USB work) 9 | are available [here](https://github.com/sylefeb/fpga-binutils/). 10 | 11 | @gojimmypi reported a success and explains how to do that 12 | [here](https://gojimmypi.blogspot.com/2020/12/ice40-fpga-programming-with-wsl-and.html). 13 | Synthetizing the core, compiling RISC-V code and flashing the device 14 | work. 15 | 16 | Under Windows, talking to the device through a terminal emulator doesn't always work. 17 | The solution may be [here](https://github.com/rpasek/usbip-wsl2-instructions). 18 | 19 | -------------------------------------------------------------------------------- /LiteX/Images/ULX3S_SDRAM.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/LiteX/Images/ULX3S_SDRAM.jpg -------------------------------------------------------------------------------- /LiteX/makeit_ulx3s.sh: -------------------------------------------------------------------------------- 1 | python3 -m boards.radiona_ulx3s_ex --device LFE5U-85F --sdram-module AS4C16M16 --cpu-type femtorv --cpu-variant petitbateau --build --load --with-oled --ecppack-compress 2 | -------------------------------------------------------------------------------- /LiteX/orange_crab.md: -------------------------------------------------------------------------------- 1 | LiteX Instructions for OrangeCrab: 2 | ---------------------------------- 3 | 4 | Before starting: 5 | 6 | Make sure you have updated `udev rules` to allow accessing the USB port of the OrangeCrab in 7 | user mode, as explained [https://github.com/BrunoLevy/learn-fpga/blob/master/FemtoRV/TUTORIALS/toolchain.md#orangecrab-ecp5](here). 8 | 9 | Synthesize and program: 10 | ``` 11 | $ cd learn-fpga/LiteX 12 | $ python3 -m litex_boards.targets.gsd_orangecrab --device 25F --cpu-type femtorv --cpu-variant gracilis --with-spi-sdcard --build --load --ecppack-compress 13 | ``` 14 | (replace `25F` with the one in your device (there is also a `45F` and a `85F` version). 15 | 16 | Build software: 17 | Edit `software/makefile.inc` 18 | - set `LITEX_DIR` and `LEARNFPGA_DIR` 19 | - set `LITEX_PLATFORM` to `gsd_orangecrab` 20 | ``` 21 | $ cd software/LiteOS 22 | $ make 23 | $ cd ../Programs 24 | $ make hello.elf 25 | ``` 26 | 27 | Copy `LiteOS/boot.bin` and `Programs/hello.elf` to a SDCard 28 | Insert the SDCard in the OrangeCrab 29 | 30 | ``` 31 | $ litex_term /dev/ttyACM0 32 | $ reboot 33 | ``` 34 | 35 | This should load LiteOS from the SDCard 36 | 37 | Run a simple program: 38 | ``` 39 | liteOS> run hello.elf 40 | ``` -------------------------------------------------------------------------------- /LiteX/software/DemoBundle/demos/demos.h: -------------------------------------------------------------------------------- 1 | #ifndef DEMOS_H 2 | #define DEMOS_H 3 | 4 | #include "command.h" 5 | #include <generated/csr.h> 6 | 7 | #define define_demo(demo,description) define_command(demo,demo,description,1) 8 | 9 | #endif 10 | 11 | -------------------------------------------------------------------------------- /LiteX/software/DemoBundle/demos/oled_test.c: -------------------------------------------------------------------------------- 1 | #include "demos.h" 2 | #include "lite_oled.h" 3 | 4 | #include <stdio.h> 5 | #include <libbase/uart.h> 6 | #include <libbase/console.h> 7 | 8 | static void oled_test(int nb_args, char** args) { 9 | uint32_t frame=0; 10 | puts("Press any key to exit"); 11 | oled_init(); 12 | oled_write_window(0,0,OLED_WIDTH-1,OLED_HEIGHT-1); 13 | for(;;) { 14 | for(uint32_t y=0; y<OLED_HEIGHT; ++y) { 15 | for(uint32_t x=0; x<OLED_WIDTH; ++x) { 16 | uint32_t R = (x+frame) & 63; 17 | uint32_t G = (x >> 3) & 63; 18 | uint32_t B = (y+frame) & 63; 19 | // pixel color: RRRRR GGGGG 0 BBBBB 20 | oled_data_uint16(B | (G << 6) | (R << 11)); 21 | } 22 | } 23 | if (readchar_nonblock()) { 24 | getchar(); 25 | break; 26 | } 27 | ++frame; 28 | } 29 | oled_off(); 30 | } 31 | 32 | #ifdef CSR_OLED_SPI_BASE 33 | define_demo(oled_test, "simple test for OLED screen"); 34 | #endif 35 | -------------------------------------------------------------------------------- /LiteX/software/DemoBundle/isr.c: -------------------------------------------------------------------------------- 1 | // This file is Copyright (c) 2020 Florent Kermarrec <florent@enjoy-digital.fr> 2 | // License: BSD 3 | 4 | #include <generated/csr.h> 5 | #include <generated/soc.h> 6 | #include <irq.h> 7 | #include <libbase/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 30 | -------------------------------------------------------------------------------- /LiteX/software/DemoBundle/raystones_tty.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/LiteX/software/DemoBundle/raystones_tty.gif -------------------------------------------------------------------------------- /LiteX/software/Doom/Doom.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/LiteX/software/Doom/Doom.gif -------------------------------------------------------------------------------- /LiteX/software/Doom/crt0.S: -------------------------------------------------------------------------------- 1 | // crt0.S for executables 2 | // interrupts and stack are already configured by OS 3 | // _start does the following tasks: 4 | // 1) save registers (ra, t0..t6, a0..a7) 5 | // 2) initialize BSS 6 | // 3) call main 7 | // 4) restore registers 8 | // 5) return to caller (LiteOS shell) 9 | 10 | .global _start 11 | _start: 12 | // save context 13 | addi sp, sp, -16*4 14 | sw ra, 0*4(sp) 15 | sw t0, 1*4(sp) 16 | sw t1, 2*4(sp) 17 | sw t2, 3*4(sp) 18 | sw a0, 4*4(sp) 19 | sw a1, 5*4(sp) 20 | sw a2, 6*4(sp) 21 | sw a3, 7*4(sp) 22 | sw a4, 8*4(sp) 23 | sw a5, 9*4(sp) 24 | sw a6, 10*4(sp) 25 | sw a7, 11*4(sp) 26 | sw t3, 12*4(sp) 27 | sw t4, 13*4(sp) 28 | sw t5, 14*4(sp) 29 | sw t6, 15*4(sp) 30 | 31 | 32 | // initialize .bss 33 | la t0, _fbss 34 | la t1, _ebss 35 | 1: beq t0, t1, 3f 36 | sw zero, 0(t0) 37 | addi t0, t0, 4 38 | j 1b 39 | 3: 40 | 41 | call main 42 | 43 | // restore context 44 | lw ra, 0*4(sp) 45 | lw t0, 1*4(sp) 46 | lw t1, 2*4(sp) 47 | lw t2, 3*4(sp) 48 | lw a0, 4*4(sp) 49 | lw a1, 5*4(sp) 50 | lw a2, 6*4(sp) 51 | lw a3, 7*4(sp) 52 | lw a4, 8*4(sp) 53 | lw a5, 9*4(sp) 54 | lw a6, 10*4(sp) 55 | lw a7, 11*4(sp) 56 | lw t3, 12*4(sp) 57 | lw t4, 13*4(sp) 58 | lw t5, 14*4(sp) 59 | lw t6, 15*4(sp) 60 | addi sp, sp, 16*4 61 | 62 | ret 63 | -------------------------------------------------------------------------------- /LiteX/software/Doom/doom_oled.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/LiteX/software/Doom/doom_oled.gif -------------------------------------------------------------------------------- /LiteX/software/Doom/exit.c: -------------------------------------------------------------------------------- 1 | #include <stdio.h> 2 | 3 | void _exit(int retcode) { 4 | printf("_exit(%d) called\n",retcode); 5 | for(;;); 6 | } 7 | -------------------------------------------------------------------------------- /LiteX/software/Doom/mc1-doom/logo/mc1-doom-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/LiteX/software/Doom/mc1-doom/logo/mc1-doom-logo.png -------------------------------------------------------------------------------- /LiteX/software/Doom/mc1-doom/src/.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | BasedOnStyle: Chromium 4 | AccessModifierOffset: -2 5 | AllowShortFunctionsOnASingleLine: None 6 | BinPackArguments: false 7 | BreakBeforeBraces: Allman 8 | ColumnLimit: 80 9 | IndentWidth: 4 10 | TabWidth: 8 11 | UseTab: Never 12 | SortIncludes: false 13 | SpaceBeforeParens: Always 14 | ... 15 | 16 | -------------------------------------------------------------------------------- /LiteX/software/Doom/mc1-doom/src/.gitignore: -------------------------------------------------------------------------------- 1 | out* 2 | CMake*.user 3 | *.wad 4 | *.dsg 5 | .doomrc 6 | -------------------------------------------------------------------------------- /LiteX/software/Doom/mc1-doom/src/d_textur.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // Copyright (C) 1993-1996 by id Software, Inc. 5 | // 6 | // This program is free software; you can redistribute it and/or 7 | // modify it under the terms of the GNU General Public License 8 | // as published by the Free Software Foundation; either version 2 9 | // of the License, or (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // DESCRIPTION: 17 | // Typedefs related to to textures etc., 18 | // isolated here to make it easier separating modules. 19 | // 20 | //----------------------------------------------------------------------------- 21 | 22 | #ifndef __D_TEXTUR__ 23 | #define __D_TEXTUR__ 24 | 25 | #include "doomtype.h" 26 | 27 | // 28 | // Flats? 29 | // 30 | // a pic is an unmasked block of pixels 31 | typedef struct 32 | { 33 | byte width; 34 | byte height; 35 | byte data; 36 | } pic_t; 37 | 38 | #endif // __D_TEXTUR__ 39 | -------------------------------------------------------------------------------- /LiteX/software/Doom/mc1-doom/src/doomdef.c: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // Copyright (C) 1993-1996 by id Software, Inc. 5 | // 6 | // This program is free software; you can redistribute it and/or 7 | // modify it under the terms of the GNU General Public License 8 | // as published by the Free Software Foundation; either version 2 9 | // of the License, or (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // DESCRIPTION: 17 | // DoomDef - basic defines for DOOM, e.g. Version, game mode 18 | // and skill level, and display parameters. 19 | // 20 | //----------------------------------------------------------------------------- 21 | 22 | #include "doomdef.h" 23 | 24 | // Location for any defines turned variables. 25 | 26 | // None. 27 | 28 | -------------------------------------------------------------------------------- /LiteX/software/Doom/mc1-doom/src/doomstat.c: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // Copyright (C) 1993-1996 by id Software, Inc. 5 | // 6 | // This program is free software; you can redistribute it and/or 7 | // modify it under the terms of the GNU General Public License 8 | // as published by the Free Software Foundation; either version 2 9 | // of the License, or (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // DESCRIPTION: 17 | // Put all global tate variables here. 18 | // 19 | //----------------------------------------------------------------------------- 20 | 21 | #include "doomstat.h" 22 | 23 | // Game Mode - identify IWAD as shareware, retail etc. 24 | GameMode_t gamemode = indetermined; 25 | GameMission_t gamemission = doom; 26 | 27 | // Language. 28 | Language_t language = english; 29 | 30 | // Set if homebrew PWAD stuff has been added. 31 | boolean modifiedgame; 32 | 33 | -------------------------------------------------------------------------------- /LiteX/software/Doom/mc1-doom/src/f_finale.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // Copyright (C) 1993-1996 by id Software, Inc. 5 | // 6 | // This program is free software; you can redistribute it and/or 7 | // modify it under the terms of the GNU General Public License 8 | // as published by the Free Software Foundation; either version 2 9 | // of the License, or (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // DESCRIPTION: 17 | // 18 | //----------------------------------------------------------------------------- 19 | 20 | #ifndef __F_FINALE__ 21 | #define __F_FINALE__ 22 | 23 | #include "doomtype.h" 24 | #include "d_event.h" 25 | // 26 | // FINALE 27 | // 28 | 29 | // Called by main loop. 30 | boolean F_Responder (event_t* ev); 31 | 32 | // Called by main loop. 33 | void F_Ticker (void); 34 | 35 | // Called by main loop. 36 | void F_Drawer (void); 37 | 38 | void F_StartFinale (void); 39 | 40 | #endif // __F_FINALE__ 41 | -------------------------------------------------------------------------------- /LiteX/software/Doom/mc1-doom/src/i_main.c: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // Copyright (C) 1993-1996 by id Software, Inc. 5 | // 6 | // This program is free software; you can redistribute it and/or 7 | // modify it under the terms of the GNU General Public License 8 | // as published by the Free Software Foundation; either version 2 9 | // of the License, or (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // DESCRIPTION: 17 | // Main program, simply calls D_DoomMain high level loop. 18 | // 19 | //----------------------------------------------------------------------------- 20 | 21 | #include "doomdef.h" 22 | 23 | #include "m_argv.h" 24 | #include "d_main.h" 25 | 26 | int 27 | main 28 | ( int argc, 29 | char** argv ) 30 | { 31 | myargc = argc; 32 | myargv = argv; 33 | 34 | D_DoomMain (); 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /LiteX/software/Doom/mc1-doom/src/i_net.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // Copyright (C) 1993-1996 by id Software, Inc. 5 | // 6 | // This program is free software; you can redistribute it and/or 7 | // modify it under the terms of the GNU General Public License 8 | // as published by the Free Software Foundation; either version 2 9 | // of the License, or (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // DESCRIPTION: 17 | // System specific network interface stuff. 18 | // 19 | //----------------------------------------------------------------------------- 20 | 21 | #ifndef __I_NET__ 22 | #define __I_NET__ 23 | 24 | // Called by D_DoomMain. 25 | 26 | void I_InitNetwork (void); 27 | void I_NetCmd (void); 28 | 29 | #endif // __I_NET__ 30 | -------------------------------------------------------------------------------- /LiteX/software/Doom/mc1-doom/src/list: -------------------------------------------------------------------------------- 1 | am_map.c 2 | d_items.c 3 | d_main.c 4 | d_net.c 5 | doomdef.c 6 | doomstat.c 7 | dstrings.c 8 | f_finale.c 9 | f_wipe.c 10 | g_game.c 11 | hu_lib.c 12 | hu_stuff.c 13 | i_main.c 14 | i_net.c 15 | i_net_dummy.c 16 | info.c 17 | i_sound_alsa.c 18 | i_sound_dummy.c 19 | i_system.c 20 | i_video_dummy.c 21 | i_video_mc1.c 22 | i_video_ncurses.c 23 | i_video_oled.c 24 | i_video_sdl2.c 25 | m_argv.c 26 | m_bbox.c 27 | m_cheat.c 28 | m_fixed.c 29 | m_menu.c 30 | m_misc.c 31 | m_random.c 32 | m_swap.c 33 | p_ceilng.c 34 | p_doors.c 35 | p_enemy.c 36 | p_floor.c 37 | p_inter.c 38 | p_lights.c 39 | p_map.c 40 | p_maputl.c 41 | p_mobj.c 42 | p_plats.c 43 | p_pspr.c 44 | p_saveg.c 45 | p_setup.c 46 | p_sight.c 47 | p_spec.c 48 | p_switch.c 49 | p_telept.c 50 | p_tick.c 51 | p_user.c 52 | r_bsp.c 53 | r_data.c 54 | r_draw.c 55 | r_main.c 56 | r_plane.c 57 | r_segs.c 58 | r_sky.c 59 | r_things.c 60 | sounds.c 61 | s_sound.c 62 | st_lib.c 63 | st_stuff.c 64 | tables.c 65 | v_video.c 66 | wi_stuff.c 67 | w_wad.c 68 | z_zone.c 69 | -------------------------------------------------------------------------------- /LiteX/software/Doom/mc1-doom/src/m_argv.c: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // Copyright (C) 1993-1996 by id Software, Inc. 5 | // 6 | // This program is free software; you can redistribute it and/or 7 | // modify it under the terms of the GNU General Public License 8 | // as published by the Free Software Foundation; either version 2 9 | // of the License, or (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // DESCRIPTION: 17 | // 18 | //----------------------------------------------------------------------------- 19 | 20 | #include <string.h> 21 | 22 | #include "m_misc.h" 23 | 24 | int myargc; 25 | char** myargv; 26 | 27 | // 28 | // M_CheckParm 29 | // Checks for the given parameter in the program's command line arguments. 30 | // Returns the argument number (1 to argc-1) or 0 if not present 31 | int M_CheckParm (const char* check) 32 | { 33 | int i; 34 | 35 | for (i = 1; i < myargc; i++) 36 | { 37 | if (!M_strcmpi (check, myargv[i])) 38 | return i; 39 | } 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /LiteX/software/Doom/mc1-doom/src/m_argv.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // Copyright (C) 1993-1996 by id Software, Inc. 5 | // 6 | // This program is free software; you can redistribute it and/or 7 | // modify it under the terms of the GNU General Public License 8 | // as published by the Free Software Foundation; either version 2 9 | // of the License, or (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // DESCRIPTION: 17 | // Nil. 18 | // 19 | //----------------------------------------------------------------------------- 20 | 21 | #ifndef __M_ARGV__ 22 | #define __M_ARGV__ 23 | 24 | // 25 | // MISC 26 | // 27 | extern int myargc; 28 | extern char** myargv; 29 | 30 | // Returns the position of the given parameter 31 | // in the arg list (0 if not found). 32 | int M_CheckParm (const char* check); 33 | 34 | #endif // __M_ARGV__ 35 | -------------------------------------------------------------------------------- /LiteX/software/Doom/mc1-doom/src/m_bbox.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // Copyright (C) 1993-1996 by id Software, Inc. 5 | // 6 | // This program is free software; you can redistribute it and/or 7 | // modify it under the terms of the GNU General Public License 8 | // as published by the Free Software Foundation; either version 2 9 | // of the License, or (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // DESCRIPTION: 17 | // Nil. 18 | // 19 | //----------------------------------------------------------------------------- 20 | 21 | #ifndef __M_BBOX__ 22 | #define __M_BBOX__ 23 | 24 | #include "m_fixed.h" 25 | 26 | // Bounding box coordinate storage. 27 | enum 28 | { 29 | BOXTOP, 30 | BOXBOTTOM, 31 | BOXLEFT, 32 | BOXRIGHT 33 | }; // bbox coordinates 34 | 35 | // Bounding box functions. 36 | void M_ClearBox (fixed_t* box); 37 | 38 | void 39 | M_AddToBox 40 | ( fixed_t* box, 41 | fixed_t x, 42 | fixed_t y ); 43 | 44 | #endif // __M_BBOX__ 45 | -------------------------------------------------------------------------------- /LiteX/software/Doom/mc1-doom/src/m_random.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // Copyright (C) 1993-1996 by id Software, Inc. 5 | // 6 | // This program is free software; you can redistribute it and/or 7 | // modify it under the terms of the GNU General Public License 8 | // as published by the Free Software Foundation; either version 2 9 | // of the License, or (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // DESCRIPTION: 17 | // 18 | //----------------------------------------------------------------------------- 19 | 20 | #ifndef __M_RANDOM__ 21 | #define __M_RANDOM__ 22 | 23 | #include "doomtype.h" 24 | 25 | // Returns a number from 0 to 255, 26 | // from a lookup table. 27 | int M_Random (void); 28 | 29 | // As M_Random, but used only by the play simulation. 30 | int P_Random (void); 31 | 32 | // Fix randoms for demos. 33 | void M_ClearRandom (void); 34 | 35 | #endif // __M_RANDOM__ 36 | -------------------------------------------------------------------------------- /LiteX/software/Doom/mc1-doom/src/m_swap.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // Copyright (C) 1993-1996 by id Software, Inc. 5 | // 6 | // This program is free software; you can redistribute it and/or 7 | // modify it under the terms of the GNU General Public License 8 | // as published by the Free Software Foundation; either version 2 9 | // of the License, or (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // DESCRIPTION: 17 | // Endianess handling, swapping 16bit and 32bit. 18 | // 19 | //----------------------------------------------------------------------------- 20 | 21 | #ifndef __M_SWAP__ 22 | #define __M_SWAP__ 23 | 24 | // Endianess handling. 25 | // WAD files are stored little endian. 26 | #ifdef __BIG_ENDIAN__ 27 | short SwapSHORT(short); 28 | long SwapLONG(long); 29 | #define SHORT(x) ((short)SwapSHORT((unsigned short) (x))) 30 | #define LONG(x) ((long)SwapLONG((unsigned long) (x))) 31 | #else 32 | #define SHORT(x) (x) 33 | #define LONG(x) (x) 34 | #endif 35 | 36 | #endif // __M_SWAP__ 37 | -------------------------------------------------------------------------------- /LiteX/software/Doom/mc1-doom/src/mc1-toolchain.cmake: -------------------------------------------------------------------------------- 1 | # -*- mode: CMake; tab-width: 2; indent-tabs-mode: nil; -*- 2 | 3 | # This file is a fairly generic CMake toolchain file for the MC1 computer. 4 | # To use it, run CMake with the argument: 5 | # -DCMAKE_TOOLCHAIN_FILE=mc1-toolchain.cmake 6 | 7 | set(CMAKE_SYSTEM_NAME Generic) 8 | set(CMAKE_SYSTEM_PROCESSOR mrisc32) 9 | set(MC1 TRUE) 10 | 11 | set(CMAKE_C_COMPILER mrisc32-elf-gcc) 12 | set(CMAKE_CXX_COMPILER mrisc32-elf-g++) 13 | 14 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 15 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 16 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 17 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 18 | -------------------------------------------------------------------------------- /LiteX/software/Doom/mc1-doom/src/p_inter.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // Copyright (C) 1993-1996 by id Software, Inc. 5 | // 6 | // This program is free software; you can redistribute it and/or 7 | // modify it under the terms of the GNU General Public License 8 | // as published by the Free Software Foundation; either version 2 9 | // of the License, or (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // DESCRIPTION: 17 | // 18 | //----------------------------------------------------------------------------- 19 | 20 | #ifndef __P_INTER__ 21 | #define __P_INTER__ 22 | 23 | boolean P_GivePower(player_t*, int); 24 | 25 | #endif // __P_INTER__ 26 | -------------------------------------------------------------------------------- /LiteX/software/Doom/mc1-doom/src/p_setup.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // Copyright (C) 1993-1996 by id Software, Inc. 5 | // 6 | // This program is free software; you can redistribute it and/or 7 | // modify it under the terms of the GNU General Public License 8 | // as published by the Free Software Foundation; either version 2 9 | // of the License, or (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // DESCRIPTION: 17 | // Setup a game, startup stuff. 18 | // 19 | //----------------------------------------------------------------------------- 20 | 21 | #ifndef __P_SETUP__ 22 | #define __P_SETUP__ 23 | 24 | // NOT called by W_Ticker. Fixme. 25 | void 26 | P_SetupLevel 27 | ( int episode, 28 | int map, 29 | int playermask, 30 | skill_t skill); 31 | 32 | // Called by startup code. 33 | void P_Init (void); 34 | 35 | #endif // __P_SETUP__ 36 | -------------------------------------------------------------------------------- /LiteX/software/Doom/mc1-doom/src/p_tick.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // Copyright (C) 1993-1996 by id Software, Inc. 5 | // 6 | // This program is free software; you can redistribute it and/or 7 | // modify it under the terms of the GNU General Public License 8 | // as published by the Free Software Foundation; either version 2 9 | // of the License, or (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // DESCRIPTION: 17 | // ? 18 | // 19 | //----------------------------------------------------------------------------- 20 | 21 | #ifndef __P_TICK__ 22 | #define __P_TICK__ 23 | 24 | // Called by C_Ticker, 25 | // can call G_PlayerExited. 26 | // Carries out all thinking of monsters and players. 27 | void P_Ticker (void); 28 | 29 | #endif // __P_TICK__ 30 | -------------------------------------------------------------------------------- /LiteX/software/Doom/mc1-doom/src/r_segs.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // Copyright (C) 1993-1996 by id Software, Inc. 5 | // 6 | // This program is free software; you can redistribute it and/or 7 | // modify it under the terms of the GNU General Public License 8 | // as published by the Free Software Foundation; either version 2 9 | // of the License, or (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // DESCRIPTION: 17 | // Refresh module, drawing LineSegs from BSP. 18 | // 19 | //----------------------------------------------------------------------------- 20 | 21 | #ifndef __R_SEGS__ 22 | #define __R_SEGS__ 23 | 24 | void 25 | R_RenderMaskedSegRange 26 | ( drawseg_t* ds, 27 | int x1, 28 | int x2 ); 29 | 30 | #endif // __R_SEGS__ 31 | -------------------------------------------------------------------------------- /LiteX/software/Doom/mc1-doom/src/r_sky.h: -------------------------------------------------------------------------------- 1 | // Emacs style mode select -*- C++ -*- 2 | //----------------------------------------------------------------------------- 3 | // 4 | // Copyright (C) 1993-1996 by id Software, Inc. 5 | // 6 | // This program is free software; you can redistribute it and/or 7 | // modify it under the terms of the GNU General Public License 8 | // as published by the Free Software Foundation; either version 2 9 | // of the License, or (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // DESCRIPTION: 17 | // Sky rendering. 18 | // 19 | //----------------------------------------------------------------------------- 20 | 21 | #ifndef __R_SKY__ 22 | #define __R_SKY__ 23 | 24 | // SKY, store the number for name. 25 | #define SKYFLATNAME "F_SKY1" 26 | 27 | // The sky map is 256*128*4 maps. 28 | #define ANGLETOSKYSHIFT 22 29 | 30 | extern int skytexture; 31 | extern int skytexturemid; 32 | 33 | // Called whenever the view size changes. 34 | void R_InitSkyMap (void); 35 | 36 | #endif // __R_SKY__ 37 | -------------------------------------------------------------------------------- /LiteX/software/Doom/mc1-doom/src/run.bat: -------------------------------------------------------------------------------- 1 | mr32sim -g -ga 0x40000ae0 -gp 0x400006c4 -gd 8 -gw 320 -gh 180 %* out/mc1doom.bin 2 | -------------------------------------------------------------------------------- /LiteX/software/Doom/mc1-doom/src/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | PROFILE_ARGS="" 4 | if [ "$1" == "--profile" ] ; then 5 | shift 1 6 | mrisc32-elf-readelf -sW out/mc1doom | grep FUNC | awk '{print $2,$8}' > /tmp/symbols.csv 7 | PROFILE_ARGS="-P /tmp/symbols.csv" 8 | fi 9 | 10 | mr32sim -g -ga 0x40000ae0 -gp 0x400006c4 -gd 8 -gw 320 -gh 180 ${PROFILE_ARGS} "$@" out/mc1doom.bin 11 | -------------------------------------------------------------------------------- /LiteX/software/Doom/regions.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * same as generated/regions.ld, except that main_ram 3 | * main_ram starts 256KB later (we keep the first 256KB 4 | * for the OS). 5 | */ 6 | MEMORY { 7 | rom : ORIGIN = 0x00000000, LENGTH = 0x00020000 8 | sram : ORIGIN = 0x01000000, LENGTH = 0x00002000 9 | main_ram : ORIGIN = 0x40040000, LENGTH = 0x01FC0000 10 | csr : ORIGIN = 0x82000000, LENGTH = 0x00010000 11 | } 12 | 13 | -------------------------------------------------------------------------------- /LiteX/software/Doom/sbrk.c: -------------------------------------------------------------------------------- 1 | /* taken from Claire Wolf's picorv32 libraries */ 2 | #include <stddef.h> 3 | #include <stdio.h> 4 | 5 | void *sbrk(ptrdiff_t incr); 6 | void *sbrk(ptrdiff_t incr) { 7 | 8 | extern unsigned char _end[]; // Defined by linker 9 | static unsigned long heap_end = 0; 10 | 11 | // printf("SBRK %d\n",(int)incr); 12 | 13 | if (heap_end == 0) 14 | heap_end = (long)_end; 15 | 16 | heap_end += incr; 17 | return (void *)(heap_end - incr); 18 | } 19 | 20 | -------------------------------------------------------------------------------- /LiteX/software/Libs/README.md: -------------------------------------------------------------------------------- 1 | Software libraries for LiteX/LiteOS 2 | ----------------------------------- 3 | 4 | |Library | Description | 5 | |-----------|---------------------------------------------| 6 | |lite_fb | graphic functions (for framebuffer) | 7 | |lite_oled | graphic functions (for SSD1331 oled screen) | 8 | |lite_stdio | (incomplete) emulation layer for stdio | 9 | |lite_elf | load and execute ELF binaries | 10 | |imgui | Dear Imgui graphic user interface | 11 | 12 | See Doxygen documentation in header files. 13 | -------------------------------------------------------------------------------- /LiteX/software/Libs/imgui/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2021 Omar Cornut 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /LiteX/software/LiteOS/Makefile: -------------------------------------------------------------------------------- 1 | # usage: 2 | # 1) make BUILD_DIR=<the directory where you generated the SOC> 3 | # (for instance, LiteX/build/radiona_ulx3s) 4 | # Alternatively you can edit this file and change LITEX_DIR and 5 | # LITEX_PLATFORM below. 6 | # 2) lxterm /dev/ttyUSBnnn --kernel boot.bin 7 | # 3) litex> reboot 8 | 9 | include ../makefile.inc 10 | 11 | # These ones are compiled from the sources in LiteX/litex/litex/soc/software/bios/ 12 | BIOS_OBJECTS=complete.o helpers.o readline.o cmd_bios.o 13 | OBJECTS = $(BIOS_OBJECTS) builtins.o isr.o main.o crt0.o 14 | 15 | all: boot.bin 16 | 17 | # pull in dependency info for *existing* .o files 18 | -include $(OBJECTS:.o=.d) 19 | 20 | boot.elf: $(OBJECTS) libliteos.a 21 | $(CC) $(LDFLAGS) \ 22 | -T linker.ld \ 23 | -N -o $@ \ 24 | $(OBJECTS) \ 25 | $(PACKAGES:%=-L$(BUILD_DIR)/software/%) \ 26 | $(LIBS:lib%=-l%) -L. -lliteos 27 | chmod -x $@ 28 | 29 | # Made crt0.o dependent on one of the generated files to make sure it 30 | # is recompiled whenever configuration is changed (for instance, when 31 | # swapping femtorv variants) 32 | crt0.o: $(CPU_DIRECTORY)/crt0.S $(BUILD_DIR)/software/include/generated/variables.mak 33 | $(assemble) 34 | 35 | -------------------------------------------------------------------------------- /LiteX/software/LiteOS/isr.c: -------------------------------------------------------------------------------- 1 | // This file is Copyright (c) 2020 Florent Kermarrec <florent@enjoy-digital.fr> 2 | // License: BSD 3 | 4 | #include <generated/csr.h> 5 | #include <generated/soc.h> 6 | #include <irq.h> 7 | #include <libbase/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 30 | -------------------------------------------------------------------------------- /LiteX/software/Programs/Makefile: -------------------------------------------------------------------------------- 1 | include ../makefile.inc 2 | 3 | all: hello.elf \ 4 | tinyraytracer.elf \ 5 | spirograph.elf \ 6 | ST_NICCC.elf \ 7 | imgui_test.elf 8 | 9 | %.elf: %.o libliteos.a crt0.o sbrk.o 10 | $(CC) ./crt0.o lt; sbrk.o $(LDFLAGS) \ 11 | -T linker.ld \ 12 | -N -o $@ \ 13 | $(PACKAGES:%=-L$(BUILD_DIR)/software/%) \ 14 | -L. -lliteos $(LIBS:lib%=-l%) -lbase 15 | chmod -x $@ 16 | 17 | -------------------------------------------------------------------------------- /LiteX/software/Programs/crt0.S: -------------------------------------------------------------------------------- 1 | // crt0.S for executables 2 | // interrupts and stack are already configured by OS 3 | // _start does the following tasks: 4 | // 1) save registers (ra, t0..t6, a0..a7) 5 | // 2) initialize BSS 6 | // 3) call main 7 | // 4) restore registers 8 | // 5) return to caller (LiteOS shell) 9 | 10 | .global _start 11 | _start: 12 | // save context 13 | addi sp, sp, -16*4 14 | sw ra, 0*4(sp) 15 | sw t0, 1*4(sp) 16 | sw t1, 2*4(sp) 17 | sw t2, 3*4(sp) 18 | sw a0, 4*4(sp) 19 | sw a1, 5*4(sp) 20 | sw a2, 6*4(sp) 21 | sw a3, 7*4(sp) 22 | sw a4, 8*4(sp) 23 | sw a5, 9*4(sp) 24 | sw a6, 10*4(sp) 25 | sw a7, 11*4(sp) 26 | sw t3, 12*4(sp) 27 | sw t4, 13*4(sp) 28 | sw t5, 14*4(sp) 29 | sw t6, 15*4(sp) 30 | 31 | 32 | // initialize .bss 33 | la t0, _fbss 34 | la t1, _ebss 35 | 1: beq t0, t1, 3f 36 | sw zero, 0(t0) 37 | addi t0, t0, 4 38 | j 1b 39 | 3: 40 | 41 | call main 42 | 43 | // restore context 44 | lw ra, 0*4(sp) 45 | lw t0, 1*4(sp) 46 | lw t1, 2*4(sp) 47 | lw t2, 3*4(sp) 48 | lw a0, 4*4(sp) 49 | lw a1, 5*4(sp) 50 | lw a2, 6*4(sp) 51 | lw a3, 7*4(sp) 52 | lw a4, 8*4(sp) 53 | lw a5, 9*4(sp) 54 | lw a6, 10*4(sp) 55 | lw a7, 11*4(sp) 56 | lw t3, 12*4(sp) 57 | lw t4, 13*4(sp) 58 | lw t5, 14*4(sp) 59 | lw t6, 15*4(sp) 60 | addi sp, sp, 16*4 61 | 62 | ret 63 | -------------------------------------------------------------------------------- /LiteX/software/Programs/hello.c: -------------------------------------------------------------------------------- 1 | #include <stdio.h> 2 | #include <stdlib.h> 3 | 4 | int main(int argc, char** argv) { 5 | printf("hello, world\n"); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /LiteX/software/Programs/linker.ld: -------------------------------------------------------------------------------- 1 | INCLUDE generated/output_format.ld 2 | ENTRY(_start) 3 | 4 | __DYNAMIC = 0; 5 | 6 | /* 7 | * We include our own 'regions.ld', with main_ram that starts 256 KB 8 | * later (the first 256 KBs are kept fo the OS). 9 | */ 10 | INCLUDE regions.ld 11 | 12 | SECTIONS 13 | { 14 | .text : 15 | { 16 | _ftext = .; 17 | /* Make sure crt0 files come first, and they, and the isr */ 18 | /* don't get disposed of by greedy optimisation */ 19 | *crt0*(.text) 20 | KEEP(*crt0*(.text)) 21 | KEEP(*(.text.isr)) 22 | 23 | *(.text .stub .text.* .gnu.linkonce.t.*) 24 | _etext = .; 25 | } > main_ram 26 | 27 | .rodata : 28 | { 29 | . = ALIGN(8); 30 | _frodata = .; 31 | *(.rodata .rodata.* .gnu.linkonce.r.*) 32 | *(.rodata1) 33 | . = ALIGN(8); 34 | _erodata = .; 35 | } > main_ram 36 | 37 | .data : 38 | { 39 | . = ALIGN(8); 40 | *(.data .data.* .gnu.linkonce.d.*) 41 | *(.data1) 42 | _gp = ALIGN(16); 43 | *(.sdata .sdata.* .gnu.linkonce.s.*) 44 | . = ALIGN(8); 45 | } > main_ram 46 | 47 | .bss : 48 | { 49 | . = ALIGN(8); 50 | _fbss = .; 51 | *(.dynsbss) 52 | *(.sbss .sbss.* .gnu.linkonce.sb.*) 53 | *(.scommon) 54 | *(.dynbss) 55 | *(.bss .bss.* .gnu.linkonce.b.*) 56 | *(COMMON) 57 | . = ALIGN(8); 58 | _ebss = .; 59 | _end = .; 60 | } > main_ram 61 | } 62 | 63 | 64 | -------------------------------------------------------------------------------- /LiteX/software/Programs/regions.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * same as generated/regions.ld, except that main_ram 3 | * main_ram starts 256KB later (we keep the first 256KB 4 | * for the OS). 5 | */ 6 | MEMORY { 7 | rom : ORIGIN = 0x00000000, LENGTH = 0x00020000 8 | sram : ORIGIN = 0x01000000, LENGTH = 0x00002000 9 | main_ram : ORIGIN = 0x40040000, LENGTH = 0x01FC0000 10 | csr : ORIGIN = 0x82000000, LENGTH = 0x00010000 11 | } 12 | -------------------------------------------------------------------------------- /LiteX/software/Programs/sbrk.c: -------------------------------------------------------------------------------- 1 | /* taken from Claire Wolf's picorv32 libraries */ 2 | #include <stddef.h> 3 | #include <stdio.h> 4 | 5 | void *sbrk(ptrdiff_t incr); 6 | void *sbrk(ptrdiff_t incr) { 7 | 8 | extern unsigned char _end[]; // Defined by linker 9 | static unsigned long heap_end = 0; 10 | 11 | // printf("SBRK %d\n",(int)incr); 12 | 13 | if (heap_end == 0) 14 | heap_end = (long)_end; 15 | 16 | heap_end += incr; 17 | return (void *)(heap_end - incr); 18 | } 19 | 20 | -------------------------------------------------------------------------------- /LiteX/software/Programs/scene1.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/LiteX/software/Programs/scene1.dat -------------------------------------------------------------------------------- /LiteX/software/README.md: -------------------------------------------------------------------------------- 1 | Software for LiteX SoCs 2 | ----------------------- 3 | 4 | This directory contains libraries and software packages for LiteX SoCs: 5 | - [DemoBundle](DemoBundle/): a ROM with several demo programs, to 6 | measure the speed of softcores (raystones), to draw shiny spheres 7 | with raytracing (tinyraytracer), to display animations on the 8 | small OLED screen (riscv-logo, julia) ... 9 | - [LiteOS](LiteOS/): a minimalistic OS that lets you load and execute 10 | programs (ELF binaries) stored on the SDCard; 11 | - [Programs](Programs/): simple example programs for LiteOS 12 | - [Doom](Doom/): a port of Doom for LiteOS 13 | - [Tagl](Tagl/): a 3D software renderer (that I wrote in the 90s) ported to LiteOS 14 | - [Libs](Libs/): common libraries (ELF support, OLED screen, framebuffer, Dear ImGui port, stdio adapter) 15 | 16 | 17 | Links, stuff to port 18 | -------------------- 19 | 20 | - [dos-like](https://github.com/mattiasgustavsson/dos-like) 21 | - [tiny-gl](https://github.com/C-Chads/tinygl) 22 | - [tcc-riscv](https://github.com/sellicott/tcc-riscv32) 23 | - [Bubble Universe](https://stardot.org.uk/forums/viewtopic.php?t=25833&sid=33182a6ffa6f84b08bb6f52cae2ad35d) 24 | - [shecc](https://github.com/sysprog21/shecc) 25 | -------------------------------------------------------------------------------- /LiteX/software/Tagl/Lib/Makefile: -------------------------------------------------------------------------------- 1 | 2 | OPTIMIZE= -O6 -DGINT -fomit-frame-pointer -funroll-loops -DNDEBUG 3 | CCX11=-I/usr/X11R6/include -DX_SHM 4 | CXXOPT= -fpermissive -Wno-deprecated $(OPTIMIZE) $(CCX11) 5 | 6 | SRC= Xgport.cc\ 7 | Xpeng.cc\ 8 | dldlinker.cc\ 9 | gcomp.cc\ 10 | gman.cc\ 11 | gport.cc\ 12 | gproc.cc\ 13 | locgman.cc\ 14 | peng_24.cc\ 15 | peng_32x.cc\ 16 | peng_32xi.cc\ 17 | peng_555.cc\ 18 | peng_565.cc\ 19 | peng_8.cc\ 20 | peng_x32.cc\ 21 | polyeng.cc\ 22 | sintab.cc\ 23 | LinG.cc 24 | 25 | OBJS= Xgport.o\ 26 | Xpeng.o\ 27 | dldlinker.o\ 28 | gcomp.o\ 29 | gman.o\ 30 | gport.o\ 31 | gproc.o\ 32 | locgman.o\ 33 | peng_24.o\ 34 | peng_32x.o\ 35 | peng_32xi.o\ 36 | peng_555.o\ 37 | peng_565.o\ 38 | peng_8.o\ 39 | peng_x32.o\ 40 | polyeng.o\ 41 | sintab.o\ 42 | LinG.o 43 | 44 | libtagl.a: $(OBJS) 45 | rm -f libtagl.a 46 | ar cq libtagl.a $(OBJS) 47 | ranlib libtagl.a 48 | 49 | .cc.o: lt; 50 | $(CXX) $(CXXOPT) -c lt; 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /LiteX/software/Tagl/Lib/gman.ih: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is copyrighted as noted below. It may be freely copied, 3 | * modified, and redistributed, provided that the copyright notice is 4 | * preserved on all copies. 5 | * 6 | * There is no warranty or other guarantee of fitness for this software, 7 | * it is provided solely "as is". Bug reports or fixes may be sent 8 | * to the author, who may or may not act on them as he desires. 9 | * 10 | * You may not include this software in a program or other software product 11 | * without supplying the source, or without informing the end-user that the 12 | * source is available for no extra charge. 13 | * 14 | * If you modify this software, you should include a notice giving the 15 | * name of the person performing the modification, the date of modification, 16 | * and the reason for such modification. 17 | * 18 | * Author: Bruno Levy 19 | * 20 | * Copyright (c) 1996, Bruno Levy. 21 | * 22 | */ 23 | /* 24 | * 25 | * gman.ih 26 | * 27 | */ 28 | 29 | #ifndef GMAN_I_H 30 | #define GMAN_I_H 31 | 32 | inline GeometryManager& operator<<( GeometryManager& output, 33 | GeometryManager& data ) 34 | { 35 | data.Playback(&output); 36 | return output; 37 | } 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /LiteX/software/Tagl/Lib/gmath.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is copyrighted as noted below. It may be freely copied, 3 | * modified, and redistributed, provided that the copyright notice is 4 | * preserved on all copies. 5 | * 6 | * There is no warranty or other guarantee of fitness for this software, 7 | * it is provided solely "as is". Bug reports or fixes may be sent 8 | * to the author, who may or may not act on them as he desires. 9 | * 10 | * You may not include this software in a program or other software product 11 | * without supplying the source, or without informing the end-user that the 12 | * source is available for no extra charge. 13 | * 14 | * If you modify this software, you should include a notice giving the 15 | * name of the person performing the modification, the date of modification, 16 | * and the reason for such modification. 17 | * 18 | * Author: Bruno Levy 19 | * 20 | * Copyright (c) 1996, Bruno Levy. 21 | * 22 | */ 23 | /* 24 | * 25 | * gmath.h 26 | * 27 | */ 28 | 29 | #ifndef GMATH_H 30 | #define GMATH_H 31 | 32 | // Tons of inline stuff here !!!! 33 | 34 | #include "gmatrix.h" 35 | #include "gvector.h" 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /LiteX/software/Tagl/Lib/gray0.bm: -------------------------------------------------------------------------------- 1 | #define gray0_width 8 2 | #define gray0_height 8 3 | static char gray0_bits[] = { 4 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 5 | -------------------------------------------------------------------------------- /LiteX/software/Tagl/Lib/gray1.bm: -------------------------------------------------------------------------------- 1 | #define gray1_width 8 2 | #define gray1_height 8 3 | static char gray1_bits[] = { 4 | 0x11, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00}; 5 | -------------------------------------------------------------------------------- /LiteX/software/Tagl/Lib/gray2.bm: -------------------------------------------------------------------------------- 1 | #define gray2_width 8 2 | #define gray2_height 8 3 | static char gray2_bits[] = { 4 | 0x11, 0x00, 0x44, 0x00, 0x11, 0x00, 0x44, 0x00}; 5 | -------------------------------------------------------------------------------- /LiteX/software/Tagl/Lib/gray3.bm: -------------------------------------------------------------------------------- 1 | #define gray3_width 8 2 | #define gray3_height 8 3 | static char gray3_bits[] = { 4 | 0x55, 0x00, 0x55, 0x00, 0x55, 0x00, 0x55, 0x00}; 5 | -------------------------------------------------------------------------------- /LiteX/software/Tagl/Lib/gray4.bm: -------------------------------------------------------------------------------- 1 | #define gray4_width 8 2 | #define gray4_height 8 3 | static char gray4_bits[] = { 4 | 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa}; 5 | -------------------------------------------------------------------------------- /LiteX/software/Tagl/Lib/gray5.bm: -------------------------------------------------------------------------------- 1 | #define gray5_width 8 2 | #define gray5_height 8 3 | static char gray5_bits[] = { 4 | 0x55, 0xff, 0x55, 0xff, 0x55, 0xff, 0x55, 0xff}; 5 | -------------------------------------------------------------------------------- /LiteX/software/Tagl/Lib/gray6.bm: -------------------------------------------------------------------------------- 1 | #define gray6_width 8 2 | #define gray6_height 8 3 | static char gray6_bits[] = { 4 | 0xdd, 0xff, 0x77, 0xff, 0xdd, 0xff, 0x77, 0xff}; 5 | -------------------------------------------------------------------------------- /LiteX/software/Tagl/Lib/gray7.bm: -------------------------------------------------------------------------------- 1 | #define gray7_width 8 2 | #define gray7_height 8 3 | static char gray7_bits[] = { 4 | 0xff, 0xff, 0xff, 0xff, 0xef, 0xff, 0xff, 0xff}; 5 | -------------------------------------------------------------------------------- /LiteX/software/Tagl/Lib/list: -------------------------------------------------------------------------------- 1 | Xgport.cc 2 | Xpeng.cc 3 | dldlinker.cc 4 | gcomp.cc 5 | glinker.cc 6 | gman.cc 7 | gport.cc 8 | gproc.cc 9 | locgman.cc 10 | peng_24.cc 11 | peng_32x.cc 12 | peng_32xi.cc 13 | peng_555.cc 14 | peng_565.cc 15 | peng_8.cc 16 | peng_x32.cc 17 | polyeng.cc 18 | sintab.cc 19 | -------------------------------------------------------------------------------- /LiteX/software/Tagl/Lib/machine.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is copyrighted as noted below. It may be freely copied, 3 | * modified, and redistributed, provided that the copyright notice is 4 | * preserved on all copies. 5 | * 6 | * There is no warranty or other guarantee of fitness for this software, 7 | * it is provided solely "as is". Bug reports or fixes may be sent 8 | * to the author, who may or may not act on them as he desires. 9 | * 10 | * You may not include this software in a program or other software product 11 | * without supplying the source, or without informing the end-user that the 12 | * source is available for no extra charge. 13 | * 14 | * If you modify this software, you should include a notice giving the 15 | * name of the person performing the modification, the date of modification, 16 | * and the reason for such modification. 17 | * 18 | * Author: Bruno Levy 19 | * 20 | * Copyright (c) 1996, Bruno Levy. 21 | * 22 | */ 23 | /* 24 | * 25 | * machine.h 26 | * 27 | */ 28 | 29 | #ifndef MACHINE_H 30 | #define MACHINE_H 31 | 32 | typedef char int8; 33 | typedef short int16; 34 | typedef int int32; 35 | 36 | typedef unsigned char uint8; 37 | typedef unsigned short uint16; 38 | typedef unsigned int uint32; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /LiteX/software/Tagl/Makefile: -------------------------------------------------------------------------------- 1 | include ../makefile.inc 2 | 3 | # Include path 4 | CFLAGS:=$(CFLAGS) -ILib 5 | CXXFLAGS:=$(CXXFLAGS) -ILib 6 | 7 | all: rotate.elf 8 | 9 | ROTATE_OBJECTS= bezier.o cmdline.o gobj.o mesh.o rotate.o smmesh.o smtri.o texture.o trimesh.o 10 | 11 | rotate.elf: $(ROTATE_OBJECTS) libtagl.a libliteos.a crt0.o sbrk.o 12 | $(CC) ./crt0.o $(ROTATE_OBJECTS) sbrk.o $(LDFLAGS) \ 13 | -T linker.ld \ 14 | -N -o $@ \ 15 | $(PACKAGES:%=-L$(BUILD_DIR)/software/%) \ 16 | -L. -ltagl -lliteos $(LIBS:lib%=-l%) -lbase 17 | chmod -x $@ 18 | 19 | LIBTAGL_OBJECTS=gcomp.o gman.o gport.o gproc.o locgman.o peng_x32.o polyeng.o sintab.o LiteXgport.o 20 | 21 | libtagl.a: $(LIBTAGL_OBJECTS) 22 | ar cq libtagl.a $(LIBTAGL_OBJECTS) 23 | ranlib libtagl.a 24 | 25 | %.o: Lib/%.cc 26 | $(compilexx) 27 | 28 | %.o: Rotate/%.cc 29 | $(compilexx) 30 | -------------------------------------------------------------------------------- /LiteX/software/Tagl/Objects/1.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/LiteX/software/Tagl/Objects/1.tga -------------------------------------------------------------------------------- /LiteX/software/Tagl/Objects/2.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/LiteX/software/Tagl/Objects/2.tga -------------------------------------------------------------------------------- /LiteX/software/Tagl/Objects/3.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/LiteX/software/Tagl/Objects/3.tga -------------------------------------------------------------------------------- /LiteX/software/Tagl/Objects/cldsmap.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/LiteX/software/Tagl/Objects/cldsmap.tga -------------------------------------------------------------------------------- /LiteX/software/Tagl/Objects/cube.geom: -------------------------------------------------------------------------------- 1 | 8 6 24 2 | -0.5 -0.5 0.5 3 | -0.5 0.5 0.5 4 | 0.5 0.5 0.5 5 | 0.5 -0.5 0.5 6 | -0.5 -0.5 -0.5 7 | -0.5 0.5 -0.5 8 | 0.5 0.5 -0.5 9 | 0.5 -0.5 -0.5 10 | 4 1 2 3 4 11 | 4 5 6 2 1 12 | 4 3 2 6 7 13 | 4 3 7 8 4 14 | 4 1 4 8 5 15 | 4 8 7 6 5 16 | -------------------------------------------------------------------------------- /LiteX/software/Tagl/Objects/evrgreen.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/LiteX/software/Tagl/Objects/evrgreen.tga -------------------------------------------------------------------------------- /LiteX/software/Tagl/Objects/meditdn.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/LiteX/software/Tagl/Objects/meditdn.tga -------------------------------------------------------------------------------- /LiteX/software/Tagl/Objects/raytrace.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/LiteX/software/Tagl/Objects/raytrace.tga -------------------------------------------------------------------------------- /LiteX/software/Tagl/Objects/refmap.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/LiteX/software/Tagl/Objects/refmap.tga -------------------------------------------------------------------------------- /LiteX/software/Tagl/Objects/sticks.geom: -------------------------------------------------------------------------------- 1 | 24 18 72 2 | 0.5 0.279243 -0.138164 3 | 0.517631 0.279243 -0.0381635 4 | 0.517631 0.177701 -0.0381635 5 | 0.5 0.177701 -0.138164 6 | -0.482369 0.279243 0.138164 7 | -0.5 0.279243 0.0381635 8 | -0.5 0.177701 0.0381635 9 | -0.482369 0.177701 0.138164 10 | -0.060899 -0.450763 -0.138164 11 | -0.0697155 -0.466035 -0.0381635 12 | -0.157654 -0.415262 -0.0381635 13 | -0.148838 -0.399992 -0.138164 14 | 0.430285 0.399993 0.138164 15 | 0.439101 0.415264 0.0381635 16 | 0.351163 0.466035 0.0381635 17 | 0.342347 0.450764 0.138164 18 | -0.412654 0.399993 -0.138164 19 | -0.42147 0.415264 -0.0381635 20 | -0.333531 0.466035 -0.0381635 21 | -0.324715 0.450764 -0.138164 22 | 0.0785304 -0.450763 0.138164 23 | 0.0873469 -0.466035 0.0381635 24 | 0.175285 -0.415262 0.0381635 25 | 0.166469 -0.399992 0.138164 26 | 4 1 2 3 4 27 | 4 5 6 7 8 28 | 4 6 1 4 7 29 | 4 5 2 1 6 30 | 4 8 3 2 5 31 | 4 7 4 3 8 32 | 4 9 10 11 12 33 | 4 13 14 15 16 34 | 4 14 9 12 15 35 | 4 13 10 9 14 36 | 4 16 11 10 13 37 | 4 15 12 11 16 38 | 4 17 18 19 20 39 | 4 21 22 23 24 40 | 4 22 17 20 23 41 | 4 21 18 17 22 42 | 4 24 19 18 21 43 | 4 23 20 19 24 44 | -------------------------------------------------------------------------------- /LiteX/software/Tagl/Objects/sunset2.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/LiteX/software/Tagl/Objects/sunset2.tga -------------------------------------------------------------------------------- /LiteX/software/Tagl/Rotate/bezier.ih: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is copyrighted as noted below. It may be freely copied, 3 | * modified, and redistributed, provided that the copyright notice is 4 | * preserved on all copies. 5 | * 6 | * There is no warranty or other guarantee of fitness for this software, 7 | * it is provided solely "as is". Bug reports or fixes may be sent 8 | * to the author, who may or may not act on them as he desires. 9 | * 10 | * You may not include this software in a program or other software product 11 | * without supplying the source, or without informing the end-user that the 12 | * source is available for no extra charge. 13 | * 14 | * If you modify this software, you should include a notice giving the 15 | * name of the person performing the modification, the date of modification, 16 | * and the reason for such modification. 17 | * 18 | * Author: Bruno Levy 19 | * 20 | * Copyright (c) 1996, Bruno Levy. 21 | * 22 | */ 23 | /* 24 | * 25 | * bezier.ih 26 | * 27 | */ 28 | 29 | #ifndef BEZIER_IH 30 | #define BEZIER_IH 31 | 32 | 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /LiteX/software/Tagl/Rotate/texture.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This software is copyrighted as noted below. It may be freely copied, 3 | * modified, and redistributed, provided that the copyright notice is 4 | * preserved on all copies. 5 | * 6 | * There is no warranty or other guarantee of fitness for this software, 7 | * it is provided solely "as is". Bug reports or fixes may be sent 8 | * to the author, who may or may not act on them as he desires. 9 | * 10 | * You may not include this software in a program or other software product 11 | * without supplying the source, or without informing the end-user that the 12 | * source is available for no extra charge. 13 | * 14 | * If you modify this software, you should include a notice giving the 15 | * name of the person performing the modification, the date of modification, 16 | * and the reason for such modification. 17 | * 18 | * Author: Bruno Levy 19 | * 20 | * Copyright (c) 1996, Bruno Levy. 21 | * 22 | */ 23 | /* 24 | * 25 | * texture.h 26 | * 27 | */ 28 | 29 | 30 | #ifndef TEXTURE_H 31 | #define TEXTURE_H 32 | 33 | extern int size; 34 | 35 | class GraphicPort; 36 | class PolygonEngine; 37 | 38 | int LoadTexture(const char* filename, GraphicPort* GP); 39 | void ToggleTextureMode(PolygonEngine* PE); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /LiteX/software/Tagl/crt0.S: -------------------------------------------------------------------------------- 1 | // crt0.S for executables 2 | // interrupts and stack are already configured by OS 3 | // _start does the following tasks: 4 | // 1) save registers (ra, t0..t6, a0..a7) 5 | // 2) initialize BSS 6 | // 3) call main 7 | // 4) restore registers 8 | // 5) return to caller (LiteOS shell) 9 | 10 | .global _start 11 | _start: 12 | // save context 13 | addi sp, sp, -16*4 14 | sw ra, 0*4(sp) 15 | sw t0, 1*4(sp) 16 | sw t1, 2*4(sp) 17 | sw t2, 3*4(sp) 18 | sw a0, 4*4(sp) 19 | sw a1, 5*4(sp) 20 | sw a2, 6*4(sp) 21 | sw a3, 7*4(sp) 22 | sw a4, 8*4(sp) 23 | sw a5, 9*4(sp) 24 | sw a6, 10*4(sp) 25 | sw a7, 11*4(sp) 26 | sw t3, 12*4(sp) 27 | sw t4, 13*4(sp) 28 | sw t5, 14*4(sp) 29 | sw t6, 15*4(sp) 30 | 31 | 32 | // initialize .bss 33 | la t0, _fbss 34 | la t1, _ebss 35 | 1: beq t0, t1, 3f 36 | sw zero, 0(t0) 37 | addi t0, t0, 4 38 | j 1b 39 | 3: 40 | 41 | call main 42 | 43 | // restore context 44 | lw ra, 0*4(sp) 45 | lw t0, 1*4(sp) 46 | lw t1, 2*4(sp) 47 | lw t2, 3*4(sp) 48 | lw a0, 4*4(sp) 49 | lw a1, 5*4(sp) 50 | lw a2, 6*4(sp) 51 | lw a3, 7*4(sp) 52 | lw a4, 8*4(sp) 53 | lw a5, 9*4(sp) 54 | lw a6, 10*4(sp) 55 | lw a7, 11*4(sp) 56 | lw t3, 12*4(sp) 57 | lw t4, 13*4(sp) 58 | lw t5, 14*4(sp) 59 | lw t6, 15*4(sp) 60 | addi sp, sp, 16*4 61 | 62 | ret 63 | -------------------------------------------------------------------------------- /LiteX/software/Tagl/linker.ld: -------------------------------------------------------------------------------- 1 | INCLUDE generated/output_format.ld 2 | ENTRY(_start) 3 | 4 | __DYNAMIC = 0; 5 | 6 | /* 7 | * We include our own 'regions.ld', with main_ram that starts 256 KB 8 | * later (the first 256 KBs are kept fo the OS). 9 | */ 10 | INCLUDE regions.ld 11 | 12 | SECTIONS 13 | { 14 | .text : 15 | { 16 | _ftext = .; 17 | /* Make sure crt0 files come first, and they, and the isr */ 18 | /* don't get disposed of by greedy optimisation */ 19 | *crt0*(.text) 20 | KEEP(*crt0*(.text)) 21 | KEEP(*(.text.isr)) 22 | 23 | *(.text .stub .text.* .gnu.linkonce.t.*) 24 | _etext = .; 25 | } > main_ram 26 | 27 | .rodata : 28 | { 29 | . = ALIGN(8); 30 | _frodata = .; 31 | *(.rodata .rodata.* .gnu.linkonce.r.*) 32 | *(.rodata1) 33 | . = ALIGN(8); 34 | _erodata = .; 35 | } > main_ram 36 | 37 | .data : 38 | { 39 | . = ALIGN(8); 40 | *(.data .data.* .gnu.linkonce.d.*) 41 | *(.data1) 42 | _gp = ALIGN(16); 43 | *(.sdata .sdata.* .gnu.linkonce.s.*) 44 | . = ALIGN(8); 45 | } > main_ram 46 | 47 | .bss : 48 | { 49 | . = ALIGN(8); 50 | _fbss = .; 51 | *(.dynsbss) 52 | *(.sbss .sbss.* .gnu.linkonce.sb.*) 53 | *(.scommon) 54 | *(.dynbss) 55 | *(.bss .bss.* .gnu.linkonce.b.*) 56 | *(COMMON) 57 | . = ALIGN(8); 58 | _ebss = .; 59 | _end = .; 60 | } > main_ram 61 | } 62 | 63 | 64 | -------------------------------------------------------------------------------- /LiteX/software/Tagl/regions.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * same as generated/regions.ld, except that main_ram 3 | * main_ram starts 256KB later (we keep the first 256KB 4 | * for the OS). 5 | */ 6 | MEMORY { 7 | rom : ORIGIN = 0x00000000, LENGTH = 0x00020000 8 | sram : ORIGIN = 0x01000000, LENGTH = 0x00002000 9 | main_ram : ORIGIN = 0x40040000, LENGTH = 0x01FC0000 10 | csr : ORIGIN = 0x82000000, LENGTH = 0x00010000 11 | } 12 | -------------------------------------------------------------------------------- /LiteX/software/Tagl/sbrk.c: -------------------------------------------------------------------------------- 1 | /* taken from Claire Wolf's picorv32 libraries */ 2 | #include <stddef.h> 3 | #include <stdio.h> 4 | 5 | void *sbrk(ptrdiff_t incr); 6 | void *sbrk(ptrdiff_t incr) { 7 | 8 | extern unsigned char _end[]; // Defined by linker 9 | static unsigned long heap_end = 0; 10 | 11 | // printf("SBRK %d\n",(int)incr); 12 | 13 | if (heap_end == 0) 14 | heap_end = (long)_end; 15 | 16 | heap_end += incr; 17 | return (void *)(heap_end - incr); 18 | } 19 | 20 | -------------------------------------------------------------------------------- /LiteX/software/Tagl/tagl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrunoLevy/learn-fpga/e468d3fee7265f81156400b3f7b982645957c7d5/LiteX/software/Tagl/tagl.png -------------------------------------------------------------------------------- /Notes/NOTES.txt: -------------------------------------------------------------------------------- 1 | YOSYS cookbook 2 | https://github.com/Ravenslofty/yosys-cookbook 3 | 4 | UART: 5 | https://github.com/BracketMaster/ECP5-RISCV32-with-C-and-UART-Example/blob/master/rtl/uart.v (Thimothy Goddard) 6 | 7 | Specialized design for AI: 8 | http://synergy.ece.gatech.edu/wp-content/uploads/sites/332/2018/01/maeri_asplos2018.pdf 9 | 10 | 11 | M5Stack mini I2C keyboard 12 | https://github.com/m5stack/M5-ProductExampleCodes/tree/master/Hat/CardKB_HAT/ 13 | 14 | I2C bit-banging: 15 | https://calcium3000.wordpress.com/2016/08/19/i2c-bit-banging-tutorial-part-i/ 16 | 17 | 18 | https://github.com/ultraembedded/core_dvi_framebuffer 19 | (+ TMDS encoder with permissive license) 20 | 21 | https://github.com/XarkLabs/Xosera (text mode VGA, HDMI ... through PMOD) 22 | 23 | 24 | SSD1331 (smaller version of SSD1351): 25 | https://www.crystalfontz.com/controllers/SolomonSystech/SSD1331/ 26 | Resolution: 96x64 27 | 28 | -------------------------------------------------------------------------------- /Notes/NOTES_ICEBreaker.txt: -------------------------------------------------------------------------------- 1 | https://github.com/icebreaker-fpga/icebreaker 2 | 3 | SPI: QSPI-DDR-capable flash 128 MBit (16 MB) 4 | http://www.winbond.com/resource-files/w25q128jv_dtr%20revc%2003272018%20plus.pdf 5 | 6 | Fast Read Dual Output (3B) / Fast Read Dual IO (BB) 7 | Fast Read Quad Output (6B) / Fast Read Quad IO (EB) -> need the non-volatile Quad Enable bit (QE) to be set 8 | QPI mode (after "enter QPI" (38h) instruction) -> need the non-volatile Quad Enable bit (QE) to be set 9 | + DTR 10 | 11 | En mode Quad IO: 8 cycles pour transmettre 32 bits, ou 4 cycles en DTR 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Notes/NOTES_OrangeCrab.txt: -------------------------------------------------------------------------------- 1 | https://github.com/gregdavill/OrangeCrab-examples 2 | --------------------------------------------------------------------------------