sending data to UART driver on BeagleBone from PC via USB serial adapter - linux-device-driver

I am trying to send data from PC using minicom program to BeagleBone driver via USB serial adapter cp2102. I am using the driver whose code is here.
I connect the adapter to bbg this way :
serial device TX -> beaglebone UART2 RX pin 22
serial device RX -> beaglebone UART2 TX pin 21 on the P9 extension.
I added all port data to the device tree, there is a device tree code:
#include "am335x-boneblack.dts"
&am33xx_pinmux {
uart2_pins: uart2_pins {
*/
pinctrl-single,pins = <
AM33XX_IOPAD(0x954, PIN_OUTPUT_PULLDOWN | MUX_MODE1)
AM33XX_IOPAD(0x950, PIN_INPUT_PULLUP | MUX_MODE1)
>;
};
};
&uart2 {
compatible = "serial"; //This is used when identifying a compatible device driver
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&uart2_pins>;
};
I open two terminal windows on my PC.
In one terminal window ,for the PC end of this experimental serial connection ,I use minicom programm :
sudo minicom ttlUSB0
In another terminal window that presents access to the serial console I enter the command :
cat /dev/hw_serial-48024000
In an open minicom program of the first terminal I enter characters .
in the second terminal I wait to receive these characters
but no data is coming..
The baud-rate value is set to the same value 115200 in the minicom program and in the BeagleBone driver.
it should look like this(but it doesn't work for me )

Related

Can I transmit serial data only using a data cable via Raspberry pi 0 w's USB port?

I have been recently trying to find out a way whether I can send serial data (large file like image data) only through the Rpi w 0's micro USB port using ttyGS0. But when I searched online I only found ways of setting up headless through serial and other stuff which was no what I wanted. But I did follow the tutorial half way
I went to '/boot/config.txt' and set 'dtoverlay=dwc2' at the end of the file after leaving a line
I went to '/boot/cmdline.txt' and did put 'modules-load=dwc2,g_serial' after 'rootwait' leaving a space
Thinking I could just use the /dev/ttyGS0 in my serial program on the Rpi and send the data the data was being sent but on my PC when I tried to access my Rpi which was on comport 12 it said port not found and couldn't open it. But it was showing up in the device manager as 'PI USB to Serial(COM12)'
Then I wondered whether it would be possible at all to access Rpi's com port this way.
If that's the case, I want to know if there is any other way to access the Rpi's USB port only using the USB cable
Note
I don't want to use Rpi's USB as a way of logging ie. 'headless setup'. I just want to receive serial data like an Arduino.
I don't want to use the GPIO pins (I tried) as they can only send limited characters at a time and I want to send an image file. Very quickly.
I don't have any serial converters at hand so i could route it to the arduino and use /dev/ttyUSB0
then read it on PC. I just only want to use the USB cable.
In case this info is required:-
my pc is a probook 6560b running windows 7
things i found while testing and stuff:-
I did do -lsusb command but i dint find my device on that list
I tried the 'ls /dev/ttyGS0' and i found '/dev/ttyGS0'
I checked many forums and some guys were asiking to use this command 'dmesg | grep tty'and show them the code . So i performed it i dont understand what alot in the piece of text means but if it would be helpfull i pasted it here:-
pi#aloypi:~ $ dmesg | grep tty
[ 0.000000] Kernel command line: coherent_pool=1M 8250.nr_uarts=1 snd_bcm2835.enable_compat_alsa=0 snd_bcm2835.enable_hdmi=1 bcm2708_fb.fbwidth=1366 bcm2708_fb.fbheight=768 bcm2708_fb.fbswap=1 smsc95xx.macaddr=B8:27:EB:6D:50:77 vc_mem.mem_base=0x1ec00000 vc_mem.mem_size=0x20000000 console=tty1 root=PARTUUID=4ab8bcad-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait modules-load=dwc2,g_serial
[ 0.001496] printk: console [tty1] enabled
[ 2.543414] 20201000.serial: ttyAMA0 at MMIO 0x20201000 (irq = 81, base_baud = 0) is a PL011 rev2
[ 2.561791] 20215040.serial: ttyS0 at MMIO 0x20215040 (irq = 53, base_baud = 50000000) is a 16550
[ 6.716694] systemd[1]: Created slice system-getty.slice.
i also tried this one 'dmesg | grep dwc2' out of curiosity and got this but i cant say anything judging it so ya
pi#aloypi:~ $ dmesg | grep dwc2
[ 0.000000] Kernel command line: coherent_pool=1M 8250.nr_uarts=1 snd_bcm2835.enable_compat_alsa=0 snd_bcm2835.enable_hdmi=1 bcm2708_fb.fbwidth=1366 bcm2708_fb.fbheight=768 bcm2708_fb.fbswap=1 smsc95xx.macaddr=B8:27:EB:6D:50:77 vc_mem.mem_base=0x1ec00000 vc_mem.mem_size=0x20000000 console=tty1 root=PARTUUID=4ab8bcad-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait modules-load=dwc2,g_serial
[ 2.379190] dwc_otg: version 3.00a 10-AUG-2012 (platform bus)
[ 2.386185] dwc_otg: FIQ enabled
[ 2.386205] dwc_otg: NAK holdoff enabled
[ 2.386219] dwc_otg: FIQ split-transaction FSM enabled
[ 2.386245] Module dwc_common_port init
[ 2.968203] modules-load=dwc2,g_serial
[ 8.344134] dwc2 20980000.usb: supply vusb_d not found, using dummy regulator
[ 8.367130] dwc2 20980000.usb: supply vusb_a not found, using dummy regulator
[ 8.626751] dwc2 20980000.usb: EPs: 8, dedicated fifos, 4080 entries in SPRAM
[ 8.647109] dwc2 20980000.usb: DWC OTG Controller
[ 8.653810] dwc2 20980000.usb: new USB bus registered, assigned bus number 1
[ 8.726672] dwc2 20980000.usb: irq 33, io mem 0x20980000
[ 8.787097] usb usb1: Manufacturer: Linux 5.10.17+ dwc2_hsotg
[ 9.371395] dwc2 20980000.usb: bound driver g_serial
[ 194.158373] dwc2 20980000.usb: new device is high-speed
[ 194.189677] dwc2 20980000.usb: new device is high-speed
[ 194.225164] dwc2 20980000.usb: new address 3
Ok looks like i made some progress
till now I did this
I went to '/boot/config.txt' and set 'dtoverlay=dwc2' at the end of the file after leaving a line
I went to '/boot/cmdline.txt' and did put 'modules-load=dwc2,g_serial' after 'rootwait' leaving a space
I did this 'sudo nano /etc/rc.local' and placed 'modeprobe g_serial use_acm=0' before 'exit 0'
Then i performed this command 'sudo systemctl stop getty#ttyGS0.service'
and then this 'sudo systemctl disable getty#ttyGS0.service'
(i think disabling getty#ttyGS0.service and puting 'modeprobe g_serial use_acm=0' in the folder metioned above allowed rpi and pc to comunicate but then again i can be wrong )
then perfored a 'sudo reboot'
this seemed to solve my problem
but i have one more problem now
whatever is sent from the rpi i can only recieve in the coolterm serial port reading software
i cant seem to use read the port from processing for some reason
(im using processing to later read the image file being sent)
here is my current serial reading program in processing
import processing.serial.*;
Serial myPort; // Create object from Serial class
String val; // Data received from the serial port
void setup()
{
myPort = new Serial(this, "COM13", 115200);
}
void draw()
{
if ( myPort.available() > 0)
{ // If data is available,
val = myPort.readStringUntil('\n'); // read it and store it in val
}
if (val!=null)
{
println(val); //print it out in the console
}
}
i kinda am stuck here :P
EDIT
welp nevermind i solved it
i finally finally got it working yaaaaaaaayyy
OK now remember all who seek for the answer when using /dev/ttyGS0 it uses the CTS and RTS protocall
(now idk if it can be disabled but please lemme know you guys)
Its like the pi asks your pc wether it is cleared to send the data and when the pc says yeah ok send the data the pi sends it
so whenever your using this method please enable rts or cts
this is what i used in processing to recieve the data
import processing.serial.*;
Serial myPort;
void setup()
{
//remember to set the COM port to which your pi is set
size(200, 200);
myPort = new Serial(this, "COM13", 115200);
}
void draw()
{
if ( myPort.available() > 0)
{
if(myPort.getCTS()==true){
myPort.setRTS(true);
print(myPort.read());
}
}
}
i hope this is of loadsa help to you guys but if there is some correction needed please lemme know yall:D
thanks

Why might `i2c_smbus_write_byte_data` be returning "Operation not permitted" on uClinux 2.4?

I am writing a C program with the aim of configuring a peripheral device (the CS5368 ADC) via the I2C interface of a Dante Brooklyn II, a board based on a Microblaze soft-core processor running uClinux 2.4.
I have implemented the configuration following the Dante OEM docs for guidance, however when running my program I am encountering an "Operation not permitted" (EPERM) error when attempting to write data to I2C using i2c_smbus_write_byte_data.
Here is the section of code containing the culprit call to i2c_smbus_write_byte_data:
// Set ADC I2S to "Slave mode all speeds".
printf("Set the CS5368 I2S mode to slave\n");
unsigned char adc_dif = 0x01; // I2S mode
unsigned char adc_mode = 0x03; // Slave mode all speeds
unsigned char data = 0x90 | (adc_dif << 2) | adc_mode;
result = i2c_smbus_write_byte_data(i2c_fd, CS5368_GCTL_MDE, data);
if (result < 0) {
perror("Failed to write to the 'Global Mode Control' register");
return -1;
}
Here is the code within context of the full source of the small program. The program begins by resetting the CS5368 via a GPIO pin before doing the configuration via I2C.
EPERM is returned whether or not I have the CS5368 wired up. I've been able to successfully configure the CS5368 using the I2C interface of an Arduino Uno, so the issue does not appear to be related to the CS5368.
To run the program I login to the board via telnet as root, so I doubt the error has anything to do with user permissions.
The OEM docs state:
The Brooklyn II module can operate as an I2C controller running at
100Khz and using 7 bit addressing mode. It supports multi-master
operation. I2C devices can be accessed from user application running
on the Brooklyn II module. The interface supports the SMBus (System
Management Bus) protocol, which is a subset from the I2C protocol.
It goes on to list the supported i2c_smbus_* functions including i2c_smbus_write_byte_data, so the issue does not appear to be related to lack of support for SMBus or I2C.
I came across a related issue where a user was getting an EPERM error code when attempting to use the I2C write API, however the solution appears to have been to use the i2c_smbus_* API instead which I am already doing.
Any advice on what could be causing this error code to be returned or how to debug the issue further would be greatly appreciated!
Edit: In case it helps, here is the full output, starting from logging onto the board via telnet after having moved the exe to /tmp via ftp:
$ telnet 169.254.72.245
Trying 169.254.72.245...
Connected to 169.254.72.245.
Escape character is '^]'.
login: root
Password:
BusyBox v1.23.2 (2018-05-31 11:33:18 AEST) hush - the humble shell
/ # cd /tmp
/var/tmp # ./cs5368-i2c-config
Open GPIO device
Set GPIO tristate outputs
Set GPIO pins low
Sleep for 10 secs
Set GPIO pins high
Close GPIO file descriptor
Searching for I2C device
Opening /dev/i2c-0
Setting I2C_SLAVE 4c...
I2C Interface found: /dev/i2c-0
Set the CS5368 as the slave
Set the CS5368 I2S mode to slave
Failed to write to the 'Global Mode Control' register: Operation not permitted

In QT how can I detect when a USB port switches from serial mode to DFU when connected to an STM32

I have a Qt5.12.4 MinGw64 app where I want to catch a USB event. In Windows 10 the MS driver for STM/USB emits error messages and I can use that as a trigger. Inelegant but it works, until I try to run it in a Win7-8.1 app where the driver is a third party STM driver with a VCP wrapper. I am thinking I need to adopt libusb to try and catch the ports change of state, but I am at a loss as how to proceed. I can see the port info in Device Manager, I just dont know how to get to it. Some of the questions going through my head....
1) Can I just make an OS call to read the port info? (if so, how?)
2) Can libusb and QSerialport co-exist on the same port?
3) What calls to LibUSB1.0 do I make to query the port status?
4) Is there a Windows cli utility like lsusb (wmic??) where I could scrape the data?
5) Which solution is likely to be the best cross platform solution?
I am using this trigger to start dfuse as a process that does a firmware update automatically on my STM board.
I have looked over the libusb1.0 docs but I do not understand just how I can use it. If that is correct solution, an example of how to query the Com port data and state would be most appreciated.
I tried using qDebug() to print out all of the serialportInfo data, while in serial or DFU state, but there is nothing there that is useful that I can use as a trigger.
USB serial mode = Serial port info is: ("COM3", "USB Serial Device", "Microsoft", "00000000001A", "\\.\COM3", "483", "5740", "1", " no data", "1")
USB DFU mode = Serial port info is: ("COM3", "N/A", "N/A", "N/A", "\\.\COM3", "N/A", "N/A", "no data", " no data", "no data")
I need some direction as to how to grab this port info so I dont really have any code that matters, but I am including an excerpt of my working process function.
This code works just fine to actually perform the firmware load. I just need a way to actually trigger it from a USB port change of state
void updateDevice_Dialog::update_firmware(QString fileName)
{
qDebug() << "Updating firmware: " << fileName ;
QDir dir;
ui->progress_label->setText("Preparing to update Firmware .....");
if(dir.setCurrent(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)+"/firmware"))
{
QSettings settings;
QString comPort = settings.value("USBPort").toString();
ui->progress_label->setText("Setting port to: "+comPort+" and starting download .....");
ui->avr_progressBar->setValue(0);
ui->avr_progressBar->setRange(0,100);
ui->avr_progressBar->setHidden(false);
progress_steps = 0; //reset avrProcess line output counter;
qDebug() << "Starting process for stm-dfu on serial port: " << comPort;
connect(avr_Process,SIGNAL(error(QProcess::ProcessError)),this,SLOT(process_error(QProcess::ProcessError)));
connect(avr_Process,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(process_finished(int,QProcess::ExitStatus)));
connect(avr_Process,SIGNAL(readyReadStandardOutput()),this,SLOT(process_readLine()));
connect(avr_Process,SIGNAL(errorOccurred(QProcess::ProcessError)),avr_Process,SLOT(kill()));
connect(avr_Process,SIGNAL(error(QProcess::ProcessError)),ui->avr_progressBar,SLOT(close()));
QString dfu_command = "\""+QCoreApplication::applicationDirPath()+"/Tools/\"dfusecommand -c -d --v --fn "
"\""+QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)+"/firmware/\""+fileName;
qDebug().noquote() << "dfu command string is: "<< dfu_command << " Current dir is: " << dir.currentPath();
avr_Process->start(dfu_command);
avr_Process->waitForFinished(20000);
}
}
From the perspective of the host system, rebooting the microcontroller into DFU will look like the original device was disconnected, and a completely different device was plugged in shortly afterwards.
If you need to watch for this, set up a libusb hotplug callback so that you'll be notified when the DFU device is attached.

Error in sending data from arduino to matlab

I want to run simple example in arduino and send data from arduino to matlab for drawing plot,
my arduino code is following:
#include <SoftwareSerial.h>
int i=0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.println(i);
i++;
}
and my matlab code is following:
arduino=serial('COM4','BaudRate',9600);
fopen(arduino)
x=linspace(1,100);
for i=1:length(x)
y(i)=instrfind(arduino);
y(i)=fscanf(arduino,'%d');
end
fclose(arduino);
disp('making plot..')
plot(x,y);
But I've faced with error! The following is matlab error:
Error using serial/fopen (line 72)
Open failed: Port: COM4 is not available. No ports
are available.
Use INSTRFIND to determine if other instrument
objects are connected to the requested device.
Error in kh (line 2)
fopen(Arduino)
and here is arduino error:
avrdude: ser_open(): can't open device "\\.\COM4": Access is denied.
My arduino uno (COM4) driver in device manager are installed.
I use matlab 2013a and ŮŽArduino 1.8.1 Genuino
How can I fix this error?
If you are using RS-232 for Arduino IDE/Monitor to communicate with your Arduino on COM4.
Since RS-232 is a point to point methodology, you can only have one program/device on each end unless you add a bunch of hijinks.
When you have the Arduino IDE/Monitor open it uses the com port and other programs are denied access.
I think you need to close the Arduino monitor program to release Com port 4 and then the Matlab program should be able to open the port.
PS : Test this using a terminal. Obviously the port needs to be open for the terminal to receive the arduino's prints. The terminal DOES open when you have the arduino ide open, but it DOES NOT open when the arduino's COM terminal is open. So theoretically, MATLAB shouldn't be having a problem when just the IDE is open.
This is how I solved the problem.
In device manager you will find the Arduino COM port.
Go to the Advance properties of the port
Set the COM port number to COM4
Then replug the USB.

Can't read data from OBD2 serial port connection on Raspberry Pi

I'm currently working on a raspberry pi project for school where I read data from an OBD2 to usb censor in my car.
When I'm using Screen to connect to the serial port everything works fine, but when I try to do it in python the serial.readline() returns an empty string.
Does anybody know how I can retrieve data from the serial port in python?
I've tried about every option available.
import serial
ser = 0
#Function to Initialize the Serial Port
def init_serial():
global ser
ser = serial.Serial()
ser.baudrate = 38400
ser.port = '/dev/ttyUSB0'
ser.timeout = 1
ser.open() #Opens SerialPort
# print port open or closed
if ser.isOpen():
print 'Open: ' + ser.portstr
#Function Ends Here
init_serial()
temp = raw_input('Type what you want to send, hit enter:\r\n')
ser.write(temp) #Writes to the SerialPort
while 1:
bytes = ser.readline() #Read from Serial Port
print bytes #Print What is Read from Port
You may not be sending valid data to get a response. I believe the ODB2 interface uses the AT command set. Sending AT\n may be a good starting point.
I'm using a Bluetooth ODB2 interface and found that the serial baudrate was fixed. Using any other baudrate failed to correctly get data.
I recommend testing from putty or other terminal that supports serial ports, until you get the device to respond correctly. Then use valid settings to troubleshoot your code.
You're not sending a \r\n with your command, ELM327 requires a new line character at the end of a command.