espressif / esp-hosted

Hosted Solution (Linux/MCU) with ESP32 (Wi-Fi + BT + BLE)
Other
706 stars 169 forks source link

ESP-Hosted-FG: SSID Length Error #404

Closed XZ-Niupitang closed 4 months ago

XZ-Niupitang commented 5 months ago

When using c_Demo to drive WiFi to turn on AP mode, the set WIFI name is VIN-LAAAPLDL2R1000154, but after starting the hotspot, the Wifi name is wrong. I checked the macro definition of SSID_LENGTH and it seems that there is no problem. How can I solve it? image image

mantriyogesh commented 5 months ago

Thank you @XZ-Niupitang ,

Let we test this and come back.

XZ-Niupitang commented 4 months ago

Thank you @XZ-Niupitang ,

Let we test this and come back.

Hi, is there any result for this problem?

XZ-Niupitang commented 4 months ago

Thank you @XZ-Niupitang ,

Let we test this and come back.

Now I have encountered some other problems during use. After successfully mounting the driver and starting the AP mode, when connecting to WIFI and using the network to transmit data, the CPU load rate will directly increase to 100%. What is the reason for this?

mantriyogesh commented 4 months ago

Can you please post the top output and the all textual logs of all possible windows (e.g. ESP, iperf server/client, dmesg,top)

XZ-Niupitang commented 4 months ago

Can you please post the top output and the all textual logs of all possible windows (e.g. ESP, iperf server/client, dmesg,top)

Sorry, I opened all logs during compilation and checked dmesg to find the problem. After modifying it, the CPU usage is still high.

mantriyogesh commented 4 months ago

Please attach the logs mentioned in https://github.com/espressif/esp-hosted/issues/404#issuecomment-2178495411 to this issue so that we also can review..

Also post your git commit at esp and host. if you have any diff, add up git diff both places.

XZ-Niupitang commented 4 months ago

Please attach the logs mentioned in #404 (comment) to this issue so that we also can review..

Also post your git commit at esp and host. if you have any diff, add up git diff both places.

CPU usage during transmission image

Esp32 Driver log image

esp32_spi.c image image

esp32_spi.h image

main.c image

image

image

image

The main part of main.c is to mount the device tree and change the reset pin to use the IO expander output. I carefully checked the overall changes and found that there are not many. I used htop to check the current CPU and found: image image My conclusion is that IO interrupts take up a lot of CPU resources. What do you think?

XZ-Niupitang commented 4 months ago

Please attach the logs mentioned in #404 (comment) to this issue so that we also can review..

Also post your git commit at esp and host. if you have any diff, add up git diff both places.

[ 5949.331948] all Execution time: 3271465 ns [ 5949.336042] gpio_get_value Execution time: 2175 ns [ 5949.340841] skb_dequeue Execution time: 700 ns [ 5949.345286] esp_alloc_skb Execution time: 2355 ns [ 5949.349991] spi_sync_transfer Execution time: 3264720 ns [ 5949.355307] process_rx_buf Execution time: 2300 ns [ 5949.360102] skb_put Execution time: 990 ns [ 5949.364207] SPI Transaction Len : 1600

root@j7-evm:~# [ 1126.027280] esp32_spi: esp32_probe: reset esp32! [ 1126.237173] esp32_spi: esp32_probe: ESP32C6 reset performed [ 1126.243853] esp32_spi: spi_init: ESP: SPI host config: GPIOs: Handshake[406] DataReady[405] [ 1126.248351] esp32_spi: esp_spi_thread: esp spi thread created [ 1126.252757] esp32_spi: spi_dev_init: ESP host driver claiming SPI bus [5],chip select [3] with init SPI Clock [26] [ 1126.473208] esp32_spi: spi_init: HOST state is READY [ 1127.067889] all Execution time: 3030 ns [ 1127.071725] gpio_get_value Execution time: 2670 ns [ 1127.076508] skb_dequeue Execution time: 0 ns [ 1127.080770] esp_alloc_skb Execution time: 0 ns [ 1127.085216] spi_sync_transfer Execution time: 0 ns [ 1127.090002] process_rx_buf Execution time: 0 ns [ 1127.094523] skb_put Execution time: 0 ns [ 1127.098436] SPI Transaction Len : 0 [ 1127.104254] esp32_spi: process_event: INIT event rcvd from ESP [ 1127.105056] all Execution time: 3138070 ns [ 1127.110080] esp32_spi: process_init_event: EVENT: 2 [ 1127.114269] gpio_get_value Execution time: 1565 ns [ 1127.119024] esp32_spi: process_init_event: EVENT: 1 [ 1127.119025] esp32_spi: process_init_event: EVENT: 0 [ 1127.119027] esp32_spi: process_init_event: EVENT: 3 [ 1127.119562] esp32_spi: process_capabilities: ESP peripheral capabilities: 0xe8

It seems that all the time is consumed in SPI transmission. However, most of the transmitted information is 1600 bytes long. In addition to modifying the underlying SPI driver, I currently have no better optimization solution. Do you have any good method for reference?

mantriyogesh commented 4 months ago

We would need to analyse this in detail @XZ-Niupitang . We would also reproduce this behaviour if the cpu utilization hitting such a high.

@SohKamYung-Espressif can you PTAL?

XZ-Niupitang commented 4 months ago

We would need to analyse this in detail @XZ-Niupitang . We would also reproduce this behaviour if the cpu utilization hitting such a high.

@SohKamYung-Espressif can you PTAL?

https://github.com/XZ-Niupitang/TDA4_ESPWIFI/tree/main

I uploaded the transplanted TDA4 driver source code and esp32c6 program source code. Please take a look and point out any errors. Thanks.

mantriyogesh commented 4 months ago

Hello @XZ-Niupitang ,

@SohKamYung-Espressif is on business travel right now, He would be back this week and check the issue in detail. Thank you for sharing the code base. Can you please let us know the base ESP-Hosted git commit you have referred for either side?

XZ-Niupitang commented 4 months ago

Hello @XZ-Niupitang ,

@SohKamYung-Espressif is on business travel right now, He would be back this week and check the issue in detail. Thank you for sharing the code base. Can you please let us know the base ESP-Hosted git commit you have referred for either side?

The base ESP-Hosted last commit was: commit af480c54895044fa33c82ecde285a8c05ac76fbb (HEAD -> master) Author: Kapil Gupta kapil.gupta@espressif.com Date: Fri May 17 11:38:14 2024 +0530

SohKamYung-Espressif commented 4 months ago

The base ESP-Hosted last commit was: commit af480c54895044fa33c82ecde285a8c05ac76fbb (HEAD -> master) Author: Kapil Gupta kapil.gupta@espressif.com Date: Fri May 17 11:38:14 2024 +0530

Hello, @XZ-Niupitang

Could you point me to your top-of-the-tree commit in https://github.com/espressif/esp-hosted/commits/master/ ? I did a git log and that commit you quoted is not present.

SohKamYung-Espressif commented 4 months ago

I used htop to check the current CPU

Can you run htop and enable the option to show kernel threads? On my version of htop, this is the K key (capital K). This is to verify which kernel threads are using CPU resources on your system.

The ESP SPI driver normally starts up the kernel thread esp32_spi to do spi transmissions.

XZ-Niupitang commented 4 months ago

The base ESP-Hosted last commit was: commit af480c54895044fa33c82ecde285a8c05ac76fbb (HEAD -> master) Author: Kapil Gupta kapil.gupta@espressif.com Date: Fri May 17 11:38:14 2024 +0530

Hello, @XZ-Niupitang

Could you point me to your top-of-the-tree commit in https://github.com/espressif/esp-hosted/commits/master/ ? I did a git log and that commit you quoted is not present.

I have not committed any code on this branch. My current code is based on commit af480c54895044fa33c82ecde285a8c05ac76fbb ,As I replied before。

XZ-Niupitang commented 4 months ago

I used htop to check the current CPU

Can you run htop and enable the option to show kernel threads? On my version of htop, this is the K key (capital K). This is to verify which kernel threads are using CPU resources on your system.

The ESP SPI driver normally starts up the kernel thread esp32_spi to do spi transmissions.

Yes, that's right, esp_spi occupies 100% of the core. In AP mode, as long as you use wifi to transfer files, this thread will always occupy a core.

SohKamYung-Espressif commented 4 months ago

I have not committed any code on this branch. My current code is based on commit af480c54895044fa33c82ecde285a8c05ac76fbb

I am unable to find this commit in the esp-hosted master branch.

Could you check https://github.com/espressif/esp-hosted/commits/master/ and let me know the name of the commit?

SohKamYung-Espressif commented 4 months ago

Can you try this patch to see if it fixes the SoftAP SSID issue?

softap_ssid_fix_1.patch

XZ-Niupitang commented 4 months ago

I have not committed any code on this branch. My current code is based on commit af480c54895044fa33c82ecde285a8c05ac76fbb

I am unable to find this commit in the esp-hosted master branch.

Could you check https://github.com/espressif/esp-hosted/commits/master/ and let me know the name of the commit?

image image image

XZ-Niupitang commented 4 months ago

Can you try this patch to see if it fixes the SoftAP SSID issue?

softap_ssid_fix_1.patch

Thanks, I will add this patch and test it again

XZ-Niupitang commented 4 months ago

Can you try this patch to see if it fixes the SoftAP SSID issue?

softap_ssid_fix_1.patch

Thanks for your support, the SSID length issue has been resolved, but the high CPU usage issue still exists. Please see the video below.

https://github.com/espressif/esp-hosted/assets/103943684/e2919695-77d4-441d-bb03-7c1a2b9775b9

SohKamYung-Espressif commented 4 months ago

the high CPU usage issue still exists

I have tested with iperf2 using a Raspberry Pi 4 as the host (our reference linux system).

With the SPI bus at 26 MHz, I am seeing the esp32_spi kthread peak at 20% of cpu (usually it is about 10-15%). This is while iperf2 throughput is around 14 Mbits/s.

I have compared your linux driver code against the master branch, and I do not see any major differences.

One possibility is hardware DMA was not enabled for SPI transfers on your SoC. The CPU would then be busy doing the SPI transfers.

XZ-Niupitang commented 4 months ago

the high CPU usage issue still exists

I have tested with iperf2 using a Raspberry Pi 4 as the host (our reference linux system).

With the SPI bus at 26 MHz, I am seeing the esp32_spi kthread peak at 20% of cpu (usually it is about 10-15%). This is while iperf2 throughput is around 14 Mbits/s.

I have compared your linux driver code against the master branch, and I do not see any major differences.

One possibility is hardware DMA was not enabled for SPI transfers on your SoC. The CPU would then be busy doing the SPI transfers.

Thanks for your reply. I will continue to check the SPI driver. I also found that SPI transmission takes up a lot of time.

XZ-Niupitang commented 4 months ago

the high CPU usage issue still exists

I have tested with iperf2 using a Raspberry Pi 4 as the host (our reference linux system).

With the SPI bus at 26 MHz, I am seeing the esp32_spi kthread peak at 20% of cpu (usually it is about 10-15%). This is while iperf2 throughput is around 14 Mbits/s.

I have compared your linux driver code against the master branch, and I do not see any major differences.

One possibility is hardware DMA was not enabled for SPI transfers on your SoC. The CPU would then be busy doing the SPI transfers.

image Thank you very much for providing the solution. It is indeed caused by not enabling DMA in the device tree.The speed has also increased a lot.

SohKamYung-Espressif commented 4 months ago

@XZ-Niupitang FYI, the patch I provided to you has been merged into master: https://github.com/espressif/esp-hosted/commit/abe8f45c577f26a88d98528e27dfd027472fa8f4

XZ-Niupitang commented 4 months ago

@XZ-Niupitang FYI, the patch I provided to you has been merged into master: abe8f45

Thanks for the support

SohKamYung-Espressif commented 4 months ago

@XZ-Niupitang

It is indeed caused by not enabling DMA in the device tree

Could you post the SPI section from your device tree here, as a reference, in case other people encounter the same problem.

XZ-Niupitang commented 4 months ago

@XZ-Niupitang

It is indeed caused by not enabling DMA in the device tree

Could you post the SPI section from your device tree here, as a reference, in case other people encounter the same problem.

Of course, I'd love to,This device tree is based on TDA4VM. I don't know if it is valid for chips of other architectures.

main_spi6: spi@2160000 {
    compatible = "ti,am654-mcspi","ti,omap4-mcspi";
    reg = <0x00 0x02160000 0x00 0x400>;
    interrupts = <GIC_SPI 190 IRQ_TYPE_LEVEL_HIGH>;
    #address-cells = <1>;
    #size-cells = <0>;
    clocks = <&k3_clks 272 1>;
    power-domains = <&k3_pds 272 TI_SCI_PD_EXCLUSIVE>;
    dmas = <&main_udmap 0xc624>, <&main_udmap 0x4624>,
           <&main_udmap 0xc625>, <&main_udmap 0x4625>,
           <&main_udmap 0xc626>, <&main_udmap 0x4626>,
           <&main_udmap 0xc627>, <&main_udmap 0x4627>;
    dma-names = "tx0", "rx0" , "tx1", "rx1", "tx2", "rx2" , "tx3", "rx3";
};