This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Why the SAM7X256 board sending NAK for every Data IN token on EndPoint1

I want to use bulk transfer on endpoint 1 of the AT91SAM7X256,so I checked the keil Memory example,But after i migrated the project,the board can not response to endpoint 1 token In packet but always send NAK.
I have changed these things.
In usbcfg.h
#define USB_CLASS 0
#define USB_MSC 0

in Usbdesc.c,change the config descriptor,change the 4 items after bNumEndpoints to 0x00,delete all functions in mscuser.c excluding MSC_Reset, and write

void MSC_BulkIn (void) {

        if(Offset < MSC_MemorySize)
        {
                USB_WriteEP(MSC_EP_IN, &Memory[Offset], 64);
                Offset += 64;
        }
        else Offset = 0;
}

void MSC_BulkOut (void) {
}

.and some small things,Can you help me what's the problem cause this issue?
The enumeration process is all rirht.

  • Do you call this MSC_BulkIn() just from the endpoint 1 ISR - USB_EndPoint1()?

    If so, you have to call MSC_BulkIn() outside of the EP1 ISR once, to start the EP interrupt sequence. Usually, this routine will be called just after the buffer (Memory) is loaded.

    The interrupt for the bulk IN endpoint occurs just when IN transaction finishes successfully. If you don't load any data to the EP buffer in the IN EP ISR, next interrupt never occurs. And the engine returns NAK to following IN transactions. Then, you have to load data to the EP buffer once outside of the ISR, to kick the interrupt sequence.

    It's same as UART TX.
    When UART TX is handled in interrupt, you have to load the first byte to the UART TX buffer to start the interrupt sequence.

    Tsuneo

  • Thanks for your reply,I followed your suggestion and invoke the MSC_BulkIn() once in the main,but still can not solve this problem,maybe some other more should be changed.

    chris