When is HAL USB ready for me to send?
I have taken the STM32Cube_FW_F1_V1.8.0 example CDC_Standalone and adapted it to my purposes. The original example intends to forward bi-direction USB communication over a serial port. I have removed the serial port stuff and intend to simply send messages over USB from my STM32F105* mcu to my USB host.
While I have gotten this somewhat working, I find that I'm missing some detail to get it working correctly. It seems that I can't get the ball rolling. For example, if I just try to send the string "Hello World!\n" to the USB from the STM32, that string does NOT come out. But if some other activity occurs first, then it does.
Subsequent to the above trouble, I added CAN bus stuff. My intent is to simply log all CAN bus traffic onto USB to my USB host. Well, if I power off my CAN bus data generator and restart my STM32, then nothing comes to my USB host. However, when I turn my CAN bus data generator on, all of a sudden my log messages start appearing on the USB host. Furthermore, they are preceded by my "Hello World!\n" message.
Therefore, it seems like the sending out of the USB message was somehow held up until some other activity occurred. I don't know if the CAN and USB interrupts are independent or conflicting. Also, there is a HAL_TIM_PeriodElapsedCallback() function I inherited from the example, and I don't know if maybe the problem is that this callback isn't called until some other activity occurred.
I'll go try and read through the code to figure out when HAL_TIM_PeriodElapsedCallback() should be called, but otherwise I would greatly appreciate some hints or direct comments as to why the ball doesn't start rolling on its own. Why don't I get "Hello World!\n" out immediately?
(Note, I'm using a virtual com port on the USB host, of course, and running TeraTerm on that USB host.)
UPDATE: HAL_TIM_PeriodElapsedCallback() is indeed being called immediately. It in turn calls USBD_CDC_SetTxBuffer() and USBD_CDC_TransmitPacket() immediately. But nothing shows up on the USB host. I can see two line feeds were supposed to have been sent, totaling "Hello World!\nStart\n", and nothing shows on the USB host. I don't think it's a USB host side flushing issue. It could be an STM32 side flushing issue, but more likely some other missing event on the STM32 side...
UPDATE: My program will start and attempt to send "Hello World!\nStart\n". I see nothing on the USB host. But if I send a single char, such as "a" **from** the USB host to the STM32, **then** I get the "Hello World!\nStart\n" back out, as well as a looped back value of the "a". That is, the USB receive code in the STM32 loops back (echoes) the "a" back out. That loop back uses the same transmit() function I've written as the hello world. The difference, however, is that the loop back code calls USBD_CDC_ReceivePacket(). I would think I could transmit to usb without having to call USBD_CDC_ReceivePacket()... Simply calling USB_Receive_Complete_Callback() from the end of my transmit function does NOT get the ball rolling. I must actually send something from the USB host so that the STM32 actually RECEIVES something.
UPDATE: It only takes a single char from the USB host. I added to main a delay loop to send out "Tick\n" every 3 seconds. Once I send a single char from the USB host, my "Hello World!\nStart\n" comes out as well as "Tick\n" every 3 seconds. I do **not** have to send another char from the USB host for each subsequent "Tick\n" message to come out. Therefore, it seems like the very first receive is somehow greasing the wheels for as many subsequent transmits as I want. I **really** want to figure out what this is, so that my "Hello World!\nStart\n" will come out on its own, with no need for the USB host to send the first char.
