-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
STM32F1 USB-CDC OUT #1
Comments
What length parameter do you use Otherwise, if the USB interrupt doesn't fire at all when the host is sending data, there must be another problem. Only in this case, I have no idea what it could be. Honestly I never tried an F1 device yet, so it may be that there are differences in its USB IP and that of the later series, such as F3. |
Basically, I call USBD_CDC_Receive function with the length of USBD_CDC_AppType .Received callback was called. Initially it is 64. I think if I send data several times, a received message should appear anyway. However, I have looked it again now and I see an interrupt when I send data from host to device (sorry, maybe it was too late yesterday when I have tried it). So, in USB_vIRQHandler, the
is true, then
is also true, so it handles a SETUP Packet with usEpId value of 0. |
It is interesting... currently when microcontroller restarts and USB is plugged in first time, I can not see any interrupt when trying to send data from host to device and host also can not read some data of the device, for example:
When I keep powering the MCU and reconnect USB cable, interrupts are starting to arrive like above (SETUP packages) and iManufacturer, iProduct, iSerial (and so on) are displayed correctly. |
Tell me about the 1.5kOhm pullup on USB_DP line, how did you implement it? Is it hardwired to 3.3V, or to a GPIO that you control via the |
The STM32F4 board was designed by me, but this one is not. It is a really cheap "Minimum System Development Board" from China. USB_DP line is hardwired to 3.3V in this case. |
In that case I recommend that you pull the DP and DM lines to ground as output pins for 1ms at startup, then reconfigure them into USB alternate function mode once the USB stack is initialized. This is necessary so the host detects the device attach-detach, and restarts the communication. |
Done that. Host detects the reset of the board and restarts communication. After restart, I can use USB device to send data from device to host. If I unplug USB and plug it again while uC is still running, I can also send data from device to host and if I try to send data from host to device, a SETUP Packet arrives described above. |
I don't have an F1 device, so I cannot test your scenario, you are on your own now. Perhaps you could try with a Cube example to compare the behavior. |
Do you have a board which has "USB_Device" instead of "USB_OTG" interface? If so, on that board, do both send and receive directions work on USB-CDC virtual communication port? I am afraid I would need deeper knowledge of USB protocol in order to find out what is wrong and why data from host to device doesn't arrive and what to do with the SETUP request coming instead of my data. Anyway, some debugging of USB communication at host side... Sending data from device to host:
The message was "Sor (230)\n", which is in hex 53 6f 72 20 28 32 33 30 29 0d 0a Sending data from host to device:
The message was "Teszt\n" which is in hex 54 65 73 7a 74 0a So, these data going through the bus between host and device. Still, on device, I only see an interrupt coming which ends up as a SETUP Packet with usEpId value of 0 when I send "Teszt\n" to device. |
I have two shared projects which use USB peripheral and CDC-ACM interface: They both work in both directions, I haven't had issues like yours so far. |
Check if you have the endpoint numbers set correctly, and debug the |
I think endpoint numbers are set correctly as my STM32F4 works well using the same settings. Anyway, USB configuration shown at host side is here:
At USB_vAllocateEPs(), device goes through endpoint number (ulEpNum) 0 to 8, where endpoint 0 and 1 has MaxPacketSize of 64 both IN and OUT directions... others has MaxPacketSize of 0. ...then it goes through initialization of endpoint 0, then it initializes endpoint 1 of both directions. Unfortunately, I have no F0 or F3 MCUs, but I think if it works on F0 and F3, it should also work on F1... I have tried to put notification endpoint also on 0x83 and is currently set to 0x8F. If I set OUT endpoint number to 0x02, then it initializes IN direction when ulEpNum==1 and OUT direction when ulEpNum==2, but otherwise the behaviour is the same. |
If you use |
Ouch, you are right... it has 8 possible endpoints instead of 16 like USB_OTG peripherals. I set it to 0x87 and now I see it when ulEpNum reaches 7, then pxEP2->MaxPacketSize is 8 and it goes through initialization. However, behaviour looks like the same. Current configuration:
|
(For the record, USB_OTG has even less endpoints.) |
Could you check these values when you are expecting to receive data through the endpoint:
|
Sorry for the late answer, I was on the roads yesterday... When I send data from host to device, USB_vIRQHandler comes up. On the second round of for cycle, (usISTR & USB_ISTR_CTR) != 0 is false. As of the state of endpoint 1 when USB_vIRQHandler comes up, the STAT_RX field of USB->EPR[1] has the value of 3 and the state of IN[1] endpoint is "USB_EP_STATE_DATA", so as far as I can see, it seems data interrupt is coming up at the appropriate IN endpoint. However, it is not handled there, |
The cheap STM32F103C8T6 "Blue Pill" dev board has a known bug in its USB implementation. It has a 10kΩ or 4.7kΩ pull-up resistor on D+ (R10 on the PCB) instead of the 1.5kΩ pull-up specified in the standard. Try replacing the resistor with the correct value and see if that solves your problem. |
Thank you your reply. I have replaced this resistor on one of my boards and tried the same code which has three virtual ports set up (these are the output of two sensors and a message port). One of them also has an input buffer set up, but not even .Received callback comes up. The other direction (USB data output) is still working. |
Dear IntergatedCircuits,
(I have pressed enter by mistake, that was the cause of initial empty issue...)
I put your code on an STM32F103C8T6 board together with USBDevice in Eclipse + HAL project.
Host can enumerate USB device and my keyboard interface work well - I can send keystrokes to host and receive Num Lock / Caps Lock status change signals, so it works well.
If I mount a USB-CDC interface, it also accessible by host and I can send data from device to host without problems.
However, I can not send messages from host to device.
The vcp_if interface is the same what I used together with my STM32F407VET6 microcontroller where both transmit / receive side work well.
So, with STM32F1, USB enumeration and endpoint configuration looks okay at host side, but by the time I try to send data from host to device, I can not see any interrupt happen on device.
STM32F4 family use xpd_usb_otg of XPD library and STM32F103 use xpd_usb from there, so USB low level behaviour differs, but otherwise the higher level interfaces I try to use are the same.
Could you please suggest what may I test on STM32F1 side?
Thank you your help in advance.
The text was updated successfully, but these errors were encountered: