Skip to content

Commit ae89bd7

Browse files
authored
Merge pull request #50 from ARMmbed/usb
Add USBCDC_ECM example
2 parents 9d789b8 + c972621 commit ae89bd7

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-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: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2019 ARM Limited. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
* Licensed under the Apache License, Version 2.0 (the License); you may
5+
* not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "mbed.h"
18+
#include "USBCDC_ECM.h"
19+
20+
/* Ethernet II frame */
21+
typedef struct {
22+
uint8_t dst_mac[6];
23+
uint8_t src_mac[6];
24+
uint16_t eth_type;
25+
char payload[12];
26+
} packet_t;
27+
28+
static packet_t packet = {
29+
.dst_mac = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
30+
.src_mac = {0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc},
31+
.eth_type = 0xaaaa, /* unused EtherType */
32+
.payload = "Hello world"
33+
};
34+
35+
USBCDC_ECM ecm;
36+
37+
int main()
38+
{
39+
while (true) {
40+
ecm.send((uint8_t *)&packet, sizeof(packet));
41+
wait(1.0);
42+
}
43+
}

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)