Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eth w5500 not work #517

Closed
hhy50 opened this issue Nov 19, 2024 · 2 comments
Closed

eth w5500 not work #517

hhy50 opened this issue Nov 19, 2024 · 2 comments

Comments

@hhy50
Copy link

hhy50 commented Nov 19, 2024

code:

use esp_idf_svc::hal::prelude::FromValueType;
use esp_idf_svc::{
    eventloop::EspSystemEventLoop,
    hal::{prelude::Peripherals, spi},
    handle::RawHandle,
    nvs::EspDefaultNvsPartition,
    sys::{esp_netif_set_hostname, EspError},
};
use std::{thread, time::Duration};

fn main() -> Result<(), EspError> {
    // It is necessary to call this function once. Otherwise some patches to the runtime
    // implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71
    esp_idf_svc::sys::link_patches();
    // Bind the log crate to the ESP Logging facilities
    esp_idf_svc::log::EspLogger::initialize_default();

    // 初始化 ESP32 环境
    let peripherals: Peripherals = Peripherals::take()?;
    let sys_event_loop = EspSystemEventLoop::take()?;
    let nvs: esp_idf_svc::nvs::EspNvsPartition<esp_idf_svc::nvs::NvsDefault> =
        EspDefaultNvsPartition::take()?;

    let pins = peripherals.pins;
    let etg_driver = esp_idf_svc::eth::EthDriver::new_spi(
        spi::SpiDriver::new(
            peripherals.spi2,
            pins.gpio2,
            pins.gpio10,
            Some(pins.gpio3),
            &spi::SpiDriverConfig::new().dma(spi::Dma::Auto(4096)),
        )?,
        pins.gpio6,
        Some(pins.gpio7),
        Some(pins.gpio4),
        esp_idf_svc::eth::SpiEthChipset::W5500,
        5.MHz().into(),
        Some(&[0x02, 0x00, 0x00, 0xfc, 0x19, 0x01]),
        None,
        sys_event_loop,
    )?;
    log::info!("is_connected: {:?}", etg_driver.is_connected());
    // spi
    let mut esp_eth = esp_idf_svc::eth::EspEth::wrap(etg_driver)?;
    log::info!("start eth driver.......");
    esp_eth.start()?;
    // esp_e
    while esp_eth.is_started()? {
        thread::sleep(Duration::from_secs(1));
    }
    log::info!("eth driver started.....");
    Ok(())
}

log:

2024-11-19T08:56:26Z INFO ] Detected 2 serial ports
[2024-11-19T08:56:26Z INFO ] Ports which match a known common dev board are highlighted
[2024-11-19T08:56:26Z INFO ] Please select a port
[2024-11-19T08:56:27Z INFO ] Serial port: '/dev/cu.usbmodem142201'
[2024-11-19T08:56:27Z INFO ] Connecting...
[2024-11-19T08:56:27Z INFO ] Using flash stub
Chip type:         esp32c3 (revision v0.4)
Crystal frequency: 40 MHz
Flash size:        4MB
Features:          WiFi, BLE
MAC address:       e4:b0:63:00:4b:30
Partition table:   partitions.csv
App/part. size:    724,672/3,145,728 bytes, 23.04%
[2024-11-19T08:56:28Z INFO ] Segment at address '0x0' has not changed, skipping write
[2024-11-19T08:56:28Z INFO ] Segment at address '0x8000' has not changed, skipping write
[00:00:03] [========================================]     376/376     0x10000                                                                                                                                                                                [2024-11-19T08:56:32Z INFO ] Flashing has completed!
Commands:
    CTRL+R    Reset chip
    CTRL+C    Exit

ESP-ROM:esp32c3-api1-20210207
Build:Feb  7 2021
rst:0x15 (USB_UART_CHIP_RESET),boot:0xc (SPI_FAST_FLASH_BOOT)
Saved PC:0x40380572
0x40380572 - check_trans_valid
    at /Users/hanhaiyang/.espressif/esp-idf/v5.2.2/components/driver/spi/gpspi/spi_master.c:804
SPIWP:0xee
mode:DIO, clock div:2
load:0x3fcd5820,len:0x1714
load:0x403cc710,len:0x968
load:0x403ce710,len:0x2f9c
entry 0x403cc710
I (19) boot: ESP-IDF v5.1.2-342-gbcf1645e44 2nd stage bootloader
I (20) boot: compile time Dec 12 2023 10:50:58
I (20) boot: chip revision: v0.4
I (25) boot.esp32c3: SPI Speed      : 40MHz
I (29) boot.esp32c3: SPI Mode       : DIO
I (33) boot.esp32c3: SPI Flash Size : 4MB
I (38) boot: Enabling RNG early entropy source...
I (44) boot: Partition Table:
I (47) boot: ## Label            Usage          Type ST Offset   Length
I (54) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (62) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (69) boot:  2 factory          factory app      00 00 00010000 00300000
I (77) boot: End of partition table
I (81) esp_image: segment 0: paddr=00010020 vaddr=3c080020 size=2142ch (136236) map
I (120) esp_image: segment 1: paddr=00031454 vaddr=3fc8ea00 size=01618h (  5656) load
I (122) esp_image: segment 2: paddr=00032a74 vaddr=40380000 size=0d5a4h ( 54692) load
I (139) esp_image: segment 3: paddr=00040020 vaddr=42000020 size=7fbc0h (523200) map
I (256) esp_image: segment 4: paddr=000bfbe8 vaddr=4038d5a4 size=012ach (  4780) load
I (262) boot: Loaded app from partition at offset 0x10000
I (262) boot: Disabling RNG early entropy source...
I (276) cpu_start: Unicore app
I (285) cpu_start: Pro cpu start user code
I (285) cpu_start: cpu freq: 160000000 Hz
I (285) cpu_start: Application information:
I (288) cpu_start: Project name:     libespidf
I (293) cpu_start: App version:      2f17587
I (298) cpu_start: Compile time:     Nov 19 2024 11:22:41
I (304) cpu_start: ELF file SHA256:  000000000...
I (309) cpu_start: ESP-IDF:          v5.2.2
I (314) cpu_start: Min chip rev:     v0.3
I (319) cpu_start: Max chip rev:     v1.99 
I (324) cpu_start: Chip rev:         v0.4
I (329) heap_init: Initializing. RAM available for dynamic allocation:
I (336) heap_init: At 3FC91A40 len 0002E5C0 (185 KiB): RAM
I (342) heap_init: At 3FCC0000 len 0001C710 (113 KiB): Retention RAM
I (349) heap_init: At 3FCDC710 len 00002950 (10 KiB): Retention RAM
I (356) heap_init: At 50000010 len 00001FD8 (7 KiB): RTCRAM
I (364) spi_flash: detected chip: generic
I (367) spi_flash: flash io: dio
W (371) i2c: This driver is an old driver, please migrate your application code to adapt `driver/i2c_master.h`
W (381) timer_group: legacy driver is deprecated, please migrate to `driver/gptimer.h`
I (390) sleep: Configure to isolate all GPIO pins in sleep state
I (397) sleep: Enable automatic switching of GPIO sleep configuration
I (404) coexist: coex firmware version: d96c1e51f
I (410) coexist: coexist rom version 9387209
I (415) main_task: Started on CPU0
I (415) main_task: Calling app_main()
E (525) w5500.mac: W5500 version mismatched, expected 0x04, got 0x00
E (525) w5500.mac: emac_w5500_init(825): vefiry chip ID failed
I (525) gpio: GPIO[6]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
E (535) esp_eth: esp_eth_driver_install(228): init mac failed
I (535) esp_idf_svc::eventloop: System event loop dropped
E (545) spi_master: spi_master_deinit_driver(309): not all CSses freed
I (555) gpio: GPIO[10]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
I (565) gpio: GPIO[3]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
I (575) gpio: GPIO[2]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 

assert failed: spi_bus_deinit_lock spi_bus_lock.c:594 (atomic_load(&lock->dev[i]) == (intptr_t)NULL)
Core  0 register dump:
MEPC    : 0x4038298e  RA      : 0x40385984  SP      : 0x3fca3210  GP      : 0x3fc8f200  
0x4038298e - panic_abort
    at /Users/hanhaiyang/.espressif/esp-idf/v5.2.2/components/esp_system/panic.c:466
0x40385984 - __ubsan_include
    at /Users/hanhaiyang/.espressif/esp-idf/v5.2.2/components/esp_system/ubsan.c:313
0x3fc8f200 - msg.1
    at ??:??
TP      : 0x3fc82384  T0      : 0x37363534  T1      : 0x7271706f  T2      : 0x33323130  
S0/FP   : 0x00000063  S1      : 0x00000001  A0      : 0x3fca324c  A1      : 0x3fc8f7a5  
A2      : 0x00000001  A3      : 0x00000029  A4      : 0x00000001  A5      : 0x3fc91000  
0x3fc91000 - arp_table
    at ??:??
A6      : 0x7a797877  A7      : 0x76757473  S2      : 0x00000009  S3      : 0x3fca3384  
S4      : 0x3fc8f7a4  S5      : 0x00000000  S6      : 0x00000000  S7      : 0x00000000  
S8      : 0x00000000  S9      : 0x00000000  S10     : 0x00000000  S11     : 0x00000000  
T3      : 0x6e6d6c6b  T4      : 0x6a696867  T5      : 0x66656463  T6      : 0x62613938  
MSTATUS : 0x00001881  MTVEC   : 0x40380001  MCAUSE  : 0x00000007  MTVAL   : 0x00000000  
0x40380001 - _vector_table
    at ??:??
MHARTID : 0x00000000  

Stack memory:
3fca3210: 0x3c08dcc8 0x3c08db94 0x3c09cea0 0x4038d05c 0x3fc8fb28 0x3c09cea0 0x3fc8fb38 0x3c08f4d8
0x3c09cea0 - __func__.3
    at ??:??
0x4038d05c - newlib_include_assert_impl
    at /Users/hanhaiyang/.espressif/esp-idf/v5.2.2/components/newlib/assert.c:93
0x3c09cea0 - __func__.3
    at ??:??
3fca3230: 0x3fc8fb3c 0x3fca3244 0x3fc8fb40 0x3c08f48c 0x3fc8f7a4 0x00343935 0x00000003 0x65737361
3fca3250: 0x66207472 0x656c6961 0x73203a64 0x625f6970 0x645f7375 0x696e6965 0x6f6c5f74 0x73206b63
3fca3270: 0x625f6970 0x6c5f7375 0x2e6b636f 0x39353a63 0x61282034 0x696d6f74 0x6f6c5f63 0x26286461
3fca3290: 0x6b636f6c 0x65643e2d 0x5d695b76 0x3d3d2029 0x6e692820 0x72747074 0x4e29745f 0x294c4c55
3fca32b0: 0x00000000 0x00000001 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fca32d0: 0x00000000 0x00000000 0x00000001 0x00000000 0x00000103 0x00000001 0x00000002 0x4203f05a
0x4203f05a - gpio_reset_pin
    at /Users/hanhaiyang/.espressif/esp-idf/v5.2.2/components/driver/gpio/gpio.c:453
3fca32f0: 0x3c080cd8 0x00000003 0x00000004 0x00000000 0x00000000 0x00000001 0x00000000 0x00000000
0x3c080cd8 - $d
    at ??:??
3fca3310: 0x00000000 0x00000000 0x00000000 0x42000000 0x00000016 0x00000221 0x00000001 0x00000000
3fca3330: 0x00000103 0x00000001 0x3fca578c 0x420421a8 0x00000000 0x00000001 0x3fca578c 0x42040bda
0x420421a8 - spi_bus_deinit_lock
    at /Users/hanhaiyang/.espressif/esp-idf/v5.2.2/components/driver/spi/spi_bus_lock.c:596
0x42040bda - spi_bus_free
    at /Users/hanhaiyang/.espressif/esp-idf/v5.2.2/components/driver/spi/gpspi/spi_common.c:932
3fca3350: 0x3fca5ab0 0x3fca3564 0x3fca355c 0x42004386 0x3fca5ab0 0x00000001 0x3fca5170 0x42000b7a
0x42004386 - esp_idf_sys::error::EspError::check_and_return
    at /Users/hanhaiyang/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp-idf-sys-0.35.0/src/error.rs:49
0x42000b7a - core::ptr::drop_in_place<esp_idf_hal::task::CriticalSection>
    at /Users/hanhaiyang/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:574
3fca3370: 0x3fca34d0 0x0000005c 0x00000000 0x00000016 0x3c080cd8 0x00000016 0x3c080cf0 0x3c080cd0
0x3c080cd8 - $d
    at ??:??
0x3c080cf0 - $d
    at ??:??
0x3c080cd0 - $d
    at ??:??
3fca3390: 0x00000001 0x00000004 0x00000000 0x00000000 0x3fca5ab0 0x0000010a 0x3fca5170 0x420013b6
0x420013b6 - esp_idf_svc::eth::EthDriver<T>::init
    at /Users/hanhaiyang/.cargo/git/checkouts/esp-idf-svc-a28457b0e32c6283/7cf3a9a/src/eth.rs:886
3fca33b0: 0xa5a5a5a5 0x00000000 0xa5a5a5a5 0x3fca33e8 0x3fca5170 0x3fca5364 0xa5a5a5a5 0xa5a5a5a5
3fca33d0: 0x3c0926dc 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0x00000000 0xa5a5a5a5 0x00000003 0x00001000
3fca33f0: 0xa5a50000 0x00000000 0x00000000 0x00000000 0x00000000 0xa5a5a5a5 0xa5a5a500 0x00001000
3fca3410: 0xa5a5a501 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fca3430: 0x00000000 0x00000014 0x00000000 0x00000000 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
3fca3450: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
3fca3470: 0xa5a5a5a5 0x3fca5ab0 0x3fca6f14 0x000007d0 0x00000000 0x00000000 0x00000000 0x00000000
3fca3490: 0x00000000 0x00000000 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
3fca34b0: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0x3fca5170
3fca34d0: 0x00000064 0x00000800 0x0000000f 0x00000000 0xffffffff 0x00000064 0x00000fa0 0x00000004
3fca34f0: 0x3fca5170 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0xa5a5a5a5
3fca3510: 0xa5a5a5a5 0xa5a5a5a5 0x3fca3630 0x4038b144 0x00000000 0x00000054 0x00000000 0x4038b144
0x4038b144 - multi_heap_internal_unlock
    at /Users/hanhaiyang/.espressif/esp-idf/v5.2.2/components/heap/multi_heap.c:171
0x4038b144 - multi_heap_internal_unlock
    at /Users/hanhaiyang/.espressif/esp-idf/v5.2.2/components/heap/multi_heap.c:171
3fca3530: 0x00000000 0x00000004 0x00000000 0x4038b144 0x00000000 0x0000000c 0x3fc91a40 0x4038b186
0x4038b144 - multi_heap_internal_unlock
    at /Users/hanhaiyang/.espressif/esp-idf/v5.2.2/components/heap/multi_heap.c:171
0x4038b186 - multi_heap_malloc_impl
    at /Users/hanhaiyang/.espressif/esp-idf/v5.2.2/components/heap/multi_heap.c:221
3fca3550: 0x00000804 0x00001800 0x3fc91df0 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fca3570: 0x00000000 0xa5a5a5a5 0xa5a5a500 0x00001000 0xa5a5a501 0x00000000 0x3fc91df0 0x40382c0a
0x40382c0a - heap_caps_malloc_base
    at /Users/hanhaiyang/.espressif/esp-idf/v5.2.2/components/heap/heap_caps.c:180
3fca3590: 0x00000000 0x3fca35d4 0x00000000 0x00000003 0x00001800 0x0000000c 0x00000000 0x40382c9e
0x40382c9e - heap_caps_malloc
    at /Users/hanhaiyang/.espressif/esp-idf/v5.2.2/components/heap/heap_caps.c:202
3fca35b0: 0x3fca4070 0x0000000c 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fca35d0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000001 0x3fca3658 0x3c0806f8 0x420003cc
0x3c0806f8 - $d
    at ??:??
0x420003cc - core::hint::black_box
    at ??:??
3fca35f0: 0x00000001 0x00000000 0x3fca4070 0x42000384 0x00000000 0x00000000 0x00000000 0x00000000
0x42000384 - <core::result::Result<T,E> as std::process::Termination>::report
    at /Users/hanhaiyang/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/process.rs:2452



ELF file SHA256: 000000000

Rebooting...
ESP-ROM:esp32c3-api1-20210207
Build:Feb  7 2021
rst:0xc (RTC_SW_CPU_RST),boot:0xc (SPI_FAST_FLASH_BOOT)
Saved PC:0x4038294a
0x4038294a - esp_restart_noos
    at /Users/hanhaiyang/.espressif/esp-idf/v5.2.2/components/esp_system/port/soc/esp32c3/system_internal.c:111
SPIWP:0xee
mode:DIO, clock div:2
load:0x3fcd5820,len:0x1714
load:0x403cc710,len:0x968
load:0x403ce710,len:0x2f9c
entry 0x403cc710
I (19) boot: ESP-IDF v5.1.2-342-gbcf1645e44 2nd stage bootloader
I (20) boot: compile time Dec 12 2023 10:50:58
I (20) boot: chip revision: v0.4
I (25) boot.esp32c3: SPI Speed      : 40MHz
I (29) boot.esp32c3: SPI Mode       : DIO
I (33) boot.esp32c3: SPI Flash Size : 4MB
I (38) boot: Enabling RNG early entropy source...
I (44) boot: Partition Table:
I (47) boot: ## Label            Usage          Type ST Offset   Length
I (54) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (62) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (69) boot:  2 factory          factory app      00 00 00010000 00300000
I (77) boot: End of partition table
I (81) esp_image: segment 0: paddr=00010020 vaddr=3c080020 size=2142ch (136236) map
I (120) esp_image: segment 1: paddr=00031454 vaddr=3fc8ea00 size=01618h (  5656) load
I (122) esp_image: segment 2: paddr=00032a74 vaddr=40380000 size=0d5a4h ( 54692) load
I (139) esp_image: segment 3: paddr=00040020 vaddr=42000020 size=7fbc0h (523200) map
I (256) esp_image: segment 4: paddr=000bfbe8 vaddr=4038d5a4 size=012ach (  4780) load
I (261) boot: Loaded app from partition at offset 0x10000
I (262) boot: Disabling RNG early entropy source...
I (276) cpu_start: Unicore app
I (285) cpu_start: Pro cpu start user code
I (285) cpu_start: cpu freq: 160000000 Hz
I (285) cpu_start: Application information:
I (288) cpu_start: Project name:     libespidf
I (293) cpu_start: App version:      2f17587
I (298) cpu_start: Compile time:     Nov 19 2024 11:22:41
I (304) cpu_start: ELF file SHA256:  000000000...
I (309) cpu_start: ESP-IDF:          v5.2.2
I (314) cpu_start: Min chip rev:     v0.3
I (319) cpu_start: Max chip rev:     v1.99 
I (324) cpu_start: Chip rev:         v0.4
I (329) heap_init: Initializing. RAM available for dynamic allocation:
I (336) heap_init: At 3FC91A40 len 0002E5C0 (185 KiB): RAM
I (342) heap_init: At 3FCC0000 len 0001C710 (113 KiB): Retention RAM
I (349) heap_init: At 3FCDC710 len 00002950 (10 KiB): Retention RAM
I (356) heap_init: At 50000010 len 00001FD8 (7 KiB): RTCRAM
I (364) spi_flash: detected chip: generic
I (367) spi_flash: flash io: dio
W (371) i2c: This driver is an old driver, please migrate your application code to adapt `driver/i2c_master.h`
W (381) timer_group: legacy driver is deprecated, please migrate to `driver/gptimer.h`
I (390) sleep: Configure to isolate all GPIO pins in sleep state
I (397) sleep: Enable automatic switching of GPIO sleep configuration
I (404) coexist: coex firmware version: d96c1e51f
I (410) coexist: coexist rom version 9387209
I (415) main_task: Started on CPU0
I (415) main_task: Calling app_main()
E (525) w5500.mac: w5500_reset(305): reset timeout
E (525) w5500.mac: emac_w5500_init(823): reset w5500 failed
I (525) gpio: GPIO[6]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
E (535) esp_eth: esp_eth_driver_install(228): init mac failed
I (535) esp_idf_svc::eventloop: System event loop dropped
E (545) spi_master: spi_master_deinit_driver(309): not all CSses freed
I (555) gpio: GPIO[10]| InputEn: 0| OutputEn: 0| OpenDrai
@hhy50
Copy link
Author

hhy50 commented Nov 19, 2024

The problem is located here:

E (525) w5500.mac: W5500 version mismatched, expected 0x04, got 0x00
E (525) w5500.mac: emac_w5500_init(825): vefiry chip ID failed
I (525) gpio: GPIO[6]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
E (535) esp_eth: esp_eth_driver_install(228): init mac failed

@ivmarkov
Copy link
Collaborator

As discussed in the room, the problem is this line:

E (525) w5500.mac: emac_w5500_init(825): vefiry chip ID failed

... and this is unlikely to be a bug in the driver. Either the SPI pins are not connected correctly, or the external Ethernet module is not W5500 compatible. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

2 participants