Open source RISC-V CPU core design practice

Case download:

1 Design Brief

In 2010, the RISC-V architecture was born at the University of California, Berkeley. With its streamlined and efficient advantages, it quickly gained the support of academia. After nearly ten years of development, the RISC-V architecture has been widely recognized by academia and industry. With the increasing maturity of the RISC-V ecosystem, future RISC-V-based processors will be widely used.

PicoRV32 is an open source RISC-V processor core that implements the RISC-V RV32IMC instruction set. It can be configured as RV32E, RV32I, RV32IC, RV32IM, or RV32IMC core, and optionally includes a built-in interrupt controller, implemented in Verilog hardware description language, which can be obtained from the RISC-V website http://riscv.org/ code, tools (gcc, binutils, etc.). PicoRV32 uses RISC-V ISR, but Trap / interrupt / interrupt return is redesigned, using a simplified scheme to complete the interrupt operation and implement a simple built-in custom interrupt controller.

The focus of this PicoRV32 is to pursue the optimization of area and frequency. The cost of its published data on Xilinx7-Series FPGA is 750-2000 LUTs, and it can be integrated to the main frequency of 250-450MHz. This practice deeply integrates the theoretical knowledge of computer architecture with the engineering practice of SP7021 + FPGA SOC platform to realize CPU-related functions, and strives to enable students to quickly and deeply master the design capabilities of embedded CPU cores for future large-scale SoC design and high-performance core Design lays a solid foundation

2 Design specifications

1  Supportt AMBA4 AXI 32 bit Bus interface.

2  Support RISC-V RV32IMC Instruction Set

3 Support Extend Co-Processor Interface

 

3 SOC integration

3.1 Implementation of hardware platform for RISC-V CPU experiment project

PicoRV32 supports 32-bit AXI4-Lite master bus system, we choose axi_ bus_ s32_bridge module from Bus Bridge series, it provides AXI slave bus interface to connect our IP,as shown in the figure below:

 

In this experiment, the related experiment is completed with the FPGA daughter board supporting the SP 7021 practice platform. The development tool of the FPGA daughter board uses XILINX's Vivado integrated development environment (version number 2018.3); in order to facilitate the connection of the user's own verification IP to the SOC system Verification, this experiment provides the corresponding design reference basic files, as follows

 

The corresponding connection between the design case and the pin connection of the SP7021 motherboard and FPGA daughter board is shown in the following table: 1: U20B on the motherboard is connected to J2 of the FPGA daughter board (Pin pin corresponding, such as 1-51 ...), providing the data transmission channel between the Plus1 main chip on the motherboard and the FPGA

 

Design Demo

FPGA daughter board

SP7021 mother board

riscv

J2

U1E

U20B

Top Port Name

Schematic Name

FPGA I/O

Schematic Name

 

1

GND

 

51

GND

 

2

GND

 

52

GND

FPGA_PAD[0]

3

B34_L24_N

T8

53

FBIO_PAD_0

FPGA_PAD[43]

4

B34_L24_P

R8

54

FBIO_PAD_1

 

5

VIN

 

55

VCC(3.3V)

 

6

VCCIO34

 

56

VCC(3.3V)

FPGA_PAD[1]

7

B34_L21_N

V9

57

FBIO_PAD_2

FPGA_PAD[42]

8

B34_L21_P

U9

58

FBIO_PAD_3

FPGA_PAD[2]

9

B34_L18_N

N6

59

FBIO_PAD_4

FPGA_PAD[41]

10

B34_L18_P

M6

60

FBIO_PAD_5

FPGA_PAD[3]

11

B34_L22_N

U6

61

FBIO_PAD_6

FPGA_PAD[40]

12

B34_L22_P

U7

62

FBIO_PAD_7

FPGA_PAD[4]

13

B34_L20_N

V6

63

FBIO_PAD_8

FPGA_PAD[39]

14

B34_L20_P

V7

64

FBIO_PAD_9

FPGA_PAD[5]

15

B34_L23_N

T6

65

FBIO_PAD_10

FPGA_PAD[38]

16

B34_L23_P

R7

66

FBIO_PAD_11

FPGA_PAD[6]

17

B34_L10_N

V4

67

FBIO_PAD_12

FPGA_PAD[37]

18

B34_L10_P

V5

68

FBIO_PAD_13

FPGA_PAD[7]

19

B34_L19_P

R6

69

FBIO_PAD_14

FPGA_PAD[36]

20

B34_L19_N

R5

70

FBIO_PAD_15

FPGA_PAD[8]

21

B34_L8_P

U4

71

FBIO_PAD_16

FPGA_PAD[35]

22

B34_L8_N

U3

72

FBIO_TCLK

FPGA_PAD[9]

23

B34_L9_N

V2

73

FBIO_RCLK

FPGA_PAD[34]

24

B34_L9_P

U2

74

FBIO_PAD_17

FPGA_PAD[10]

25

B34_L7_N

V1

75

FBIO_PAD_18

FPGA_PAD[33]

26

B34_L7_P

U1

76

FBIO_PAD_19

FPGA_PAD[11]

27

B34_L13_P

N5

77

FBIO_PAD_20

FPGA_PAD[32]

28

B34_L13_N

P5

78

FBIO_PAD_21

FPGA_PAD[12]

29

B34_L12_P

T5

79

FBIO_PAD_22

FPGA_PAD[31]

30

B34_L12_N

T4

80

FBIO_PAD_23

FPGA_PAD[13]

31

B34_L11_N

T3

81

FBIO_PAD_24

FPGA_PAD[30]

32

B34_L11_P

R3

82

FBIO_PAD_25

FPGA_PAD[29]

33

B34_L14_P

P4

83

FBIO_PAD_26

FPGA_PAD[28]

34

B34_L14_N

P3

84

FBIO_PAD_27

FPGA_PAD[14]

35

B34_L16_N

N4

85

FBIO_PAD_28

FPGA_PAD[27]

36

B34_L16_P

M4

86

FBIO_PAD_29

FPGA_PAD[15]

37

B34_L17_N

T1

87

FBIO_PAD_30

FPGA_PAD[26]

38

B34_L17_P

R1

88

FBIO_PAD_31

FPGA_PAD[16]

39

B34_L15_N

R2

89

FBIO_PAD_32

FPGA_PAD[25]

40

B34_L15_P

P2

90

FBIO_PAD_33

FPGA_PAD[17]

41

B34_L3_N

N1

91

FBIO_PAD_34

FPGA_PAD[24]

42

B34_L3_P

N2

92

FBIO_PAD_35

FPGA_PAD[18]

43

B34_L1_N

M1

93

FBIO_PAD_RSTB

FPGA_PAD[23]

44

B34_L1_P

L1

94

EXT0_INT

 

45

VCCIO34

 

95

VCC(3.3V)

 

46

VIN

 

96

VCC(3.3V)

FPGA_PAD[19]

47

B34_L4_P

M3

97

EXT1_INT

FPGA_PAD[20]

48

B34_L4_N

M2

98

 

 

49

GND

 

99

GND

 

50

GND

 

100

GND

3.2 Implementation of System Software Platform of RISC-V CPU Experiment Project

The supporting CPU system compilation and development tools have been integrated into the IDE development tools.

RISC-V CPU IP design practice preparation work:

In the IDE environment, as shown below, select the sp7021 project name, click the right mouse button and select Copy in the pop-up menu

 

Next, select the sp7021 project name again

Click the right mouse button and select Paste in the pop-up menu, the following picture appears

Fill in riscv in the Project name box to complete the creation of riscv project name and directory, as shown below

Next, you need to copy all the files and folders under the installation directory \SP7021\example\riscv to the gpio project directory built above (the path is: installation directory \SP7021\workspace\riscv\), the file with the same name is selected to be overwritten, so RISC-V Program codes and compilers required for CPU IP design practice are placed in the following paths:

1)In the install directory \SP7021\workspace\riscv\picorv32\firmware\hello.c

2)In the install directory \SP7021\workspace\riscv\riscv64-unknown-elf-gcc-8.3.0-2019.08.0-x86_64-w64-mingw32 folder is the RISC-V compiler

3)In the install directory \SP7021\workspace\riscv\main.c

Finally, as shown in the figure below, select the red box 1 with the mouse, then click the right mouse button to display the drop-down menu, and then select the red box 2, refresh the copy action just now, so that the file just copied can be displayed in the IDE environment.

hello.c

#include "firmware.h"

void hello(void)

{

    print_str("hello world \n");

    unsigned int i, add=0, mul, div;

    for (i=1;i<=100;i++)

    {

        add = add + i;

        mul = add * i;

        div = mul / i;

        print_str("index");print_str("\t");

        print_str("add value");print_str("\t");

        print_str("mul value");print_str("\t");

        print_str("div value \n");

        print_dec(i); print_str("\t"); print_dec(add); print_str("\t");

        print_str("\t");

        print_dec(mul); print_str("\t"); print_dec(div); print_str("\n");

        print_str("**************************************************** \n");

    }

    print_str("RISCV selftest finished \n");

}

The application program of PicoRV32 CPU realizes the programming of addition, multiplication and division of 32-bit unsigned numbers. In the IDE environment, when the entire project is compiled, hello.c will be automatically compiled by riscv gcc and converted into a binary code file firmware.inc for the main program of the project to call.

main.c

UINT8 fw[] = {

#include "picorv32/firmware/firmware.inc"

};

int main(void)

{

    printf("Build @%s, %s\n", __DATE__, __TIME__);

    /* copy riscv fw to 0x00000000 */

    memcpy(0x00000000, fw, sizeof(fw));

    printf("riscv fw (%08x %08x) size: %d bytes\n", *(UINT32 *)0, *(UINT32 *)4, sizeof(fw));

    hw_init();

    sys_init();

    disp_hdmi_init();

    fbio_init();

    while(1);

}

The main program of the entire project runs on the SP7021 CPU. After power-on, the initialization of the SP7021 + FPAG system is completed, as follows: 1: Initialize the DRAM space, put the PicoRV32 CPU binary code file firmware.inc into DRAM; 2: Reset the FPGA, and point the PicoRV32 CPU Boot address in the FPGA to the DRAM address 0; 3: After resetting the FPGA, the main program enters idle mode, and the PicoRV32 CPU in the FPGA starts to fetch and execute instructions from the DRAM, and the execution result is displayed through the serial port of SP7021

 

3.3 Run the Program code

After compile in the Plus1 IDE environment, download to the platform and see the following information in the terminal window