ECE 471/571 STM32 FreeRTOS+LwIP Example - Monitor DHCP State

In STM32CubeMX

  1. Initialize all peripherals with in default mode? - yes
  2. System Core
  3. Connectivity: enable Ethernet: RMII (already enabled))
  4. Middleware - enable FreeRTOS
  5. Middleware - enable LwIP
  6. System Core Again

Adapt and compile a project

  1. Open source/main.c
  2. Update the following code fragment:
    /* USER CODE BEGIN Includes */
    #include <string.h>
    /* USER CODE END Includes */
    
  3. Update the following code fragment:
      /* USER CODE BEGIN 2 */
      MX_LWIP_Init();
    
      /* USER CODE END 2 */
    
  4. Update the following code fragment:
    void StartDefaultTask(void const * argument)
    {
      /* init code for LWIP */
      // MX_LWIP_Init(); -- moved back to the main function
      /* USER CODE BEGIN 5 */
      char buffer[50]; // Worst case: IPv6 would need 48 characters plus terminating \0
    
      /* Infinite loop */
      for(;;)
      {
        {
          extern struct netif gnetif;
    
          // This is not very efficient way to print as it does not save CPU time
          // using busy-wait to send each character but it does serve diagnostic purpose
    
          if (netif_is_link_up(&gnetif)) {
              HAL_UART_Transmit(&huart3, (uint8_t*)"IF is up\r\n", 10, 2);
              HAL_UART_Transmit(&huart3, (uint8_t*)"IP ADDR: ", 9, 2);
              ipaddr_ntoa_r( &gnetif.ip_addr , buffer, sizeof(buffer));
              HAL_UART_Transmit(&huart3, (uint8_t*)buffer, strlen(buffer), 6);
              HAL_UART_Transmit(&huart3, (uint8_t*)"\r\n", 2, 2);
    
              HAL_UART_Transmit(&huart3, (uint8_t*)"IP MASK: ", 9, 2);
              ipaddr_ntoa_r(&gnetif.netmask, buffer, sizeof(buffer));
              HAL_UART_Transmit(&huart3, (uint8_t*)buffer, strlen(buffer), 6);
              HAL_UART_Transmit(&huart3, (uint8_t*)"\r\n", 2, 2);
    
              HAL_UART_Transmit(&huart3, (uint8_t*)"IP GATE: ", 9, 2);
              ipaddr_ntoa_r(&gnetif.gw, buffer, sizeof(buffer));
              HAL_UART_Transmit(&huart3, (uint8_t*)buffer, strlen(buffer), 6);
              HAL_UART_Transmit(&huart3, (uint8_t*)"\r\n", 2, 2);
    
              HAL_UART_Transmit(&huart3, (uint8_t*)"LNK MTU: ", 9, 2);
              utoa(gnetif.mtu, buffer, 10);
              HAL_UART_Transmit(&huart3, (uint8_t*)buffer, strlen(buffer), 2);
              HAL_UART_Transmit(&huart3, (uint8_t*)"\r\n", 2, 2);
    
          } else {
              HAL_UART_Transmit(&huart3, (uint8_t*)"IF is down\r\n", 12, 2);
          }
    
          HAL_UART_Transmit(&huart3, (uint8_t*)"\r\n", 2, 2);
        }
        osDelay(1000);
      }
      /* USER CODE END 5 */
    }
    

web site front local main page local list page general bookmarks software bookmarks go back copyright info