upgrade to IDF v6.0.1
This commit is contained in:
parent
04baaf5a5e
commit
d626619c20
13 changed files with 1298 additions and 326 deletions
1
firmware/.gitignore
vendored
1
firmware/.gitignore
vendored
|
|
@ -1,4 +1,5 @@
|
|||
build/
|
||||
managed_components/
|
||||
|
||||
# Created by https://www.toptal.com/developers/gitignore/api/cmake,c++
|
||||
# Edit at https://www.toptal.com/developers/gitignore?templates=cmake,c++
|
||||
|
|
|
|||
|
|
@ -3,4 +3,6 @@
|
|||
cmake_minimum_required(VERSION 3.22)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
# "Trim" the build. Include the minimal set of components, main, and anything it depends on.
|
||||
#idf_build_set_property(MINIMAL_BUILD ON)
|
||||
project(inet_mon)
|
||||
|
|
|
|||
12
firmware/README.md
Normal file
12
firmware/README.md
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# GPIOs
|
||||
|
||||
| ESP32-S3 | W5500 |
|
||||
| ------- |-------|
|
||||
| GPIO12 | SCLK |
|
||||
| GPIO11 | MOSI |
|
||||
| GPIO13 | MISO |
|
||||
| GPIO10 | SCS |
|
||||
| GPIO09 | RST |
|
||||
| GPIO14 | INT |
|
||||
| 3V3 | 3V3 |
|
||||
| GND | GND |
|
||||
21
firmware/dependencies.lock
Normal file
21
firmware/dependencies.lock
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
dependencies:
|
||||
espressif/w5500:
|
||||
component_hash: e6e47022a1f509d1d1197652a554aea84a8cd4d99161061e187ecf4b78a7f6ca
|
||||
dependencies:
|
||||
- name: idf
|
||||
require: private
|
||||
version: '>=6.0'
|
||||
source:
|
||||
registry_url: https://components.espressif.com/
|
||||
type: service
|
||||
version: 1.0.1
|
||||
idf:
|
||||
source:
|
||||
type: idf
|
||||
version: 6.0.1
|
||||
direct_dependencies:
|
||||
- espressif/w5500
|
||||
- idf
|
||||
manifest_hash: c4bad2fb618779164783fe779b8924d7a6d94e582838878b2cc5d584eab2d703
|
||||
target: esp32s3
|
||||
version: 3.0.0
|
||||
|
|
@ -1,2 +1,11 @@
|
|||
idf_component_register(SRCS "inet_mon.c"
|
||||
INCLUDE_DIRS ".")
|
||||
idf_component_register(
|
||||
SRCS "inet_mon_main.cpp"
|
||||
PRIV_REQUIRES spi_flash
|
||||
REQUIRES
|
||||
esp_event
|
||||
esp_netif
|
||||
esp_eth
|
||||
driver
|
||||
nvs_flash
|
||||
INCLUDE_DIRS ""
|
||||
)
|
||||
|
|
|
|||
17
firmware/main/idf_component.yml
Normal file
17
firmware/main/idf_component.yml
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
## IDF Component Manager Manifest File
|
||||
dependencies:
|
||||
## Required IDF version
|
||||
idf:
|
||||
version: '>=5.5.4'
|
||||
# # Put list of dependencies here
|
||||
# # For components maintained by Espressif:
|
||||
# component: "~1.0.0"
|
||||
# # For 3rd party components:
|
||||
# username/component: ">=1.0.0,<2.0.0"
|
||||
# username2/component2:
|
||||
# version: "~1.0.0"
|
||||
# # For transient dependencies `public` flag can be set.
|
||||
# # `public` flag doesn't have an effect dependencies of the `main` component.
|
||||
# # All dependencies of `main` are public by default.
|
||||
# public: true
|
||||
espressif/w5500: ^1.0.1
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
#include <stdio.h>
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
|
||||
}
|
||||
226
firmware/main/inet_mon_main.cpp
Normal file
226
firmware/main/inet_mon_main.cpp
Normal file
|
|
@ -0,0 +1,226 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include "sdkconfig.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_chip_info.h"
|
||||
#include "esp_flash.h"
|
||||
#include "esp_system.h"
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_netif.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
#include "driver/spi_master.h"
|
||||
|
||||
#include "esp_eth.h"
|
||||
#include "esp_eth_mac.h"
|
||||
#include "esp_eth_phy.h"
|
||||
#include "esp_eth_com.h"
|
||||
|
||||
#include "esp_eth_mac_w5500.h"
|
||||
#include "esp_eth_phy_w5500.h"
|
||||
|
||||
static const char *TAG = "INETMON";
|
||||
|
||||
// -------------------- PIN CONFIG --------------------
|
||||
#define PIN_SCK 12
|
||||
#define PIN_MOSI 11
|
||||
#define PIN_MISO 13
|
||||
#define PIN_CS 10
|
||||
#define PIN_RST 9
|
||||
#define PIN_INT 14
|
||||
|
||||
static esp_eth_handle_t eth_handle = NULL;
|
||||
|
||||
|
||||
// -------------------- EVENT HANDLER --------------------
|
||||
static void eth_event_handler(void *arg, esp_event_base_t event_base,
|
||||
int32_t event_id, void *event_data)
|
||||
{
|
||||
switch (event_id) {
|
||||
|
||||
case ETHERNET_EVENT_CONNECTED:
|
||||
ESP_LOGI(TAG, "Ethernet LINK UP");
|
||||
break;
|
||||
|
||||
case ETHERNET_EVENT_DISCONNECTED:
|
||||
ESP_LOGI(TAG, "Ethernet LINK DOWN");
|
||||
break;
|
||||
|
||||
case ETHERNET_EVENT_START:
|
||||
ESP_LOGI(TAG, "Ethernet START");
|
||||
break;
|
||||
|
||||
case ETHERNET_EVENT_STOP:
|
||||
ESP_LOGI(TAG, "Ethernet STOP");
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void got_ip_event_handler(void *arg, esp_event_base_t event_base,
|
||||
int32_t event_id, void *event_data)
|
||||
{
|
||||
ip_event_got_ip_t *event = (ip_event_got_ip_t *)event_data;
|
||||
|
||||
ESP_LOGI(
|
||||
TAG,
|
||||
"IP: " IPSTR " GW: " IPSTR " MASK: " IPSTR,
|
||||
IP2STR(&event->ip_info.ip),
|
||||
IP2STR(&event->ip_info.gw),
|
||||
IP2STR(&event->ip_info.netmask)
|
||||
);
|
||||
}
|
||||
|
||||
extern "C" void app_main(void)
|
||||
{
|
||||
printf("Hello world!\n");
|
||||
|
||||
/* Print chip information */
|
||||
esp_chip_info_t chip_info;
|
||||
uint32_t flash_size;
|
||||
esp_chip_info(&chip_info);
|
||||
printf("This is %s chip with %d CPU core(s), %s%s%s%s, ",
|
||||
CONFIG_IDF_TARGET,
|
||||
chip_info.cores,
|
||||
(chip_info.features & CHIP_FEATURE_WIFI_BGN) ? "WiFi/" : "",
|
||||
(chip_info.features & CHIP_FEATURE_BT) ? "BT" : "",
|
||||
(chip_info.features & CHIP_FEATURE_BLE) ? "BLE" : "",
|
||||
(chip_info.features & CHIP_FEATURE_IEEE802154) ? ", 802.15.4 (Zigbee/Thread)" : ""
|
||||
);
|
||||
|
||||
unsigned major_rev = chip_info.revision / 100;
|
||||
unsigned minor_rev = chip_info.revision % 100;
|
||||
printf("silicon revision v%d.%d, ", major_rev, minor_rev);
|
||||
if(esp_flash_get_size(NULL, &flash_size) != ESP_OK) {
|
||||
printf("Get flash size failed");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("%" PRIu32 "MB %s flash\n", flash_size / (uint32_t)(1024 * 1024),
|
||||
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");
|
||||
|
||||
printf("Minimum free heap size: %" PRIu32 " bytes\n", esp_get_minimum_free_heap_size());
|
||||
|
||||
fflush(stdout);
|
||||
|
||||
ESP_LOGI(TAG, "Starting W5500 Ethernet...");
|
||||
|
||||
// NVS + event loop
|
||||
ESP_ERROR_CHECK(nvs_flash_init());
|
||||
ESP_ERROR_CHECK(esp_netif_init());
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
|
||||
esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, ð_event_handler, NULL);
|
||||
esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &got_ip_event_handler, NULL);
|
||||
|
||||
// ---------------- SPI BUS ----------------
|
||||
spi_bus_config_t buscfg = {};
|
||||
|
||||
buscfg.mosi_io_num = PIN_MOSI;
|
||||
buscfg.miso_io_num = PIN_MISO;
|
||||
buscfg.sclk_io_num = PIN_SCK;
|
||||
|
||||
buscfg.quadwp_io_num = -1;
|
||||
buscfg.quadhd_io_num = -1;
|
||||
|
||||
buscfg.data4_io_num = -1;
|
||||
buscfg.data5_io_num = -1;
|
||||
buscfg.data6_io_num = -1;
|
||||
buscfg.data7_io_num = -1;
|
||||
|
||||
buscfg.max_transfer_sz = 0;
|
||||
buscfg.flags = 0;
|
||||
buscfg.isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO;
|
||||
buscfg.intr_flags = 0;
|
||||
|
||||
ESP_ERROR_CHECK(
|
||||
spi_bus_initialize(SPI2_HOST, &buscfg, SPI_DMA_CH_AUTO)
|
||||
);
|
||||
|
||||
// ---------------- SPI DEVICE CONFIG ----------------
|
||||
spi_device_interface_config_t spi_devcfg = {};
|
||||
|
||||
spi_devcfg.command_bits = 16;
|
||||
spi_devcfg.address_bits = 8;
|
||||
spi_devcfg.mode = 0;
|
||||
|
||||
spi_devcfg.clock_speed_hz = 5 * 1000 * 1000;
|
||||
|
||||
spi_devcfg.spics_io_num = PIN_CS;
|
||||
spi_devcfg.queue_size = 20;
|
||||
|
||||
// ---------------- W5500 CONFIG ----------------
|
||||
eth_w5500_config_t w5500_config =
|
||||
ETH_W5500_DEFAULT_CONFIG(SPI2_HOST, &spi_devcfg);
|
||||
|
||||
w5500_config.int_gpio_num = PIN_INT;
|
||||
|
||||
// ---------------- MAC / PHY ----------------
|
||||
eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG();
|
||||
eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();
|
||||
|
||||
phy_config.reset_gpio_num = PIN_RST;
|
||||
|
||||
// ---------------- CREATE MAC + PHY ----------------
|
||||
esp_eth_mac_t *mac =
|
||||
esp_eth_mac_new_w5500(&w5500_config, &mac_config);
|
||||
|
||||
esp_eth_phy_t *phy =
|
||||
esp_eth_phy_new_w5500(&phy_config);
|
||||
|
||||
esp_eth_config_t eth_config =
|
||||
ETH_DEFAULT_CONFIG(mac, phy);
|
||||
|
||||
ESP_ERROR_CHECK(
|
||||
esp_eth_driver_install(ð_config, ð_handle)
|
||||
);
|
||||
|
||||
uint8_t mac_addr[6];
|
||||
ESP_ERROR_CHECK(
|
||||
esp_eth_ioctl(
|
||||
eth_handle,
|
||||
ETH_CMD_G_MAC_ADDR,
|
||||
mac_addr
|
||||
)
|
||||
);
|
||||
|
||||
ESP_LOGI(
|
||||
TAG,
|
||||
"Ethernet MAC: %02X:%02X:%02X:%02X:%02X:%02X",
|
||||
mac_addr[0],
|
||||
mac_addr[1],
|
||||
mac_addr[2],
|
||||
mac_addr[3],
|
||||
mac_addr[4],
|
||||
mac_addr[5]
|
||||
);
|
||||
|
||||
// ---------------- NETWORK INTERFACE ----------------
|
||||
esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH();
|
||||
esp_netif_t *eth_netif = esp_netif_new(&cfg);
|
||||
|
||||
ESP_ERROR_CHECK(
|
||||
esp_netif_attach(
|
||||
eth_netif,
|
||||
esp_eth_new_netif_glue(eth_handle)
|
||||
)
|
||||
);
|
||||
|
||||
// ---------------- START ETH ----------------
|
||||
ESP_ERROR_CHECK(esp_eth_start(eth_handle));
|
||||
|
||||
ESP_LOGI(TAG, "W5500 init complete, waiting for DHCP...");
|
||||
|
||||
while (true) {
|
||||
vTaskDelay(pdMS_TO_TICKS(2000));
|
||||
}
|
||||
|
||||
// printf("Restarting now.\n");
|
||||
// esp_restart();
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue