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

Smartcard USB application

Hello,
Im writing a usb communication tool on the LPC2368 for smartcard devices. I still don't get any communication between the host and the smartcard device for couple of weeks know. It seems like the program is be missing something and i dont know what.

Do you Know where I can find any smartcard USB application for arm7 microcontroller?

Can anybody help me on it? If necessary I will post the fully commented code that I have written.

Thanks in advance

Parents
  • Hello Tsuneo,
    thanks for your quick reply.
    Yes I have verified the reader is bus-powered!
    Here the definition of WBVAL1:

    #define WBVAL1(x) ((x >> 24) & 0xFF), ((x >> 16) & 0xFF), ((x >> 8) & 0xFF), (x & 0xFF) //DWORD to 4 bytes
    

    Talking about the endpoint configurations, I leaned on that fixed endpoint configuration of the LPC23xx manual but I refered to the physical Endpoints (second column) instead of the logical ones. Hmmm. I will try now to follow your recommendations and reconfigure the endpoints accordingly. I will let you know throughout the day whether any change happens.
    Here is the definitions of the endpoints events. I wondered why the Programm doesnt reach the configured endpoints!

    /*
     *  USB Endpoint 3 Event Callback
     *   Called automatically on USB Endpoint 3 Event
     *    Parameter:       event
     */
     void USB_EndPoint3 (DWORD event) {
            Biib(50);
      switch (event) {
        case USB_EVT_IN:
    
                    USB_DataInStage3();
    
          break;
            case USB_EVT_OUT:
    
                    USB_DataOutStage3();
    
                    break;
      }
    }
    
    void USB_DataInStage3 (void) {
      DWORD cnt;
    
      if (EP1DataSnd.Count > USB_MAX_PACKET0) {
        cnt = USB_MAX_PACKET0;
      } else {
        cnt = EP1DataSnd.Count;
      }
    
      cnt = USB_WriteEP(0x83, EP1DataSnd.pData,cnt);
      EP1DataSnd.pData += cnt;
      EP1DataSnd.Count -= cnt;
    }
    
    void USB_DataOutStage3 (void) {
      DWORD cnt;
      if(EP1DataRcv.Count==0)
        EP1DataRcv.pData = (unsigned char*)RXBuffer;
    
      cnt = USB_ReadEP(0x03, EP1DataRcv.pData);
      EP1DataRcv.pData += cnt;
      EP1DataRcv.Count += cnt;
    
      if(EP1DataRcv.Count >= RECEIVE_BUFFER_MAX)
      {
                    EP1DataRcv.pData = (unsigned char*)RXBuffer;
                    EP1DataRcv.Count = 0;
      }
    }
    
    
    /*
     *  USB Endpoint 4 Event Callback
     *   Called automatically on USB Endpoint 4 Event
     *    Parameter:       event
     */
     void USB_DataInStage4 (void) {
      DWORD cnt;
    
      if (EP1DataSnd.Count > USB_MAX_PACKET0) {
        cnt = USB_MAX_PACKET0;
      } else {
        cnt = EP1DataSnd.Count;
      }
    
      cnt = USB_WriteEP(0x84, EP1DataSnd.pData,cnt);
      EP1DataSnd.pData += cnt;
      EP1DataSnd.Count -= cnt;
    }
    
    void USB_EndPoint4 (DWORD event) {
    Biib(50);
     USB_DataInStage4();
    }
    
    
    /*
     *  USB Endpoint 5 Event Callback
     *   Called automatically on USB Endpoint 5 Event
     *    Parameter:       event
     */
    
     /* Receive the datas from the Host (Bulk-Out Endpoint, 0x05) */
     BYTE USB_DataOutStage5 (void) {
      DWORD cnt;
      if(EP1DataRcv.Count==0)
        EP1DataRcv.pData = (unsigned char*)RXBuffer;
    
      cnt = USB_ReadEP(0x05, EP1DataRcv.pData);
      if (cnt > 0)
      {
            EP1DataRcv.pData += cnt;
            EP1DataRcv.Count += cnt;
            /* if(EP1DataRcv.Count >= RECEIVE_BUFFER_MAX)
              {
                    EP1DataRcv.pData = (unsigned char*)RXBuffer;
                    EP1DataRcv.Count = 0;
              }      */
              return 0;
      }
      return 1;
    }
    
    
    void USB_EndPoint5 (DWORD event) {
    Biib(50);
    //if (event == USB_EVT_OUT)
            if (!USB_DataOutStage5())
                    return;
    }
    
    BYTE USBEndP5 (void) {
            if (!USB_DataOutStage5())
                    return 0;
            else
                    return 1;
    }
    

    Im very grateful about the fact that you spend your time trying to release me from a problem that seems to try to bring me down!
    Thanks a lot Tsuneo!!

Reply
  • Hello Tsuneo,
    thanks for your quick reply.
    Yes I have verified the reader is bus-powered!
    Here the definition of WBVAL1:

    #define WBVAL1(x) ((x >> 24) & 0xFF), ((x >> 16) & 0xFF), ((x >> 8) & 0xFF), (x & 0xFF) //DWORD to 4 bytes
    

    Talking about the endpoint configurations, I leaned on that fixed endpoint configuration of the LPC23xx manual but I refered to the physical Endpoints (second column) instead of the logical ones. Hmmm. I will try now to follow your recommendations and reconfigure the endpoints accordingly. I will let you know throughout the day whether any change happens.
    Here is the definitions of the endpoints events. I wondered why the Programm doesnt reach the configured endpoints!

    /*
     *  USB Endpoint 3 Event Callback
     *   Called automatically on USB Endpoint 3 Event
     *    Parameter:       event
     */
     void USB_EndPoint3 (DWORD event) {
            Biib(50);
      switch (event) {
        case USB_EVT_IN:
    
                    USB_DataInStage3();
    
          break;
            case USB_EVT_OUT:
    
                    USB_DataOutStage3();
    
                    break;
      }
    }
    
    void USB_DataInStage3 (void) {
      DWORD cnt;
    
      if (EP1DataSnd.Count > USB_MAX_PACKET0) {
        cnt = USB_MAX_PACKET0;
      } else {
        cnt = EP1DataSnd.Count;
      }
    
      cnt = USB_WriteEP(0x83, EP1DataSnd.pData,cnt);
      EP1DataSnd.pData += cnt;
      EP1DataSnd.Count -= cnt;
    }
    
    void USB_DataOutStage3 (void) {
      DWORD cnt;
      if(EP1DataRcv.Count==0)
        EP1DataRcv.pData = (unsigned char*)RXBuffer;
    
      cnt = USB_ReadEP(0x03, EP1DataRcv.pData);
      EP1DataRcv.pData += cnt;
      EP1DataRcv.Count += cnt;
    
      if(EP1DataRcv.Count >= RECEIVE_BUFFER_MAX)
      {
                    EP1DataRcv.pData = (unsigned char*)RXBuffer;
                    EP1DataRcv.Count = 0;
      }
    }
    
    
    /*
     *  USB Endpoint 4 Event Callback
     *   Called automatically on USB Endpoint 4 Event
     *    Parameter:       event
     */
     void USB_DataInStage4 (void) {
      DWORD cnt;
    
      if (EP1DataSnd.Count > USB_MAX_PACKET0) {
        cnt = USB_MAX_PACKET0;
      } else {
        cnt = EP1DataSnd.Count;
      }
    
      cnt = USB_WriteEP(0x84, EP1DataSnd.pData,cnt);
      EP1DataSnd.pData += cnt;
      EP1DataSnd.Count -= cnt;
    }
    
    void USB_EndPoint4 (DWORD event) {
    Biib(50);
     USB_DataInStage4();
    }
    
    
    /*
     *  USB Endpoint 5 Event Callback
     *   Called automatically on USB Endpoint 5 Event
     *    Parameter:       event
     */
    
     /* Receive the datas from the Host (Bulk-Out Endpoint, 0x05) */
     BYTE USB_DataOutStage5 (void) {
      DWORD cnt;
      if(EP1DataRcv.Count==0)
        EP1DataRcv.pData = (unsigned char*)RXBuffer;
    
      cnt = USB_ReadEP(0x05, EP1DataRcv.pData);
      if (cnt > 0)
      {
            EP1DataRcv.pData += cnt;
            EP1DataRcv.Count += cnt;
            /* if(EP1DataRcv.Count >= RECEIVE_BUFFER_MAX)
              {
                    EP1DataRcv.pData = (unsigned char*)RXBuffer;
                    EP1DataRcv.Count = 0;
              }      */
              return 0;
      }
      return 1;
    }
    
    
    void USB_EndPoint5 (DWORD event) {
    Biib(50);
    //if (event == USB_EVT_OUT)
            if (!USB_DataOutStage5())
                    return;
    }
    
    BYTE USBEndP5 (void) {
            if (!USB_DataOutStage5())
                    return 0;
            else
                    return 1;
    }
    

    Im very grateful about the fact that you spend your time trying to release me from a problem that seems to try to bring me down!
    Thanks a lot Tsuneo!!

Children