www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Trying to program USB device using STM32F

I'm using STM32F745(can be found in kynix: http://www.kynix.com) 
on my own board, and I am trying to program USB device (I tried 
virtual COM and HID, separately).

But after plugging into PC it is detected (after a while) with 
"Unknown device (device descriptor request failed)" error.

Electrically (PCB):
I think that PCB is not an error here - I just have D+ and D- 
short tracks from the connector to the uC and that's all.
I have a pull-up 1.5k (I tried with and without it), but it is 
not even needed in STM32. I have check connection and a cable and 
I'm certain it connects.

Code:

I'm using HAL and STM32CubeMx generated code merged with my 
project. Generally programs freezes.

1) After executing line (from library code) USBx->GAHBCFG |= 
USB_OTG_GAHBCFG_GINT;. I know that, as I tried printing before 
and after that line and only first printf() prints. I don't 
understand how the program can stuck there.
Anyway, if I disable VBUS sensing then the program doesn't get 
stuck there and the whole MX_USB_DEVICE_Init finishes.

2) But then, program executes few cycles (for example, it will 
print "done" and lit the LED) and after that it freezes. 
Completely. This LED should blink in an infinite loop, but it 
doesn't. I have other LED to be enabled in all error handlers 
(like hard fault etc.) and it seems that the the program doesn't 
go there (as the LED is off), so I don't understand where it get 
stuck.

     *After virtual COM, I tried HID but to no avail. It gives me 
the same behavior.
     *If I power the board from the charger (not PC) then the 
program doesn't get stuck.
Jan 25 2018