espressif / esp-hosted

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

esp32-c3 not responding #101

Open er-rahul-km opened 2 years ago

er-rahul-km commented 2 years ago

Hi, I am stuck at esp32-c3-mini integration in host mode with my hardware. I am running esp32-c3 in spi mode for both wifi and bluetooth. As per document link given below https://github.com/espressif/esp-hosted/blob/master/docs/Linux_based_host/porting_guide.md

My host has debian os. We have modified our dtb and driver code matching with our hardware. I can load driver esp32_spi.ko at host successfully. I am giving my dmesg logs here.. [ 144.947874] esp32_spi: loading out-of-tree module taints kernel. [ 144.953483] esp_reset, ESP32: Resetpin of Host is 108 [ 144.955374] esp_reset, ESP32: Triggering ESP reset. [ 144.986323] ESP32 peripheral is registered to SPI bus [2],chip select [0], SPI Clock [10]

We have also verified spi signals at esp32 using DSO(Digital storage Oscilloscope) and seems it is valid when driver is loaded. I am able see clocks also at DSO.

I ran ifconfig -a at host. I received following messages ethap0: flags=4098<BROADCAST,MULTICAST> mtu 1500 ether 00:00:00:00:00:00 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

ethsta0: flags=4098<BROADCAST,MULTICAST> mtu 1500 ether 00:00:00:00:00:00 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

As per the documentation i am expecting to receive

[ 65.591541] esp32: Triggering ESP reset. [ 65.593385] ESP32 device is registered to SPI bus [0],chip select [0] [ 66.201597] Received INIT event from esp32 [ 66.201613] ESP32 capabilities: 0x78 [ 66.619381] Bluetooth: BNEP (Ethernet Emulation) ver 1.3 [ 66.619388] Bluetooth: BNEP filters: protocol multicast [ 66.619404] Bluetooth: BNEP socket layer initialized

But i am not getting these logs. My esp32 is not working.

Following logs given below i got from esp32-c3 using uart interface via minicom. I (501) NETWORK_ADAPTER: ESP Bluetooth MAC addr: a0-76-4e-6c-9e-46

I (501) SPI_DRIVER: Using SPI interface
I (511) gpio: GPIO[3]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0 I (521) gpio: GPIO[4]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0 I (1531) pp: pp rom version: 9387209
I (1531) net80211: net80211 rom version: 9387209
I (1541) NETWORK_ADAPTER: Initial set up done

Please confirm whether there would be any extra logs when driver would be loaded at host.

Please provide me solution to solve issue for esp32-c3 host mode integration.

mantriyogesh commented 2 years ago

Hello @er-rahul-km,

Thanks a lot for exact description of the problem.

For your logs, I could clearly infer, The first transaction is not happening, that means SPI instance which is configured in device tree, is running correctly.

Some suggestion based on our experience:

  1. Before going into deep debugging, it would be really good to verify pins and wires are correctly connected
  2. Please check expected SPI instance is correctly configured in device tree
  3. The chip select also is expected to be correctly set.
  4. In stead of jumping directly to spi disable, Could you please verify using some userspace drivers like spidev, if spi is getting correctly configured? This way we will ensure the SPI peripheral is correctly instantiated.
  5. the device would be listed as say /dev/spidev0 or something.
  6. Now you can disable the spi so that kernel driver would be able to able to access SPI instance exposed in step 5.
er-rahul-km commented 2 years ago

Dear MantriYogesh, I did checked my connection well. I checked SPI instance, It is correct. I checked CS that is correctly set. Spi is correctly configured. Dievice is /dev/spidev0 does exist after driver load.

Now when i do dmesg on host, It is showing that data ready pin and handshake pin is working. But application is not receiving event 1 and event 2 . This is the reason in my case esp32-c3 is not working. my kernel version is 4.14 Please provide solution to this bug.

Rainbow-Cai commented 2 years ago

Dear @mantriyogesh , Could you please provide a solution for this problem?

mantriyogesh commented 2 years ago

@er-rahul-km

  1. Please send us the logs when you are using userspace driver like spidev?
  2. ls -lrt /dev/spi*
  3. what was the SPI instance configured in DT
  4. Whats is chip select used
mantriyogesh commented 2 years ago

Could you please provide the dmesg log for the last run? We will be in better position to understand the issue..

Overall, to run hosted driver, transport has to be setup first. While porting for Linux using porting guide, steps to keep in mind:

er-rahul-km commented 2 years ago

Hi @mantriyogesh I am show my device tree node, host dmesg logs and esp32 logs here device tree node &ecspi3 { fsl,spi-num-chipselects = <1>; pinctrl-names = "default"; pinctrl-0 = <&pinctrl_ecspi3 &pinctrl_ecspi3_cs>; cs-gpios = <&gpio4 11 0>; status = "okay";

esp32: spi@0 {
    reg = <0>;
    compatible = "spidev";
    spi-max-frequency = <30000000>;
};

};

&esp32{ status = "disabled"; };

   pinctrl_ecspi3: ecspi3grp {                  /* ESP32-C3 SPI */
            fsl,pins = <
        MX7D_PAD_I2C1_SCL__ECSPI3_MISO      0x3B    /* 0xf */ 
        MX7D_PAD_I2C1_SDA__ECSPI3_MOSI      0x3B    /* 0xf */ 
        MX7D_PAD_I2C2_SCL__ECSPI3_SCLK      0x3B    /* 0xf */ 
            >;
    };

    pinctrl_ecspi3_cs: ecspi3_cs_grp {
            fsl,pins = <
        MX7D_PAD_I2C2_SDA__ECSPI3_SS0       0x34      
            >;
    };

dmesg logs for esp32 driver [ 4.962491] systemd-journald[115]: Received request to flush runtime journal from PID 1 [ 5.937665] evbug: Connected device: input0 (30370000.snvs:snvs-powerkey at snvs-pwrkey/input0) [ 5.988393] 8021q: 802.1Q VLAN Support v1.8 [ 6.101769] Generic PHY 30be0000.ethernet-1:00: attached PHY driver [Generic PHY] (mii_bus:phy_addr=30be0000.ethernet-1:00, irq=POLL) [ 6.117859] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready [ 6.203820] Bluetooth: HCI UART driver ver 2.3 [ 6.206979] Bluetooth: HCI UART protocol H4 registered [ 6.231371] Bluetooth: HCI UART protocol LL registered [ 6.235483] Bluetooth: HCI UART protocol Intel registered [ 6.325900] imx-sdma 30bd0000.sdma: no iram assigned, using external mem [ 6.373762] spi_imx 30830000.ecspi: probed [ 6.380979] spi_imx 30840000.ecspi: probed [ 6.398415] imx-sdma 30bd0000.sdma: loaded firmware 4.5 [ 6.455179] Bluetooth: hci0: change remote baud rate command in firmware [ 7.535362] wl18xx_driver wl18xx.0.auto: Falling back to user helper [ 7.785295] Bluetooth: BNEP (Ethernet Emulation) ver 1.3 [ 7.789328] Bluetooth: BNEP filters: protocol multicast [ 7.794042] Bluetooth: BNEP socket layer initialized [ 8.010001] wlcore: wl18xx HW: 183x or 180x, PG 2.2 (ROM 0x11) [ 8.023238] wlcore: loaded [ 8.243392] fec 30be0000.ethernet eth0: Link is Up - 100Mbps/Full - flow control off [ 8.258181] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready [ 8.859078] wlcore: PHY firmware version: Rev 8.2.0.0.242 [ 8.974734] wlcore: firmware booted (Rev 8.9.0.0.78) [ 8.988185] IPv6: ADDRCONF(NETDEV_UP): wlan0: link is not ready [ 31.121292] random: crng init done [ 31.123410] random: 7 urandom warning(s) missed due to ratelimiting [ 155.812223] esp32_spi: loading out-of-tree module taints kernel. [ 155.817886] esp_reset, ESP32: Resetpin of Host is 77 [ 155.818407] esp_reset, ESP32: Triggering ESP reset. [ 155.819174] ESP32 peripheral is registered to SPI bus [2],chip select [0], SPI Clock [10]

If i compare these logs with rpi. Here i did not receive event 1 and event 2 But i checked in that HANDSHAKE and DATA_READY interrupt is being received by driver.

When i insert esp32 lkm driver i get following massages at esp32 vai serial cable

ESP-ROM:esp32c3-api1-20210207 Build:Feb 7 2021 rst:0x1 (POWERON),boot:0xd (SPI_FAST_FLASH_BOOT) SPIWP:0xee mode:DIO, clock div:1 load:0x3fcd6100,len:0x18e8 load:0x403ce000,len:0x8d4 load:0x403d0000,len:0x2d94 entry 0x403ce000 I (30) boot: ESP-IDF v4.3.2-198-gb9a96186fd-dirty 2nd stage bootloader I (30) boot: compile time 16:20:33 I (30) boot: chip revision: 3 I (34) boot.esp32c3: SPI Speed : 80MHz I (39) boot.esp32c3: SPI Mode : DIO I (43) boot.esp32c3: SPI Flash Size : 4MB
I (48) boot: Enabling RNG early entropy source...
I (53) boot: Partition Table:
I (57) boot: ## Label Usage Type ST Offset Length
I (64) boot: 0 nvs WiFi data 01 02 00009000 00004000
I (72) boot: 1 otadata OTA data 01 00 0000d000 00002000
I (79) boot: 2 phy_init RF data 01 01 0000f000 00001000
I (87) boot: 3 factory factory app 00 00 00010000 00100000
I (94) boot: 4 ota_0 OTA app 00 10 00110000 00100000
I (102) boot: 5 ota_1 OTA app 00 11 00210000 00100000
I (109) boot: End of partition table
I (113) boot: Defaulting to factory image
I (118) esp_image: segment 0: paddr=00010020 vaddr=3c090020 size=1dac8h (121544) mp I (146) esp_image: segment 1: paddr=0002daf0 vaddr=3fc90000 size=02528h ( 9512) ld I (148) esp_image: segment 2: paddr=00030020 vaddr=42000020 size=8fd74h (589172) mp I (243) esp_image: segment 3: paddr=000bfd9c vaddr=3fc92528 size=01530h ( 5424) ld I (245) esp_image: segment 4: paddr=000c12d4 vaddr=40380000 size=0ff44h ( 65348) ld I (261) esp_image: segment 5: paddr=000d1220 vaddr=50000010 size=00010h ( 16) ld I (267) boot: Loaded app from partition at offset 0x10000
I (267) boot: Disabling RNG early entropy source...
I (281) cpu_start: Pro cpu up.
I (294) cpu_start: Pro cpu start user code
I (294) cpu_start: cpu freq: 160000000
I (294) cpu_start: Application information:
I (297) cpu_start: Project name: network_adapter
I (302) cpu_start: App version: release0.4-60-g22180f7
I (309) cpu_start: Compile time: Jan 24 2022 16:20:27
I (315) cpu_start: ELF file SHA256: 62947a515a849a33...
I (321) cpu_start: ESP-IDF: v4.3.2-198-gb9a96186fd-dirty
I (327) heap_init: Initializing. RAM available for dynamic allocation:
I (335) heap_init: At 3FC98BA0 len 00027460 (157 KiB): DRAM
I (341) heap_init: At 3FCC0000 len 0001F060 (124 KiB): STACK/DRAM
I (348) heap_init: At 50000020 len 00001FE0 (7 KiB): RTCRAM
I (354) spi_flash: detected chip: generic
I (359) spi_flash: flash io: dio
I (363) sleep: Configure to isolate all GPIO pins in sleep state
I (369) sleep: Enable automatic switching of GPIO sleep configuration
I (377) cpu_start: Starting scheduler.
I (381) NETWORK_ADAPTER: ** I (381) NETWORK_ADAPTER: ESP-Hosted Firmware version :: 0.4
I (391) NETWORK_ADAPTER: Transport used :: SPI
I (401) NETWORK_ADAPTER: ** I (411) NETWORK_ADAPTER: Supported features are:
I (421) NETWORK_ADAPTER: - WLAN over SPI
I (421) ESP_BT: - BT/BLE
I (431) ESP_BT: - HCI Over SPI
I (431) ESP_BT: - BLE only
I (441) BTDM_INIT: BT controller compile version [33175c8]
I (441) coexist: coexist rom version 9387209
I (441) phy_init: phy_version 907,3369105-dirty,Dec 3 2021,14:55:12
I (491) system_api: Base MAC address is not set
I (491) system_api: read default base MAC address from EFUSE
I (491) BTDM_INIT: Bluetooth MAC: 84:f7:03:60:b8:e6

I (501) NETWORK_ADAPTER: ESP Bluetooth MAC addr: 84-f7- 3-60-b8-e6

I (501) SPI_DRIVER: Using SPI interface
I (511) gpio: GPIO[3]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: I (521) gpio: GPIO[4]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: I (1531) pp: pp rom version: 9387209
I (1531) net80211: net80211 rom version: 9387209
I (1541) NETWORK_ADAPTER: Initial set up done // stuck here

Checked before sending above logs are give below: I am using chip select 0. i am using esp32 at SPI3 of imx7 After disabling spi in device tree /dev/spidev is not listed

I hope these are helpful to resolve the issue

mantriyogesh commented 2 years ago

Hello @er-rahul-km

To summarise from your logs,

  1. Handshake and data ready are mapped to correct GPIO and working.
  2. ESP log is correct
  3. chip select is 0, configured correctly.
  4. We can not confirm the device tree just by looking at it, as it very specific to the board/SoC. However the initial analysis of device tree looks fine. \ One reference device Tree we we used for other board/SoC looks like this

Please proceed with following steps:

In short, Unless SPI instance is not working fine, esp32 kernel driver is not testable

er-rahul-km commented 2 years ago

Hi @mantriyogesh, I tested host and ESP32 with all modes of SPI mode 1, 2, 3. I did not got positive result. I tested ESP32 SPI slave example with user-space spidev application. i took application from link given below. https://github.com/azorg/spi Application is able to send data to ESP32. I verified data through serial cable. Now please suggest what to do next.

mantriyogesh commented 2 years ago

Both, RX and TX cases need to be verified with user space driver Can you please give output of:

ls -lrt /dev/spi*

These tests are done for SPI 3 with chip select 0 .. correct?

er-rahul-km commented 2 years ago

Hi @mantriyogesh When no driver is loaded ls -lrt /dev/spi ls: cannot access '/dev/spi': No such file or directory

after running script i got this crw-rw-rw- 1 root root 221, 0 Feb 21 05:30 /dev/spi0

I treid with the esps0 also but it does not work with this also crw-rw-rw- 1 root root 221, 0 Feb 21 05:30 /dev/esps0

mantriyogesh commented 2 years ago

Hello @er-rahul-km, It doesn't make sense at this point to try treid with the esps0 also but it does not work with this also, the driver has to be loaded first.

As I already stated, repeating stepwise procedure,

Unless /dev/spidevX.Y is created as output of device tree, and is tested with userspace driver like spidev (TX,RX), you should not proceed ahead to disable the spidev driver.

To add further, This kind of porting is prerequisite for ESP-Hosted project and is out of scope for ESP-Hosted. But as you are stuck, we are trying to help to get you working software. Getting the platform up, is critical, without which, loading driver or using serial driver like /dev/esps0 does not make any sense. Getting platform up differs platform to platform.

/dev/esps0 as described in documentation, is serial interface, over ESP hosted kernel module. So unless first transaction for SPI is not done, serial driver /dev/esps0 (which works on top of transport like SPI), will not work.

Could you please confirm if /dev/spidevX.Y is tested using spidev in RX and TX so that you can transfer some logical data to and fro host and ESP32? Which device are you using spidev on?

er-rahul-km commented 2 years ago

hi @mantriyogesh ,

Thank you for your support and cooperation.

Sorry for the confusion arised.

As you suggested now we have followed first 2 steps only.

"Device Tree Modify & load Device tree settings for getting expected SPI instance. Make a note of which /dev/spidevX.Y is created newly for this instance. Verify SPI is working Use any user space driver like spidev to verify SPI on /dev/spidevX.Y Configure host as SPI master and ESP32 (all supported variants like S2, C3) as SPI slave. For ESP32 SPI slave driver, you can use ESP32 IDF SPI slave examples"

After following above steps following is output step 1 : Device Tree spidev is enable in dtb ls -lrt /dev/spi* crw------- 1 root root 153, 0 Feb 21 07:44 /dev/spidev1.0 crw------- 1 root root 153, 1 Feb 21 07:44 /dev/spidev2.0 // This device is being used for test

step 2 : Verify SPI is working We have used base code User space application for spidev test at host is based on https://github.com/azorg/spi and we have customized it for our changes and code is placed at url https://gist.github.com/er-rahul-km/a6538eb46973fa9f67af0ab49bde77d5

Logs of spi test are given below: On host side logs:

root@cl-debian:~/Downloads/esp-hosted/spi-master# ./spi_test SPI: open device='/dev/spidev2.0' mode=0 bits=8 lsb=0 max_speed=30000000 [Hz]

spi_init() return 0 write buffer: ABCDEFGHIJKLMNOPQRSTUVWXYZABCD // sent to esp32 from host read buffer: �his is the receiver, sendin�� // Received from esp32 at host

Logs on ESp32C3 application running at esp32 built from esp-idf/esp-idf-v4.4/examples/peripherals/spi_slave/receiver Esp32 uart console logs given below:

Received: ABCDEFGHIJKLMNOPQRSTUVWXYZAB���������������������������������������.

Our observation for Tx (Host-->Esp32): Seems like last 2bytes are always missing. Data transmitted from host is 30 bytes, but at esp32 I am getting 2 byts lesser than transmitted. I changed this size also, but data recieved at esp32 remains two bytes lesser than transmitted.

Our observation for Rx(Esp32-->Host) : As per source code for esp32 given in example esp-idf/esp-idf-v4.4/examples/peripherals/spi_slave/receiver/main/app_main.c sprintf(sendbuf, "This is the receiver, sending data for transmission number %04d.", n); //line no 148 Received string at host is not exactly as per code. First byte is corrupt. I received only 28 bytes.

I am not using Handshake signal for now at host side user space application used for spidev.

Can you please help?

mantriyogesh commented 2 years ago

Seems like last 2bytes are always missing.

Once the both, RX and TX works correctly (possibly back to back), we can move ahead to disable spidev and add code change in esp_spi.c to change SPI Bus instance and Chip select number from porting guide

Getting the underlying platform up, is step wise process. We appreciate your patience.

er-rahul-km commented 2 years ago

Hi @mantriyogesh, Thanks for you reply. We have checked with mode 1 and mode 3. My first byte corruption at receive is solved now. Regarding missing of last 2 bytes i noticed that this issue occurs only when packet size is more that 28 bytes. I tested with less than 28 bytes, the packets are received correctly at both ends. I am not sure what is the cause of the issue. Please help..

mantriyogesh commented 2 years ago

Hello @er-rahul-km

We cannot comment on your application as such as it is out of scope.

But it is worth to check size of read/write buffers, number of bytes passed in spi_exchange etc.

er-rahul-km commented 2 years ago

Hi @mantriyogesh We have tested same user space application on raspberrypi (host) with esp32c3 (slave) and it is working fine. No issues are there. So, it doesn't seems application issue. We need your support to make it working on our i.mx7d board.

mantriyogesh commented 2 years ago

It is worthwhile to check SPI documentation for the expected board. As the application works on Raspberry Pi, there has to be some difference with respect to i.mx7d Linux SPI driver or with respect to SPI timings.

Can you lower frequency to say 1M and try?

Once you have working back to back SPI transactions for TX and RX at user space, proceed with next set of steps

er-rahul-km commented 2 years ago

hi @mantriyogesh,

I tested my host device in loopback mode. I did not get any errors during transmission and reception. I am assured that my spi is working fine. Esp32-c3 problem is still same.

mantriyogesh commented 2 years ago

Did you try frequency like 1M ?

mantriyogesh commented 2 years ago

Also can you please get logic analyser output? That will help to get clear picture.

er-rahul-km commented 2 years ago

hi @mantriyogesh, Thanks for your support. With your support we are able to communicate with esp32 successfully.

I ran following command esp-hosted/host/linux/host_control/c_support/test.out scan I am able to get list of available APs. After that i started basic testing for Bluetooth and followed following link https://github.com/espressif/esp-hosted/blob/master/docs/Linux_based_host/Getting_started.md Test 1: I tested for gatt server setting in section 2.1.1. It worked. Test 2: I tested for gatt client in section 2.1.2 . At step 8 I executed scan on, But i cannot see bluetooth device list on host. I followed step from 1 to 7 precisely.
Can you please help why it is not listing available bluetooth device.

Thanks

mantriyogesh commented 2 years ago

Hello @er-rahul-km,

Good to know that the ESP-Hosted is loaded fine. Can you please let us know the issue you fixed, this might help someone later point of time.

With respect to Test 2, Can you please provide bluetoothctl & btmon logs?

mantriyogesh commented 2 years ago

Any updates?

mantriyogesh commented 2 years ago

@er-rahul-km Any updates further? Were you be able to get it working?

er-rahul-km commented 2 years ago

Hi @mantriyogesh, I am sorry for late reply, I was traveling. I am grateful to you for your support.

My most of the issues are resolved but still i am facing issues. I was able to run ESP32 with my host. ESP32 is running at lower clock speed 1Mhz. But i am facing one problem. When i load driver at host i did not get event. To make it work I need to unload driver and reload it again. When i load driver 2nd time it works. Please provide the solution to this issue.

mantriyogesh commented 2 years ago

Hello @er-rahul-km

To understand the current state, please answer,

For your scenario of driver loaded second time, can you please

mantriyogesh commented 2 years ago

Any updates?

mantriyogesh commented 2 years ago

Hello @er-rahul-km

Any further updates? Were you able to get the software working?

mantriyogesh commented 2 years ago

Hello @er-rahul-km

Can you please help closing issue in case you have working solution?

mantriyogesh commented 2 years ago

@er-rahul-km were you able to get the solution working?

KingMichaelCoy commented 2 years ago

I also have a problem. My ArduinoCode code uploads successfully of a ble controller sketch but Bluetooth does not show on laptop or cellphone as midi device? What do I do?

mantriyogesh commented 2 years ago

@KingMichaelCoy Can you please raise a separate issue for this?

er-rahul-km commented 2 years ago

Dear mantra, The software was working. But there is existence of bug. I need to load driver 2 times. Then it does work. Can you suggest what could be to problem.

On Mon, 28 Mar 2022, 12:20 pm mantriyogesh, @.***> wrote:

Hello @er-rahul-km https://github.com/er-rahul-km

Any further updates? Were you able to get the software working?

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

mantriyogesh commented 2 years ago

@er-rahul-km ,

Can you please test over master at both the ESP & Host? There are quite a number of fixes that had gone in since your last commit.

There should not be need to load the driver two times. Can you please let me know, exactly, what works & wat doesn't? It will help us to understand the context.

Also, can you please share the logs? It will be easier to understand the command and associated log, if you run the tail -F /var/log/kern.log & in the same terminal and load the driver & connect with AP (or something else?)