AT91SAM7 UDP

The datasheet says that after you put bytes in the endpoint’s FIFO and set TXPKTRDY to 1, you have to wait until the host ACKs the packet and TXPKTRDY goes to 0 again before writing another packet. TXPKTRDY is deasserted by the hardware when the host ACKs the packet at the same time as TXCOMP is set to 1.

It says that. However, what I’m seeing is different.

I poll TXPKTRDY to make sure it’s 0, I fill the FIFO, and set TXPKTRDY. The host gets the packet, and can even display its contents, which are correct. TXPKTRDY never returns to 0, though. And here’s the kicker. TXCOMP transitions as one would expect. TXPKTRDY just doesn’t do so at the same time.

I’m polling TXPKTRDY (not enabling the endpoint interrupt), as I’m trying to debug the problem, but the datasheet says nothing about having the interrupt enabled. It does, however, say that I cannot set TXPKTRDY to 1 again unless it is already 0, which it’s not, since it didn’t get reset when TXCOMP got set.

What’s up with that? Everything I recall seeing states that TXCOMP is set to 1 and TXPKTRDY is set to 0 by hardware when the packet is ACKed by the host. I recall no exceptions to this. This is a ping-pong endpoint, but the timing diagram for that in the datasheet still states that relationship quite clearly.

The datasheet I’m referring to is that of the AT91SAM7XC128/256/512, and the timing diagram is figure 33-8 in my copy of it. It is labeled “Data IN Transfer for Ping-pong Endpoint”. It might be numbered differently in a different version of the datasheet or in one for something else like the AT91SAM7S64.

I looked into writing a packet driver but decided against it b/c the ethernet mac is so convoluted and I couldn’t find any good examples.

You could take a look at how FreeRTOS does this. The files you need to look at are in:

FreeRTOSV5.0.0/FreeRTOS/Demo/ARM7_AT91SAM7X256_Eclipse/RTOSDemo/webserver/

they are:

SAM7_EMAC.c

EMAC_ISR.c

If you need the patches to make this work, use mine (the code is for a different board setup, not the Olimex SAM7x-256

http://pastebin.com/f25126d57

These are my personal patches, if anyone finds a problem with them let me know. I also have a different patch to get UDP packets working using this demo.

electronjunkie:
I looked into writing a packet driver but decided against it b/c the ethernet mac is so convoluted and I couldn’t find any good examples.

It’s not that kind of UDP. In the SAM datasheets, UDP refers to the USB Device Port.

Thanks, though.

I found my problem. I was doing everything right except I was using bDescriptorType instead of bmAttributes when building EPTYPE. It thought it was supposed to be an isochronous endpoint, which was wrong, since the low two bytes of bDescriptorType for an endpoint descriptor are always 01.