Sat Aug 17 14:57:37 EDT 2013


Starting to see how it works.  Basically, I'm not implementing a
properly buffered serial stream, but just allow the current OUT packet
to be read through the `OUT1>` word.  Currently the interrupt handler
somehow returns EP back to USB controller, but this needs to be done
elsewhere, i.e. when all data is read, or explicitly.

Som, how to NAK an OUT transaction?

After data is updated, this is what happens:

    UIR TRNIF low    \ ready for next transaction
    UCON PKTDIS low  \ clear PKTDIS flag (automatically set for SETUP packet)

That's not it.  The important flag is UOWN in the STAT register of the
EP descriptor.

Reading the code, it seems this should really just work, at least on
the OUT side: buffer is only passed to USB controller when it is read

The trouble is probably that IN buffer gets overwritten.  Basically,
>IN1 should block until buffer is ready to go out.

I cleaned it up a bit to use an explicit IN1-write pointer instead of
the buffer counter.  Doesn't change behaviour.


After cleanup, still problem.

To see if it's in or out, I tried this, together with feeding it a
counting range.

: testx
    \ init-debug
    0 begin OUT1> drop dup >IN1 1 + again ;

The IN sequence doesn't have any gaps, so it seems something gets lost
in the OUT part.

Ok, found it: didn't toggle DATAx bit!
Looks like it got silently ignored, or I didn't check an error condition.

Yep, it's in the data sheet: ignored *BUT* ack is sent to host! BDnSTAT Register (CPU Mode)

  The Data Toggle Sync Enable bit, DTSEN (BDnSTAT<3>), controls data
  toggle parity checking.  Setting DTSEN enables data toggle
  synchronization by the SIE; when enabled, it checks the data
  packet’s par- ity against the value of DTS (BDnSTAT<6>). If a packet
  arrives with an incorrect synchronization, the data will essentially
  be ignored; it will not be written to the USB RAM and the USB
  transfer complete interrupt flag will not be set. The SIE will send
  an ACK token back to the host to Acknowledge receipt, however. The
  effects of the DTSEN bit on the SIE are summarized in Table 17-3.

[1] http://www.microchip.com/forums/m715201.aspx