Debug problem in Freedom Studio

I installed the Freedom Studio, and follow the setup guide.
The example compiles OK, but fail to debug.
in Debugger setup page, the Config options is “-f openocd.cfg”, and I use the configuration file at demo_gpio/bsp/env/freedom-e300-hifive1/openocd.cfg
The last lines in Console with error message:
Flash sector 64 protected
failed erasing sectors 64 to 64
flash_erase returned -4
dropped ‘gdb’ connection

I checked the configuration file, and found that “flash protect 0 64 last off” is commented out.
But the debug session will fail even if I enable the flash protect off command.

Which openocd configuration file should be used to debug the HiFive?

Hi Simon,

By default, the examples included in Freedom Studio should use the openocd.cfg file located in the root project directory (not the one in the bsp folder). They should be exactly the same except the one in the root directory has the last line commented out… at least it should be.

I add back the last commented line, but still fail to debug, seems gdb client send a wrong command:

Debug: 34810 5919 command.c:143 script_debug(): command - ocd_riscv.cpu ocd_riscv.cpu invoke-event reset-end
Debug: 34811 5920 gdb_server.c:2569 gdb_v_packet(): wrote 56084 bytes from vFlash image to flash
Debug: 34812 5922 gdb_server.c:2705 gdb_input_inner(): received packet: 'P20=0000402000000000’
Debug: 34813 5923 gdb_server.c:1313 gdb_set_register_packet(): -
Debug: 34814 5923 riscv.c:450 riscv_get_gdb_reg_list(): reg_class=0
Debug: 34815 5923 riscv.c:451 riscv_get_gdb_reg_list(): riscv_get_gdb_reg_list: rtos_hartid=0 current_hartid=0
Debug: 34816 5923 riscv.c:1010 riscv_set_current_hartid(): setting hartid to 0, was 0
Debug: 34817 5923 riscv.c:1024 riscv_set_current_hartid(): registers already initialized, skipping
Error: 34820 5924 gdb_server.c:1337 gdb_set_register_packet(): gdb sent a packet with wrong register size
Debug: 34821 5924 gdb_server.c:1018 gdb_connection_closed(): GDB Close, Target: riscv.cpu, state: halted, gdb_actual_connections=0
Debug: 34822 5924 target.c:1512 target_call_event_callbacks(): target event 6 (gdb-end)
Debug: 34823 5924 target.c:1512 target_call_event_callbacks(): target event 24 (gdb-detach)
Info : 34824 5924 server.c:503 server_loop(): dropped ‘gdb’ connection
Debug: 34825 5977 riscv.c:262 riscv_deinit_target(): riscv_deinit_target()
Debug: 34826 5977 riscv-011.c:1493 deinit_target(): riscv_deinit_target()

Seems gdb client send P20=0000402000000000, FE310 has 32bit registers, not 64-bit ones. How to fix this?

I fix below:

  1. add back “flash protect 0 64 last off” in openocd.cfg
  2. fix openocd src/server/gdb_server.c, in gdb_set_register_packet, Line 1336:
    if ((unsigned int)chars != strlen(separator + 1)) {
    LOG_ERROR(“gdb sent a packet with wrong register size”);
    separator[1 + 8] = ‘\0’;
    LOG_WARNING(“fix to %s”, separator + 1);
    // free(bin_buf);

With the first fix, flash is unlocked, so openocd will not say "failed erasing sectors 64 to 64"
With the second fix, gdb server will patch the P command, if the value execeed 32-bit(as I test, gdb client will send register value in 64-bit).

Now, Freedom Studio will not display error while start debug session, but still fail to stop at the entry point.
The program downloaded to HiFive is running OK.
But if debugging, minicom will output:
Program has exited with code:0x00000008

Thanks @simonqian. This is very strange indeed.

Are you using the toolchain and openOCD binaries included with Freedom Studio, or are you pointing to versions built with Freedom-E-SDK?

Also just want to double check a few things.

All of the examples and launch files were organized by board (HiFive1, E51FPGA, etc…). Be sure that you are importing the HiFive1 examples and not one of the other platforms.

Also are you importing the HiFive1 examples bundled with Freedom Studio, or the Freedom-E-SDK examples? They are essentially the same examples, just packaged in different ways.

When launching the debugger, be sure you are selecting the launch configuration that corresponds to the project you are working on.

I use the executable binaries in Freedom Studio, but since I have to fix openocd, so I re-compile it.
I import the examples in in FreedomStudio/SiFive/Examples, which corresponds to the hardware.

After I import the examples, there are no debug launch configurations, so I created new launch configuration.
ofc, the openocd configuration file is the one in the project.

Ok, I see what is going on.

If you are creating your own launch configuration, be sure to use the following gdb launch command:
> set arch riscv:rv32

All of the projects include a .launch file which should create a launch configuration for you. Here is a screenshot of where the included configurations are under Run–>Debug Configurations, and also what the debug options look like for the included examples.

Let me know if this works for you. (you may also want to switch back to the bundled binary)

Thanks, it works.:grinning:

1 Like