Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cdc_loop example at high speed #110

Open
EmbeddedMagic opened this issue Apr 1, 2022 · 3 comments
Open

cdc_loop example at high speed #110

EmbeddedMagic opened this issue Apr 1, 2022 · 3 comments

Comments

@EmbeddedMagic
Copy link

Hi, I am using a blue pill with STM32F103 and the cdc_loop example. To evaluate the stability, I have a PC software that sends an 8byte number to the device. The device will echo the number and the PC will compare if TX=RX. Then the PC increments the number by 1 and send again to the device....all this happens at maximum speed.
It happens that the device is not echoing after 100...3000 transmission. It seems

static int32_t ep_write(uint8_t ep, void *buf, uint16_t blen) {
...
    /* invalid or not ready */
    default:
        return -1;     <-- 
}

-1 is returned. What could be the route cause of that?
Thx a lot for your response!

@GrantMTG
Copy link

GrantMTG commented Apr 1, 2022

Maybe you could copy the result to a local variable and see the reason (the value at *reg):

volatile uint16_t *reg = EPR(ep);
switch (*reg & (USB_EPTX_STAT | USB_EP_T_FIELD | USB_EP_KIND))
   :

@EmbeddedMagic
Copy link
Author

EmbeddedMagic commented Apr 1, 2022

The mask (USB_EPTX_STAT | USB_EP_T_FIELD | USB_EP_KIND) is 0x0730.
reg is pointing to adr. 0x40005C04 which is I guess is register USB_EP1R, ep is 0x81.
In good case (case (USB_EP_TX_NAK | USB_EP_BULK):) reg is 0x7061 when entering the case and 0x70A1 when leaving the case.

In bad case (default:) reg is for example 0xA0A1 or 0xE0A1 (breakpoint at return statement)
FYI: I use a jLink debugger and can therefore inspect these values.

I also tried resending after -1 is returned in a do-while-loop. This didn't work either, but I need to deep dive more into it. This seems to be the obvious solution.

So Dmitry is from Ukraine? I really hope he is safe. I am of course not in the position to expect any answer from him.

@GrantMTG
Copy link

GrantMTG commented Apr 1, 2022

Well, FWIW, I never wrote at that level, I always used usbd_ep_write().

I'm going to hazard a guess that the endpoint isn't ready, try again later... you could implement that and see if the situation resolves if you do retry.

It's probably the middle of the night where Dmitry is and/or the war might be affecting him or his locale.

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

No branches or pull requests

2 participants