Skip to content

Commit 6eecf43

Browse files
committed
Add USBCDC_ECM example
1 parent 92f55ad commit 6eecf43

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

USB/USBCDC_ECM/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## USBCDC_ECM example
2+
3+
The example sends an Ethernet frame that carries "Hello world" payload with a custom EtherType to the host PC. You can capture the frame by using a program called "Wireshark":
4+
5+
1. Flash the board, and ensure the target's USB is plugged into the PC.
6+
2. Open Wireshark.
7+
3. Click **Capture > Options** to select the correct capture interface.
8+
4. Click **Capture > Start**.
9+
5. Click captured packet from source address 12:34:56:78:9a:bc to see the "Hello world" payload.
10+
11+
**Note:** Because Windows doesn't provide native support for the USB CDC-ECM model, you must use third party drivers to use this class on Windows.

USB/USBCDC_ECM/main.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include "mbed.h"
2+
#include "USBCDC_ECM.h"
3+
4+
/* Ethernet II frame */
5+
typedef struct {
6+
uint8_t dst_mac[6];
7+
uint8_t src_mac[6];
8+
uint16_t eth_type;
9+
char payload[12];
10+
} packet_t;
11+
12+
static packet_t packet = {
13+
.dst_mac = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
14+
.src_mac = {0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc},
15+
.eth_type = 0xaaaa, /* unused EtherType */
16+
.payload = "Hello world"
17+
};
18+
19+
USBCDC_ECM ecm;
20+
21+
int main()
22+
{
23+
while (true) {
24+
ecm.send((uint8_t *)&packet, sizeof(packet));
25+
wait(1.0);
26+
}
27+
}

USB/USBCDC_ECM/mbed-os.lib

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/ARMmbed/mbed-os/#0063e5de32fc575f061244c96ac60c41c07bd2e6

0 commit comments

Comments
 (0)