F103 USB HID works when not debugging (swd)
Hello,
I'm trying a really simple HID mouse-moving example (https://notes.iopush.net/stm32-custom-usb-hid-step-by-step-2/) and if I connect my bluepill via usb to the computer (macOS), as expected, it connects and the mousecursor slowly drifts to the right. All fine.
Now I'd like to set some breakpoints to follow the program flow and understand better what is happening, but when I run from the debugger (CubeIDE + stlink v2, via SWD) the bluepill doesn't connect with the PC. It goes through the mainloop with dev_state being a few times USBD_STATE_DEFAULT (the else part) and after that always through USBD_STATE_SUSPENDED.
The mainloop does something like this:
counters[hUsbDeviceFS.dev_state]++;
if (hUsbDeviceFS.dev_state == USBD_STATE_CONFIGURED)
{
mouseHID.x = 10;
USBD_HID_SendReport(&hUsbDeviceFS, &mouseHID, sizeof(struct mouseHID_t));
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13,GPIO_PIN_RESET);
HAL_Delay(100);
}
else if (hUsbDeviceFS.dev_state == USBD_STATE_SUSPENDED){
HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13); //Toggle the state of pin PC9
HAL_Delay(10);
}
else if (hUsbDeviceFS.dev_state == USBD_STATE_ADDRESSED){
HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13); //Toggle the state of pin PC9
HAL_Delay(100);
}
else {
HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13); //Toggle the state of pin PC9
HAL_Delay(50);
}
I found a post which looks like it's the same issue (https://community.st.com/s/question/0D50X00009XkXyVSAV/usb-cdc-dont-work-in-debug?t=1565295850752 and https://hackaday.io/project/19799/logs) but calling "USB_DEVICE_MasterHardReset"-workaround doesn't seem to work (anymore?) since it gets into an endless loop in HardFault_Handler.
Maybe after the call to change the pin + delay, the pin has to be "restored" to whatever it was set to initially, but I can't see to find any code which does an initial configuration for GPIO_PIN_12...?
Any ideas, anyone?
