sipeed / M0S_BL616_example

M0S BL616 example (M0S dock)
Apache License 2.0
32 stars 8 forks source link

Debugging with JTAG #12

Open JohnnyZig opened 1 year ago

JohnnyZig commented 1 year ago

Is it possible to use JTAG with this dev board? How? According to document in this repo pins needed for JTAG are not on the pin header.

gamelaster commented 1 year ago

@JohnnyZig it's very hard. Due GPIO multiplex decisions, JTAG option 1. Is not all broken out, and option 2. is available on headers, but it is shared with other stuff, which makes communication not working properly.

Only option is to change GPIO configuration through ISP or your firmware at beginning remap it.

JohnnyZig commented 1 year ago

So, this is development board without debug pins available? :confused:

Is there an example program available with remapped JTAG? Where I can find (in official documentation) JTAG remap options?

I have soldered wires on pins 0, 1, 2, 3 but that didn't work with "Sipeed USB-JTAG/TTL" (FTDI based with metal casing) adapter. Same adapter works with "Longan Nano" (GD32VF103CBT6 MCU) board.

gamelaster commented 1 year ago

@JohnnyZig Correct, it doesn't have debug pins available on usual pins. As I mentioned, both multiplex options doesn't work, due shared GPIOs with other stuff.

Sadly, I can't find the source code I used during testing this, but I just used HAL pin cfg functions to set it to JTAG.

JohnnyZig commented 1 year ago

Do you remember which pins did you use? Did you remove capacitor at BOOT/2 pin? Are external resistors needed? Which HW programmer did you use? Did you use OpenOCD?

Anything that you can remember will be helpful to me as for the past few days I've tried many things to get JTAG working. There is almost nothing about JTAG in documentation or in the SDK.

I tried remapping JTAG pins adding this code to the blinky example of this repo:

#define JTAG_TDI    GPIO_PIN_11
#define JTAG_TMS    GPIO_PIN_12
#define JTAG_TCK    GPIO_PIN_13
#define JTAG_TDO    GPIO_PIN_14

bflb_gpio_init(gpio, JTAG_TMS, GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1 | GPIO_FUNC_JTAG);
bflb_gpio_init(gpio, JTAG_TCK, GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1 | GPIO_FUNC_JTAG);
bflb_gpio_init(gpio, JTAG_TDO, GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1 | GPIO_FUNC_JTAG);
bflb_gpio_init(gpio, JTAG_TDI, GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1 | GPIO_FUNC_JTAG);

Is information in SDK correct?

define GPIO_FUNC_JTAG (26 << GPIO_FUNC_SHIFT)

Datasheet also uses 26 for JTAG function, but reference manual uses 17. There is no mentioning of JTAG clock enable in documentation or in SDK.

Even when using pins 0, 1, 2, 3 (with wires soldered to the SoM) and programming mode (which shouldn't have JTAG pins remapped) it was not successful. Soldering is good because (temporary placed) LEDs will lit on every of the 4 pins.

gamelaster commented 1 year ago

Do you remember which pins did you use?

12 - 15

Did you remove capacitor at BOOT/2 pin?

No

 Are external resistors needed?

No

Which HW programmer did you use?

I don't remember exactly, could be FT232H or M0S Dock with CK-Link firmware

Did you use OpenOCD?

I don't remember, maybe OpenOCD, maybe CK-Link

This is some code I found that I tried to use, I couldn't find my final code, but I probably used this: (GPIOs are wrong) image

Even when using pins 0, 1, 2, 3 (with wires soldered to the SoM) and programming mode (which shouldn't have JTAG pins remapped) it was not successful. Soldering is good because (temporary placed) LEDs will lit on every of the 4 pins.

I experienced weird issues on both 0,1,2,3 and alternate JTAG pinout (which you can change with EFUSE change), only the 12-15 worked for me, on M0P Dock.

mrhempman69 commented 11 months ago

@JohnnyZig Did you get this to work ever?

JohnnyZig commented 11 months ago

No, not really. Barely managed to get OpenOCD to recognize the chip, didn't manage to get it to single step in GDB. Currently waiting for my custom PCB which exposes default JTAG pins (which are not exposed on shitty Sipeed's M0s dock) and I'll try again.

JohnnyZig commented 10 months ago

Tried with multiple combinations and JTAG is not working. Tried it with:

Tried with and without JTAG pullup&pulldown resistors and with and without JTAG in series resistors.

Tried with multiple JTAG HW adapters:

Tried it with SW:

Tried it with multiple examples from Bouffalo's and Sipeed's SDK.

OpenOCD recognizes the CPU core but that's all: Info : JTAG tap: riscv.cpu tap/device found: 0x10000b6f (mfg: 0x5b7 (T-HEAD Semiconductor Co Ltd), part: 0x0000, ver: 0x1)

Looking at electrical signals with logic analyzer it seems that replying to JTAG IDCODE works, but later reading RISC-V CSR registers (0x11) fails. Also, OpenOCD will only recognize MCU after fresh power-on-restart of MCU.

I had plans to play with this MCU over Christmas, spent already two months with it and I can't even single step it in debugger (not to mention flash it over JTAG/GDB). HW is pretty impressive, but it is useless without proper tools and documentation. Where is clock chapter in datasheet/reference manual? Where is support in standard opensource tools like upstream OpenOCD, upstream GDB and upstream GCC? LLVM seems to be working (at least for my simple blinky).

According to this guy debugging should work with OpenOCD and GDB. (BL618 is same as 616 but has more GPIOs) https://www.codingfield.com/blog/2023-01/getting-started-with-bl618dk/#openocd

(Yesterday, while I was drinking my morning coffee I managed to get ESP32C3 (MCU I never used before) to get to respond to OpenOCD and GDB commands - just recompile ESP's OpenOCD, start it and that's it! Yes, it has less impressive Hw but at lest it works)

My good men, I wish you more luck than I had!

RikkaW commented 2 months ago

I was able to debug with CLion & OpenOCD like that blog just now.

It only needs a board that have default JTAG pins (pin 0-3?) exposed and a not so new JTAG adapter (or their openocd will say "JTAG not supported"). Upstream OpenOCD and any JTAG adapter should work.

But:

image

gamelaster commented 2 months ago

@RikkaW flash driver support for BL618 is not available in OpenOCD. I work on one, but it might take time until it's done. About that pause, that's weird, maybe something is misconfigured in OpenOCD TCL script? Reset MCU seems to be also matter of configuration in TCL script. About full-real reset, yeah, for that full HW RESET is needed (or proper SW reset implementation in OpenOCD)