# Final Project:Run FreeRTOS on VexRiscv and access the peripherals such as VGA. <contributed by `eddie9712`,`zong55555`> ## Run FreeRTOS on VexRiscv: ### Environment: ``` operating system: ubuntu 18.04 compiler: g++/gcc 9.3.0 riscv-compiler:riscv32-unknown-elf-gcc ``` ### CPU generation: Just followed the steps described on the [repository](https://github.com/SpinalHDL/VexRiscv/blob/1b65a9e523341980de46b5b3f92b41bc7b6a1903/README.md),I gernerated a CPU with the smallest one: `sbt "runMain vexriscv.demo.GenSmallest"` After that, I got a VCPU `VexRiscv.v`(described in verilog) under the VexRiscv directory. ### Regression test: [What is regression test?](https://en.wikipedia.org/wiki/Regression_testing) If you choose the big(full) one to generate, you will get the errors on regression test(CSR,MMU), so I test the small one for testing first. According to the tutorial, I try to run the regression tests with my (small one)CPU: ``` cd (path to VexRiscv repo)/VexRiscv/src/test/cpp/regression make clean run IBUS=SIMPLE DBUS=SIMPLE CSR=no MMU=no DEBUG_PLUGIN=no MUL=no DIV=no ``` Then I got: ``` SUCCESS I-IO SUCCESS I-IO SUCCESS I-IO SUCCESS I-IO SUCCESS I-IO SUCCESS I-IO SUCCESS I-IO ..... SUCCESS rv32ui-p-sw SUCCESS rv32ui-p-sw SUCCESS rv32ui-p-sw SUCCESS rv32ui-p-sw SUCCESS rv32ui-p-sw SUCCESS rv32ui-p-sw Dhrystone Benchmark, Version 2.1 (Language: C) Program compiled without 'register' attribute Please give the number of runs through the benchmark: Execution starts, 200 runs through Dhrystone Execution ends Final values of the variables used in the benchmark: Int_Glob: 5 should be: 5 Bool_Glob: 1 should be: 1 Ch_1_Glob: A should be: A Ch_2_Glob: B should be: B ...... pc missmatch 7454fbcc should be 80004df0 FAIL QueueSet_rv32i_O3 at PC=7454fbcc REF PC=80004df0 REF I=fb010113 time=632780 pc missmatch 16655770 should be 80004c5c FAIL recmutex_rv32i_O3 at PC=16655770 REF PC=80004c5c REF I=fb010113 time=659692 pc missmatch 30fb5048 should be 80004c5c FAIL PollQ_rv32i_O3 at PC=30fb5048 REF PC=80004c5c REF I=fb010113 time=632396 pc missmatch fc6d5f20 should be 80005e3c FAIL crhook_rv32i_O0 at PC=fc6d5f20 REF PC=80005e3c REF I=fd010113 time=745688 pc missmatch c7b9655c should be 80004c5c FAIL test1_rv32i_O3 at PC=c7b9655c REF PC=80004c5c REF I=fb010113 time=768612 pc missmatch 9b9ba0c4 should be 8000533c FAIL QueueOverwrite_rv32i_O0 at PC=9b9ba0c4 REF PC=8000533c REF I=fd010113 time=799120 pc missmatch 50c814dc should be 8000533c FAIL TaskNotify_rv32i_O0 at PC=50c814dc REF PC=8000533c REF I=fd010113 time=798818 pc missmatch 93dcac44 should be 80004c5c FAIL countsem_rv32i_O3 at PC=93dcac44 REF PC=80004c5c REF I=fb010113 time=633836 pc missmatch 968c78e4 should be 800056a0 FAIL AltPollQ_rv32i_O0 at PC=968c78e4 REF PC=800056a0 REF I=fd010113 time=882484 pc missmatch c8343a48 should be 8000533c FAIL countsem_rv32i_O0 at PC=c8343a48 REF PC=8000533c REF I=fd010113 time=885342 pc missmatch 3a745494 should be 80007098 FAIL blocktim_rv32i_O3 at PC=3a745494 REF PC=80007098 REF I=fc010113 time=633200 pc missmatch d68753c4 should be 8000533c FAIL PollQ_rv32i_O0 at PC=d68753c4 REF PC=8000533c REF I=fd010113 time=882180 pc missmatch 50d63660 should be 80004c5c FAIL dynamic_rv32i_O3 at PC=50d63660 REF PC=80004c5c REF I=fb010113 time=712264 pc missmatch d8cfd6e8 should be 8000552c FAIL crhook_rv32i_O3 at PC=d8cfd6e8 REF PC=8000552c REF I=fb010113 time=597576 pc missmatch 718d65e4 should be 8000533c FAIL dead_rv32i_O0 at PC=718d65e4 REF PC=8000533c REF I=fd010113 time=799672 pc missmatch 5bdc6228 should be 80004c5c FAIL EventGroupsDemo_rv32i_O3 at PC=5bdc6228 REF PC=80004c5c REF I=fb010113 time=687132 pc missmatch b5ba49b0 should be 80004c5c FAIL semtest_rv32i_O3 at PC=b5ba49b0 REF PC=80004c5c REF I=fb010113 time=690998 pc missmatch 6b15b5bc should be 80006f98 FAIL QPeek_rv32i_O3 at PC=6b15b5bc REF PC=80006f98 REF I=fd010113 time=684292 pc missmatch ae23fef8 should be 80004c5c FAIL dead_rv32i_O3 at PC=ae23fef8 REF PC=80004c5c REF I=fb010113 time=607566 pc missmatch 767b76c should be 80006fc8 FAIL GenQTest_rv32i_O3 at PC= 767b76c REF PC=80006fc8 REF I=ff010113 time=687164 pc missmatch 5c09a83c should be 80004c5c FAIL flop_rv32i_O3 at PC=5c09a83c REF PC=80004c5c REF I=fb010113 time=682966 pc missmatch 1b2c8850 should be 80004f64 FAIL AltPollQ_rv32i_O3 at PC=1b2c8850 REF PC=80004f64 REF I=fb010113 time=632812 pc missmatch 404792dc should be 80004c5c FAIL integer_rv32i_O3 at PC=404792dc REF PC=80004c5c REF I=fb010113 time=684310 pc missmatch c89dac88 should be 800076ec FAIL blocktim_rv32i_O0 at PC=c89dac88 REF PC=800076ec REF I=fc010113 time=882712 pc missmatch e520ac04 should be 80004df0 FAIL QueueSetPolling_rv32i_O3 at PC=e520ac04 REF PC=80004df0 REF I=fb010113 time=611066 pc missmatch cfe50510 should be 80005680 FAIL QueueSet_rv32i_O0 at PC=cfe50510 REF PC=80005680 REF I=fd010113 time=885464 pc missmatch 6964244 should be 800072d0 FAIL AltQTest_rv32i_O3 at PC= 6964244 REF PC=800072d0 REF I=ff010113 time=688890 pc missmatch f8e354c4 should be 800073a4 FAIL AltBlock_rv32i_O3 at PC=f8e354c4 REF PC=800073a4 REF I=fc010113 time=632428 pc missmatch 574ff234 should be 80004c5c FAIL TaskNotify_rv32i_O3 at PC=574ff234 REF PC=80004c5c REF I=fb010113 time=607122 pc missmatch c1decf84 should be 80004c5c FAIL QueueOverwrite_rv32i_O3 at PC=c1decf84 REF PC=80004c5c REF I=fb010113 time=607386 pc missmatch e5abd4f0 should be 80005680 FAIL QueueSetPolling_rv32i_O0 at PC=e5abd4f0 REF PC=80005680 REF I=fd010113 time=803288 pc missmatch d06861c should be 8000533c FAIL dynamic_rv32i_O0 at PC= d06861c REF PC=8000533c REF I=fd010113 time=1143154 pc missmatch e8503270 should be 80007734 FAIL QPeek_rv32i_O0 at PC=e8503270 REF PC=80007734 REF I=fd010113 time=1055672 pc missmatch 6c3542e0 should be 80004c5c FAIL sp_flop_rv32i_O3 at PC=6c3542e0 REF PC=80004c5c REF I=fb010113 time=789712 pc missmatch 7b1b0acc should be 80008250 FAIL AltQTest_rv32i_O0 at PC=7b1b0acc REF PC=80008250 REF I=fd010113 time=1059102 pc missmatch 5c6af040 should be 80007a58 FAIL AltBlock_rv32i_O0 at PC=5c6af040 REF PC=80007a58 REF I=fc010113 time=882776 pc missmatch f24577a4 should be 8000533c FAIL recmutex_rv32i_O0 at PC=f24577a4 REF PC=8000533c REF I=fd010113 time=968760 pc missmatch df849098 should be 80008250 FAIL GenQTest_rv32i_O0 at PC=df849098 REF PC=80008250 REF I=fd010113 time=1059584 pc missmatch cfe00634 should be 8000533c FAIL semtest_rv32i_O0 at PC=cfe00634 REF PC=8000533c REF I=fd010113 time=1066250 pc missmatch d82765fc should be 8000533c FAIL sp_flop_rv32i_O0 at PC=d82765fc REF PC=8000533c REF I=fd010113 time=1396866 pc missmatch 8f279f48 should be 8000533c FAIL integer_rv32i_O0 at PC=8f279f48 REF PC=8000533c REF I=fd010113 time=1054354 pc missmatch 64aaed2c should be 8000533c FAIL flop_rv32i_O0 at PC=64aaed2c REF PC=8000533c REF I=fd010113 time=1050046 pc missmatch 96c2ef4 should be 8000533c FAIL EventGroupsDemo_rv32i_O0 at PC= 96c2ef4 REF PC=8000533c REF I=fd010113 time=1057410 pc missmatch 828b82a8 should be 8000533c FAIL test1_rv32i_O0 at PC=828b82a8 REF PC=8000533c REF I=fd010113 time=1323838 **************************************************************** Had simulate 19405153 clock cycles in 7.27207 s (2668.45 Khz) REGRESSION FAILURE 44/836 **************************************************************** Str_2_Loc: DHRYSTONE PROGRAM, 2'ND STRING should be: DHRYSTONE PROGRAM, 2'ND STRING Clock cycles=216630 DMIPS per Mhz: 0.52 SUCCESS dhrystoneO3 **************************************************************** Had simulate 1382621 clock cycles in 2.84145 s (486.59 Khz) REGRESSION SUCCESS 792/792 **************************************************************** ``` (Explanation: We had the test file(in hex) which represented the machine code for RISCV in the `/resources` directory, and the `main.cpp` in the `/regression` would load the benchmarks and compared the result with an right Riscv CPU to make sure the data that generated by VexRiscv matched with the right CPU generated) As the result, the VexRiscv CPU past the regression test with specific benchmarks. When I executed FREERTOS with command: `make clean run IBUS=SIMPLE DBUS=SIMPLE CSR=no MMU=no DEBUG_PLUGIN=no MUL=no DIV=no FREERTOS=yes` I got the results "FAIL" for all of the RTOS tests: ``` pc missmatch 288876c should be 8000822c FAIL AltQTest_rv32i_O0 at PC= 288876c REF PC=8000822c REF I=fd010113 time=1059556 pc missmatch 72b68430 should be 8000747c FAIL AltQTest_rv32i_O3 at PC=72b68430 REF PC=8000747c REF I=ff010113 time=690180 pc missmatch 6094bd8 should be 80007a34 FAIL AltBlock_rv32i_O0 at PC= 6094bd8 REF PC=80007a34 REF I=fc010113 time=882718 pc missmatch fb5c16c0 should be 80007558 FAIL AltBlock_rv32i_O3 at PC=fb5c16c0 REF PC=80007558 REF I=fc010113 time=636710 pc missmatch 400d7008 should be 80005694 FAIL AltPollQ_rv32i_O0 at PC=400d7008 REF PC=80005694 REF I=fd010113 time=884300 pc missmatch 1c97a4e4 should be 8000519c FAIL AltPollQ_rv32i_O3 at PC=1c97a4e4 REF PC=8000519c REF I=fb010113 time=635958 pc missmatch ddda7a7c should be 800076c8 FAIL blocktim_rv32i_O0 at PC=ddda7a7c REF PC=800076c8 REF I=fc010113 time=884418 pc missmatch caa35718 should be 800071a8 FAIL blocktim_rv32i_O3 at PC=caa35718 REF PC=800071a8 REF I=fc010113 time=636828 pc missmatch 76a1ee54 should be 80005330 FAIL countsem_rv32i_O0 at PC=76a1ee54 REF PC=80005330 REF I=fd010113 time=885638 pc missmatch c9b81e58 should be 80004df0 FAIL countsem_rv32i_O3 at PC=c9b81e58 REF PC=80004df0 REF I=fb010113 time=638012 pc missmatch c29b0050 should be 80005330 FAIL dead_rv32i_O0 at PC=c29b0050 REF PC=80005330 REF I=fd010113 time=800390 pc missmatch 112c4a3c should be 80004df0 FAIL dead_rv32i_O3 at PC=112c4a3c REF PC=80004df0 REF I=fb010113 time=610436 pc missmatch 88596808 should be 80005330 FAIL EventGroupsDemo_rv32i_O0 at PC=88596808 REF PC=80005330 REF I=fd010113 time=1057616 pc missmatch 8fb8ce50 should be 80004df0 FAIL EventGroupsDemo_rv32i_O3 at PC=8fb8ce50 REF PC=80004df0 REF I=fb010113 time=690228 pc missmatch b18c69e0 should be 80005330 FAIL flop_rv32i_O0 at PC=b18c69e0 REF PC=80005330 REF I=fd010113 time=1051482 pc missmatch acb72d58 should be 80004ea0 FAIL flop_rv32i_O3 at PC=acb72d58 REF PC=80004ea0 REF I=fb010113 time=683674 pc missmatch 6813110 should be 80005330 FAIL integer_rv32i_O0 at PC= 6813110 REF PC=80005330 REF I=fd010113 time=1055898 pc missmatch da52ee58 should be 80004df0 FAIL integer_rv32i_O3 at PC=da52ee58 REF PC=80004df0 REF I=fb010113 time=688046 pc missmatch b88bbdbc should be 80007710 FAIL QPeek_rv32i_O0 at PC=b88bbdbc REF PC=80007710 REF I=fd010113 time=1055750 pc missmatch 8b2dc1a0 should be 8000709c FAIL QPeek_rv32i_O3 at PC=8b2dc1a0 REF PC=8000709c REF I=fd010113 time=688892 pc missmatch 43f8cf30 should be 80005674 FAIL QueueSet_rv32i_O0 at PC=43f8cf30 REF PC=80005674 REF I=fd010113 time=885662 pc missmatch d04ea6c0 should be 80005298 FAIL QueueSet_rv32i_O3 at PC=d04ea6c0 REF PC=80005298 REF I=fb010113 time=637418 pc missmatch a4cb4b9c should be 80005330 FAIL recmutex_rv32i_O0 at PC=a4cb4b9c REF PC=80005330 REF I=fd010113 time=967684 pc missmatch 6878cb70 should be 80004df0 FAIL recmutex_rv32i_O3 at PC=6878cb70 REF PC=80004df0 REF I=fb010113 time=662876 pc missmatch 8f5f12c4 should be 80005330 FAIL semtest_rv32i_O0 at PC=8f5f12c4 REF PC=80005330 REF I=fd010113 time=1065608 pc missmatch 45032d80 should be 80004df0 FAIL semtest_rv32i_O3 at PC=45032d80 REF PC=80004df0 REF I=fb010113 time=695314 pc missmatch 2625e644 should be 80005330 FAIL TaskNotify_rv32i_O0 at PC=2625e644 REF PC=80005330 REF I=fd010113 time=799090 pc missmatch ca58d678 should be 80004df0 FAIL TaskNotify_rv32i_O3 at PC=ca58d678 REF PC=80004df0 REF I=fb010113 time=610896 pc missmatch 3759e240 should be 80005e30 FAIL crhook_rv32i_O0 at PC=3759e240 REF PC=80005e30 REF I=fd010113 time=746954 pc missmatch d05f9220 should be 800056a8 FAIL crhook_rv32i_O3 at PC=d05f9220 REF PC=800056a8 REF I=fb010113 time=597740 pc missmatch b835ed74 should be 80005330 FAIL dynamic_rv32i_O0 at PC=b835ed74 REF PC=80005330 REF I=fd010113 time=1143656 pc missmatch 62ecb7c should be 80004df0 FAIL dynamic_rv32i_O3 at PC= 62ecb7c REF PC=80004df0 REF I=fb010113 time=715772 pc missmatch d6138bc0 should be 8000822c FAIL GenQTest_rv32i_O0 at PC=d6138bc0 REF PC=8000822c REF I=fd010113 time=1059192 pc missmatch ffa95a70 should be 800070d0 FAIL GenQTest_rv32i_O3 at PC=ffa95a70 REF PC=800070d0 REF I=ff010113 time=690926 pc missmatch ad3920a8 should be 80005330 FAIL PollQ_rv32i_O0 at PC=ad3920a8 REF PC=80005330 REF I=fd010113 time=883952 pc missmatch 403295cc should be 80004df0 FAIL PollQ_rv32i_O3 at PC=403295cc REF PC=80004df0 REF I=fb010113 time=636702 pc missmatch fa3a1298 should be 80005330 FAIL QueueOverwrite_rv32i_O0 at PC=fa3a1298 REF PC=80005330 REF I=fd010113 time=801002 pc missmatch 70464ee8 should be 80004df0 FAIL QueueOverwrite_rv32i_O3 at PC=70464ee8 REF PC=80004df0 REF I=fb010113 time=611724 pc missmatch aa1a456c should be 80005674 FAIL QueueSetPolling_rv32i_O0 at PC=aa1a456c REF PC=80005674 REF I=fd010113 time=803704 pc missmatch f34bf9dc should be 80005298 FAIL QueueSetPolling_rv32i_O3 at PC=f34bf9dc REF PC=80005298 REF I=fb010113 time=613308 pc missmatch a1fbf1cc should be 80005330 FAIL sp_flop_rv32i_O0 at PC=a1fbf1cc REF PC=80005330 REF I=fd010113 time=1397460 pc missmatch ed3940b8 should be 80004df0 FAIL sp_flop_rv32i_O3 at PC=ed3940b8 REF PC=80004df0 REF I=fb010113 time=794382 pc missmatch 68010a88 should be 80005330 FAIL test1_rv32i_O0 at PC=68010a88 REF PC=80005330 REF I=fd010113 time=1323832 pc missmatch 25bd33fc should be 80004ea0 FAIL test1_rv32i_O3 at PC=25bd33fc REF PC=80004ea0 REF I=fb010113 time=771190 **************************************************************** Had simulate 19448656 clock cycles in 9.33982 s (2082.34 Khz) REGRESSION FAILURE 44/836 **************************************************************** ``` However, I thought that the description had mentioned that they had ported the FreeRtos to VexRiscv CPU , so I found a [repository](https://github.com/Dolu1990/FreeRTOS-RISCV) from homepage. After I get the repository, and I run `make` under the directory `FreeRTOS/Demo/Common/` then I got an error: ``` CC ../arch/boot.S riscv32-unknown-elf-gcc -c -Wall -Wextra -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wsign-compare -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wunused -I. -I../arch -I.. -I./conf -I./include -I../../Source/include -I../Common/include -I../../Source/portable/GCC/RISCV -fomit-frame-pointer -fno-strict-aliasing -fno-builtin -D__gracefulExit -mcmodel=medany -march=rv32i -mabi=ilp32 -g -O0 -DPRINT_ENABLE -o ../arch/boot.o ../arch/boot.S CC ../../Source/portable/GCC/RISCV/portasm.S riscv32-unknown-elf-gcc -c -Wall -Wextra -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wsign-compare -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wunused -I. -I../arch -I.. -I./conf -I./include -I../../Source/include -I../Common/include -I../../Source/portable/GCC/RISCV -fomit-frame-pointer -fno-strict-aliasing -fno-builtin -D__gracefulExit -mcmodel=medany -march=rv32i -mabi=ilp32 -g -O0 -DPRINT_ENABLE -o ../../Source/portable/GCC/RISCV/portasm.o ../../Source/portable/GCC/RISCV/portasm.S CC ../../Source/portable/GCC/RISCV/port.c riscv32-unknown-elf-gcc -c -Wall -Wextra -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wsign-compare -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wunused -I. -I../arch -I.. -I./conf -I./include -I../../Source/include -I../Common/include -I../../Source/portable/GCC/RISCV -fomit-frame-pointer -fno-strict-aliasing -fno-builtin -D__gracefulExit -mcmodel=medany -march=rv32i -mabi=ilp32 -g -O0 -DPRINT_ENABLE -o ../../Source/portable/GCC/RISCV/port.o ../../Source/portable/GCC/RISCV/port.c In file included from ../../Source/portable/GCC/RISCV/port.c:78: ../../Source/include/FreeRTOS.h:98:10: fatal error: FreeRTOSConfig.h: No such file or directory 98 | #include "FreeRTOSConfig.h" | ^~~~~~~~~~~~~~~~~~ compilation terminated. make: *** [Makefile:123: ../../Source/portable/GCC/RISCV/port.o] Error 1 ``` When I was searching the `"FreeRTOSConfig.h"` file, I found there was a folder `/Demo/scripts/packTest.py` that contained a scipt to generate the hex files of Freertos directly , so I run the script with `pyhton packTest.py` ,it would generate the hex files in `/scripts/bin`,and then I moved them into the `/resources/freertos/` then run the regression tests.However I still got the PC missmatch failure: ``` pc missmatch 7454fbcc should be 80004df0 FAIL QueueSet_rv32i_O3 at PC=7454fbcc REF PC=80004df0 REF I=fb010113 time=632780 pc missmatch 16655770 should be 80004c5c FAIL recmutex_rv32i_O3 at PC=16655770 REF PC=80004c5c REF I=fb010113 time=659692 pc missmatch 30fb5048 should be 80004c5c FAIL PollQ_rv32i_O3 at PC=30fb5048 REF PC=80004c5c REF I=fb010113 time=632396 pc missmatch fc6d5f20 should be 80005e3c FAIL crhook_rv32i_O0 at PC=fc6d5f20 REF PC=80005e3c REF I=fd010113 time=745688 pc missmatch c7b9655c should be 80004c5c FAIL test1_rv32i_O3 at PC=c7b9655c REF PC=80004c5c REF I=fb010113 time=768612 pc missmatch 9b9ba0c4 should be 8000533c FAIL QueueOverwrite_rv32i_O0 at PC=9b9ba0c4 REF PC=8000533c REF I=fd010113 time=799120 pc missmatch 50c814dc should be 8000533c FAIL TaskNotify_rv32i_O0 at PC=50c814dc REF PC=8000533c REF I=fd010113 time=798818 pc missmatch 93dcac44 should be 80004c5c FAIL countsem_rv32i_O3 at PC=93dcac44 REF PC=80004c5c REF I=fb010113 time=633836 pc missmatch 968c78e4 should be 800056a0 FAIL AltPollQ_rv32i_O0 at PC=968c78e4 REF PC=800056a0 REF I=fd010113 time=882484 pc missmatch c8343a48 should be 8000533c FAIL countsem_rv32i_O0 at PC=c8343a48 REF PC=8000533c REF I=fd010113 time=885342 pc missmatch 3a745494 should be 80007098 FAIL blocktim_rv32i_O3 at PC=3a745494 REF PC=80007098 REF I=fc010113 time=633200 pc missmatch d68753c4 should be 8000533c FAIL PollQ_rv32i_O0 at PC=d68753c4 REF PC=8000533c REF I=fd010113 time=882180 pc missmatch 50d63660 should be 80004c5c FAIL dynamic_rv32i_O3 at PC=50d63660 REF PC=80004c5c REF I=fb010113 time=712264 pc missmatch d8cfd6e8 should be 8000552c FAIL crhook_rv32i_O3 at PC=d8cfd6e8 REF PC=8000552c REF I=fb010113 time=597576 pc missmatch 718d65e4 should be 8000533c FAIL dead_rv32i_O0 at PC=718d65e4 REF PC=8000533c REF I=fd010113 time=799672 pc missmatch 5bdc6228 should be 80004c5c FAIL EventGroupsDemo_rv32i_O3 at PC=5bdc6228 REF PC=80004c5c REF I=fb010113 time=687132 pc missmatch b5ba49b0 should be 80004c5c FAIL semtest_rv32i_O3 at PC=b5ba49b0 REF PC=80004c5c REF I=fb010113 time=690998 pc missmatch 6b15b5bc should be 80006f98 FAIL QPeek_rv32i_O3 at PC=6b15b5bc REF PC=80006f98 REF I=fd010113 time=684292 pc missmatch ae23fef8 should be 80004c5c FAIL dead_rv32i_O3 at PC=ae23fef8 REF PC=80004c5c REF I=fb010113 time=607566 pc missmatch 767b76c should be 80006fc8 FAIL GenQTest_rv32i_O3 at PC= 767b76c REF PC=80006fc8 REF I=ff010113 time=687164 pc missmatch 5c09a83c should be 80004c5c FAIL flop_rv32i_O3 at PC=5c09a83c REF PC=80004c5c REF I=fb010113 time=682966 pc missmatch 1b2c8850 should be 80004f64 FAIL AltPollQ_rv32i_O3 at PC=1b2c8850 REF PC=80004f64 REF I=fb010113 time=632812 pc missmatch 404792dc should be 80004c5c FAIL integer_rv32i_O3 at PC=404792dc REF PC=80004c5c REF I=fb010113 time=684310 pc missmatch c89dac88 should be 800076ec FAIL blocktim_rv32i_O0 at PC=c89dac88 REF PC=800076ec REF I=fc010113 time=882712 pc missmatch e520ac04 should be 80004df0 FAIL QueueSetPolling_rv32i_O3 at PC=e520ac04 REF PC=80004df0 REF I=fb010113 time=611066 pc missmatch cfe50510 should be 80005680 FAIL QueueSet_rv32i_O0 at PC=cfe50510 REF PC=80005680 REF I=fd010113 time=885464 pc missmatch 6964244 should be 800072d0 FAIL AltQTest_rv32i_O3 at PC= 6964244 REF PC=800072d0 REF I=ff010113 time=688890 pc missmatch f8e354c4 should be 800073a4 FAIL AltBlock_rv32i_O3 at PC=f8e354c4 REF PC=800073a4 REF I=fc010113 time=632428 pc missmatch 574ff234 should be 80004c5c FAIL TaskNotify_rv32i_O3 at PC=574ff234 REF PC=80004c5c REF I=fb010113 time=607122 pc missmatch c1decf84 should be 80004c5c FAIL QueueOverwrite_rv32i_O3 at PC=c1decf84 REF PC=80004c5c REF I=fb010113 time=607386 pc missmatch e5abd4f0 should be 80005680 FAIL QueueSetPolling_rv32i_O0 at PC=e5abd4f0 REF PC=80005680 REF I=fd010113 time=803288 pc missmatch d06861c should be 8000533c FAIL dynamic_rv32i_O0 at PC= d06861c REF PC=8000533c REF I=fd010113 time=1143154 pc missmatch e8503270 should be 80007734 FAIL QPeek_rv32i_O0 at PC=e8503270 REF PC=80007734 REF I=fd010113 time=1055672 pc missmatch 6c3542e0 should be 80004c5c FAIL sp_flop_rv32i_O3 at PC=6c3542e0 REF PC=80004c5c REF I=fb010113 time=789712 pc missmatch 7b1b0acc should be 80008250 FAIL AltQTest_rv32i_O0 at PC=7b1b0acc REF PC=80008250 REF I=fd010113 time=1059102 pc missmatch 5c6af040 should be 80007a58 FAIL AltBlock_rv32i_O0 at PC=5c6af040 REF PC=80007a58 REF I=fc010113 time=882776 pc missmatch f24577a4 should be 8000533c FAIL recmutex_rv32i_O0 at PC=f24577a4 REF PC=8000533c REF I=fd010113 time=968760 pc missmatch df849098 should be 80008250 FAIL GenQTest_rv32i_O0 at PC=df849098 REF PC=80008250 REF I=fd010113 time=1059584 pc missmatch cfe00634 should be 8000533c FAIL semtest_rv32i_O0 at PC=cfe00634 REF PC=8000533c REF I=fd010113 time=1066250 pc missmatch d82765fc should be 8000533c FAIL sp_flop_rv32i_O0 at PC=d82765fc REF PC=8000533c REF I=fd010113 time=1396866 pc missmatch 8f279f48 should be 8000533c FAIL integer_rv32i_O0 at PC=8f279f48 REF PC=8000533c REF I=fd010113 time=1054354 pc missmatch 64aaed2c should be 8000533c FAIL flop_rv32i_O0 at PC=64aaed2c REF PC=8000533c REF I=fd010113 time=1050046 pc missmatch 96c2ef4 should be 8000533c FAIL EventGroupsDemo_rv32i_O0 at PC= 96c2ef4 REF PC=8000533c REF I=fd010113 time=1057410 pc missmatch 828b82a8 should be 8000533c FAIL test1_rv32i_O0 at PC=828b82a8 REF PC=8000533c REF I=fd010113 time=1323838 **************************************************************** Had simulate 19405153 clock cycles in 7.27207 s (2668.45 Khz) REGRESSION FAILURE 44/836 **************************************************************** ``` Then I decided to change my CPU to the big one.However,I still failed on the regression test: ``` pc missmatch 80000020 should be 80000154 FAIL TaskNotify_rv32i_O3 at PC=80000020 REF PC=80000154 REF I=ffc10113 time=336470 pc missmatch 80000020 should be 80000154 FAIL dead_rv32im_O3 at PC=80000020 REF PC=80000154 REF I=ffc10113 time=333870 pc missmatch 80000020 should be 80000154 FAIL QueueOverwrite_rv32i_O3 at PC=80000020 REF PC=80000154 REF ..... pc missmatch 80000020 should be 80000154 FAIL test1_rv32i_O0 at PC=80000020 REF PC=80000154 REF I=ffc10113 time=711096 pc missmatch 80000020 should be 80000154 FAIL test1_rv32im_O3 at PC=80000020 REF PC=80000154 REF I=ffc10113 time=400036 pc missmatch 80000020 should be 80000154 FAIL test1_rv32i_O3 at PC=80000020 REF PC=80000154 REF I=ffc10113 time=401804 pc missmatch 80000020 should be 80000154 FAIL sp_flop_rv32i_O0 at PC=80000020 REF PC=80000154 REF I=ffc10113 time=754740 ``` As a result, I cheked the errors above, all of the errors were triggered because of the PC was not match to the right CPU. Simultaneously, they had the same error about PC missmatch, so I went to check assembly code and I found all of them triggered an error when they executed a function call: `portRESTORE_CONTEXT`: ``` portRESTORE_CONTEXT 8000046c: 00020117 auipc sp,0x20 80000470: f7c12103 lw sp,-132(sp) # 800203e8 <pxCurrentTCB> 80000474: 00012103 lw sp,0(sp) 80000478: 07c12283 lw t0,124(sp) 8000047c: 34129073 csrw mepc,t0 ..... ``` the right cpu returned to the interrupt address `PC=80000154`(trap entry) yet the Vex cpu returned to the address `0x80000020` which was an `nop` instruction. I found that the the trap_entry of the Vex was configured with `0x80000020l` in the `GenFull.scala`(under VexRiscv/src/main/scala/vexriscv/demo/) : ``` .... new MulPlugin, new DivPlugin, new CsrPlugin(CsrPluginConfig.small(0x80000020l)), new DebugPlugin(ClockDomain.current.clone(reset = Bool().setName("debugReset"))), new BranchPlugin( earlyBranch = false, ``` Therefore I modified the return address to the right address `0x80000154`, then I passed the regression test of the FREERTOS which meant the FREERTOS could run on the VexRiscv.However, it still had some errors with CSR and MMU: ![](https://i.imgur.com/TnxL19L.png) ![](https://i.imgur.com/3jaMbWC.png) In conclusion, there were the steps to run FREERTOS that I took: 1.Get the freertos tests hex file [here](https://github.com/Dolu1990/FreeRTOS-RISCV)(run the scripts in the `scripts directory` and copy the generated hex files to the `.../resources /freertos/`) 2.Modify the CSR address in the scala file under `.../src/main/scala/vexriscv/demo/` 3.Generate the big cpu(GenFull) 4.Run the regression test ## Access the peripherals such as VGA: ``` sudo apt-get install libsdl2-dev sbt "runMain vexriscv.demo.Briey" cd src/test/cpp/briey/ make clean run ``` Show the VGA ![](https://i.imgur.com/NpHYmNQ.png) run the verilator simulation of the Briey SoC which can be then connected to [OpenOCD](https://github.com/SpinalHDL/openocd_riscv) ``` sudo apt-get install libtool automake libusb-1.0.0-dev texinfo libusb-dev libyaml-dev pkg-config git clone https://github.com/SpinalHDL/openocd_riscv.git cd openocd_riscv ./bootstrap ./configure --enable-ftdi --enable-dummy make sudo make install ``` ``` src/openocd -f tcl/interface/jtag_tcp.cfg -c "set BRIEY_CPU0_YAML /home/zong/workspace/VexRiscv/cpu0.yaml" -f tcl/target/briey.cfg ``` connect OpenOCD ![](https://i.imgur.com/Z8LvSE5.png) VGA testbench ![](https://i.imgur.com/9FpEQ0Y.png) ## Reference list: [Final Project: VexRiscv](https://hackmd.io/@oR8-QX4TQzGKDJ72DmqDUg/S1eKmCbkU) [SpinalHDL/VexRiscv](https://github.com/SpinalHDL/VexRiscv/blob/1b65a9e523341980de46b5b3f92b41bc7b6a1903/README.md) [jens-na/VexRiscv](https://github.com/jens-na/VexRiscv) [regression test](https://en.wikipedia.org/wiki/Regression_testing) [OpenOCD](https://github.com/SpinalHDL/openocd_riscv)