我是卓波,很高兴你来看我的博客。
系列文章:
stm32+lwip(一):使用STM32CubeMX生成项目
很多时候,我们想直接获取以太网帧的数据或者直接发送以太网帧数据。在使用STM32CubeMX生成的工程当中,有两个函数就是直接跟以太网通信有关:
1 /** 2 * This function should do the actual transmission of the packet. The packet is 3 * contained in the pbuf that is passed to the function. This pbuf 4 * might be chained. 5 * 6 * @param netif the lwip network interface structure for this ethernetif 7 * @param p the MAC packet to send (e.g. IP packet including MAC addresses and type) 8 * @return ERR_OK if the packet could be sent 9 * an err_t value if the packet couldn't be sent 10 * 11 * @note Returning ERR_MEM here if a DMA queue of your MAC is full can lead to 12 * strange results. You might consider waiting for space in the DMA queue 13 * to become availale since the stack doesn't retry to send a packet 14 * dropped because of memory failure (except for the TCP timers). 15 */ 16 17 static err_t low_level_output(struct netif *netif, struct pbuf *p)
1 /** 2 * Should allocate a pbuf and transfer the bytes of the incoming 3 * packet from the interface into the pbuf. 4 * 5 * @param netif the lwip network interface structure for this ethernetif 6 * @return a pbuf filled with the received packet (including MAC header) 7 * NULL on memory error 8 */ 9 static struct pbuf * low_level_input(struct netif *netif)
这两个函数就是实现与以太网的通信,本来需要我们自己实现。现在STM32CubeMX已经帮我们实现好,因此收发以太网数据可以通过调用或修改这两个函数实现。
发送测试
1 /** 2 ***************************************************************************** 3 * @file ethernet_test.c 4 * @author Zorb 5 * @version V1.0.0 屔е屔е/wV6GW*&/R"V6ń((rB8rZ;>GV6Os>G?V6ǖ>kr'j((ń(v&r$&ON|((е鍕zss"GjZk&"G&ON|(ńш乩屔((