pyrsp icon indicating copy to clipboard operation
pyrsp copied to clipboard

Embedded testing with Flash and HW break points

Open Spudmn opened this issue 3 years ago • 3 comments

I am making some changes to get pyrsp to work with my embedded test setup.

I found that pyrsp as it is now, seems to run it’s applications from RAM, (also noticed it is using SW break points). I am adding the ability to use flash and add HW breakpoints.

Soon I will offer you a pull request for these changes. But I would like to discuss how you would like to select the option to use flash and HW Break points.

I don’t want to break any existing code so how would you like to set this option in your code?

FYI I am use a Black magic probe.

Spudmn avatar May 18 '22 19:05 Spudmn

actually i believe pyrsp runs your code from wherever the elf file maps your code section, this is even true if you run the code on an external mcu using a swd debugger.

also run has a param where to set pc to (in case there is no elf file for example) to start the running:

def run(self, start=None, setpc=True):
    """ sets pc to start if given or to entry address from elf header,
        passes control to the device and handles breakpoints
    """

btw you can do hw breakpoints "manually" by running:

tmp = self.fetch(b'Z1,%s,2' % addr)
if tmp!= b'OK': print('failed to set breakpoint')

if you want to add hw breakpoints, i think it makes most sense to change

    def set_br(self, sym, cb, quiet=False):

into

    SWBR=0;HWBR=1;WWATCH=2;RWATCH=3
    def set_br(self, sym, cb, type=SWBR, quiet=False):

and also set_br_a() accordingly

and then this line

                tmp = self.fetch(b'Z0,%s,2' % addr)

into this:

                tmp = self.fetch(b'Z%s,%s,2' % (type,addr))

stef avatar May 18 '22 21:05 stef

When doing a load, pyrsp uses the “M” command.

The Black magic probe treats this as a memory write, and because it is into flash memory it has no effect (I am using a STM32F4).

I have codded up a fix for this and it writes to flash using vFlashWrite. You need to vFlashErase before and vFlashDone after you write to flash also.

Re the hw breakpoints, I will do a separate pull request for this

def set_br(self, sym, cb, type=SWBR, quiet=False):

Spudmn avatar May 19 '22 03:05 Spudmn

aaah. so it's not about running code it's about uploading code.

it would be nice if the decision between M / flash would be automatic in cortex arch.

stef avatar May 19 '22 12:05 stef