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

LAN8670 PLCA Configuration error (IDFGH-14401) #48

Closed
3 tasks done
alexsb3 opened this issue Jan 11, 2025 · 1 comment · Fixed by #49
Closed
3 tasks done

LAN8670 PLCA Configuration error (IDFGH-14401) #48

alexsb3 opened this issue Jan 11, 2025 · 1 comment · Fixed by #49
Assignees
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally

Comments

@alexsb3
Copy link

alexsb3 commented Jan 11, 2025

Checklist

  • Checked the issue tracker for similar issues to ensure this is not a duplicate
  • Read the documentation to confirm the issue is not addressed there and your configuration is set correctly
  • Tested with the latest version to ensure the issue hasn't been fixed

How often does this bug occurs?

always

Expected behavior

I'm configuring the PLCA parameters of the LAN8670 using the following commands:
LAN867X_ETH_CMD_S_EN_PLCA, LAN867X_ETH_CMD_S_PLCA_NCNT, LAN867X_ETH_CMD_S_PLCA_ID, LAN867X_ETH_CMD_S_PLCA_TOT, LAN867X_ETH_CMD_S_MAX_BURST_COUNT, LAN867X_ETH_CMD_S_BURST_TIMER from esp_eth_phy_lan867x.h

I expect that when I view the modified values with the get commands (example LAN867X_ETH_CMD_G_EN_PLCA) from esp_eth_phy_lan867x.h, I should see all the modifications I have done to the PLCA of the LAN8670.

Actual behavior (suspected bug)

What I get is that some modifications are carried out some not:

  • Values that are modified correctly: LAN867X_ETH_CMD_S_PLCA_NCNT, LAN867X_ETH_CMD_S_PLCA_ID, LAN867X_ETH_CMD_S_MAX_BURST_COUNT, LAN867X_ETH_CMD_S_BURST_TIMER.

  • Values that NOT are modified correctly: LAN867X_ETH_CMD_S_EN_PLCA, LAN867X_ETH_CMD_S_PLCA_TOT

I suspect that when the command access the different registers to modify the values of the PLCA parameters, the registers that additionally have some of the bits reserved block the modification of the other bits. I suspect that this is the case since the parameters that I can modify not have any of the bits reserved and the other ones have some parts with reserved bits.

Pictures from the lan8670 datasheet

PLCA Enable NOT being able to modification:
image

PLCA Node Count and PLCA ID being able to modification:
image

PLCA TOT NOT being able to modification:
image

PLCA Max Burst Count and PLCA Burst Timer being able to modification:
image

Error logs or terminal output

I (31) boot: ESP-IDF v5.3.1 2nd stage bootloader
I (31) boot: compile time Dec 15 2024 18:48:01
I (31) boot: Multicore bootloader
I (35) boot: chip revision: v1.0
I (39) boot.esp32: SPI Speed      : 40MHz
I (43) boot.esp32: SPI Mode       : DIO
I (48) boot.esp32: SPI Flash Size : 2MB
I (52) boot: Enabling RNG early entropy source...
I (58) boot: Partition Table:
I (61) boot: ## Label            Usage          Type ST Offset   Length  
I (69) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (76) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (84) boot:  2 factory          factory app      00 00 00010000 00100000
I (91) boot: End of partition table
I (95) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=13330h ( 78640) map
I (131) esp_image: segment 1: paddr=00023358 vaddr=3ffb0000 size=02468h (  9320) load
I (135) esp_image: segment 2: paddr=000257c8 vaddr=40080000 size=0a850h ( 43088) load
I (153) esp_image: segment 3: paddr=00030020 vaddr=400d0020 size=34914h (215316) map
I (228) esp_image: segment 4: paddr=0006493c vaddr=4008a850 size=02ea8h ( 11944) load
I (239) boot: Loaded app from partition at offset 0x10000
I (239) boot: Disabling RNG early entropy source...
I (251) cpu_start: Multicore app
I (260) cpu_start: Pro cpu start user code
I (260) cpu_start: cpu freq: 160000000 Hz
I (260) app_init: Application information:
I (263) app_init: Project name:     SPE_client
I (268) app_init: App version:      1
I (272) app_init: Compile time:     Jan  4 2025 17:55:02
I (278) app_init: ELF file SHA256:  09c1a4bfd...
I (283) app_init: ESP-IDF:          v5.3.1
I (288) efuse_init: Min chip rev:     v0.0
I (293) efuse_init: Max chip rev:     v3.99 
I (298) efuse_init: Chip rev:         v1.0
I (303) heap_init: Initializing. RAM available for dynamic allocation:
I (310) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (316) heap_init: At 3FFB3748 len 0002C8B8 (178 KiB): DRAM
I (322) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (329) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (335) heap_init: At 4008D6F8 len 00012908 (74 KiB): IRAM
I (343) spi_flash: detected chip: generic
I (346) spi_flash: flash io: dio
W (350) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (364) main_task: Started on CPU0
I (374) main_task: Calling app_main()
I (404) esp_eth.netif.netif_glue: 24:0a:c4:5f:e7:6f
I (404) esp_eth.netif.netif_glue: ethernet attached to netif
I (404) lan867x_client: PLCA values previous modification 

I (414) lan867x_client: Original PLCA Enable: TRUE. 

I (414) lan867x_client: Original Total Nodes: 8. 

I (424) lan867x_client: Original PLCA ID: 255. 

I (424) lan867x_client: Original Time Window: 0. 

I (434) lan867x_client: Original Burst Packets: 128. 

I (434) lan867x_client: Original Burst Timer: 0. 

I (444) ethernet_init: Ethernet(LAN867x[23,18]) Started
I (454) ethernet_init: Ethernet(LAN867x[23,18]) Link Up
I (454) ethernet_init: Ethernet(LAN867x[23,18]) HW Addr 24:0a:c4:5f:e7:6f
I (464) esp_netif_handlers: eth ip: 192.168.1.101, mask: 255.255.255.0, gw: 192.168.1.255
I (474) lan867x_client: Ethernet Got IP Address
I (474) lan867x_client: ~~~~~~~~~~~
I (484) lan867x_client: ETHIP:192.168.1.101
I (484) lan867x_client: ETHMASK:255.255.255.0
I (494) lan867x_client: ETHGW:192.168.1.255
I (494) lan867x_client: ~~~~~~~~~~~
I (514) lan867x_client: 
 PLCA values after modification 

I (514) lan867x_client: New PLCA Enable: TRUE. 

I (514) lan867x_client: New Total Nodes: 3. 

I (514) lan867x_client: New PLCA ID: 1. 

I (524) lan867x_client: New Time Window: 0. 

I (524) lan867x_client: New Burst Packets: 64. 

I (534) lan867x_client: New Burst Timer: 3. 

I (534) main_task: Returned from app_main()

Steps to reproduce the behavior

  1. Create an ESP-IDF project
  2. Add the IDF Component lan867x 1.0.1 (https://components.espressif.com/components/espressif/lan867x/versions/1.0.1)
  3. Use the lan867x_tcp_sockets/client example and add some modifications to use the all the PLCA commands:

Code:

#include <stdio.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_mac.h"
#include "esp_netif.h"
#include "esp_eth.h"
#include "esp_eth_phy_lan867x.h"
#include "esp_event.h"
#include "esp_log.h"
#include "ethernet_init.h"
#include "lwip/sockets.h"
#include "sdkconfig.h"

#define SOCKET_ADDRESS "192.168.1.100"
#define SOCKET_PORT 5000
#define SOCKET_MAX_LENGTH 1400

#define CONFIG_EXAMPLE_LAN867X_USE_PLCA 1

static const char *TAG = "lan867x_client";
static SemaphoreHandle_t xGotIpSemaphore;

/* Event handler for IP_EVENT_ETH_GOT_IP (Connect Driver to TCP/IP Stack) */
static void got_ip_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *data)
{
ip_event_got_ip_t *event = (ip_event_got_ip_t *) data;
const esp_netif_ip_info_t *ip_info = &event->ip_info;

ESP_LOGI(TAG, "Ethernet Got IP Address");
ESP_LOGI(TAG, "~~~~~~~~~~~");
ESP_LOGI(TAG, "ETHIP:" IPSTR, IP2STR(&ip_info->ip));
ESP_LOGI(TAG, "ETHMASK:" IPSTR, IP2STR(&ip_info->netmask));
ESP_LOGI(TAG, "ETHGW:" IPSTR, IP2STR(&ip_info->gw));
ESP_LOGI(TAG, "~~~~~~~~~~~");
xSemaphoreGive(xGotIpSemaphore);

}

void app_main(void)
{
// Create default event loop that running in background
ESP_ERROR_CHECK(esp_event_loop_create_default());

// Initialize semaphore
xGotIpSemaphore = xSemaphoreCreateBinary();

// Initialize Ethernet driver (lan867x)
uint8_t eth_port_cnt = 0;
esp_eth_handle_t *eth_handles;
ESP_ERROR_CHECK(ethernet_init_all(&eth_handles, &eth_port_cnt));

/* (Connect Driver to TCP/IP Stack) */

// Initialize TCP/IP network interface aka the esp-netif (should be called only once in application)
ESP_ERROR_CHECK(esp_netif_init());

/* Static IP Definition */
esp_netif_ip_info_t ip_info = {
    .ip = {.addr = ESP_IP4TOADDR(192, 168, 1, 101)},
    .netmask = {.addr =  ESP_IP4TOADDR(255, 255, 255, 0)},
    .gw = {.addr = ESP_IP4TOADDR(192, 168, 1, 255)}
};

// Apply network interface configuration for Ethernet
esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH();
// Create network interface for Ethernet driver
esp_netif_t *eth_netif = esp_netif_new(&cfg);

// Attach Ethernet driver to TCP/IP stack
ESP_ERROR_CHECK(esp_netif_attach(eth_netif, esp_eth_new_netif_glue(eth_handles[0])));
// Register user defined event handers
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &got_ip_event_handler, NULL));

// Stop DHCP client
esp_netif_dhcpc_stop(eth_netif);
// Set a static IP address
esp_netif_set_ip_info(eth_netif, &ip_info);


ESP_LOGI(TAG, "PLCA values previous modification \n");

// Get PLCA Enable
bool en_plca_original;
esp_eth_ioctl(eth_handles[0], LAN867X_ETH_CMD_G_PLCA_ID, &en_plca_original);
if (en_plca_original==false){
    ESP_LOGI(TAG, "Original PLCA Enable: FALSE. \n");
}
else{
    ESP_LOGI(TAG, "Original PLCA Enable: TRUE. \n");
}

// Get Count Nodes
uint8_t tot_nodes_plca_original;
esp_eth_ioctl(eth_handles[0], LAN867X_ETH_CMD_G_PLCA_NCNT, &tot_nodes_plca_original);
ESP_LOGI(TAG, "Original Total Nodes: %d. \n", tot_nodes_plca_original);

// Get PLCA ID
uint8_t id_plca_original;
esp_eth_ioctl(eth_handles[0], LAN867X_ETH_CMD_G_PLCA_ID, &id_plca_original);
ESP_LOGI(TAG, "Original PLCA ID: %d. \n", id_plca_original);

// Get Window Send data
uint8_t tot_plca_original;
esp_eth_ioctl(eth_handles[0], LAN867x_ETH_CMD_G_PLCA_TOT, &tot_plca_original);
ESP_LOGI(TAG, "Original Time Window: %d. \n", tot_plca_original);

// Get Burst Count
uint8_t burst_plca_original;
esp_eth_ioctl(eth_handles[0], LAN867X_ETH_CMD_G_MAX_BURST_COUNT, &burst_plca_original);
ESP_LOGI(TAG, "Original Burst Packets: %d. \n", burst_plca_original);

// Get Burst Timer
uint8_t burst_timer_plca_original;
esp_eth_ioctl(eth_handles[0], LAN867X_ETH_CMD_G_BURST_TIMER, &burst_timer_plca_original);
ESP_LOGI(TAG, "Original Burst Timer: %d. \n", burst_timer_plca_original);


// Configure PLCA

#if CONFIG_EXAMPLE_LAN867X_USE_PLCA
// Set PLCA Node Count
uint8_t plca_node_count = 3;
esp_eth_ioctl(eth_handles[0], LAN867X_ETH_CMD_S_PLCA_NCNT, &plca_node_count);

// Set PLCA ID
uint8_t plca_id = 1;
esp_eth_ioctl(eth_handles[0], LAN867X_ETH_CMD_S_PLCA_ID, &plca_id);

// Set Time Window
uint8_t plca_time = 48;
esp_eth_ioctl(eth_handles[0], LAN867x_ETH_CMD_S_PLCA_TOT, &plca_time);

// Burst Count
uint8_t burst_plca = 64;
esp_eth_ioctl(eth_handles[0], LAN867X_ETH_CMD_S_MAX_BURST_COUNT, &burst_plca);

// Burst Timer
uint8_t burst_timer_plca = 3;
esp_eth_ioctl(eth_handles[0], LAN867X_ETH_CMD_S_BURST_TIMER, &burst_timer_plca);

// Enable or disable PLCA
bool plca_en = true;
esp_eth_ioctl(eth_handles[0], LAN867X_ETH_CMD_S_EN_PLCA, &plca_en);

#endif // otherwise rely on CSMA/CD

// Start Ethernet driver state machine
esp_eth_start(eth_handles[0]);

/* Misc. and Control of Ethernet Driver */

// Get MAC address and save it as a string
char mac_str[18];
uint8_t mac_data[6];
esp_eth_ioctl(eth_handles[0], ETH_CMD_G_MAC_ADDR, &mac_data);
sprintf(mac_str, "%02x:%02x:%02x:%02x:%02x:%02x", mac_data[0], mac_data[1], mac_data[2], mac_data[3], mac_data[4], mac_data[5]);

// Check PLCA status
vTaskDelay(pdMS_TO_TICKS(50));

ESP_LOGI(TAG, "\n PLCA values after modification \n");

// Get PLCA Enable
bool en_plca_new;
esp_eth_ioctl(eth_handles[0], LAN867X_ETH_CMD_G_PLCA_ID, &en_plca_new);
if (en_plca_new==false){
    ESP_LOGI(TAG, "New PLCA Enable: FALSE. \n");
}
else{
    ESP_LOGI(TAG, "New PLCA Enable: TRUE. \n");
}

// Get Count Nodes
uint8_t tot_nodes_plca_new;
esp_eth_ioctl(eth_handles[0], LAN867X_ETH_CMD_G_PLCA_NCNT, &tot_nodes_plca_new);
ESP_LOGI(TAG, "New Total Nodes: %d. \n", tot_nodes_plca_new);

// Get PLCA ID
uint8_t id_plca_new;
esp_eth_ioctl(eth_handles[0], LAN867X_ETH_CMD_G_PLCA_ID, &id_plca_new);
ESP_LOGI(TAG, "New PLCA ID: %d. \n", id_plca_new);

// Get Window Send data
uint8_t tot_plca_new;
esp_eth_ioctl(eth_handles[0], LAN867x_ETH_CMD_G_PLCA_TOT, &tot_plca_new);
ESP_LOGI(TAG, "New Time Window: %d. \n", tot_plca_new);

// Get Burst Count
uint8_t burst_plca_new;
esp_eth_ioctl(eth_handles[0], LAN867X_ETH_CMD_G_MAX_BURST_COUNT, &burst_plca_new);
ESP_LOGI(TAG, "New Burst Packets: %d. \n", burst_plca_new);

// Get Burst Timer
uint8_t burst_timer_plca_new;
esp_eth_ioctl(eth_handles[0], LAN867X_ETH_CMD_G_BURST_TIMER, &burst_timer_plca_new);
ESP_LOGI(TAG, "New Burst Timer: %d. \n", burst_timer_plca_new);

}

Project release version

Using VSC with ESP-IDF v5.3.1

System architecture

Intel/AMD 64-bit (modern PC, older Mac)

Operating system

Windows

Operating system version

Windows 10 Home

Shell

PowerShell

Additional context

No response

@github-actions github-actions bot changed the title LAN8670 PLCA Configuration error LAN8670 PLCA Configuration error (IDFGH-14401) Jan 11, 2025
bogdankolendovskyy added a commit to bogdankolendovskyy/esp-eth-drivers that referenced this issue Jan 13, 2025
Commit fixe the byte order in truct that defines TOTMR register and adds padding to prevent possible issues among compilers.
Also addresses two typos made in custom_ioctl commands.

Closes espressif#48
bogdankolendovskyy added a commit to bogdankolendovskyy/esp-eth-drivers that referenced this issue Jan 13, 2025
Commit fixe the byte order in truct that defines TOTMR register and adds padding to prevent possible issues among compilers.
Also addresses two typos made in custom_ioctl commands.

Closes espressif#48
@bogdankolendovskyy bogdankolendovskyy self-assigned this Jan 13, 2025
bogdankolendovskyy added a commit to bogdankolendovskyy/esp-eth-drivers that referenced this issue Jan 14, 2025
Commit fixe the byte order in truct that defines TOTMR register and adds padding to prevent possible issues among compilers.
Also addresses two typos made in custom_ioctl commands.

Closes espressif#48
@kostaond
Copy link
Collaborator

@alexsb3 thank you for reporting the issue! It will be fixed soon. See linked PR for more information.

@espressif-bot espressif-bot added Status: In Progress Work is in progress and removed Status: Opened labels Jan 14, 2025
bogdankolendovskyy added a commit to bogdankolendovskyy/esp-eth-drivers that referenced this issue Jan 16, 2025
Commit fixe the byte order in truct that defines TOTMR register and adds padding to prevent possible issues among compilers.
Also addresses two typos made in custom_ioctl commands.

Closes espressif#48
@espressif-bot espressif-bot added Status: Done Issue is done internally Resolution: Done Issue is done internally and removed Status: In Progress Work is in progress labels Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants