Can't debug hello_world example on K210 with OpenOCD [resolved]



  • I'm trying to run the hello_world example on K210.

    Compiling in terminal#1 :

    $ git clone https://github.com/kendryte/kendryte-standalone-sdk.git
    $ cd /kendryte-standalone-sdk/src/hello_world 
    $ mkdir build
    $ cd build 
    $ cmake ../../../ -DPROJ=mymain -DTOOLCHAIN=/opt/kendryte-toolchain/bin
    $ make
    

    Launch OpenOCD in another terminal (terminal#2):

    $ cd /opt/kendryte-openocd
    $ ./bin/openocd -f ./tcl/kendryte.cfg
    
    | |/ /___ _ __   __| |_ __ _   _| |_ ___  
    | ' // _ \ '_ \ / _` | '__| | | | __/ _ \ 
    | . \  __/ | | | (_| | |  | |_| | ||  __/ 
    |_|\_\___|_| |_|\__,_|_|   \__, |\__\___| 
                               |___/          
    Kendryte Open On-Chip Debugger For RISC-V v0.2.3 (2019-02-21)
    Licensed under GNU GPL v2
    adapter speed: 3000 kHz
    Info : J-Link V10 compiled Jul 23 2019 13:46:10
    Info : Hardware version: 10.10
    Info : VTarget = 3.386 V
    Info : clock speed 3000 kHz
    Info : JTAG tap: riscv.cpu tap/device found: 0x04e4796b (mfg: 0x4b5 (<unknown>), part: 0x4e47, ver: 0x0)
    Core [0] halted at 0x80002b8c due to debug interrupt
    Info : Examined RISCV core; found 2 harts
    Info : Listening on port 3333 for gdb connections
    Core [1] halted at 0x80001eba due to debug interrupt
    Core [0] halted at 0x80002b8c due to debug interrupt
    Info : Listening on port 6666 for tcl connections
    Info : Listening on port 4444 for telnet connections
    

    Try to debug hello_world example from terminal#1:

    me@ubuntu:~/kendryte-standalone-sdk/src/hello_world/build$ riscv64-unknown-elf-gdb hello_world --eval-command="target remote 127.0.0.1:3333"
    
    GNU gdb (GDB) 8.2
    Copyright (C) 2018 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.
    Type "show copying" and "show warranty" for details.
    This GDB was configured as "--host=x86_64-pc-linux-gnu --target=riscv64-unknown-elf".
    Type "show configuration" for configuration details.
    For bug reporting instructions, please see:
    <http://www.gnu.org/software/gdb/bugs/>.
    Find the GDB manual and other documentation resources online at:
        <http://www.gnu.org/software/gdb/documentation/>.
    
    For help, type "help".
    Type "apropos word" to search for commands related to "word"...
    Reading symbols from hello_world...done.
    Remote debugging using 127.0.0.1:3333
    warning: Target-supplied registers are not supported by the current architecture
    0x000000008000fbbc in uart_channel_getc (channel=UART_DEVICE_3) at /home/sni/kendryte-standalone-sdk/lib/drivers/uart.c:123
    123	    return uart_channel_getc(s_uart_debug_channel);
    (gdb) load
    Loading section .text, size 0x13758 lma 0x80000000
    Loading section .rodata, size 0x2558 lma 0x80013760
    Loading section .sdata2._global_impure_ptr, size 0x8 lma 0x80015cb8
    Loading section .sdata2.clint, size 0x8 lma 0x80015cc0
    Loading section .sdata2.get_select_pll2, size 0x3 lma 0x80015cc8
    Loading section .sdata2.get_source_pll2, size 0x3 lma 0x80015cd0
    Loading section .sdata2.CSWTCH.14, size 0x3 lma 0x80015cd8
    Loading section .eh_frame, size 0x58 lma 0x80015ce0
    Loading section .fini_array, size 0x8 lma 0x80015d38
    Loading section .data, size 0x1180 lma 0x80015d40
    Start address 0x80000000, load size 93865
    Transfer rate: 28 KB/sec, 6704 bytes/write.
    (gdb) c
    Continuing.
    # nothing happens
    

    [Meanwhile, in terminal#2]

    [...]
    Info : accepting 'gdb' connection on tcp/3333
    

    I'm using a J-Link from Segger. Version of JLink software : v6.48b

    Is anybody facing the same issue?
    What could be the source of the problem? Am I running the right commands?

    Thank you in advance for your help!



  • Hello @kwonsk,

    Everything works well now. I guess my mistake was to start the serial terminal after openocd and gdb.

    Thank you very much!



  • Hi @sni

    I think firmware in the flash doesn't matter because "(gdb) load" command will load hello_world binary.
    Could you do followings?

    1. make sure serial terminal is ready (you said micro python interactive console, then it should OK)
    2. start openocd
    3. start gdb
      and then load & continue as you did previously
      (gdb)load
      (gdb)c

    I guess , you should get two "hello..." messages.
    If not, well... I have no idea yet.

    kwonsk



  • Hello @kwonsk ,

    Thank you for your answer.
    I have open a third terminal and access the serial output by this command:

    $ sudo screen /dev/ttyUSB0 115200
    

    But I don't see any output, besides the MicroPython interactive console.

    One important detail : I have MaixPy 4.0.30 firmware installed. Could it be in conflict?

    EDIT : By burning the hello_world.bin on the board, the serial terminal outputs the following message "Core 0 Hello world \n Core 1 Hello world" when I press the restart button. However, I'm still not able to run the program from the GDB console.



  • Hi sni

    Why did you think "something must happen to gdb console" ?
    hello_world.c program just say "hello world..." to serial port, therefore "something must happen to serial terminal
    connected to the board". If you did'nt see any output from the serial terminal, then something must be wrong.
    Did you check serial terminal output?
    When you do "Control-C" in the gdb terminal, debugger should break program somewhere in the code.
    That means "Something happened" in the gdb console.
    I also have used "openocd+jlink" for debugging purpose before and it works well.
    I could'nt see anything wrong with your debugging session log yet.

    kwonsk