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

[eppp]: Add support for USB host -- device transport #590

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion components/eppp_link/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
idf_component_register(SRCS "eppp_link.c"
if(CONFIG_EPPP_LINK_USB_CDC_DEVICE)
set(transport_srcs eppp_usb_device.c)
elseif(CONFIG_EPPP_LINK_USB_CDC_HOST)
set(transport_srcs eppp_usb_host.c)
endif()

idf_component_register(SRCS eppp_link.c eppp_sdio_slave.c eppp_sdio_host.c ${transport_srcs}
INCLUDE_DIRS "include"
PRIV_REQUIRES esp_netif esp_driver_spi esp_driver_gpio esp_timer driver)

if(CONFIG_EPPP_LINK_USB_CDC_DEVICE)
idf_component_optional_requires(PRIVATE espressif__esp_tinyusb)
endif()
57 changes: 57 additions & 0 deletions components/eppp_link/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ menu "eppp_link"
bool "SPI"
help
Use SPI.

config EPPP_LINK_DEVICE_SDIO
bool "SDIO"
depends on SOC_SDMMC_HOST_SUPPORTED || SOC_SDIO_SLAVE_SUPPORTED
help
Use SDIO.

config EPPP_LINK_USB_CDC
bool "USB"
depends on SOC_USB_OTG_SUPPORTED
help
Use USB CDC.

endchoice

config EPPP_LINK_CONN_MAX_RETRY
Expand All @@ -34,8 +47,52 @@ menu "eppp_link"
config EPPP_LINK_PACKET_QUEUE_SIZE
int "Packet queue size"
default 64
depends on EPPP_LINK_DEVICE_SPI
help
Size of the Tx packet queue.
You can decrease the number for slower bit rates.

choice EPPP_LINK_SDIO_ROLE
prompt "Choose SDIO host or slave"
depends on EPPP_LINK_DEVICE_SDIO
default EPPP_LINK_DEVICE_SDIO_HOST if SOC_SDMMC_HOST_SUPPORTED
help
Select which either SDIO host or slave

config EPPP_LINK_DEVICE_SDIO_HOST
bool "Host"
depends on SOC_SDMMC_HOST_SUPPORTED
help
Use SDIO host.

config EPPP_LINK_DEVICE_SDIO_SLAVE
bool "SLAVE"
depends on SOC_SDIO_SLAVE_SUPPORTED
help
Use SDIO slave.

endchoice

choice EPPP_LINK_USB_CDC_ROLE
prompt "Choose USB CDC device or host"
depends on EPPP_LINK_USB_CDC
default EPPP_LINK_USB_CDC_DEVICE
help
Choose the preferred USB role, either device or host.

config EPPP_LINK_USB_CDC_HOST
bool "Host"
depends on EPPP_LINK_USB_CDC
help
Use USB CDC (ACM) host.

config EPPP_LINK_USB_CDC_DEVICE
bool "Device"
select TINYUSB_CDC_ENABLED
depends on EPPP_LINK_USB_CDC
help
Use USB CDC device.

endchoice

endmenu
15 changes: 10 additions & 5 deletions components/eppp_link/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ brings in the WiFi connectivity from the "SLAVE" microcontroller.
SLAVE micro HOST micro
\|/ +----------------+ +----------------+
| | | serial line | |
+---+ WiFi NAT PPPoS |======== UART / SPI =======| PPPoS client |
+---+ WiFi NAT PPPoS |=== UART / SPI / SDIO =====| PPPoS client |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could remove the “channels” from this image and phrase it as link channel or something like that.

| (server)| | |
+----------------+ +----------------+
```
Expand All @@ -39,14 +39,19 @@ brings in the WiFi connectivity from the "SLAVE" microcontroller.

## Throughput

Tested with WiFi-NAPT example, no IRAM optimizations
Tested with WiFi-NAPT example

### UART @ 3Mbauds
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Link TCP UDP
UART @ 3Mbauds 2Mbits/s 2Mbits/s
SPI @ 16MHz 5Mbits/s 8Mbits/s
SDIO 9Mbits/s 11Mbits/s


* TCP - 2Mbits/s
* UDP - 2Mbits/s

### SPI @ 20MHz
### SPI @ 16MHz

* TCP - 6Mbits/s
* UDP - 10Mbits/s
* TCP - 5Mbits/s
* UDP - 8Mbits/s

### SDIO

* TCP - 9Mbits/s
* UDP - 11Mbits/s
85 changes: 82 additions & 3 deletions components/eppp_link/eppp_link.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "esp_event.h"
#include "esp_netif_ppp.h"
#include "eppp_link.h"
#include "esp_serial_slave_link/essl_sdio.h"

#if CONFIG_EPPP_LINK_DEVICE_SPI
#include "driver/spi_master.h"
Expand All @@ -38,6 +39,12 @@ struct packet {
uint8_t *data;
};

#if CONFIG_EPPP_LINK_USB_CDC
#define EPPP_NEEDS_TASK 0
#else
#define EPPP_NEEDS_TASK 1
#endif

#if CONFIG_EPPP_LINK_DEVICE_SPI
#define MAX_PAYLOAD 1500
#define MIN_TRIGGER_US 20
Expand Down Expand Up @@ -86,7 +93,22 @@ struct eppp_handle {
bool netif_stop;
};


typedef esp_err_t (*transmit_t)(void *h, void *buffer, size_t len);

#if CONFIG_EPPP_LINK_DEVICE_SDIO
esp_err_t eppp_sdio_host_tx(void *h, void *buffer, size_t len);
esp_err_t eppp_sdio_host_rx(esp_netif_t *netif);
esp_err_t eppp_sdio_slave_rx(esp_netif_t *netif);
esp_err_t eppp_sdio_slave_tx(void *h, void *buffer, size_t len);
esp_err_t eppp_sdio_host_init(struct eppp_config_sdio_s *config);
esp_err_t eppp_sdio_slave_init(void);
void eppp_sdio_slave_deinit(void);
void eppp_sdio_host_deinit(void);
#elif CONFIG_EPPP_LINK_USB_CDC
esp_err_t eppp_transport_init(esp_netif_t *netif);
esp_err_t eppp_transport_tx(void *h, void *buffer, size_t len);
void eppp_transport_deinit(void);
#else
static esp_err_t transmit(void *h, void *buffer, size_t len)
{
struct eppp_handle *handle = h;
Expand Down Expand Up @@ -125,9 +147,10 @@ static esp_err_t transmit(void *h, void *buffer, size_t len)
#elif CONFIG_EPPP_LINK_DEVICE_UART
ESP_LOG_BUFFER_HEXDUMP("ppp_uart_send", buffer, len, ESP_LOG_VERBOSE);
uart_write_bytes(handle->uart_port, buffer, len);
#endif
#endif // DEVICE UART or SPI
return ESP_OK;
}
#endif

static void netif_deinit(esp_netif_t *netif)
{
Expand Down Expand Up @@ -209,7 +232,13 @@ static esp_netif_t *netif_init(eppp_type_t role, eppp_config_t *eppp_config)

esp_netif_driver_ifconfig_t driver_cfg = {
.handle = h,
#if CONFIG_EPPP_LINK_DEVICE_SDIO
.transmit = role == EPPP_CLIENT ? eppp_sdio_host_tx : eppp_sdio_slave_tx,
#elif CONFIG_EPPP_LINK_USB_CDC
.transmit = eppp_transport_tx,
#else
.transmit = transmit,
#endif
};
const esp_netif_driver_ifconfig_t *ppp_driver_cfg = &driver_cfg;

Expand Down Expand Up @@ -657,9 +686,24 @@ esp_err_t eppp_perform(esp_netif_t *netif)
}
return ESP_OK;
}
#elif CONFIG_EPPP_LINK_DEVICE_SDIO

esp_err_t eppp_perform(esp_netif_t *netif)
{
struct eppp_handle *h = esp_netif_get_io_driver(netif);
if (h->stop) {
return ESP_ERR_TIMEOUT;
}
if (h->role == EPPP_SERVER) {
return eppp_sdio_slave_rx(netif);
} else {
return eppp_sdio_host_rx(netif);
}
}

#endif // CONFIG_EPPP_LINK_DEVICE_SPI / UART

#if EPPP_NEEDS_TASK
static void ppp_task(void *args)
{
esp_netif_t *netif = args;
Expand All @@ -668,6 +712,7 @@ static void ppp_task(void *args)
h->exited = true;
vTaskDelete(NULL);
}
#endif

static bool have_some_eppp_netif(esp_netif_t *netif, void *ctx)
{
Expand Down Expand Up @@ -700,6 +745,15 @@ void eppp_deinit(esp_netif_t *netif)
}
#elif CONFIG_EPPP_LINK_DEVICE_UART
deinit_uart(esp_netif_get_io_driver(netif));
#elif CONFIG_EPPP_LINK_DEVICE_SDIO
struct eppp_handle *h = esp_netif_get_io_driver(netif);
if (h->role == EPPP_CLIENT) {
eppp_sdio_host_deinit();
} else {
eppp_sdio_slave_deinit();
}
#elif CONFIG_EPPP_LINK_USB_CDC
eppp_transport_deinit();
#endif
netif_deinit(netif);
}
Expand All @@ -714,7 +768,6 @@ esp_netif_t *eppp_init(eppp_type_t role, eppp_config_t *config)
esp_netif_t *netif = netif_init(role, config);
if (!netif) {
ESP_LOGE(TAG, "Failed to initialize PPP netif");
remove_handlers();
return NULL;
}
esp_netif_ppp_config_t netif_params;
Expand All @@ -732,6 +785,24 @@ esp_netif_t *eppp_init(eppp_type_t role, eppp_config_t *config)
}
#elif CONFIG_EPPP_LINK_DEVICE_UART
init_uart(esp_netif_get_io_driver(netif), config);
#elif CONFIG_EPPP_LINK_DEVICE_SDIO
esp_err_t ret;
if (role == EPPP_SERVER) {
ret = eppp_sdio_slave_init();
} else {
ret = eppp_sdio_host_init(&config->sdio);
}

if (ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to initialize SDIO %d", ret);
return NULL;
}
#elif CONFIG_EPPP_LINK_USB_CDC
esp_err_t ret = eppp_transport_init(netif);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to initialize USB CDC driver %d", ret);
return NULL;
}
#endif
return netif;
}
Expand All @@ -754,6 +825,12 @@ esp_netif_t *eppp_open(eppp_type_t role, eppp_config_t *config, int connect_time
return NULL;
}
#endif
#if CONFIG_EPPP_LINK_DEVICE_SDIO
if (config->transport != EPPP_TRANSPORT_SDIO) {
ESP_LOGE(TAG, "Invalid transport: SDIO device must be enabled in Kconfig");
return NULL;
}
#endif

if (config->task.run_task == false) {
ESP_LOGE(TAG, "task.run_task == false is invalid in this API. Please use eppp_init()");
Expand All @@ -780,11 +857,13 @@ esp_netif_t *eppp_open(eppp_type_t role, eppp_config_t *config, int connect_time

eppp_netif_start(netif);

#if EPPP_NEEDS_TASK
if (xTaskCreate(ppp_task, "ppp connect", config->task.stack_size, netif, config->task.priority, NULL) != pdTRUE) {
ESP_LOGE(TAG, "Failed to create a ppp connection task");
eppp_deinit(netif);
return NULL;
}
#endif
int netif_cnt = get_netif_num(netif);
if (netif_cnt < 0) {
eppp_close(netif);
Expand Down
19 changes: 19 additions & 0 deletions components/eppp_link/eppp_sdio.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once

#define MAX_SDIO_PAYLOAD 1500
#define SDIO_ALIGN(size) (((size) + 3U) & ~(3U))
#define SDIO_PAYLOAD SDIO_ALIGN(MAX_SDIO_PAYLOAD)
#define PPP_SOF 0x7E

// Interrupts and registers
#define SLAVE_INTR 0
#define SLAVE_REG_REQ 0

// Requests from host to slave
#define REQ_RESET 1
#define REQ_INIT 2
Loading
Loading