2018-07-25 05:55 AM
Dear All,
I would like to ask how to manage USB CDC on the nucleo-l4r5zi board. I would like to send data from a uC to the PC via USB.
The main function looks like that:
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_USB_DEVICE_Init();
uint8_t myBuf[] = "Hello World \r\n";
uint8_t stat;
while (1)
{
stat = CDC_Transmit_FS(myBuf, 12);
if(stat!=USBD_OK)
HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_7);
HAL_Delay(500);
HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_14);
}
}
The main problem is inside the function CDC_Transmit_FS(...), in line:
if (hcdc->TxState != 0)
{
return USBD_BUSY;
}
I do not know how to make the TxState 0.
I also removed SB193 and 195 from the board as it states in the ref manual of the board.
2018-07-29 09:47 AM
Hi Mike,
I also had some trouble with USB CDC in the last few weeks on an STM32L433CC.
1) Modify MX_USB_DEVICE_Init(...) to wait until the USB connection is established
#define USB_DEVICE_CONNECTION_TIMEOUT_MS 2000
...
/* USER CODE BEGIN USB_DEVICE_Init_PostTreatment */
uint32_t tickstart_ms = HAL_GetTick();
while(hUsbDeviceFS.dev_state != USBD_STATE_CONFIGURED){
// wait until USB state is configured or timeout is reached
if ((HAL_GetTick() - tickstart_ms) > USB_DEVICE_CONNECTION_TIMEOUT_MS) {
break;
}
}
}
/* USER CODE END USB_DEVICE_Init_PostTreatment */
2) Update the HAL library to the latest version
https://community.st.com/s/question/0D50X00009ZDBaESAX/usb-stall-behavior-cubemx-cdc
Did your PC recognize the device correctly as a Virtual COM Port or is any error shown in the device manager?
Kind regards,
Moritz