#include "stm32h7xx_hal.h"
#include "lwip.h"
ETH_HandleTypeDef heth;
ETH_TxPacketConfig TxConfig;
void SystemClock_Config(void);
void MX_GPIO_Init(void);
void MX_ETH_Init(void);
void Error_Handler(void);
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_ETH_Init();
while (1)
{
// 用户代码
}
}
void MX_ETH_Init(void)
{
heth.Instance = ETH;
heth.Init.MACAddr = macaddress;
heth.Init.MediaInterface = HAL_ETH_RMII_MODE;
heth.Init.RxMode = ETH_RXPOLLING_MODE;
heth.Init.ChecksumMode = ETH_CHECKSUM_BY_HARDWARE;
heth.Init.PhyAddress = DP83848_PHY_ADDRESS;
if (HAL_ETH_Init(&heth) != HAL_OK)
{
Error_Handler();
}
memset(&TxConfig, 0, sizeof(ETH_TxPacketConfig));
TxConfig.Attributes = ETH_TX_PACKETS_FEATURES_CSUM | ETH_TX_PACKETS_FEATURES_CRCPAD;
TxConfig.ChecksumCtrl = ETH_CHECKSUM_IPHDR_PAYLOAD_INSERT_PHDR_CALC;
TxConfig.CRCPadCtrl = ETH_CRC_PAD_INSERT;
}
|