Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISP_DFU_20 driver transfer file in case of USB 2.0 (NUVOTON M487KM) driver development #36

Open
SANKETMODHE7028 opened this issue Feb 19, 2024 · 112 comments

Comments

@SANKETMODHE7028
Copy link

SANKETMODHE7028 commented Feb 19, 2024

some issues happen in data transmission .

1 . i have to transmit or receiving the data . so how to do this?
2. i have to change in DFU_Transfer file ?
3. void HSUSBD_ProcessSetupPacket(void)
{
/* Setup packet process */
gUsbCmd.bmRequestType = (uint8_t)(HSUSBD->SETUP1_0 & 0xfful);
gUsbCmd.bRequest = (uint8_t)((HSUSBD->SETUP1_0 >> 8) & 0xfful);
gUsbCmd.wValue = (uint16_t)HSUSBD->SETUP3_2;
gUsbCmd.wIndex = (uint16_t)HSUSBD->SETUP5_4;
gUsbCmd.wLength = (uint16_t)HSUSBD->SETUP7_6;

/* USB device request in setup packet: offset 0, D[6..5]: 0=Standard, 1=Class, 2=Vendor, 3=Reserved */
switch(gUsbCmd.bmRequestType & 0x60ul)
{
case REQ_STANDARD:
{

    HSUSBD_StandardRequest();
    break;
}

case REQ_CLASS:
{
    DFU_ClassRequest();
    break;
}

4.In hsusbd_user.c file only HSUSBD_StandardRequest() function is working for configuration part . when DFU_ClassRequest() ; function is called?
5. suppose i have to pass data so I have to calling seperately?
6. please give me the proper logic.

for example : - I have to transmit arr[10] = {1,2,3,4,5,6,7,8,9,0}; how to transmit ?
control in or control out.

case:

pc utility <--------------------------------> device
TX
command 9 ----------------------> 1st byte received.
RX
2 received <------------------------ 2 (device sending 2)
ACK
6 -------------------------> ACK byte received

64 bytes received < -------------------------- 64 bytes data packet send to pc

note :- 9 and 6 are random value of 1 bytes.

this is the flow of code so please find a perfect logic for this .

@ychuang3
Copy link
Contributor

I'm not quite clear on your point of concern. You don't need to trace the driver unless you want to write a separate driver yourself. Using this sample, please refer to the documentation under the WindowsTool directory.

@SANKETMODHE7028
Copy link
Author

I'm not quite clear on your point of concern. You don't need to trace the driver unless you want to write a separate driver yourself. Using this sample, please refer to the documentation under the WindowsTool directory.

ok ........
only give me idea when the DFU_CLASS_REQUEST function is called?
and how to buffer read or write?

@ychuang3
Copy link
Contributor

DFU_ClassRequest() is called when DFU class command received from USB Host (Windows PC).
Data is from USB Host and directly programmed to flash., refer to the WriteData().

Could you explain the purpose of wanting to trace the code? Thank you.

@SANKETMODHE7028
Copy link
Author

DFU_ClassRequest() is called when DFU class command received from USB Host (Windows PC). Data is from USB Host and directly programmed to flash., refer to the WriteData().

Could you explain the purpose of wanting to trace the code? Thank you.

ok.....
suppose i have to transmit this buffer having some data buff[10] = {1,2,3,4,5,6,6,7,8} . how to send this device to pc?
can i used directly controll_ in() function ?

@ychuang3
Copy link
Contributor

The USB device is passive, and all data transmission is initiated by the USB Host. Therefore, you must perform read operations from the Windows PC side for the USB device to receive commands and carry out corresponding data transfers. We do not provide the source code for the Windows side; this sample is intended for firmware updates. What is the purpose of sending data to the PC side? There may be other suitable sample codes, but since you haven't clearly explained your purpose, I'm unable to provide specific helpful suggestions.

@SANKETMODHE7028
Copy link
Author

The USB device is passive, and all data transmission is initiated by the USB Host. Therefore, you must perform read operations from the Windows PC side for the USB device to receive commands and carry out corresponding data transfers. We do not provide the source code for the Windows side; this sample is intended for firmware updates. What is the purpose of sending data to the PC side? There may be other suitable sample codes, but since you haven't clearly explained your purpose, I'm unable to provide specific helpful suggestions.

I am not getting properly concept. do you have any proper datasheet on DFU ?
and how to handle this please explain first..

actually i am working on project so my task is to transmit or receive the data . using DFU_transfer file .

@ychuang3
Copy link
Contributor

You can find DFU spec. by Google search...

Looks like your project is not on Nuvoton M480 platform, right?
I think you don't even run the sample code.

@SANKETMODHE7028
Copy link
Author

controller is NUVOTON M487KM .

actually totally working in background only HSUSBD_StandardRequest(); this function run for configuration part.

URB 165 URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE Down 15:22:29.574 18 bytes IN PENDING DISPATCH_LEVEL
URB 166 URB_FUNCTION_CONTROL_TRANSFER Up 15:22:29.585 18 bytes IN SUCCESS DISPATCH_LEVEL
URB 167 URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE Down 15:22:29.585 9 bytes IN PENDING DISPATCH_LEVEL
URB 168 URB_FUNCTION_CONTROL_TRANSFER Up 15:22:29. 597 9 bytes IN SUCCESS DISPATCH_LEVEL
URB 169 URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE Down 15:22:29.597 27 bytes IN PENDING DISPATCH_LEVEL
URB 170 URB_FUNCTION_CONTROL_TRANSFER Up 15:22:29.609 27 bytes IN SUCCESS DISPATCH_LEVEL
URB 171 URB_FUNCTION_SELECT_CONFIGURATION Down 15:22:29.609 27 bytes OUT DISPATCH_LEVEL
URB 172 URB_FUNCTION_SELECT_CONFIGURATION Up 15:22:29.621 27 bytes IN SUCCESS DISPATCH_LEVEL

only this is showing in usb analyser

@SANKETMODHE7028
Copy link
Author

You can find DFU spec. by Google search...

Looks like your project is not on Nuvoton M480 platform, right? I think you don't even run the sample code.

i searched this but how to use in my project?

@SANKETMODHE7028
Copy link
Author

You can find DFU spec. by Google search...
Looks like your project is not on Nuvoton M480 platform, right? I think you don't even run the sample code.

i searched this but how to use in my project?

@ychuang3
Copy link
Contributor

The link to USB org including DFU spec.
https://www.usb.org/documents?search=&type%5B0%5D=55&items_per_page=50

Please find:
image

HSUSBD_StandardRequest() is for standard request, that is, for any USB device. DFU data transfer use class commands, not standard commands.

Do you run the ISP tool or any program supports DFU on the host PC?

@SANKETMODHE7028
Copy link
Author

The link to USB org including DFU spec. https://www.usb.org/documents?search=&type%5B0%5D=55&items_per_page=50

Please find: image

HSUSBD_StandardRequest() is for standard request, that is, for any USB device. DFU data transfer use class commands, not standard commands.

Do you run the ISP tool or any program supports DFU on the host PC?

I have Numicro ICP programing tool utility .
and in my project EL series utility are used . for that host (pc) sending first command to slave (device)..
so how to use this class command?

@SANKETMODHE7028
Copy link
Author

The link to USB org including DFU spec. https://www.usb.org/documents?search=&type%5B0%5D=55&items_per_page=50
Please find: image
HSUSBD_StandardRequest() is for standard request, that is, for any USB device. DFU data transfer use class commands, not standard commands.
Do you run the ISP tool or any program supports DFU on the host PC?

I have Numicro ICP programing tool utility . and in my project EL series utility are used . for that host (pc) sending first command to slave (device).. so how to use this class command?

i am using this DFU file and discriptor file . only changed in VID and PID for HMI detection . remaining code is same . so what i do first step?

@ychuang3
Copy link
Contributor

Not ICP tool, please use ISP tool which is for ISP_XXX samples.

@SANKETMODHE7028
Copy link
Author

SANKETMODHE7028 commented Feb 22, 2024

Not ICP tool, please use ISP tool which is for ISP_XXX samples.

Do you have link of ISP tool? please send

@SANKETMODHE7028
Copy link
Author

Not ICP tool, please use ISP tool which is for ISP_XXX samples.

Do you have link of ISP tool? please send

I downloaded ISP tool , suppose i start this what happened in next step ? directly calling DFU_class_request function ?

@ychuang3
Copy link
Contributor

Sorry, ISP is for USBD HID, not DFU.
For DFU, just run the tool in BSP bsp\SampleCode\ISP\ISP_DFU_20\WindowsTool.
Please read the PDF in this folder.

@SANKETMODHE7028
Copy link
Author

Sorry, ISP is for USBD HID, not DFU. For DFU, just run the tool in BSP bsp\SampleCode\ISP\ISP_DFU_20\WindowsTool. Please read the PDF in this folder.

hello sir , actually in my case my pc is host . first pc sending 1 byte . so how to response to this ? how to know 1 byte receive in device?

@ychuang3
Copy link
Contributor

Do you run dfu-util.exe on the host PC?
If not, what's the host application?

@SANKETMODHE7028
Copy link
Author

Do you run dfu-util.exe on the host PC? If not, what's the host application?

Dear sir,
We have our custom USB communication Utility at PC side, with this PC utility we are communicating our sensor reading to host PC. Our PC utility is implemented by basic byte communication and sending data over 64 byte packet format. Kindly help to check received byte and send byte to host PC utility.

@ychuang3
Copy link
Contributor

What's the USB device class supported by your PC utility?
If it does not support DFU class device , you will never receive class commands.
Does you PC utility found M487?
You log messages are standard transfers done by Windows, not your PC utility.

@SANKETMODHE7028
Copy link
Author

What's the USB device class supported by your PC utility? If it does not support DFU class device , you will never receive class commands. Does you PC utility found M487? You log messages are standard transfers done by Windows, not your PC utility.

Dear sir,
We have our own HMI drivers for our product communication. We have already implemented HMI protocol setup with different controller of NXP, they are working OK with HMI Based PC utility.
Currently we are porting our Nuvoton controller for NXP, hence same HMI protocol is need to be implemented in Nuvoton M487 controller, so that same PC software will support Nuvoton communication also.
Currently we have selected Base code of nuvoton from BSP base as ISP, we have modifed VID and PID and configuration updated in ISP code, with this changes now Nuvoton detecting as HMI port in our PC, now next step is to communicate with PC host for this purpose we need to send and receive byte and packet, can you please explain how we can use ISP existing function to write and read byte from Host PC.
If same HMI protocol not possible with our shortlisted ISP base code then kindly suggest another BSP code which can fullfill our requirment.

@ychuang3
Copy link
Contributor

If you modify PID and VID of any M487 sample code, your PC utility can find it, too.
But, you cannot communicate with each other.
For example, if you modify the mass storage USB device PID and VID, your PC utility can find it, too.
However, they cannot communicate with each other, because you PC utility does not run mass storage class.

So, I am asking what's the USB device class your PC utility is running.
If it is not running DFU class, select ISP_DFU sample is a wrong choice.

If you cannot tell what's the USB device class of you PC utility, we cannot go further.

@SANKETMODHE7028
Copy link
Author

If you modify PID and VID of any M487 sample code, your PC utility can find it, too. But, you cannot communicate with each other. For example, if you modify the mass storage USB device PID and VID, your PC utility can find it, too. However, they cannot communicate with each other, because you PC utility does not run mass storage class.

So, I am asking what's the USB device class your PC utility is running. If it is not running DFU class, select ISP_DFU sample is a wrong choice.

If you cannot tell what's the USB device class of you PC utility, we cannot go further.

Dear sir,
In our last product we used NXP LPC controller and PC side HMI communication done with CDC class. PC utility uses CDC class request to send and receive data from controller.

@ychuang3
Copy link
Contributor

OK, obviously ISP_DFU20 is not CDC.
You can try HSUSBD_VCOM_SerialEmulator sample code. VCOM is a subclass of CDC.
I am not sure your PC utility is running VCOM or not.
Can you connect the NXP device to Windows and then check "Device Manager" to see what type of device presented?

@SANKETMODHE7028
Copy link
Author

OK, obviously ISP_DFU20 is not CDC. You can try HSUSBD_VCOM_SerialEmulator sample code. VCOM is a subclass of CDC. I am not sure your PC utility is running VCOM or not. Can you connect the NXP device to Windows and then check "Device Manager" to see what type of device presented?

ur PC utility is running VCOM or not.

Dear sir,
Will check HSUSBD_VCOM sample code and update you.
Our PC utility using HMI COM port, we have purchased USB distribution for our company, when we connect our product to PC then we install our PC drivers, then in device manager they will represent as "HMI USB device" in USB port list and in driver detail are company name list listed.

For NXP devices different USB drivers are available like HID, CDC and VCOM, when they are connected to PC then they represented as base driver used for testing, we our previous version we shortlisted CDC driver example and modified its endpoints and descriptor as per our HMI driver required and implemented same communication with PC with USB port of NXP controller.

Same communication we need to implement in Nuvoton M487KMCAN controller also, as we have our own HMI drivers and PC utility are already developed, hence we just need to modify Nuvoton M487KMCAN drivers to match our existing HMI protocol.

@ychuang3
Copy link
Contributor

Since it requires installing an additional driver, it seems there must be some custom handshake protocol involved.
Unless you are familiar with the specifics of these protocols, the only method I can think of is to intercept the USB transfers between the NXP device and its PC utility to replicate its transmission scenario.

@SANKETMODHE7028
Copy link
Author

SANKETMODHE7028 commented Feb 26, 2024

Since it requires installing an additional driver, it seems there must be some custom handshake protocol involved. Unless you are familiar with the specifics of these protocols, the only method I can think of is to intercept the USB transfers between the NXP device and its PC utility to replicate its transmission scenario.

this is the flow of data transmission

host (pc utility) ***************************device
9(1 byte data) ---------TX-----------> 9 received

In this case first pc utility sending 1 byte of data to device first.

2 received  <------------------------  2(1 byte data)

after receiving the data device sending 1 byte data to pc.

6(ACK byte) -------------------------> ACK received

data is recieved pc sending ACK bit to device.
then sending to 64 bytes of packet.

                <---------------------------   64 bytes of packet transmit

@ychuang3
Copy link
Contributor

Bu the USB analyzer, can you see the first 9 bytes send from the PC utility?

@SANKETMODHE7028
Copy link
Author

What is the difference between personal laptops and office laptops? operating systems?

https://support.datasci.com/hc/en-us/articles/360058411434-FinePointe-Controller-Fix-Error-USB-Device-Invalid-Configuration-Descriptor

there will be no difference in operating system . but why its not working i dont know sir. i also confused.

@ccli0
Copy link

ccli0 commented Mar 21, 2024

Perhaps you could seek assistance from the IT department in your office, or alternatively, you could try testing on another computer within the office environment.

@ychuang3
Copy link
Contributor

Nu-Link ICE looks fine. So, what's the problem?

actually in my office computer setup is there on that pc its not working . on my personal laptop its working.

sir configDiscriptor not proper set in my case . so what i do now?

Unknown USB Device (configDiscriptor not proper)
==> You should have modified the content of M480 USBD configuration descriptors, including configuration descriptor, interface descriptors, and endpoint descriptors.

The origin setting of M480 USBD example must be fine.
Please show me what modification have you made.

@SANKETMODHE7028
Copy link
Author

Nu-Link ICE looks fine. So, what's the problem?

actually in my office computer setup is there on that pc its not working . on my personal laptop its working.

sir configDiscriptor not proper set in my case . so what i do now?

Unknown USB Device (configDiscriptor not proper) ==> You should have modified the content of M480 USBD configuration descriptors, including configuration descriptor, interface descriptors, and endpoint descriptors.

The origin setting of M480 USBD example must be fine. Please show me what modification have you made.

/*!<USB Configure Descriptor /
#ifdef ICCARM
#pragma data_alignment=4
uint8_t gu8ConfigDescriptor[] =
{
#else
uint8_t gu8ConfigDescriptor[] attribute((aligned(4))) =
{
#endif
LEN_CONFIG, /
bLength /
DESC_CONFIG, /
bDescriptorType /
35, 0x00, /
wTotalLength 0x43 /
0x01, /
bNumInterfaces 2 /
0x01, /
bConfigurationValue /
0x00, /
iConfiguration /
0xC0, /
bmAttributes /
0x50, //0x52 /
MaxPower */

/* INTERFACE descriptor */
LEN_INTERFACE,  /* bLength              */
DESC_INTERFACE, /* bDescriptorType      */
0x00,           /* bInterfaceNumber     */
0x00,           /* bAlternateSetting    */
0x02,           /* bNumEndpoints        */
0xFF,           /* bInterfaceClass      */
0xFF,           /* bInterfaceSubClass   */
0xFF,           /* bInterfaceProtocol   */
0x00,           /* iInterface           */


/* Communication Class Specified INTERFACE descriptor */
    0x05,           /* Size of the descriptor, in bytes */
    0x24,           /* CS_INTERFACE descriptor type */
    0x00,           /* Header functional descriptor subtype */
    0x10, 0x01,     /* Communication device compliant to the communication spec. ver. 1.10 */

    /* Communication Class Specified INTERFACE descriptor */
    0x05,           /* Size of the descriptor, in bytes */
    0x24,           /* CS_INTERFACE descriptor type */
    0x01,           /* Call management functional descriptor */
    0x00,           /* BIT0: Whether device handle call management itself. */
    /* BIT1: Whether device can send/receive call management information over a Data Class Interface 0 */
    0x01,           /* Interface number of data class interface optionally used for call management */

    /* Communication Class Specified INTERFACE descriptor */
    0x04,           /* Size of the descriptor, in bytes */
    0x24,           /* CS_INTERFACE descriptor type */
    0x02,           /* Abstract control management functional descriptor subtype */
    0x00,           /* bmCapabilities       */

    /* Communication Class Specified INTERFACE descriptor */
    0x05,           /* bLength              */
    0x24,           /* bDescriptorType: CS_INTERFACE descriptor type */
    0x06,           /* bDescriptorSubType   */
    0x00,           /* bMasterInterface     */
    0x01,           /* bSlaveInterface0     */


/* ENDPOINT descriptor */
LEN_ENDPOINT,                   /* bLength          */
DESC_ENDPOINT,                  /* bDescriptorType  */
(EP_INPUT | INT_IN_EP_NUM),     /* bEndpointAddress */
EP_INT,                         /* bmAttributes     */
/* wMaxPacketSize */
EPC_MAX_PKT_SIZE & 0x00FF,
((EPC_MAX_PKT_SIZE & 0xFF00) >> 8),
0x01,                           /* bInterval        */

/* INTERFACE descriptor */
LEN_INTERFACE,  /* bLength              */
DESC_INTERFACE, /* bDescriptorType      */
0x01,           /* bInterfaceNumber     */
0x00,           /* bAlternateSetting    */
0x02,           /* bNumEndpoints        */
0x0A,           /* bInterfaceClass      */
0x00,           /* bInterfaceSubClass   */
0x00,           /* bInterfaceProtocol   */
0x00,           /* iInterface           */

/* ENDPOINT descriptor */
LEN_ENDPOINT,                   /* bLength          */
DESC_ENDPOINT,                  /* bDescriptorType  */
0x82,//(EP_INPUT | BULK_IN_EP_NUM),    /* bEndpointAddress */
EP_BULK,                        /* bmAttributes     */
/* wMaxPacketSize */
EPA_MAX_PKT_SIZE & 0x00FF,
((EPA_MAX_PKT_SIZE & 0xFF00) >> 8),
0x00,                           /* bInterval        */

/* ENDPOINT descriptor */
LEN_ENDPOINT,                   /* bLength          */
DESC_ENDPOINT,                  /* bDescriptorType  */
0x03,//(EP_OUTPUT | BULK_OUT_EP_NUM),  /* bEndpointAddress */
EP_BULK,                        /* bmAttributes     */
/* wMaxPacketSize */
EPB_MAX_PKT_SIZE & 0x00FF,
((EPB_MAX_PKT_SIZE & 0xFF00) >> 8),
0x00,                           /* bInterval        */

};

@ychuang3
Copy link
Contributor

I was wrong from the beginning, so I didn't continue reading further.
Why modify the interface number?
Also, the total length hasn't been modified.

35, 0x00, / wTotalLength 0x43 /

0x01, / bNumInterfaces 2 /

When you are modifying the descriptor, you must know what you are doing. I suggest you read the USB spec. Chapter 9 carefully.
Due to the incorrect descriptor content, the PC identifies it as an Unknown device.
Your knowledge is clearly insufficient for this project. You need to do more learning.

@SANKETMODHE7028
Copy link
Author

I was wrong from the beginning, so I didn't continue reading further. Why modify the interface number? Also, the total length hasn't been modified.

35, 0x00, / wTotalLength 0x43 /

0x01, / bNumInterfaces 2 /

When you are modifying the descriptor, you must know what you are doing. I suggest you read the USB spec. Chapter 9 carefully. Due to the incorrect descriptor content, the PC identifies it as an Unknown device. Your knowledge is clearly insufficient for this project. You need to do more learning.

actually i compairing with my old project thats whay.

@SANKETMODHE7028
Copy link
Author

I was wrong from the beginning, so I didn't continue reading further. Why modify the interface number? Also, the total length hasn't been modified.

35, 0x00, / wTotalLength 0x43 /

0x01, / bNumInterfaces 2 /

When you are modifying the descriptor, you must know what you are doing. I suggest you read the USB spec. Chapter 9 carefully. Due to the incorrect descriptor content, the PC identifies it as an Unknown device. Your knowledge is clearly insufficient for this project. You need to do more learning.

actually i compairing with my old project thats whay.

Capture3

@SANKETMODHE7028
Copy link
Author

SANKETMODHE7028 commented Mar 21, 2024

I was wrong from the beginning, so I didn't continue reading further. Why modify the interface number? Also, the total length hasn't been modified.

35, 0x00, / wTotalLength 0x43 /

0x01, / bNumInterfaces 2 /

When you are modifying the descriptor, you must know what you are doing. I suggest you read the USB spec. Chapter 9 carefully. Due to the incorrect descriptor content, the PC identifies it as an Unknown device. Your knowledge is clearly insufficient for this project. You need to do more learning.

actually i compairing with my old project thats whay.

Capture3

Capture4
now its working

@SANKETMODHE7028
Copy link
Author

why its not showing usb virtual com ? its showing (COM4)

@ychuang3
Copy link
Contributor

Why isn't this a virtual COM?

@SANKETMODHE7028
Copy link
Author

good morning sir ,

now how to recieve 1 byte from host? and how to checking this receive or not?

@SANKETMODHE7028
Copy link
Author

Why isn't this a virtual COM?

hello sir ,

our pc utility only understand USB HMI DEVICE . now i am used VCOM so its showing me an error .its showing USB HMI device not connected.

before that i am using DFU in that case its fine.
IMG_20240322_170413

@ychuang3
Copy link
Contributor

Neither of DFU and VCOM is suitable for this utility.
DFU is fine? No, it cannot work, right?
You must modify the USB device firmware, starting with the descriptor modifications.

Before proceeding, I would like to ask:

  1. Do you have a physical 'HMI USB device' that can be connected to this utility?
  2. Do you have any documentation related to the HMI USB device? It should at least include an example of the descriptor.

If you don't have either of the above, please obtain at least one of them.

@SANKETMODHE7028
Copy link
Author

Neither of DFU and VCOM is suitable for this utility. DFU is fine? No, it cannot work, right? You must modify the USB device firmware, starting with the descriptor modifications.

Before proceeding, I would like to ask:

  1. Do you have a physical 'HMI USB device' that can be connected to this utility?
  2. Do you have any documentation related to the HMI USB device? It should at least include an example of the descriptor.

If you don't have either of the above, please obtain at least one of them.

hcc_u8 usb_device_descriptor[] =
{
(hcc_u8)0x12u, // bLength -- Size of the Descriptor in Bytes (18 bytes)
(hcc_u8)STDD_DEVICE, // bDescriptorType -- Device Descriptor (0x01)
(hcc_u8)USB_VER, // bcdUSB -- USB Specification Number which device complies too.
(hcc_u8)((USB_VER) >> 8),
(hcc_u8)0xFF, // bDeviceClass -- Class Code (Assigned by USB Org)
// if equal to Zero, each interface specifies it’s own class code
// If equal to 0xFF, the class code is vendor specified.
// Otherwise field is valid Class Code.
(uint8)0xFF, // bDeviceSubClass -- Subclass Code (Assigned by USB Org)
(uint8)0xFF, // bDeviceProtocol -- Protocol Code (Assigned by USB Org)
(uint8)EP0_PACKET_SIZE, // bMaxPacketSize -- Maximum Packet Size for Zero Endpoint.
// Valid Sizes are 8, 16, 32, 64
(hcc_u8)(USB_VID), (hcc_u8)((USB_VID) >> 8),// idVendor -- Vendor ID (Assigned by USB Org)
(hcc_u8)(USB_PID), (hcc_u8)((USB_PID) >> 8),// idProduct -- Product ID (Assigned by Manufacturer)
(hcc_u8)(USB_REL), (hcc_u8)((USB_REL) >> 8),// bcdDevice -- Device Release Number
(hcc_u8)1, // iManufacturer -- Index of Manufacturer String Descriptor
(hcc_u8)2, // iProduct -- Index of Product String Descriptor
(hcc_u8)3, // iSerialNumber -- Index of Serial Number String Descriptor
(hcc_u8)1 // bNumConfigurations -- Number of Possible Configurations
};

//=========================================================================================================================
//=========================================================================================================================

hcc_u8 usb_config_descriptor[] =
{
// Configuration Descriptor
(hcc_u8)0x09u, // bLength -- Size of Descriptor in Bytes
(hcc_u8)STDD_CONFIG, // bDescriptorType -- Configuration Descriptor (0x02)
(hcc_u8)(35), (hcc_u8)(0), // wTotalLength -- Total length in bytes of data returned
(hcc_u8)0x01u, // bNumInterfaces -- Number of Interfaces
(hcc_u8)0x01u, // bConfigurationValue -- Value to use as an argument to select this configuration
(hcc_u8)0x0u, // iConfiguration -- Index of String Descriptor describing this configuration
(hcc_u8)BM_ATTRIBUTES, // bmAttributes -- D7 Reserved, set to 1. (USB 1.0 Bus Powered)
// D6 Self Powered
// D5 Remote Wakeup
// D4..0 Reserved, set to 0.
(hcc_u8)MAX_POWER, // bMaxPower -- Maximum Power Consumption in 2mA units

// OTG Descriptor
(hcc_u8)0x03u, 
(hcc_u8)0x09u, 
(hcc_u8)0x00u,


// Interface Descriptor
(hcc_u8)0x09u,								// bLength -- Size of Descriptor in Bytes (9 Bytes)
(hcc_u8)STDD_INTERFACE,						// bDescriptorType -- Interface Descriptor (0x04)
(hcc_u8)0x00u,								// bInterfaceNumber -- Number of Interface
(hcc_u8)0x00u,								// bAlternateSetting -- Value used to select alternative setting
(hcc_u8)0x02u,								// bNumEndpoints -- Number of Endpoints used for this interface
(hcc_u8)0xFF,								// bInterfaceClass -- Class Code (Assigned by USB Org)
(hcc_u8)0xFF,								// bInterfaceSubClass -- Subclass Code (Assigned by USB Org)
(hcc_u8)0xFF,								// bInterfaceProtocol -- Protocol Code (Assigned by USB Org)
(hcc_u8)0x00,								// iInterface -- Index of String Descriptor Describing this interface

//Endpoint descriptor 1
(hcc_u8)0x07,								// bLength -- Size of Descriptor in Bytes (7 bytes)
STDD_ENDPOINT,								// bDescriptorType -- Endpoint Descriptor (0x05)
(hcc_u8)0x82,								// bEndpointAddress -- Endpoint Address
											// Bits 0..3b Endpoint Number.
											// Bits 4..6b Reserved. Set to Zero
											// Bits 7 Direction 0 = Out, 1 = In (Ignored for Control Endpoints)
BULK_TRANSFER,								// bmAttributes -- Bits 0..1 Transfer Type
											// 00 = Control
											// 01 = Isochronous
											// 10 = Bulk
											// 11 = Interrupt
											// Bits 2..7 are reserved. If Isochronous endpoint,
											// Bits 3..2 = Synchronisation Type (Iso Mode)
											// 00 = No Synchonisation
											// 01 = Asynchronous
											// 10 = Adaptive
											// 11 = Synchronous
											// Bits 5..4 = Usage Type (Iso Mode)
											// 00 = Data Endpoint
											// 01 = Feedback Endpoint
											// 10 = Explicit Feedback Data Endpoint
											// 11 = Reserved
EP0_PACKET_SIZE, (hcc_u8)0x00,				// wMaxPacketSize -- Maximum Packet Size this endpoint is capable of sending or receiving
(hcc_u8)0x00,								// bInterval -- Interval for polling endpoint data transfers. 
											// Value in frame counts. Ignored for Bulk & Control Endpoints. Isochronous must 
											// equal 1 and field may range from 1 to 255 for interrupt endpoints.

//Endpoint descriptor 3
(hcc_u8)0x07,								// bLength -- Size of Descriptor in Bytes (7 bytes)
STDD_ENDPOINT,								// bDescriptorType -- Endpoint Descriptor (0x05)
(hcc_u8)0x03,								// bEndpointAddress -- Endpoint Address
											// Bits 0..3b Endpoint Number.
											// Bits 4..6b Reserved. Set to Zero
											// Bits 7 Direction 0 = Out, 1 = In (Ignored for Control Endpoints)
BULK_TRANSFER,								// bmAttributes -- Bits 0..1 Transfer Type
											// 00 = Control
											// 01 = Isochronous
											// 10 = Bulk
											// 11 = Interrupt
											// Bits 2..7 are reserved. If Isochronous endpoint,
											// Bits 3..2 = Synchronisation Type (Iso Mode)
											// 00 = No Synchonisation
											// 01 = Asynchronous
											// 10 = Adaptive
											// 11 = Synchronous
											// Bits 5..4 = Usage Type (Iso Mode)
											// 00 = Data Endpoint
											// 01 = Feedback Endpoint
											// 10 = Explicit Feedback Data Endpoint
											// 11 = Reserved
EP0_PACKET_SIZE, (hcc_u8)0x00,				// wMaxPacketSize -- Maximum Packet Size this endpoint is capable of sending or receiving
(hcc_u8)0x00								// bInterval -- Interval for polling endpoint data transfers. Value in frame counts. 
											// Ignored for Bulk & Control Endpoints. Isochronous must equal 1 and field may range 
											// from 1 to 255 for interrupt endpoints.

};

hello sir , this is working USB HMI device of our old device of MCF controller . refference to this we are modifying on NUVOTON M487 .

@SANKETMODHE7028
Copy link
Author

uint8_t gu8DeviceDescriptor[] =
{
#else
uint8_t gu8DeviceDescriptor[] attribute((aligned(4))) =
{
#endif
(uint8_t)LEN_DEVICE, /* bLength /
(uint8_t)DESC_DEVICE, /
bDescriptorType /
(uint8_t)USB_VER, // bcdUSB -- USB Specification Number which device complies too.
(uint8_t)((USB_VER) >> 8),//0x00, 0x02, /
bcdUSB /
(uint8_t)0xFF, /
bDeviceClass : See interface /
(uint8_t)0xFF, /
bDeviceSubClass : See interface*/
(uint8_t)0xFF, /* bDeviceProtocol : See interface /
(uint8_t)EP0_PACKET_SIZE, //(uint8_t)CEP_MAX_PKT_SIZE, /
bMaxPacketSize0 /
/
idVendor /
(uint8_t)USBD_VID & 0x00FF,
(uint8_t)((USBD_VID & 0xFF00) >> 8),
/
idProduct /
(uint8_t)USBD_PID & 0x00FF,
(uint8_t)((USBD_PID & 0xFF00) >> 8),
(uint8_t)USBD_REL & 0xFF,///0x00, /
bcdDevice*/
(uint8_t)(USBD_REL & 0xFF) >> 8,
(uint8_t)0x01, /* iManufacturer : index of string Manufacturer /
(uint8_t)0x02, /
iProduct : index of string descriptor of product*/
(uint8_t)0x03, /* iSerialNumber : index of string serial number*/
(uint8_t)0x01 /*bNumConfigurations */
};

#define u8_usbConfigDescriptorDFU_LENGTH (18 + (9 * 1))

/*!<USB Configure Descriptor /
#ifdef ICCARM
#pragma data_alignment=4
uint8_t gu8ConfigDescriptor[] =
#else
uint8_t gu8ConfigDescriptor[] attribute((aligned(4))) =
#endif
{
(uint8_t)0x09, /
bLength: Configuation Descriptor size /
(uint8_t)STDD_CONFIG,//0x02, /
bDescriptorType: Configuration /
(uint8_t)u8_usbConfigDescriptorDFU_LENGTH, /
wTotalLength: Bytes returned /
(uint8_t)0x00,
(uint8_t)0x01, /
bNumInterfaces: 1 interface /
(uint8_t)0x01, /
bConfigurationValue: /
(uint8_t)0x00, /
iConfiguration: /
(uint8_t)0xC0, /// 0x80, /
bmAttributes: /
(uint8_t)0x50, // 0x32, /
MaxPower 100 mA /
/
09 */

// OTG Descriptor

// 0x03,
// 0x09,
// 0x00,

/************ Descriptor of DFU interface 0 Alternate setting 0 *********/
(uint8_t)0x09u,   /* bLength: Interface Descriptor size */
(uint8_t)0x04u,   /* bDescriptorType: */
(uint8_t)0x00u,   /* bInterfaceNumber: Number of Interface */
(uint8_t)0x00u,   /* bAlternateSetting: Alternate setting */
(uint8_t)0x00u,// 0x02,   /* bNumEndpoints*/
(uint8_t)0xFF,  //0xFE,   /* bInterfaceClass: DFU */
(uint8_t)0xFF,  //0x01,   /* bInterfaceSubClass */
(uint8_t)0xFF,  //0x02,   /* nInterfaceProtocol, switched to 0x02 while in dfu_mode */
(uint8_t)0x00u,   /* iInterface: */



/******************** DFU Functional Descriptor********************/
0x07, //0x09,   /*blength = 7 Bytes*/
0x05, // 0x21,   /* DFU Functional Descriptor*/
0x82,			// bEndpointAddress -- Endpoint Address
0x02, // 0x0B,   /*bmAttributes, bitCanDnload | bitCanUpload */
0xFF,   /*DetachTimeOut= 255 ms*/
0x00,

// (TRANSFER_SIZE & 0x00FF),(TRANSFER_SIZE & 0xFF00) >> 8, /* TransferSize = 1024 Byte*/
TRANSFER_SIZE, (uint8_t)0x00,
0x10, /* bcdDFUVersion = 1.1 */
0x01,

///EP DISCRIPTOR 3
(uint8_t)0x07,								// bLength -- Size of Descriptor in Bytes (7 bytes)
 0x05,        ///STDD_ENDPOINT,								// bDescriptorType -- Endpoint Descriptor (0x05)
(uint8_t)0x03,								// bEndpointAddress -- Endpoint Address


0x2 ,//BULK_TRANSFER
EP0_PACKET_SIZE, (uint8_t)0x00,				// wMaxPacketSize -- Maximum Packet Size this endpoint is capable of sending or receiving
(uint8_t)0x00								// bInterval -- Interval for polling endpoint data transfers. Value in frame counts.

};

this is modified DFU driver in this case USB HMI DEVICE detected fine.

@ychuang3
Copy link
Contributor

ISP_DFU_20 only uses control transfer for communication and does not utilize bulk transfer. However, the HMI USB uses bulk transfer (as indicated by the descriptor). Therefore, without modifying the DFU, it cannot function properly.

Modifying only the PID/VID and class code merely deceives the HMI USB driver on the PC side. If the same modifications are made to the VCOM sample code descriptor, the HMI USB driver will make the same determination.

Forget about ISP_DFU_20; you cannot use it to implement an HMI USB device unless you have the ability to write the bulk transfer part yourself.

I still recommend using the VCOM example code, as it utilizes bulk transfer, which is more favorable for modification into an HMI USB device. First, modify the VCOM descriptor to be exactly the same as the HMI USB device, note that it must be identical. Then see what happens next.

@SANKETMODHE7028
Copy link
Author

ISP_DFU_20 only uses control transfer for communication and does not utilize bulk transfer. However, the HMI USB uses bulk transfer (as indicated by the descriptor). Therefore, without modifying the DFU, it cannot function properly.

Modifying only the PID/VID and class code merely deceives the HMI USB driver on the PC side. If the same modifications are made to the VCOM sample code descriptor, the HMI USB driver will make the same determination.

Forget about ISP_DFU_20; you cannot use it to implement an HMI USB device unless you have the ability to write the bulk transfer part yourself.

I still recommend using the VCOM example code, as it utilizes bulk transfer, which is more favorable for modification into an HMI USB device. First, modify the VCOM descriptor to be exactly the same as the HMI USB device, note that it must be identical. Then see what happens next.

i modify in vcom interface discriptor as it same as old code . but i got error.

sir, i have to change in VCOM transfer file also?

@ychuang3
Copy link
Contributor

ISP_DFU_20 only uses control transfer for communication and does not utilize bulk transfer. However, the HMI USB uses bulk transfer (as indicated by the descriptor). Therefore, without modifying the DFU, it cannot function properly.
Modifying only the PID/VID and class code merely deceives the HMI USB driver on the PC side. If the same modifications are made to the VCOM sample code descriptor, the HMI USB driver will make the same determination.
Forget about ISP_DFU_20; you cannot use it to implement an HMI USB device unless you have the ability to write the bulk transfer part yourself.
I still recommend using the VCOM example code, as it utilizes bulk transfer, which is more favorable for modification into an HMI USB device. First, modify the VCOM descriptor to be exactly the same as the HMI USB device, note that it must be identical. Then see what happens next.

i modify in vcom interface discriptor as it same as old code . but i got error.

sir, i have to change in VCOM transfer file also?

No, please read my comments. I think it's clear enough.
Please modify the descitpor as just a clone of HMI USB device.
You have the descriptor dump of the exact HMI USB device, right?

@SANKETMODHE7028
Copy link
Author

ISP_DFU_20 only uses control transfer for communication and does not utilize bulk transfer. However, the HMI USB uses bulk transfer (as indicated by the descriptor). Therefore, without modifying the DFU, it cannot function properly.
Modifying only the PID/VID and class code merely deceives the HMI USB driver on the PC side. If the same modifications are made to the VCOM sample code descriptor, the HMI USB driver will make the same determination.
Forget about ISP_DFU_20; you cannot use it to implement an HMI USB device unless you have the ability to write the bulk transfer part yourself.
I still recommend using the VCOM example code, as it utilizes bulk transfer, which is more favorable for modification into an HMI USB device. First, modify the VCOM descriptor to be exactly the same as the HMI USB device, note that it must be identical. Then see what happens next.

i modify in vcom interface discriptor as it same as old code . but i got error.
sir, i have to change in VCOM transfer file also?

No, please read my comments. I think it's clear enough. Please modify the descitpor as just a clone of HMI USB device. You have the descriptor dump of the exact HMI USB device, right?

uint8_t gu8OtherConfigDescriptorFS[] =
uint8_t gu8OtherConfigDescriptorHS[] =
uint8_t gu8ConfigDescriptorFS[] =
uint8_t gu8OtherConfigDescriptorFS[] =

This 4 configuDiscriptors in this code . so in this case i have to modify all of these? ya only one (uint8_t gu8OtherConfigDescriptorFS[] =) ?

actualy first discriptor i modify as same as HMI USB Device but its showing me USB VIRTUAL COM with yellow (error mark)
**

@ychuang3
Copy link
Contributor

ychuang3 commented Apr 1, 2024

Please make all the descriptors identical, this should not be difficult.
I've mentioned the word 'clone' several times.

@SANKETMODHE7028
Copy link
Author

Please make all the descriptors identical, this should not be difficult. I've mentioned the word 'clone' several times.

thanks sir, Its showing me HMI USB Device in device manager . but pc utility not understanding this is HMI USB Device. pc utility showing me HMI USB Device not connected.

@ychuang3
Copy link
Contributor

ychuang3 commented Apr 3, 2024

Just as you cloned the descriptor of the HMI USB device, next, you need to clone the behavior of the HMI USB device. First, use a USB analyzer to log the normal transfer content of the HMI USB device, then log the transfer content of the M487, and compare where the differences occur in which transfer. Begin modifications from there.

@SANKETMODHE7028
Copy link
Author

Just as you cloned the descriptor of the HMI USB device, next, you need to clone the behavior of the HMI USB device. First, use a USB analyzer to log the normal transfer content of the HMI USB device, then log the transfer content of the M487, and compare where the differences occur in which transfer. Begin modifications from there.

hello sir , in device manager it will showing HMI USB Device . But in USB analyser it will showing USB VIRTUAL COM . so pc utility showing HMI USB Device not connected.

@ychuang3
Copy link
Contributor

ychuang3 commented Apr 5, 2024

Not changing a set of descriptors would make it another device. Descriptors only describe the device, but the actual behavior of the device remains unchanged. This should be quite obvious and not difficult to understand. You must realize that you still have a lot to modify.
In my previous response, I have explained what needs to be done next. Please read and understand it before proceeding further.

@SANKETMODHE7028
Copy link
Author

CaptureHMI
this is the old HMI USB Device communication . first bit 9 sending by host . then 2 sending by device . then host ACK the bit 6 sending to device . and then 64 byte of packet sending one by one.

@ychuang3
Copy link
Contributor

ychuang3 commented Apr 5, 2024

Please compare the step by step log of your M487 device with the golden sample (standard USB HMI device), and find out the first differnet transfer. I guess it can be a vendor specific control transfer.

@SANKETMODHE7028
Copy link
Author

Please compare the step by step log of your M487 device with the golden sample (standard USB HMI device), and find out the first differnet transfer. I guess it can be a vendor specific control transfer.

standerd request in both devices are same. but how to check its vendor specific controll transfer?

@ychuang3
Copy link
Contributor

ychuang3 commented Apr 6, 2024

Please compare the USB analyzer logs of both and identify the first differing transfer.
For this transfer, you need to instruct the M487 to respond in the same way as a USB HMI device.

@SANKETMODHE7028
Copy link
Author

SANKETMODHE7028 commented Oct 21, 2024

hello sir i got one issue. i worked on 8051series ML51SD1AE controller

Here is my task is to blink LED
I use 4 GPIO pin and 4 led are there.
in these case

first line high so LED on and then other 3 lines going to open drain mode.
. 2nd line high so LED on then 1st ,3rd,and 4th pin going to open drain mode.
3rd line high so LED on then first 2 and 4th pin going to open drain mode.
4th pin high so LED on then first 3 pin going to open drain mode .
this is 4 cases works fine but one issue is generated . if pin going to open drain mode at that time the voltage 0.5 to 0.7 varrying .
i also checked in push pull , pull down/up mode then also pin having something voltage are there. what i do to avoid these error ?

@ychuang3
Copy link
Contributor

8051 series ML51SD1AE controller?
This is for the M480 series.

Please submit your question in the correct place:
https://github.com/OpenNuvoton/ML51_BSP_KEIL/issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants