12 changed files with 145 additions and 20 deletions
-
5.settings/stm32cubeide.project.prefs
-
3.vscode/settings.json
-
10LWIP/Target/ethernetif.c
-
2STM32F407VETX_FLASH.ld
-
8iflytop_xsync/xs_flash.c
-
2iflytop_xsync/xs_flash.h
-
10usrc/base_service/config_service.c
-
9usrc/main.cpp
-
1usrc/project_configs.h
-
100usrc/service/network_service.c
-
9usrc/service/network_service.h
-
6xsync_stm32 Debug.launch
@ -1,5 +1,6 @@ |
|||
2F62501ED4689FB349E356AB974DBE57=E20EF8A1CFA8D2AA5E7713614514A9E1 |
|||
635E684B79701B039C64EA45C3F84D30=C8B026EBE17C208F17FB66CE4235156C |
|||
66BE74F758C12D739921AEA421D593D3=1 |
|||
8DF89ED150041C4CBC7CB9A9CAA90856=31CD5EEFA9F35C65D8E334D24F421EB1 |
|||
DC22A860405A8BF2F2C095E5B6529F12=31CD5EEFA9F35C65D8E334D24F421EB1 |
|||
8DF89ED150041C4CBC7CB9A9CAA90856=E20EF8A1CFA8D2AA5E7713614514A9E1 |
|||
DC22A860405A8BF2F2C095E5B6529F12=071C30CF380DE7D03307EB9085476C68 |
|||
eclipse.preferences.version=1 |
@ -0,0 +1,100 @@ |
|||
/* USER CODE BEGIN Header */ |
|||
/** |
|||
****************************************************************************** |
|||
* File Name : LWIP.c |
|||
* Description : This file provides initialization code for LWIP |
|||
* middleWare. |
|||
****************************************************************************** |
|||
* @attention |
|||
* |
|||
* Copyright (c) 2024 STMicroelectronics. |
|||
* All rights reserved. |
|||
* |
|||
* This software is licensed under terms that can be found in the LICENSE file |
|||
* in the root directory of this software component. |
|||
* If no LICENSE file comes with this software, it is provided AS-IS. |
|||
* |
|||
****************************************************************************** |
|||
*/ |
|||
/* USER CODE END Header */ |
|||
|
|||
/* Includes ------------------------------------------------------------------*/ |
|||
#include "lwip.h" |
|||
#include "lwip/init.h" |
|||
#include "lwip/netif.h" |
|||
#if defined(__CC_ARM) |
|||
#include "lwip/sio.h" |
|||
#endif |
|||
#include "ethernetif.h" |
|||
// |
|||
#include "base_service/base_service.h" |
|||
|
|||
#define TAG "network" |
|||
|
|||
static struct netif gnetif; |
|||
static ip4_addr_t ipaddr; |
|||
static ip4_addr_t netmask; |
|||
static ip4_addr_t gw; |
|||
static uint8_t IP_ADDRESS[4]; |
|||
static uint8_t NETMASK_ADDRESS[4]; |
|||
static uint8_t GATEWAY_ADDRESS[4]; |
|||
|
|||
uint8_t g_mac[6]; |
|||
|
|||
static void ethernet_link_status_updated(struct netif *netif) { |
|||
if (netif_is_up(netif)) { |
|||
ZLOGI(TAG, "ethernet_link_status_updated: netif_is_up"); |
|||
} else { |
|||
ZLOGI(TAG, "ethernet_link_status_updated: netif_is_down"); |
|||
} |
|||
} |
|||
|
|||
void network_service_init() { |
|||
ZLOGI(TAG, "network_service_init"); |
|||
|
|||
*(uint32_t *)(IP_ADDRESS) = config_get()->ip; |
|||
*(uint32_t *)(NETMASK_ADDRESS) = config_get()->netmask; |
|||
*(uint32_t *)(GATEWAY_ADDRESS) = config_get()->gw; |
|||
|
|||
// IP_ADDRESS[0] = 192; |
|||
// IP_ADDRESS[1] = 168; |
|||
// IP_ADDRESS[2] = 8; |
|||
// IP_ADDRESS[3] = 10; |
|||
// NETMASK_ADDRESS[0] = 255; |
|||
// NETMASK_ADDRESS[1] = 255; |
|||
// NETMASK_ADDRESS[2] = 255; |
|||
// NETMASK_ADDRESS[3] = 255; |
|||
// GATEWAY_ADDRESS[0] = 192; |
|||
// GATEWAY_ADDRESS[1] = 168; |
|||
// GATEWAY_ADDRESS[2] = 8; |
|||
// GATEWAY_ADDRESS[3] = 1; |
|||
|
|||
memcpy(g_mac, config_get()->mac, 6); |
|||
|
|||
/* Initilialize the LwIP stack with RTOS */ |
|||
tcpip_init(NULL, NULL); |
|||
|
|||
/* IP addresses initialization without DHCP (IPv4) */ |
|||
IP4_ADDR(&ipaddr, IP_ADDRESS[0], IP_ADDRESS[1], IP_ADDRESS[2], IP_ADDRESS[3]); |
|||
IP4_ADDR(&netmask, NETMASK_ADDRESS[0], NETMASK_ADDRESS[1], NETMASK_ADDRESS[2], NETMASK_ADDRESS[3]); |
|||
IP4_ADDR(&gw, GATEWAY_ADDRESS[0], GATEWAY_ADDRESS[1], GATEWAY_ADDRESS[2], GATEWAY_ADDRESS[3]); |
|||
|
|||
/* add the network interface (IPv4/IPv6) with RTOS */ |
|||
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); |
|||
} |
|||
|
|||
/* Set the link callback function, this function is called on change of link status*/ |
|||
netif_set_link_callback(&gnetif, ethernet_link_status_updated); |
|||
osThreadDef(EthLink, ethernet_link_thread, osPriorityBelowNormal, 0, 512); |
|||
osThreadCreate(osThread(EthLink), &gnetif); |
|||
} |
@ -0,0 +1,9 @@ |
|||
#pragma once |
|||
#ifdef __cplusplus |
|||
extern "C" { |
|||
#endif |
|||
void network_service_init(); |
|||
|
|||
#ifdef __cplusplus |
|||
} |
|||
#endif |
Write
Preview
Loading…
Cancel
Save
Reference in new issue