Teensy 4.1 send Ethernet RAW data

UncleMa

New member
Dear all,

I am working on a project which is using a WizNET Ethernet shield to send data in 802.1Q format. But the data to transfer has grown a lot (> 1500 kByte per Second) and as a result the Ethernet transfer rate has become to slow (limiting factor seems to be the SPI interface). That's why I would like to use the on-board Ethernet interface.

My question now: How can I send Ethernet data in RAW format by using the Teensy 4.1 on-board Ethernet? The NativeEthernet library is great for TCP or UDP, but I found no RAW transfer mode.

A simplified example how 802.1Q data has been sent over Ethernet until now by using the WizNET ethernet shield (using the MACRAW mode):

Code:
  /*
  | Destination MAC | Source MAC      | 802.1Q Header | EthType | Payload    |
  | 0x1A1B1C1D1E1F  | 0x2A2B2C2D2E2F  | 0x8100 0x8000 | 0x8146  | 0xCAFECAFE |
  */
  byte mybuffer[] = { 0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x81,0x00,0x80,0x00,0x81,0x46,0xCA,0xFE,0xCA,0xFE};
  SOCKET socket;

  W5100.init();
  W5100.writeSnMR(socket, SnMR::MACRAW); 
  W5100.execCmdSn(socket, Sock_OPEN);

  W5100.send_data_processing(socket, mybuffer, sizeof(mybuffer));
  W5100.execCmdSn(socket, Sock_SEND_MAC);

Any help will be appreciated!

Greetings,
M.


PS: I've been using Teensy 4.1 for over a year now and I love it - you did a great job!
 
You could probably adapt the initialization code from either the NativeEthernet or QNEthernet libraries and just utilize the send function, taking into account some of the state management as necessary. I know in QNEthernet, the raw stuff happens in lwip_t41.h and lwip_t41.c. Do you just need output?
 
Alternatively, do you just need to enable VLAN tagging? lwIP, I believe, supports that, and I could look into how to add that to QNEthernet.
 
Thanks a lot for your reply, Shawn! Yes it is a one-way communication (only sending, no data receiving).

All right then, I will try to adapt the QNEthernet library for my purposes. I think the best solution will be to activate ETHARP_SUPPORT_VLAN in the lwIP library in order to support VLAN tagging...
 
Yep, that’s the one, and also LWIP_HOOK_VLAN_SET. See ethernet.c:ethernet_output(). Define those in lwipopts.h. (You may already know this; just stating it for future readers.)
 
@UncleMa I just added an `Ethernet.sendRaw(frame, len)` function to the library. Watch for that when next I push "v0.10.0-snapshot".
 
The function signature of `LWIP_HOOK_VLAN_SET` can be found here:
https://github.com/ssilverman/QNEth...604d5b5f209366f17247c8ac/src/lwip/opt.h#L3024

See also `LWIP_HOOK_VLAN_SET` instructions in lwip/opt.h and its use in netif/ethernet.c. Just do a search for that word.
For example: https://github.com/ssilverman/QNEth...b5f209366f17247c8ac/src/netif/ethernet.c#L277

To implement: Set `LWIP_HOOK_VLAN_SET` to the name of your function in lwipopts.h. For example:
Code:
#define LWIP_HOOK_VLAN_SET(netif, p, src, dst, eth_type) my_hook_vlan_set((netif), (p), (src), (dst), (eth_type))
s32_t my_hook_vlan_set(struct netif* netif, struct pbuf* pbuf, const struct eth_addr* src, const struct eth_addr* dst, u16_t eth_type);

Then you need to implement the function somewhere in your code.
 
Last edited:
Can you be more specific? I don't understand the question. Do you mean just how you enable VLAN things in general?

Update: Did you mean "setting up VLAN"?
 
Back
Top