How to STALL a Data USB Transaction?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to STALL a Data USB Transaction?

780 Views
dgalbarra
Contributor I

Hi All

 

I'm using the USB Stack provided by Freescale at AN3564.

 

I want to send a Class-specific comand to my HCS08JM60 Evaluation Board. This command is  "Host to Device", I pretend to ACK the SETUP stage, and when I receive the Data from Host, I would like to analyze the data, and depending on the value received, I can accept the data or reject them. I pretend to STALL the EP0 if the data are not valid, but I don't know how to do it!!

 

This is the code I'm using:

void USB_CtrlTrf_RxData(void){

...

...

if(data not valid){
          Bdtmap.ep0Bo.Cnt = EP0_BUFF_SIZE;
          Bdtmap.ep0Bo.Addr = 0x0C;
          EPCTL0_EPSTALL = 1;
          Bdtmap.ep0Bo.Stat._byte = _SIE|_BDTSTALL;
          Bdtmap.ep0Bi.Stat._byte = _SIE|_BDTSTALL;
        }

 

I'm using a hardware USB sniffer, and I can see that both the DATA and STATUS Transfers are Ackowledged, so it seems that this is not working (I can see also that the data sent is not valid, so I expected the EP0 to STALL). I supposed that the DATA stage would be Acknowledged, but I expected the STATUS stage ("In" Transaction with no data) to be Stalled, and I don't see that. Could it be possible that, due to the time to process data, when I set the stall bit, the Status Stage has already finished? If so, how could I avoid that? Can I pause after data stage?

 

Thanks in advance!

David

Labels (1)
0 Kudos
2 Replies

384 Views
Tsuneo
Contributor IV

You are on the right track, but..
For Control Write transfer, the stack prepares ZLP on the EP0 IN for STATUS stage in advance, in USB_CtrlEP_SetupStage_Complete().

Usb_Ep0_Handler.c

void USB_CtrlEP_SetupStage_Complete(void)
{
    int Tmp;
  
  if(Ctrl_Trf_Session_Owner == CLASS_NULL)
    {
        ...
    }
   else   
    {
        if(Setup_Pkt.CtlReqT.DataDir == DEV_TO_HOST)
          {
              ...
          }
        else   
          {
            Ctrl_Trf_State = CTL_TRF_DATA_RX;
                                              // <----- ZLP is filled to EP0 IN here
                                              // <----- comment these three lines
            Bdtmap.ep0Bi.Cnt = 0;
            Bdtmap.ep0Bi.Addr = 0x08;         /*can calculate the addree according the offset in Bdtmap*/
            Bdtmap.ep0Bi.Stat._byte = _SIE|_DATA1|_DTS;

            Bdtmap.ep0Bo.Cnt = EP0_BUFF_SIZE;
            Bdtmap.ep0Bo.Addr = 0x0C;         /*can calculate the addree according the offset in Bdtmap*/
            Bdtmap.ep0Bo.Stat._byte = _SIE|_DATA1|_DTS;
          }
    }

Host moves to STATUS stage immediately after it puts the last OUT transaction on DATA stage. Therefore, STATUS stage has finished, while the firmware is processing the data on DATA stage.

Comment above three lines. And then, the host is waiting at STATUS stage (EP0 IN is NAKing).
In USB_CtrlTrf_RxData(),
- To accept the request, run above three lines here.
- To cancel with STALL, do as you wrote on your post (STALL on IN EP is enough).

Tsuneo

0 Kudos

384 Views
dgalbarra
Contributor I

Thank you very much, Tsuneo!

 

I'll test it as soon as possible!

0 Kudos