Skip to content

Conversation

@fleutot
Copy link

@fleutot fleutot commented Dec 8, 2025

No description provided.

Copy link
Owner

@rgrr rgrr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. See my comments

unsigned int first_chunk_size;

if (ft_extRttBuf->aUp.WrOff > ft_extRttBuf->aUp.RdOff) {
bytes_available = ft_extRttBuf->aUp.WrOff - ft_extRttBuf->aUp.RdOff;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I'm claiming that my code already considers wrap-around correctly. This would be almost immediately visible otherwise.
Please prove me wrong.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are probably right, but I don't know where the wrap-around logic is, can you show me?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There it is:

            if (ft_extRttBuf->aUp.WrOff > ft_extRttBuf->aUp.RdOff) {
                ft_cnt = MIN(ft_cnt, ft_extRttBuf->aUp.WrOff - ft_extRttBuf->aUp.RdOff);
            }
            else {
                ft_cnt = MIN(ft_cnt, ft_extRttBuf->aUp.SizeOfBuffer - ft_extRttBuf->aUp.RdOff);
            }
            ft_cnt = MIN(ft_cnt, sizeof(ft_buf));

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if WrOff < RdOff (write is below read), ft_cnt becomes the amount from RdOff to the end of the buffer, and doesn't copy until WrOff (does not wrap around). Why is it working, then? Is it reading the remainder (from start of buffer until WrOff) at a later execution of the loop? This requires an extra wake up from xEventGroupWaitBits, in that case?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the transfer is split in at least two on wrap-around. I think this is nothing special and nothing dangerous. The code stays simple, that's more important (to me).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When does the read of the remainder occurs? What if there is no more Event posted for a while, then the rest of the data is delayed? Did I get this right?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On next iteration. Delay is neglectable.

#define SWD_RETRY_MS 2
#define SWD_MAX_RETRIES 10

#define SWD_OPERATION_WITH_RETRY(result, operation) \
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you experience problems requiring retry mechanism?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but it is probably caused by a noisy line. Dealing with electrical motors here.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, understood. But in this case shouldn't the retry mechanism go into a deeper layer?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe? What are you suggesting?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm... checking the code in swd_host.c shows that there are already retries, see swd_transfer_retry(). Yet not sure if this is called by all relevant SWD routines. But I think this is the actual place for a lever.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if your retry implementation solves your actual problem.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I've been seeing is that an erroneous read (possibly caused by noisy line, hard to do something about it 100 %), triggered a reconnect of the probe. That takes about half a second. The thought around this (which I am happy to see you challenge) was to lose less data.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question is: do you recognize any change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants