Struggling to get USB CDC device working with NUCLEO-F411RE directly connected to computer, but not with STM32F411E-DISCO
I have been struggling to get USB CDC device to work for the Nucleo without any additional USB peripherals. USB CDC works perfectly fine when I use the DISCO-board connected through the USB-micro, with the same MCU as the NUCLEO.
I have connected a cut USB A cable and using code like shown in this blog post (just other pin locations for the F411 compared to F042): https://shawnhymel.com/1795/getting-started-with-stm32-nucleo-usb-virtual-com-port/
I have tested removing the ground and shield connections as well as the 5V from the Nucleo, one at a time. When I connect the USB-cable to my computer I don't see any new devices in windows device manager. Why is the connection not recognized? Do I need additional resistors on the D+ and D- lines, when I want to set it up as device?
In a desperate attempt I have also tried adding this renumeration code, but the device is still not detected:
/* USER CODE BEGIN USB_DEVICE_Init_PreTreatment */
/*
* Force host to re-enumerate device
*/
GPIO_InitTypeDef GPIO_InitStruct = { 0 }; // All zeroed out
GPIO_InitStruct.Pin = GPIO_PIN_12; // Hardcoding this - PA12 is D+
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; // Push-pull mode
GPIO_InitStruct.Pull = GPIO_PULLDOWN; // Resetting so pull low
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; // Really shouldn't matter in this case
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); // Initialize with above settings
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET); // Yank low
HAL_Delay(50); // Enough time for host to disconnect device
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_SET); // Back high - so host will enumerate
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_12); // Deinitialize the pin
/* USER CODE END USB_DEVICE_Init_PreTreatment */
