esp-idf icon indicating copy to clipboard operation
esp-idf copied to clipboard

Can P4 be added as supported chip to tusb_ncm example? (IDFGH-15502)

Open savenlid opened this issue 6 months ago • 13 comments

Is your feature request related to a problem?

No response

Describe the solution you'd like.

I would like to see the P4 supported here.

Describe alternatives you've considered.

No response

Additional context.

No response

savenlid avatar Jun 16 '25 14:06 savenlid

@savenlid It already is, could you please clarify your request? Are you missing support for P4 in some specific part of ESP-IDF?

igrr avatar Jun 16 '25 14:06 igrr

Hi

In many places P4 is not included. Example: https://github.com/espressif/esp-idf/tree/adcbdd7da4fca12cd48ca5338e3fa0e8cf6695ce/examples/peripherals/usb/device/tusb_ncm

Specifically for USB i try to understand how the code would select USB port between the 3 avilable port of the P4. For S2, S3 there is only 1 to choose from. I admit I am in early stage of looking into RNDIS. I want to access internal web-server in P4, not provide net-work access/routing to other interfaces ( ethernet-wifi) So am also in the process of understanding static routing directives for netif. Not covered by the normal examples that focus on being a "router".

Thanks /NIcholas

savenlid avatar Jun 16 '25 16:06 savenlid

Thank you for the clarification, I have updated the issue title to indicate the example you are interested in.

igrr avatar Jun 16 '25 20:06 igrr

Hello @savenlid ,

the tusb_ncm example shows how you can expose wifi network interface over USB. Since P4 does not have integrated WiFi, adding P4 support is not straighforward. We have plans to extend this example to also expose wired ethernet network connection, or P4 + WiFi companion chip (typically ESP32-C6), however I can't commit to any specific date as of now.

select USB port between the 3 avilable port of the P4

Only 2 out of the 3 USB ports are available for custom USB functions. One is Full Speed (12Mbit/s) the other one is High Speed (480 Mbit/s). You can select the port in menuconfig (Top) → Component config → TinyUSB Stack → USB Peripheral

I want to access internal web-server in P4

Typically, you'd want to access it through network interface (WiFi/wired ethernet) and only then extend with USB. Are you trying to expose the webserver via USB only?

tore-espressif avatar Jun 17 '25 06:06 tore-espressif

Thank you @tore-espressif

I would prefer the C5 over C6 since its a "hotter" chip, but its not important. Running the C5/C6 I have up and running with help from espressif, so its not an issue for me personally.

Thanks for USB port selection help.

Yes, I want webserver exposed to all interfaces, but at the same time I shall not switch/route any traffic between interfaces. I am reding docs like crazy, seems this is not an netif resposiblity, looks as if its within lwip i need to fix the routing table. Not sure there is any natural L2 switching unless you use the netif "L2-tap" so, I will continue reading about lwip-routing-table. I am still not clear over how the web.server task "connects" to the ip-stack, still reading :-) /Nicholas

savenlid avatar Jun 17 '25 07:06 savenlid

Yes, I want webserver exposed to all interfaces

This is not a good example to start with, it doesn't use netif nor lwip. It just passes packets between USB and Wi-Fi without even touching esp_netif. If you want to run a webserver on NCM, you can check this example, the first -- configuration (provisioning) part of it: https://github.com/espressif/esp-idf/tree/adcbdd7da4fca12cd48ca5338e3fa0e8cf6695ce/examples/network/sta2eth (it creates a virtual netif and connects it to the NCM) then adding Ethernet (native) and Wi-Fi (over esp-wifi-remote) should be straight-forward.

david-cermak avatar Jun 17 '25 10:06 david-cermak

@david-cermak

Hi, yes, I slowly started to understand that this was L2 switching between 2 ports, having no use for netif/lwip. I also slowly starts to understand that lwip normally don't do any routing, so that problem does not exist. It seems to me that many examples are not in sync with latest version of esp-tiny-usb. https://components.espressif.com/components/espressif/esp_tinyusb ( dont mention RNDIS/NCM unfortunately) The doc link https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/api-reference/peripherals/usb_device.html give some examples code. (I prefer actually this root-doc before example-code that seems to be written by other people, and sometimes lags behind) The page give no hint to what h files should be included in you c file.

netif, ethernet and wifi I have up and running since before. We started with S3, and now we are on P4+C5 combo.

Thanks for helping, I will look into your examples. Lots of information to digest as a newbie to esp32 family :-)

savenlid avatar Jun 17 '25 11:06 savenlid

@david-cermak

https://github.com/espressif/esp-idf/tree/adcbdd7da4fca12cd48ca5338e3fa0e8cf6695ce/examples/network/sta2eth

examples/network/sta2eth/main/usb_ncm_iface.c

Line 121 const tinyusb_net_config_t net_config = {

I cant find the definition, in github. I tried have applicable inclues ( I think ) I have tinusb component in yaml. I did : idf.py reconfigure

But no: error: unknown type name 'tinyusb_net_config_t'

FYI: I did not compile the example, I try to cherry pick from the example.

has this type been depreciated ?

Thanks

savenlid avatar Jun 17 '25 13:06 savenlid

Hi @savenlid you can find the deffinition of the tinyusb_net_config_t in esp-usb repo.

I have tinusb component in yaml.

You need to have esp_tinyusb in your yaml file, like so

Once you hit idf.py set-target <your_targe> the component manager will download the esp_tinyusb component from the ESP registry and will include it to your project.

peter-marcisovsky avatar Jun 18 '25 11:06 peter-marcisovsky

I did fix that problem. I now try to integrate the RNDIS interaction with netif from this examples/network/sta2eth example into my own project.

I use the repo as reference, and goes to github for finding the definitions.

It goes fairly well, but...

i was missing some libs in linking. C:/Espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/14.2.0/../../../../riscv32-esp-elf/bin/ld.exe: esp-idf/espressif__tinyusb/libespressif__tinyusb.a(rndis_reports.c.obj): in function `rndis_query':

I did add to my example: ethernet_init: path: ${IDF_PATH}/examples/ethernet/basic/components/ethernet_init

2 problems: #1, I dont want example code in my real-app #2, idf.py complained about my project eth kconfigds beging in conflict with examples kconfig. I removed it, I dont want to stray into example code directories and they kconfigs.

I still have the link-errors. I try to solve them, being a seasoned coder, i lack esp32 enviroment skills, its very clever this environment, but also a bit complicated to understand, i am in a steep learning curve. :-)

I try to fix the below errors now, any hints are deeply appriciated.

added espressif/ethernet_init: '>=0.5.0'

this took the linking problems down a bit. C:\Windows\system32\cmd.exe /C "cd . && C:\Espressif\tools\riscv32-esp-elf\esp-14.2.0_20241119\riscv32-esp-elf\bin\riscv32-esp-elf-g++.exe -march=rv32imafc_zicsr_zifencei_xesppie -mabi=ilp32f -nostartfiles -march=rv32imafc_zicsr_zifencei_xesppie -mabi=ilp32f --specs=nosys.specs -Wl,--cref -Wl,--defsym=IDF_TARGET_ESP32P4=0 -Wl,--Map=C:/workspace/batteries-chargers/esp32/ch1_p4/build/blink.map -Wl,--no-warn-rwx-segments -Wl,--orphan-handling=warn -fno-rtti -fno-lto -Wl,--gc-sections -Wl,--warn-common -T rom.api.ld -T esp32p4.peripherals.ld -T esp32p4.rom.ld -T esp32p4.rom.api.ld -T esp32p4.rom.rvfp.ld -T esp32p4.rom.wdt.ld -T esp32p4.rom.systimer.ld -T esp32p4.rom.version.ld -T esp32p4.rom.newlib.ld -T memory.ld -T sections.ld -Wl,--enable-non-contiguous-regions @CMakeFiles\blink.elf.rsp -o blink.elf && cd ." C:/Espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/14.2.0/../../../../riscv32-esp-elf/bin/ld.exe: esp-idf/espressif__tinyusb/libespressif__tinyusb.a(ecm_rndis_device.c.obj): in function handle_incoming_packet': C:/workspace/batteries-chargers/esp32/ch1_p4/managed_components/espressif__tinyusb/src/class/net/ecm_rndis_device.c:338:(.text.handle_incoming_packet+0x76): undefined reference to **tud_network_recv_cb'**

C:/Espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/14.2.0/../../../../riscv32-esp-elf/bin/ld.exe: esp-idf/espressif__tinyusb/libespressif__tinyusb.a(ecm_rndis_device.c.obj): in function netd_open': C:/workspace/batteries-chargers/esp32/ch1_p4/managed_components/espressif__tinyusb/src/class/net/ecm_rndis_device.c:182:(.text.netd_open+0x206): undefined reference to **tud_network_init_cb'**

C:/Espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/14.2.0/../../../../riscv32-esp-elf/bin/ld.exe: esp-idf/espressif__tinyusb/libespressif__tinyusb.a(ecm_rndis_device.c.obj): in function netd_control_xfer_cb': C:/workspace/batteries-chargers/esp32/ch1_p4/managed_components/espressif__tinyusb/src/class/net/ecm_rndis_device.c:256:(.text.netd_control_xfer_cb+0xfc): undefined reference to tud_network_init_cb'

savenlid avatar Jun 18 '25 12:06 savenlid

@savenlid

tud_network_init_cb is the callback from the tinyusb, which should be declared in your application, but is is optional to use it. Is was removed in the last changes in the upstream: https://github.com/hathach/tinyusb/commit/b6ce41188e6780436dc9a9a0ed1232631753e3bb

tud_network_mac_address is the mac address buffer, you should have in your application: example

roma-jam avatar Jun 18 '25 12:06 roma-jam

Yes, it became clear after a while.

Callbacks etc.

I will read and merge and interpolate with the example.

Down to 1 link error now.

Thanks for all help.

Den ons 18 juni 2025 14:50Roma Jam @.***> skrev:

roma-jam left a comment (espressif/esp-idf#16142) https://github.com/espressif/esp-idf/issues/16142#issuecomment-2984068614

@savenlid https://github.com/savenlid

tud_network_init_cb is the callback from the tinyusb, which should be declared in your application, but is is optional to use it. Is was removed in the last changes in the upstream: @.*** https://github.com/hathach/tinyusb/commit/b6ce41188e6780436dc9a9a0ed1232631753e3bb

tud_network_mac_address is the mac address buffer, you should have in your application: example https://github.com/hathach/tinyusb/blob/master/examples/device/net_lwip_webserver/src/main.c#L75

— Reply to this email directly, view it on GitHub https://github.com/espressif/esp-idf/issues/16142#issuecomment-2984068614, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEDCDUG7FIK7TJJSLTS554L3EFOB7AVCNFSM6AAAAAB7NOHTAWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDSOBUGA3DQNRRGQ . You are receiving this because you were mentioned.Message ID: @.***>

savenlid avatar Jun 18 '25 14:06 savenlid

@roma-jam

Hi,

examples seems to use a function that has disappeared ? https://github.com/search?q=repo%3Aespressif/esp-idf%20tinyusb_net_send_sync&type=code Only 2 examples refer to it.

Thus I take your advice to look into the the tiny-usb example instead.

Its seems to me that its more "generic" freertos / tiny-usb and not esp32:ified code. I assume netif is omitted, I also see other differences in nomenclature.

I will try to pull it together, but it will take some time for sure, quite a lot material to digest.

Is someone could find it in their hearts to make a S2/S3/P4 example how to do RNDIS into the "netif" network and connect to the webserver i would be very grateful.

In the mean time I will continue the battle, reading, coding, repeat.

Best regards /Nicholas

savenlid avatar Jun 18 '25 21:06 savenlid

Since there was no further response from the user I am closing the issues. Feel free to reopen this or create a new issue if there are any more problems.

Cheers, Ondrej

Indastri avatar Jul 08 '25 12:07 Indastri