Browse Source

update

master
zhaohe 2 years ago
parent
commit
01d4238731
  1. 5
      .settings/stm32cubeide.project.prefs
  2. 3
      .vscode/settings.json
  3. 10
      LWIP/Target/ethernetif.c
  4. 2
      STM32F407VETX_FLASH.ld
  5. 8
      iflytop_xsync/xs_flash.c
  6. 2
      iflytop_xsync/xs_flash.h
  7. 10
      usrc/base_service/config_service.c
  8. 9
      usrc/main.cpp
  9. 1
      usrc/project_configs.h
  10. 100
      usrc/service/network_service.c
  11. 9
      usrc/service/network_service.h
  12. 6
      xsync_stm32 Debug.launch

5
.settings/stm32cubeide.project.prefs

@ -1,5 +1,6 @@
2F62501ED4689FB349E356AB974DBE57=E20EF8A1CFA8D2AA5E7713614514A9E1
635E684B79701B039C64EA45C3F84D30=C8B026EBE17C208F17FB66CE4235156C
66BE74F758C12D739921AEA421D593D3=1
8DF89ED150041C4CBC7CB9A9CAA90856=31CD5EEFA9F35C65D8E334D24F421EB1
DC22A860405A8BF2F2C095E5B6529F12=31CD5EEFA9F35C65D8E334D24F421EB1
8DF89ED150041C4CBC7CB9A9CAA90856=E20EF8A1CFA8D2AA5E7713614514A9E1
DC22A860405A8BF2F2C095E5B6529F12=071C30CF380DE7D03307EB9085476C68
eclipse.preferences.version=1

3
.vscode/settings.json

@ -84,7 +84,8 @@
"zflash.h": "c",
"iflytop_xsync.h": "c",
"config.h": "c",
"config_service.h": "c"
"config_service.h": "c",
"base_service.h": "c"
},
"files.autoGuessEncoding": false,
"files.encoding": "gbk"

10
LWIP/Target/ethernetif.c

@ -166,6 +166,8 @@ void HAL_ETH_ErrorCallback(ETH_HandleTypeDef *handlerEth)
}
/* USER CODE BEGIN 4 */
// add by zhaohe
extern uint8_t g_mac[];
/* USER CODE END 4 */
@ -202,7 +204,13 @@ static void low_level_init(struct netif *netif)
heth.Init.RxBuffLen = 1536;
/* USER CODE BEGIN MACADDRESS */
// add by zhaohe
// MACAddr[0] = g_mac[0];
// MACAddr[1] = g_mac[1];
// MACAddr[2] = g_mac[2];
// MACAddr[3] = g_mac[3];
// MACAddr[4] = g_mac[4];
// MACAddr[5] = g_mac[5];
/* USER CODE END MACADDRESS */
hal_eth_init_status = HAL_ETH_Init(&heth);

2
STM32F407VETX_FLASH.ld

@ -47,7 +47,7 @@ MEMORY
{
CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 64K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 384K
}
/* Sections */

8
iflytop_xsync/xs_flash.c

@ -1,9 +1,11 @@
#include "xs_flash.h"
#include "xs_log.h"
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include "xs_log.h"
static uint32_t* _rawstartadd;
static uint32_t* _defaultdata;
static uint32_t _rawsize;
@ -54,7 +56,7 @@ void xs_flash_init(uint32_t* rawstartadd, uint32_t* defaultdata, uint32_t rawsiz
_rawsize = rawsize;
// ÁÈ¡flashÊý¾Ý
memcpy(_rawstartadd, (uint32_t*)(FLASH_START_ADD), _rawsize);
memcpy(_rawstartadd, (uint32_t*)(FLASH_START_ADD), _rawsize * 4);
// УÑéÊý¾Ý
if (_xs_check_raw_data()) {
@ -82,6 +84,7 @@ bool xs_flash_factory_reset(void) {
}
bool xs_flash_flush(void) {
#if PC_NVS_ENABLE
_rawstartadd[0] = FLASH_MASK_VAL;
_rawstartadd[_rawsize - 1] = xs_compute_checksum(_rawstartadd, _rawsize - 1);
@ -95,5 +98,6 @@ bool xs_flash_flush(void) {
}
}
HAL_FLASH_Lock(); // ÉÏËø
#endif
return true;
}

2
iflytop_xsync/xs_flash.h

@ -25,7 +25,7 @@
*/
#define FLASH_MASK_VAL 0xABCD
#define FLASH_START_ADD 0x08078000 //
#define FLASH_START_ADD 0x08060000 //
#define FLASH_EARSE_SECTOR FLASH_SECTOR_7
/**

10
usrc/base_service/config_service.c

@ -25,11 +25,13 @@ static void create_default_config() { //
static mac_t mac;
xs_id_generate_random_mac(&mac);
memcpy(&_default_val_config.mac[0], mac.mac, 6);
ZLOGD(TAG, "random mac is %02x:%02x:%02x:%02x:%02x:%02x", mac.mac[0], mac.mac[1], mac.mac[2], mac.mac[3], mac.mac[4], mac.mac[5]);
dump_config(&_default_val_config);
// ZLOGD(TAG, "random mac is %02x:%02x:%02x:%02x:%02x:%02x", mac.mac[0], mac.mac[1], mac.mac[2], mac.mac[3], mac.mac[4], mac.mac[5]);
// dump_config(&_default_val_config);
}
void config_init(void) {
ZLOGI(TAG, "config_init");
/**
* @brief
*/
@ -39,8 +41,8 @@ void config_init(void) {
*/
xs_flash_init(&_config, &_default_val_config, sizeof(config_t) / 4);
ZLOGI(TAG, "xs_flash_is_first_run: %d", xs_flash_is_first_run());
ZLOGI(TAG, "");
// ZLOGI(TAG, "xs_flash_is_first_run: %d", xs_flash_is_first_run());
// ZLOGI(TAG, "");
/**
* @brief

9
usrc/main.cpp

@ -3,6 +3,7 @@
//
#include "base_service/base_service.h"
#include "service/network_service.h"
//
#define TAG "main"
using namespace std;
@ -11,7 +12,6 @@ extern void umain();
extern "C" {
extern void MX_LWIP_Init(void);
void StartDefaultTask(void const* argument) {
// MX_LWIP_Init();
umain();
}
}
@ -27,13 +27,14 @@ void umain() {
* @brief
*/
xs_gpio_init_as_output(&m_debug_led, PC_DEBUG_LIGHT_GPIO, kxs_gpio_nopull, false, false);
/**
* @brief
*/
config_init();
/**
* @brief
*/
network_service_init();
while (true) {
xs_gpio_write(&m_debug_led, true);

1
usrc/project_configs.h

@ -17,4 +17,3 @@
#define PC_IRQ_PREEMPTPRIORITY_DEFAULT 5
#define PC_NVS_ENABLE 1
#define PC_NVS_CONFIG_FLASH_SECTOR 8

100
usrc/service/network_service.c

@ -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, &ethernetif_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);
}

9
usrc/service/network_service.h

@ -0,0 +1,9 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
void network_service_init();
#ifdef __cplusplus
}
#endif

6
xsync_stm32 Debug.launch

@ -33,11 +33,11 @@
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.frequency" value="0"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.halt_all_on_reset" value="false"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.log_file" value="D:\workspace\p_lusterinc\xsync_stm32\Debug\st-link_gdbserver_log.txt"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.low_power_debug" value="enable"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.low_power_debug" value="disable"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.max_halt_delay" value="2"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.reset_strategy" value="connect_under_reset"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.reset_strategy" value="system_reset"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.stlink_check_serial_number" value="false"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.stlink_txt_serial_number" value=""/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.stlink_txt_serial_number" value="001B00273132510838363431"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlink.watchdog_config" value="none"/>
<booleanAttribute key="com.st.stm32cube.ide.mcu.debug.stlinkenable_rtos" value="false"/>
<stringAttribute key="com.st.stm32cube.ide.mcu.debug.stlinkrestart_configurations" value="{&quot;fVersion&quot;:1,&quot;fItems&quot;:[{&quot;fDisplayName&quot;:&quot;Reset&quot;,&quot;fIsSuppressible&quot;:false,&quot;fResetAttribute&quot;:&quot;Software system reset&quot;,&quot;fResetStrategies&quot;:[{&quot;fDisplayName&quot;:&quot;Software system reset&quot;,&quot;fLaunchAttribute&quot;:&quot;system_reset&quot;,&quot;fGdbCommands&quot;:[&quot;monitor reset\r\n&quot;],&quot;fCmdOptions&quot;:[&quot;-g&quot;]},{&quot;fDisplayName&quot;:&quot;Hardware reset&quot;,&quot;fLaunchAttribute&quot;:&quot;hardware_reset&quot;,&quot;fGdbCommands&quot;:[&quot;monitor reset hardware\r\n&quot;],&quot;fCmdOptions&quot;:[&quot;-g&quot;]},{&quot;fDisplayName&quot;:&quot;Core reset&quot;,&quot;fLaunchAttribute&quot;:&quot;core_reset&quot;,&quot;fGdbCommands&quot;:[&quot;monitor reset core\r\n&quot;],&quot;fCmdOptions&quot;:[&quot;-g&quot;]},{&quot;fDisplayName&quot;:&quot;None&quot;,&quot;fLaunchAttribute&quot;:&quot;no_reset&quot;,&quot;fGdbCommands&quot;:[],&quot;fCmdOptions&quot;:[&quot;-g&quot;]}],&quot;fGdbCommandGroup&quot;:{&quot;name&quot;:&quot;Additional commands&quot;,&quot;commands&quot;:[]},&quot;fStartApplication&quot;:true}]}"/>

Loading…
Cancel
Save