Close

How to test custom logic part of Caravel chip

A project log for Lab Computer "Marina"

How many Caravel chips does it take to make a usable lab computer for debugging digital electronics? Let's find out...

shaosSHAOS 08/17/2023 at 06:401 Comment

I moved everything needed to my own repo: https://gitlab.com/shaos/marina

For example this is my own location of original blink program:

https://gitlab.com/shaos/marina/-/blob/main/blink/blink.c

If you look into function void configure_io() you may see how IOs are configured:

At the end of the function you can see how it sets those configuration values to the actual hardware. Before calling this function it's also setting up the only GPIO pin (that is connected to LED in efabless "mother" board):

    reg_gpio_mode1 = 1;
    reg_gpio_mode0 = 0;
    reg_gpio_ien = 1;
    reg_gpio_oeb = 0;

It's basically means OUTPUT and it must be OUTPUT (inverted indication):

Then to switch LED On we need to write there 0 and to switch LED Off we need to write there 1:

	while (1) {

        reg_gpio_out = 1; // OFF
        reg_mprj_datah = 0x0000002a;
        reg_mprj_datal = 0xaaaaaaaa;

//		delay(50000);
		delay(2000000);

        reg_gpio_out = 0;  // ON
        reg_mprj_datah = 0x00000015;
        reg_mprj_datal = 0x55555555;

//		delay(50000);
		delay(2000000);

    }

Here also clearly visible way to program IOs - reg_mprj_datal covers lower 32 bits, and reg_mprj_datah cover higher 6 bits (if it's defined as inputs you can read from those variables as well).

In this case on-board custom logic is not connected to anything - everything is controlled by RISC-V programmatically, but what if we need to connect IOs to user custom logic? Then IOs must be configured to one of this settings:

//      GPIO_MODE_USER_STD_INPUT_NOPULL
//      GPIO_MODE_USER_STD_INPUT_PULLDOWN
//      GPIO_MODE_USER_STD_INPUT_PULLUP
//      GPIO_MODE_USER_STD_OUTPUT
//      GPIO_MODE_USER_STD_BIDIRECTIONAL
//      GPIO_MODE_USER_STD_ANALOG

But then Caravel RISC-V will not be able to read or write IOs, so what can be done to programmatically write user inputs and read user outputs? TinyTapeout discord user anish experimentally found bits that need to be set for this:

#define GPIO_MODE_MGMT_CONTROLLED_IO 0x00F
#define GPIO_MODE_USER_CONTROLLED_IO 0x00E

So we set user custom design inputs to GPIO_MODE_MGMT_CONTROLLED_IO and user custom design outputs to GPIO_MODE_USER_CONTROLLED_IO (Note: I gave those macro names. Names proposed by anish were different). Now we can build custom tester of on-board custom logic:

https://gitlab.com/shaos/marina/-/blob/main/shaos_test1/main.c?ref_type=heads

Discussions

SHAOS wrote 08/17/2023 at 06:49 point

Forgot to mention that efabless added some simple functions to print stings, hexadecimal and decimal numbers to serial output through FTDI chip on "mother" board (from PC side it's 9600 COM-port).

  Are you sure? yes | no