You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

189 lines
4.9 KiB

2 years ago
2 years ago
1 year ago
2 years ago
2 years ago
1 year ago
2 years ago
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * File Name : LWIP.c
  5. * Description : This file provides initialization code for LWIP
  6. * middleWare.
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * Copyright (c) 2024 STMicroelectronics.
  11. * All rights reserved.
  12. *
  13. * This software is licensed under terms that can be found in the LICENSE file
  14. * in the root directory of this software component.
  15. * If no LICENSE file comes with this software, it is provided AS-IS.
  16. *
  17. ******************************************************************************
  18. */
  19. /* USER CODE END Header */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "lwip.h"
  22. #include "lwip/init.h"
  23. #include "lwip/netif.h"
  24. #if defined ( __CC_ARM ) /* MDK ARM Compiler */
  25. #include "lwip/sio.h"
  26. #endif /* MDK ARM Compiler */
  27. #include "ethernetif.h"
  28. /* USER CODE BEGIN 0 */
  29. /* USER CODE END 0 */
  30. /* Private function prototypes -----------------------------------------------*/
  31. static void ethernet_link_status_updated(struct netif *netif);
  32. /* ETH Variables initialization ----------------------------------------------*/
  33. void Error_Handler(void);
  34. /* USER CODE BEGIN 1 */
  35. /* USER CODE END 1 */
  36. /* Variables Initialization */
  37. struct netif gnetif;
  38. ip4_addr_t ipaddr;
  39. ip4_addr_t netmask;
  40. ip4_addr_t gw;
  41. /* USER CODE BEGIN 2 */
  42. /* USER CODE END 2 */
  43. /**
  44. * LwIP initialization function
  45. */
  46. void MX_LWIP_Init(void)
  47. {
  48. /* Initialize the LwIP stack with RTOS */
  49. tcpip_init( NULL, NULL );
  50. /* IP addresses initialization with DHCP (IPv4) */
  51. ipaddr.addr = 0;
  52. netmask.addr = 0;
  53. gw.addr = 0;
  54. /* add the network interface (IPv4/IPv6) with RTOS */
  55. netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &tcpip_input);
  56. /* Registers the default network interface */
  57. netif_set_default(&gnetif);
  58. /* We must always bring the network interface up connection or not... */
  59. netif_set_up(&gnetif);
  60. /* Set the link callback function, this function is called on change of link status*/
  61. netif_set_link_callback(&gnetif, ethernet_link_status_updated);
  62. /* Create the Ethernet link handler thread */
  63. /* USER CODE BEGIN H7_OS_THREAD_DEF_CREATE_CMSIS_RTOS_V1 */
  64. osThreadDef(EthLink, ethernet_link_thread, osPriorityBelowNormal, 0, configMINIMAL_STACK_SIZE *2);
  65. osThreadCreate (osThread(EthLink), &gnetif);
  66. /* USER CODE END H7_OS_THREAD_DEF_CREATE_CMSIS_RTOS_V1 */
  67. /* Start DHCP negotiation for a network interface (IPv4) */
  68. dhcp_start(&gnetif);
  69. /* USER CODE BEGIN 3 */
  70. /* USER CODE END 3 */
  71. }
  72. #ifdef USE_OBSOLETE_USER_CODE_SECTION_4
  73. /* Kept to help code migration. (See new 4_1, 4_2... sections) */
  74. /* Avoid to use this user section which will become obsolete. */
  75. /* USER CODE BEGIN 4 */
  76. /* USER CODE END 4 */
  77. #endif
  78. /**
  79. * @brief Notify the User about the network interface config status
  80. * @param netif: the network interface
  81. * @retval None
  82. */
  83. static void ethernet_link_status_updated(struct netif *netif)
  84. {
  85. if (netif_is_up(netif))
  86. {
  87. /* USER CODE BEGIN 5 */
  88. /* USER CODE END 5 */
  89. }
  90. else /* netif is down */
  91. {
  92. /* USER CODE BEGIN 6 */
  93. /* USER CODE END 6 */
  94. }
  95. }
  96. #if defined ( __CC_ARM ) /* MDK ARM Compiler */
  97. /**
  98. * Opens a serial device for communication.
  99. *
  100. * @param devnum device number
  101. * @return handle to serial device if successful, NULL otherwise
  102. */
  103. sio_fd_t sio_open(u8_t devnum)
  104. {
  105. sio_fd_t sd;
  106. /* USER CODE BEGIN 7 */
  107. sd = 0; // dummy code
  108. /* USER CODE END 7 */
  109. return sd;
  110. }
  111. /**
  112. * Sends a single character to the serial device.
  113. *
  114. * @param c character to send
  115. * @param fd serial device handle
  116. *
  117. * @note This function will block until the character can be sent.
  118. */
  119. void sio_send(u8_t c, sio_fd_t fd)
  120. {
  121. /* USER CODE BEGIN 8 */
  122. /* USER CODE END 8 */
  123. }
  124. /**
  125. * Reads from the serial device.
  126. *
  127. * @param fd serial device handle
  128. * @param data pointer to data buffer for receiving
  129. * @param len maximum length (in bytes) of data to receive
  130. * @return number of bytes actually received - may be 0 if aborted by sio_read_abort
  131. *
  132. * @note This function will block until data can be received. The blocking
  133. * can be cancelled by calling sio_read_abort().
  134. */
  135. u32_t sio_read(sio_fd_t fd, u8_t *data, u32_t len)
  136. {
  137. u32_t recved_bytes;
  138. /* USER CODE BEGIN 9 */
  139. recved_bytes = 0; // dummy code
  140. /* USER CODE END 9 */
  141. return recved_bytes;
  142. }
  143. /**
  144. * Tries to read from the serial device. Same as sio_read but returns
  145. * immediately if no data is available and never blocks.
  146. *
  147. * @param fd serial device handle
  148. * @param data pointer to data buffer for receiving
  149. * @param len maximum length (in bytes) of data to receive
  150. * @return number of bytes actually received
  151. */
  152. u32_t sio_tryread(sio_fd_t fd, u8_t *data, u32_t len)
  153. {
  154. u32_t recved_bytes;
  155. /* USER CODE BEGIN 10 */
  156. recved_bytes = 0; // dummy code
  157. /* USER CODE END 10 */
  158. return recved_bytes;
  159. }
  160. #endif /* MDK ARM Compiler */