Stm32CubeMX 版本:6.8.1
硬件库版本:STM32Cube FW_H7 V1.11.0
usart.c#include <stdio.h>
#if 1//标准库需要的支持函数
struct __FILE
{ int handle;
}; FILE __stdout; //定义_sys_exit()以避免使用半主机模式
void _sys_exit(int x)
{ x = x;
} //重定义fputc函数
int fputc(int ch, FILE *f)
{ while((USART1->ISR&0X40)==0);//循环发送,直到发送完毕 USART1->TDR=(uint8_t)ch; return ch;
}
#endif cc.h/* Define random number generator function */
#define LWIP_RAND() ((u32_t)rand())#if defined ( __ICCARM__ ) /*!< IAR Compiler */
#pragma location = 0x30000400
extern unsigned char memp_memory_RX_POOL_base[];#elif defined ( __CC_ARM ) /* MDK ARM Compiler */
extern unsigned char __attribute__((at(0x30000400))) memp_memory_RX_POOL_base[];#elif defined ( __GNUC__ ) /* GNU Compiler */
extern unsigned char memp_memory_RX_POOL_base[] __attribute__((section(".Rx_PoolSection")));
#endif
#endif /* __CC_H__ */ethernetif.c/* Accept broadcast address and ARP traffic *//* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */#if LWIP_ARPnetif->flags |= NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP;#elsenetif->flags |= NETIF_FLAG_BROADCAST;#endif /* LWIP_ARP *//* USER CODE BEGIN PHY_PRE_CONFIG */HAL_GPIO_WritePin(ETH_RESET_GPIO_Port,ETH_RESET_Pin,GPIO_PIN_RESET);HAL_Delay(50);HAL_GPIO_WritePin(ETH_RESET_GPIO_Port,ETH_RESET_Pin,GPIO_PIN_SET);HAL_Delay(50);
/* USER CODE END PHY_PRE_CONFIG *//* Set PHY IO functions */LAN8742_RegisterBusIO(&LAN8742, &LAN8742_IOCtx);/* Initialize the LAN8742 ETH PHY */LAN8742_Init(&LAN8742);if(linkchanged){/* Get MAC Config MAC */HAL_ETH_GetMACConfig(&heth, &MACConf);MACConf.DuplexMode = duplex;MACConf.Speed = speed;HAL_ETH_SetMACConfig(&heth, &MACConf);//HAL_ETH_Start(&heth);HAL_ETH_Start_IT(&heth);netif_set_up(netif);netif_set_link_up(netif);}lwip.c 添加函数一下函数 注释掉it.c void ETH_IRQHandler(void)void ETH_IRQHandler(void)
{/* USER CODE BEGIN ETH_IRQn 0 */ethernetif_input(&gnetif);/* USER CODE END ETH_IRQn 0 */HAL_ETH_IRQHandler(&heth);/* USER CODE BEGIN ETH_IRQn 1 *//* USER CODE END ETH_IRQn 1 */
}main.cvoid SystemClock_Config(void)
{RCC_OscInitTypeDef RCC_OscInitStruct = {0};RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};/** Supply configuration update enable*/HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);/** Configure the main internal regulator output voltage*/__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE0);while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}__HAL_RCC_D2SRAM1_CLK_ENABLE();__HAL_RCC_D2SRAM2_CLK_ENABLE();/** Initializes the RCC Oscillators according to the specified parameters* in the RCC_OscInitTypeDef structure.MX_GPIO_Init();
MX_USART1_UART_Init();
HAL_Delay(500);
MX_LWIP_Init();
遗留问题
FILE __stdout; 不能注释,未找到原因,如知道原因,私信告诉小弟一声,谢谢。
链接:https://pan.baidu.com/s/1CGMPRxnMNRE2bVL5F0r97Q
提取码:qr2o