I'm having trouble making stm32 work as a communication port over USB.
I can't believe it's so difficult to send a string over USB.
I created a new project using STM32CubeIDE.
I performed the following steps:
- RCC -> HSE Crystal Enabled (25MHz)
- USB_OTG_FS -> Device_Only
- USB_DEVICE -> Communication Device Class (Virtual Port Com)
- Clock Configuration -> Automatic Resolve. USB 48MHz.
- Heap Size -> 0x800, Stack Size 0x800.
- GPIO -> Pin 30. Output Led
- Added 5s delay before while loop.
- Added led blink code in the while loop.
- Added CDC_Transmit_FS in the while loop.
When executing the program, the led flashes at the correct time (500ms) and the CDC_Transmit_FS function returns USBD_BUSY.
And Windows 10 does not detect the USB device.
I tested it on two different computers. I tested inverting the D+ and D- signals of the USB cable. I installed "STM32 Virtual COM Port Driver".
I'm using a custom PCB, and this PCB has an older code that was not generated by the STM32CubeIDE where the USB port reads pendrives.
So I believe the hardware is correct.
** STM32F105RBT6 ST-Link V2 Windows 10 **
Any ideas?
int main(void)
{
/* USER CODE BEGIN 1 */
uint8_t buffer[] = "Hello World\r\n";
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USB_DEVICE_Init();
/* USER CODE BEGIN 2 */
HAL_Delay(5000);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_GPIO_WritePin(LED_ON_GPIO_Port, LED_ON_Pin, GPIO_PIN_SET);
HAL_Delay(500);
HAL_GPIO_WritePin(LED_ON_GPIO_Port, LED_ON_Pin, GPIO_PIN_RESET);
HAL_Delay(500);
CDC_Transmit_FS(buffer, sizeof(buffer));
}
/* USER CODE END 3 */
}```