espressif / esp-hosted

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

ESP32 Power Cycle Breaks SDIO Driver hosted on Linux #43

Open dwhitters opened 3 years ago

dwhitters commented 3 years ago

Issue

The char device registration and addition is occurring in the probe function and the deletion and unregistration is occurring in the remove function.

This results in additions when the ESP32 is detected while the driver is running, and unregistration when the ESP32 is no longer powered. Unregistering the device while a node that is connected to it is in use by a process (e.g. cat) results in the node no longer being connected/usable, even though the ESP32 may come back and the device will again be registered with the kernel with the same number.

Steps to Reproduce

  1. Power ESP32 on
  2. Build and insert the kernel module using ./rpi_init.sh sdio
  3. cat /dev/esps0 | xxd
  4. Power off ESP32
  5. Power on ESP32
    • The /dev/esps0 node will no longer operate.
  6. Kill cat
  7. cat /dev/esps0 | xxd
    • This will result in the following error: cat: /dev/esps0: No such device or address

Potential Solution

Char device registration appears to be typical in the __init function of a device driver as seen in the following link: https://embetronicx.com/tutorials/linux/device-drivers/device-file-creation-for-character-drivers/ This way, a device is always registered with the kernel, regardless of if an external device is connected to the driver. Nodes can then be created and attached to the kernel device; they remain usable, regardless of the presence of the external device.

When the _esp_serialinit is moved to the init function and the _esp_serialcleanup is moved to the exit function, the device node remains operable across power cycles.

mantriyogesh commented 3 years ago

Hello @dwhitters ,

Thank you for your valuable suggestion. We will work on this and try to this proposed solution over master.

If you already have working solution, we welcome you to submit the pull request as well. We will try to review and merge the solution.