2022-03-27 08:02 AM
I've extended the USB-CDC example using Cube IDE to report serial port line state -- Ring, etc. My example works on STM32F1, however, it does NOT function correctly on STM32F4.
Here's the meat:
/* USER CODE BEGIN PRIVATE_FUNCTIONS_IMPLEMENTATION */
USBD_StatusTypeDef USBD_CtlSendNotification(USBD_HandleTypeDef *pdev,
uint8_t *pbuf, uint16_t len)
{
/* Set EP0 State */
//pdev->ep0_state = USBD_EP0_STATUS_IN ;
pdev->ep_in[2].total_length = len;
pdev->ep_in[2].rem_length = len;
/* Start the transfer */
USBD_LL_Transmit(pdev, CDC_CMD_EP, pbuf, len);
return USBD_OK;
}
uint8_t CDC_Notify_FS(uint8_t linestate) {
USBD_HandleTypeDef *pdev = &hUsbDeviceFS;
USBD_CDC_HandleTypeDef *hcdc =
(USBD_CDC_HandleTypeDef*) hUsbDeviceFS.pClassData;
uint8_t ifalt = 0U;
uint16_t status_info = 0U;
uint8_t ret = USBD_OK;
uint8_t dbuf[12];
dbuf[0] = 0xA1; //bmRequestType TODO: Add Define for USB_SERIAL_STATE
dbuf[1] = 0x20; //SERIAL_STATE
dbuf[2] = 0x00; // wValue
dbuf[3] = 0x00;
dbuf[4] = 0x00; // windex (interface) TODO: pdev->dev_address ?
dbuf[5] = 0x00;
dbuf[6] = 0x02; // wlen
dbuf[7] = 0x00;
dbuf[8] = linestate & 0x7F; // linestate 7:0
dbuf[9] = 0x00; // reserved 15:8
USBD_CtlSendNotification(pdev, (uint8_t*) (void*) &dbuf, 0x0A);
return ret;
}
/* USER CODE END PRIVATE_FUNCTIONS_IMPLEMENTATION */
Do I need to do any other initialization (on STM32F4) before I'm able to send a 10 byte buffer down the Interrupt-endpoint 82?
2022-03-28 07:35 AM
Hello @Bmora.1 ,
In order to allow a better analysis this issue, could you please give us more details about your problem.
Thanks in advance.
BeST Regards,
Walid
2022-03-28 01:32 PM
Make the dbuf array global or static.
JW