Stm32 Virtual COM Port - Can not connect - c

This is a code, part of my project;
//----------------------------------------------------------------------------
// USB: Virtual COM ----------------------------------------------------------
//----------------------------------------------------------------------------
USB_Interrupts_Config();
Set_USBClock();
USB_Init();
while (bDeviceState != CONFIGURED)
;
//----------------------------------------------------------------------------
// Main Loop -----------------------------------------------------------------
//----------------------------------------------------------------------------
while(1)
{
USB_printf("Main Function");
GPIO_SetBits(GPIOC, GPIO_Pin_10);
Wait(200);
GPIO_ResetBits(GPIOC, GPIO_Pin_10);
Wait(200);
}
After plugging my usb to the Circuit, Virtual COM Port Driver installation finishes correctly and LED blinking is also OK.
But when I try to connect COM port via Hyper Terminal or 3th party tools, I can not
achieve it.
Is there any opinion?
Thanks..

I had similar issue with a slightly different wording - it is possible to connect to the device until it's reset. My custom board would enumerate VCP correctly but would not connect after device reset. Turns out, that USB host keeps the enumerated address for the device, while device looses its address after reset/reprogramming. To avoid such issues, software reset should also perform USB physical layer reset (disconnecting pullup on D+/D- pin, depending on the speed used). In such a case it should be possible to connect to the device after disabling and then re-enabling it in the device manager or re-plugging

Not Necessarilly the answer but may be worth checking.
If your periodically send information out of the COM port and it appears your program does ( never used STM32 ), Windows (hyperterm so I assume windows XP) can detect that as a serial mouse and enumerates it as a mouse thus opening the port and preventing any other application from using it.
We have had many issues with this with our devices (CP2103's from SiLabs), and also is a common problem with GPS recievers.
This answer GPS Detected as serial mouse as a good description of the issue and possible workarrounds.

Related

How to detect when USB is disconnected?

I use a virtual com port for communication between the microcontroller and the computer.
I have mk. stm32h743 self-powered from its own 3.3V power supply. With the help of a cube, I raised a virtual com port. How can you understand that the USB is disconnected from the device ? When you connect Usb, it calls "CDC_Init_FS" and hUsbDeviceFS.dev_state is set to 3, which corresponds to "USBD_STATE_CONFIGURED". But when you disconnect the USB there is no callback "HAL_PCD_DisconnectCallback (PCD_HandleTypeDef * hpcd);"Why "HAL_PCD_DisconnectCallback (PCD_HandleTypeDef * hpcd);" not called when USB is disabled?
I have no way to track Vbus voltages. So I did it like this :
void HAL_PCD_SuspendCallback(PCD_HandleTypeDef hpcd)
{
USBD_LL_Suspend((USBD_HandleTypeDef)hpcd->pData);
__HAL_PCD_GATE_PHYCLOCK(hpcd);
if (hpcd->Init.low_power_enable)
{
SCB->SCR |= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk |
SCB_SCR_SLEEPONEXIT_Msk));
}
SBD_LL_DevDisconnected(&hUsbDeviceFS);
}
Hello.
I have a problem with USB working properly - USB CDC (Virtual Com Port) with CubeMX HAL after disconnecting the USB cable and connecting again.
For the test I created a project similar to the one presented here - https://www.youtube.com/watch?v=AYICE0gU-Sg using STM32CubeIDE and STM32CubeMX.
The program writes data in the while (1) loop to the USB port after uploading to STM32.
while(1)
{
CDC_Transmit_FS(buffer, sizeof(buffer));
HAL_Delay(1000);
}
The data is written out, visible in Windows 7 (Tera Term).
When I disconnect the USB cable (OTG FS port) and reconnect, Windows sends the message "USB device not recognized".
Data is not received.
In order for the data to be transferred and the cable to be recognized, I must do a Reset on the board.
Hardware:
MCU: STM32H743VIT
Software: STM32CubeIDE v1.2
Firmware package: STM32Cube_FW_H7_V1.7.0
How to make the USB device work all the time correctly (after disconnecting the cable and reconnecting it), so that it is recognized by Windows and data is transferred?

Force connection on specific USB port/symlink

I am planning to use Dump1090 and I want to have 2 RTLSDR dongles on the same computer, always plugged into the same USB port. I am planning to assign a symlink "adsb" to the port for the RTL dongle that has an ADS-B antenna connected to it. Is there a way to force the connection on this specific USB port?
By default, the code takes the first device available.
Thank you
https://github.com/antirez/dump1090/blob/master/dump1090.c

Detecting a RS-232 com port in Linux

I have an ECR(Electronic Cash Register) device,it has a RS-232 com port cable for the connection to PC but I have not been given any drivers for it. I am trying to connect the device to PC but PC is not able to detect the cable. How to detect this device attached on this RS-232? I am working under Linux. Any help on how to find the device is appreciated?
Following is the code snippet I found in C to connect to device based on Baudrate and Com Port number.
int OpenComport(int comport_number, int baudrate)
int SendByte(int comport_number, unsigned char byte)
int SendBuf(int comport_number, unsigned char *buf, int size)
Please see my answer to a related question which shows how to open and configure the serial port.
On Linux, serial ports are almost always /dev/ttyS[0123] (that is /dev/ttyS0, /dev/ttyS1, etc.) for the hardwired ports, and /dev/ttyUSB* for USB ports. The hardwired "devices" may appear only when the hardware is present on some distributions. On others, they always appear whether there is hardware or not. (Try cat /dev/ttyS2 and see if you get the error "no such device".) This is a kernel configuration option which is frequently set to create the device entries whether the hardware is there or not.
The USB ports are present only when there is hardware plugged in, but if there are multiple USB serial ports, it can be difficult identifying which is which.
There is a mechanism within /etc/udev/rules.d/* which can be configured if some aspects of the devices are consistent. See man 7 udev for details.
For applications I have written, I determine which device is which by writing to the device and identifying its response. For devices which don't respond, this is either a worthy programming challenge or a mundane configuration solution.
I think you need to do a little reading about RS-232, and well, C programming also. There are no drivers for RS-232. It is a very "dumb" protocol - you basically just shove data out the port.
The PC cannot detect the cable? That's because it's not USB. Believe it or not, Plug-and-play didn't always exist; you tell the software what port the device is supposedly connected to, and it tries to talk to it.
Furthermore, those aren't "code snippets", those are just function prototypes. There isn't any actual code there.
1>since there's no operating system on your ECR so I guess u don't need any drivers ,instead a firmware will be there in the ECR , which tries to communicate with your Linux UART driver
2> Rs-232 is basically a serial protocol , I mean it has 9 wires , and hence a connecter with 9 pins are used DB-9 connectors ,all the communications inside a processor is in parallel format so a chip called UART is used to convert all the parallel data into serial data , and since yu want to pass the data in Rs-232 format , it needs to be packaged in that format .
3> Linux kernel already has a uart driver , which is implemented for RS-232 . so need to worry about drivers from Linux side.
4> Open a terminal type " dmesg | grep tty " ( connect only the ECR to the PC for rs-232 ports ). it will return something like ttyS or ttyUSB etc , however u just concentrate on ttyS if u have connected only through rs-232 cable .
5> Once u are sure of the ttyS device from the dmesg use minicom (its easy to use ) to communicate with the device.
regards,
Zubraj

Arduino Mini and WiFi shield -> not present (status 255)

I have an issue with the WiFi shield. As you can see in the picture below, I am experimenting with the Arduino Mini and the WiFi shield.
I have read the tutorial-guide and connected all the necessary pins between the Mini and the shield. I use the example code which is provided in the tutorial, e.g. reading the WiFi shield's MAC-address or scanning for networks near me.
But anything I get is the error message, that the shield is not connected. But there is a connection between the two Pin 7's (the handshake pins) and even to any other required pin.
I even support my circuit with an additional power supply of 5V (the voltage regulator in the picture), so what's wrong with it? Or might it be that the WiFi shield itself is damaged or has a malfunction? How to verify this?
One last question is: Do they deliver the shield with an installed firmware or does the user have to install it?
The code I use is for example:
uint8_t wl_status = 0;
void setup()
{ // code to run once
// Open serial communications
Serial.begin(115200);
Serial.println("*** Arduino board online ***");
// check for the presence of the shield:
wl_status = WiFi.status();
if (wl_status == WL_NO_SHIELD)
{
Serial.println("-E- WiFi shield not present");
// don't continue:
//while(true);
}
else
{ // Initialize Wifi
Serial.println("-I- Initializing Wifi..");
printAddress(1);
// Scan for existing networks:
Serial.println("-I- Scanning available networks..");
listNetworks();
}
Serial.print("-D- Wifistatus : ");
Serial.print(wl_status, DEC);
Serial.println("");
}
The printAddress()-function simply prints out the MAC-address of the shield.
Have you tried removing the jumper? It puts the shield in programming mode. Picture here
I proved whether a different power source will work or not; the problem still remained.
Arduino support suggested that we should use the SPI connection of the board instead of wiring. It was worth a try, so I combined the WiFi-shield with an Arduino Uno and could finally start practising. Forget the Arduino Mini and use Uno or Mega instead.
According to the startup trouble, the current firmware version still has bugs, e.g. connection dies after a few seconds both on server side and client side. I recommend checking the Git repository frequently for updates. Issue #9 (Connection dies after a few seconds) has been solved on server side only, however the problem still exists on client side. I will wait for the next version of the firmware.

Activate and deactivate usb device in c?

We have a laser scanner which is connected all the time to a certain usb port.
The usb device should be deactivated normally.
Only at certain times I have to activate this usb device at the usb port with a litte c program.
So how can I activate a deactivated usb device in c?
Thanks for your information.
Update:
I forgot to mention to operating system: Windows XP, Windows Vista, Windows 7, ...
The laser scanner is a Honeywell Voyager MS 9540 product.
In the documentation I read that if the usb scanner is connected to a serial port, you can send enable and disable commands over the serial port in order to enable or disable scanning. But I thought it would be easier to simply enable or disable a usb port/device.
I bit more information would be useful ...
For usb connection you can use libusb (see also: libusb-win32). Since it's used by CUPS (a printing software) too, i guess its ideal for you.

Resources