Open dwhitters opened 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.
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
./rpi_init.sh sdio
cat /dev/esps0 | xxd
cat /dev/esps0 | xxd
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.