Custom Accelerator in FreedomStudio

Hi, I have built Freedom E300 with custom Accelerator (AccumulatorExampleModule) from Rocketchip. I can run demo_gpio on the Arty with this new generated image. Now I would like to test the accelerator and I would like to compile and run it in FreedomStudio. My understanding is that since I am using built in accelerator on ROCC interface so I don’t need to rebuilt the tool. Am I right? From this https://github.com/seldridge/rocket-rocc-examples I get header file rocc.h and accumulator.h. And add the following line in demo_gpio after reset_demo

doWrite(y, addr, data[0]);

As per the repository mention before. But I am getting unhandled trap and program exit with code 03. Is there any thing I am missing? Do I need to make any changes in any *.s file to switch on the accerator?

Regards
Nauman

How are you running the program? If you are using the pk you will need to modify its boot process to enable accelerators.

That would involve adding a write_csr(mstatus, MSTATUS_XS) somewhere in minit.c presumably around here

Hi, I am running the code through FreedomStudio and following Freedom E300 Arty FPGA Dev Kit Getting Started Guide and https://github.com/riscv/riscv-gnu-toolchain/issues/190#issuecomment-264083212. About this write_csr(mstatus, MSTATUS_XS) when I use it in my main program I don’t get the error but nothing happening it’s like accelerator is not working. And as per the Riscv instruction set manual (Privileged Architectures V1.10) page 23 XS[1:0] is read only so I am not sure whether I should write it or not.

Hello Nauman,
did you make any progress on that issue? I am trying to do the same thing and have the same issue of the unhandled trap.
Thanks
Lukas

Hi, I was able to run it by including write_csr(mstatus, MSTATUS_XS). Did you try it? Are you building the example accumulator accelerator from rocket chip?

Not yet. I was going to try that next. I just need to integrate write_csr somewhere in my program before I call the accelerator? And did you somehow modify the original freedom sourcecodes? Because to me it looks like the Accumulator example is included in the freedom-e300-arty by default.

Please see this for the changes in Freedom code https://github.com/sifive/freedom/issues/37. For the software I used https://github.com/seldridge/rocket-rocc-examples. You need write_scr at the start of your code.

Okay, this looks more promising than anything I have found on RoCC myself so far. I probably won’t be able to try it before the weekend, I am kinda swamped in work here, but I’ll try it saturday and get back to you if more questions arise.
Thanks a lot
Lukas

Hello @Nauman,
Did you test it the Accumulator Rocc accelerator? I’ve build and deploy on Artix board, but it seems to not work as expected, I mean:

core freq at 32000000 Hz
[INFO] Write R[1] = 0xdead
[INFO] Read R[1]
[INFO] Received 0x0 (expected 0xdead)
[INFO] Accum R[1] with 0xffffe042
[INFO] Read R[1]
[INFO] Received 0x0 (expected 0xbeef)

What about your results?