Sporadic USB protocol error on calling XUD_GetBuffer() Topic is solved

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
dsteinwe
XCore Addict
Posts: 144
Joined: Wed Jun 29, 2016 8:59 am

Post by dsteinwe »

It is not the variable but the timer event, that causes a control token for the ep0 channel. That should never happen! Currently, I can reproduce this bug with 100% guarantee. The (pseudo) code causing the bug, is:

Code: Select all

function task(...) {
    // ...
    timer test_timer;
    unsigned test_enabled = 1;
    unsigned test_timeout;
    test_timer :> test_timeout;
    test_timeout += 100u * 1000u * 100u;
    // ...
    while (true) {
    	// ...
    	select {
    		// ...
    		case (test_enabled) => test_timer when timerafter(test_timeout) :> void :
             	    printf(">>>>>>>>>>>>>>>>>>>>\n");
                    test_enabled = 0;
                break;
	        // ...
    	}
    }
}
I have also added a debug output to the function:

Code: Select all

XUD_Result_t XUD_GetSetupBuffer(XUD_ep e, unsigned char buffer[], unsigned *datalength)
{
    volatile XUD_ep_info *ep = (XUD_ep_info*) e;
    unsigned isReset;
    unsigned length;
    unsigned lengthTail;

    /* Check if we missed a reset */
    if(ep->resetting)
    {
        printf("================== RESET1\n");
        return XUD_RES_RST;
    }

    /* Store buffer address in EP structure */
    ep->buffer = (unsigned) &buffer[0];

    /* Mark EP as ready for SETUP data */
    unsigned * array_ptr_setup = (unsigned *)ep->array_ptr_setup;
    *array_ptr_setup = (unsigned) ep;

    /* Wait for XUD response */
    asm volatile("testct %0, res[%1]" : "=r"(isReset) : "r"(ep->client_chanend));

    if(isReset)
    {
        printf("================== RESET2\n");
        return XUD_RES_RST;
    }
	// ...
When I start the firmware I got the output
>>>>>>>>>>>>>>>>>>>> 1
================== RESET2
If I increase the value of test_timeout by *10u, it doesn't reset anymore.

Any suggestions are welcome!


View Solution
User avatar
dsteinwe
XCore Addict
Posts: 144
Joined: Wed Jun 29, 2016 8:59 am

Post by dsteinwe »

Finally, I have solved my problem. My Project had used a distributed interface across multiple threads to share global states and some functionality. I have refactored this part, using this module: https://github.com/xcore/sc_util/tree/m ... ule_xc_ptr. Now everything works fine.