cancel
Showing results for 
Search instead for 
Did you mean: 

Stm32L0 CDC Tx Issue

ronald
Associate
Posted on July 21, 2015 at 21:19

I am having some issues with the CDC Transmit Library.

I have a STM32l0-discovery board, when the device is powered through the st-link usb connector. Whenever I transmit data over the Virtual Comport using CDC_Transmit_FS the �C just hangs.

If I connect the User USB Port to my machine it doesn't hang, even when the device isn't open. Does anybody have any experience with this, I see 2 solutions, discovering if it is connected, or fixing the bug, in some thread I saw that there was a while (pCDC->TxState) state but that is not available in this one so I can't exit that loop after a while.

I used STM32CubeMX 4.7.1 to generate the code for SW4STM32 toolset.

#stm32l0-cdc
1 REPLY 1
ronald
Associate
Posted on July 22, 2015 at 16:13

I found the reasoning behind this:

InsideCDC_Transmit_FS there is a function call toUSBD_CDC_SetTxBuffer, which usespClassData, which when calling this when not transmitted data yet will be null. Modifying CDC_Transmit_FS to the following will fix the issue:

uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len)
{
uint8_t result = USBD_OK;
/* USER CODE BEGIN 7 */
if
(hUsbDevice_0->pClassData == NULL) 
return
USBD_FAIL;
USBD_CDC_SetTxBuffer(hUsbDevice_0, Buf, Len);
result = USBD_CDC_TransmitPacket(hUsbDevice_0);
/* USER CODE END 7 */
return
result;
}