A problem about Debug Module

When I read a word from memory using program buffer,I find that a error was returned back in cmderr abstractcs.The cmderr is 4,The detailed information is that “An abstract command couldn’t execute because the hart wasn’t in the expected state (running/halted).”
I don’t know how to solve the problem.Whether I nedd to set the hartsel and haltreq ?

Yes, the SiFive implementation of the debug spec requires that the core be halted before attempting to execute abstract commands.

When a debugger wants to halt a single hart it selects it in hartsel and sets haltreq, then waits
for allhalted to indicate the hart is halted before clearing haltreq to 0.

If you do that before you try to read the word from memory with the program buffer, it should work.

Thanks,however I find that I failed to set the haltreq to 1, but I can success to set dmactive to 1.So I don’t know what problem happened.
And I also don’t know how to set hartsel because I don’t know whether a single hart or multiple harts are running after being reset at power-up.If it is a single hart,what is the index of the hart to select.
I just want to halt all the hart in order to using Astract command.
Additional information:Hart Summary is 0x0000_0000;Hart Info is 0x0011_1380.

I don’t believe that haltreq is readable in all implementations, so it’s OK that you can’t read it back. But yes, you will need to set dmactive to 1 in order to do anything in the Debug Module.

You can figure out how many harts there are by writing to hartsel, then reading dmstatus to see if anynonexistent or allrunning. If you set hartsel to too high a number, then you would get anynonexistent status.

In general for a single core system it’s most likely you just want to set hartsel to 0.

Once you have successfully halted the hart, you can know by checking dmstatus to see allhalted.