Linux virtual device driver using serial - linux-device-driver

I'm trying to search for sample code of Linux virtual device driver using serial.
I have the following requirements:
Embedded board and certain controller are connected with USB-serial.
The device driver(embedded board) sends data via serial. (not to userspace)
The device driver(embedded board) received data as ack via serial. (not from userspace)
The device driver(embedded board) shows manipulated data on sysfs.
My question is
Is there any reference code that I can follow?
Thanks in advance.

Related

How to receive CAN data in a linux device driver?

I want to read the CAN bus and get the data from a specific device on the CAN bus. I have implemented this previously using the Socket communication api that is available in the user space (sys/socket).
I now have a similar requirement but this time working on device drivers which work in the kernel space. The same socket communication is i suppose not available in the kernel space which is why i guess i am not able to compile the kernel module with #include .
An approach i have come up to is to create a device driver for device creation and a supporting user-space program to interact it and provide CAN data by using socket communication. If there is any better approach please suggest me.

How to flash without STLINK

My STLINKV2 is not working anymore, not detected by Linux, it failed after the first successful flash. I ordered a new one but it will take 60+ days to arrive. Meanwhile I have heard on Youtube you can program Bluepills directly by connecting cut open USB cable to certain pins and then using a jumper. But I cannot get any precie information on this, is this really possible and how?
You should use the embedded bootloader. You can flash it through several interfaces. Look at AN2606, maybe you can find an already written flasher. Good luck STM32CubeProgrammer handle it.
If you intend to program it through usb, look also at AN3156 all protocols document are referred in chapter 2 of AN2606
THOSE AREN'T CUT OPEN USB CABLES they are USB to serial adapters for arduino's bootloader
They connect them like this:
The problem is that this requires the Arduino STM32 bootloader to be flashed in it.
Another option will be to use STM32CubeProg this program allows you to program your stm over
Serial
SPI
I2C
USB
You'll need to set the BOOT0 and BOOT1 pins to the correct value (HIGH slash LOW) to allow it to go in flash mode during boot.
Here is semi outdated tutorial which tells most of the steps to program a STM using serial. (the Flash Loader Demonstrator is outdated and you should use STM32CubeProg)

Sending serial data without RS232 port

I want to send data serially from MATLAB, but my laptop doesn't have a serial port. Do I have to use a USB-to-RS232 converter? Will my program remain the same?
I have some RS232-USB-Converters and never had any trouble. I need adapters for embedded devices and embedded development.
If your driver is properly installed and works then it is presented as an serial device to the OS.
The device presented (on linux) is named differently (ttyUSB) but that doesn't matter.
And using stdio functions like fopen/fclose is one more layer above (libcall, not syscall).

MATLAB USB HID data receive

Is there a way to receive the data sent over USB to PC using HID protocol in MATLAB? I tried the host hid receiver block found in STM32 blockset in Simulink but it gives an error saying that STM32 device not found so I guess that blockset is spesific for a STM32 device.
Under Linux, you can read from /dev/input/mice. It covers position data and clicks. You might need to adjust the reading privileges of the device file.

Does any interrupt occur when a usb device is connected?

I am working on USB HIDs on linux platform. Keyboards, mouse etc., are examples of Human Interface Devices. Whenever a HID is inserted to a system, at first device enumeration occurs. Then an entry in the form of hidraw appears in the /dev directory.
In linux, "usbhid and hid" are the modules which are called when an HID device is inserted. When I disabled these modules (using rmmod and system restart), the devices were not enumerated and no hidraw entry appeared on /dev(as expected).
Now my question is there any way to know if any USB HID device is connected to a system with the above two modules being disabled i.e does any interrupt or signal generate upon hardware insertion.
I am planning to execute some code when such signal or interrupt occurs(in C). Any kind of help is appreciated.
Thanks,
Insertion of the device is detected through the voltage level changes occuring on the D+ and the D- lines. I do not think that insertion of USB device generates any interrupt. The voltage level changes are read by the hub(root or any hub further down on the line) and according reported to the core.
The USB core driver would be notified about the same. So may be you can write a user-space driver which targets a specific device (using Vendor and Product ID) and through this you can carry out your functionality.
If you are doing this in user mode, you get get a notification using udev (which use netlink internally).
You can match a device using the vendorId and productId field in the rulefile.
SUBSYSTEMS=="usb", ATTRS{idVendor}=="abcd", ATTRS{idProduct}=="1234"