#include "main.h" #include "ethernetif.h" #include "lwip/netif.h" #include "lwip/tcpip.h" #include "app_ethernet.h" #include "log.h" #include "bsp_fsmc_sram.h" #include "bsp_fsmc_nandflash.h" #include "nandflash.h" #include "myFile.h" #include "string.h" /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ struct netif gnetif; /* network interface structure */ /* Semaphore to signal Ethernet Link state update */ osSemaphoreId Netif_LinkSemaphore = NULL; /* Ethernet link thread Argument */ struct link_str link_arg; /* Private function prototypes -----------------------------------------------*/ static void SystemClock_Config(void); static void StartThread(void const * argument); static void ToggleLed4(void const * argument); static void BSP_Config(void); static void Netif_Config(void); /* Private functions ---------------------------------------------------------*/ /** * @brief Main program * @param None * @retval None */ int main(void) { /* STM32F2xx HAL library initialization: - Configure the Flash prefetch, instruction and Data caches - Configure the Systick to generate an interrupt each 1 msec - Set NVIC Group Priority to 4 - Global MSP (MCU Support Package) initialization */ HAL_Init(); /* Configure the system clock to 120 MHz */ SystemClock_Config(); MX_FSMC_SRAM_Init(); NAND_Init(); /* Init task */ osThreadDef(Start, StartThread, osPriorityNormal, 0, configMINIMAL_STACK_SIZE * 4); osThreadCreate (osThread(Start), NULL); /* Start scheduler */ osKernelStart(); /* We should never get here as control is now taken by the scheduler */ for( ;; ); } /** * @brief Start Thread * @param argument not used * @retval None */ static void StartThread(void const * argument) { /* Initialize LCD and LEDs */ BSP_Config(); log_init(); /* Create tcp_ip stack thread */ tcpip_init(NULL, NULL); /* Initialize the LwIP stack */ Netif_Config(); /* Notify user about the network interface config */ User_notification(&gnetif); #ifdef USE_DHCP /* Start DHCPClient */ osThreadDef(DHCP, DHCP_thread, osPriorityBelowNormal, 0, configMINIMAL_STACK_SIZE * 2); osThreadCreate (osThread(DHCP), &gnetif); #endif /* Start toogleLed4 task : Toggle LED4 every 250ms */ // osThreadDef(LED4, ToggleLed4, osPriorityNormal, 0, configMINIMAL_STACK_SIZE*8); // osThreadCreate(osThread(LED4), NULL); for( ;; ) { /* Delete the Init Thread */ osThreadTerminate(NULL); } } /** * @brief Initializes the lwIP stack * @param None * @retval None */ static void Netif_Config(void) { ip_addr_t ipaddr; ip_addr_t netmask; ip_addr_t gw; #ifdef USE_DHCP ip_addr_set_zero_ip4(&ipaddr); ip_addr_set_zero_ip4(&netmask); ip_addr_set_zero_ip4(&gw); #else IP_ADDR4(&ipaddr,IP_ADDR0,IP_ADDR1,IP_ADDR2,IP_ADDR3); IP_ADDR4(&netmask,NETMASK_ADDR0,NETMASK_ADDR1,NETMASK_ADDR2,NETMASK_ADDR3); IP_ADDR4(&gw,GW_ADDR0,GW_ADDR1,GW_ADDR2,GW_ADDR3); #endif /* USE_DHCP */ netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, ðernetif_init, &tcpip_input); /* Registers the default network interface. */ netif_set_default(&gnetif); if (netif_is_link_up(&gnetif)) { /* When the netif is fully configured this function must be called.*/ netif_set_up(&gnetif); } else { /* When the netif link is down this function must be called */ netif_set_down(&gnetif); } netif_set_link_callback(&gnetif,ethernetif_update_config); /* create a binary semaphore used for informing ethernetif of frame reception */ osSemaphoreDef(Netif_SEM); Netif_LinkSemaphore = osSemaphoreCreate(osSemaphore(Netif_SEM) , 1 ); link_arg.netif = &gnetif; link_arg.semaphore = Netif_LinkSemaphore; osThreadDef(LinkThr, ethernetif_set_link, osPriorityBelowNormal, 0, configMINIMAL_STACK_SIZE * 2); osThreadCreate (osThread(LinkThr), &link_arg); } /** * @brief Initializes the LCD and LEDs resources. * @param None * @retval None */ static void BSP_Config(void) { } ///** // * @brief Toggle LED4 thread // * @param pvParameters not used // * @retval None // */ //static void ToggleLed4(void const * argument) //{ // for( ;; ) // { // /* Toggle LED4 each 250ms */ // LOG_PRINT(LOG_INFO,"udp"); // osDelay(100); // } //} ///** // * @brief EXTI line detection callbacks // * @param GPIO_Pin: Specifies the pins connected EXTI line // * @retval None // */ //void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) //{ // if (GPIO_Pin == GPIO_PIN_14) // { // osSemaphoreRelease(Netif_LinkSemaphore); // } //} /** * @brief System Clock Configuration * The system Clock is configured as follow : * System Clock source = PLL (HSE) * SYSCLK(Hz) = 120000000 * HCLK(Hz) = 120000000 * AHB Prescaler = 1 * APB1 Prescaler = 4 * APB2 Prescaler = 2 * HSE Frequency(Hz) = 25000000 * PLL_M = 25 * PLL_N = 240 * PLL_P = 2 * PLL_Q = 5 * VDD(V) = 3.3 * Flash Latency(WS) = 3 * @param None * @retval None */ static void SystemClock_Config(void) { RCC_ClkInitTypeDef RCC_ClkInitStruct; RCC_OscInitTypeDef RCC_OscInitStruct; /* Enable HSE Oscillator and activate PLL with HSE as source */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLM = 25; RCC_OscInitStruct.PLL.PLLN = 240; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; RCC_OscInitStruct.PLL.PLLQ = 4; if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */ RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK) { Error_Handler(); } } /** * @brief This function is executed in case of error occurrence. * @param None * @retval None */ static void Error_Handler(void) { /* User may add here some code to deal with this error */ while(1) { } } void vApplicationMallocFailedHook( void ) { LOG_PRINT(LOG_ERROR,"malloc error"); } void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName ) { LogPrint(LOG_ERROR,__FILE__,__FUNCTION__,__LINE__,"task :%s Õ»Òç³ö\r\n",pcTaskName); } int fputc(int ch, FILE *stream) { return ch; } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t* file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* Infinite loop */ while (1) { } } #endif void ethernetif_notify_conn_changed(struct netif *netif) { if (netif_is_link_up(netif)) { LOG_PRINT(LOG_INFO,"link up"); } else { LOG_PRINT(LOG_INFO,"link down"); } } /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/