pyocd / pyOCD

Open source Python library for programming and debugging Arm Cortex-M microcontrollers
https://pyocd.io
Apache License 2.0
1.13k stars 484 forks source link

SWO never flushes if target doesn't send timestamps. #831

Open Dirbaio opened 4 years ago

Dirbaio commented 4 years ago

Currently, the SWO parser buffers all events until a timestamp is received: https://github.com/mbedmicro/pyOCD/blob/ee63c7b64b313bad65dfa9871b7acb55fdda055d/pyocd/trace/swo.py#L116-L132

In my current project, I'm just sending printf debugging data over ITM port 0, and I want to receive it from Python. However, it seems no timestamps are being sent, so the data is never flushed, and gets buffered forever.

I'm not sure whether I want these timestamps or not, or what's the best way to enable them (from the firmware or from pyOCD?). Either way, shouldn't pyOCD offer an API to read raw SWO data, and process timestamps in a higher-level layer? (SWV, not SWO?)

flit commented 4 years ago

Yes, there should be an API (and TCP port) for accessing the raw SWO data. Timestamps need to be processed at the event-generation layer, though. There should really be a SWOReader class that manages the basic SWO init and reading, and SWVReader would be a downstream.

In my setups, I've always done the SWO setup from pyOCD so the configuration can be changed without requiring firmware changes. But either way works.

For this particular bug, we should have a timeout where, if a timestamp hasn't been received in N seconds and/or N packets are buffered, then the queue is flushed. An additional possibility would be for the SWOParser (or the object using it) to introspect the target's configuration to see if timestamps are being sent, and disable buffering if not. Probably both methods are required.

aonsquared commented 4 years ago

Count my vote for adding this feature, as I'm also just sending printf data over ITM port 0.