Hi jeremyzhou,
Thanks for trying to help me!
I also forgot to mention, that from time to time it is possible to make the windows to detect a CDC device, and it is listed in Device Manager. However, after few seconds later the hart fault happens and the device stops working. So, here I am in doubt about USB data lines are the problem... Would it help if I post a complete PCB layout of the board that is faulty? If so, you can find it attached.
Actually, I was trying to find a reason for hard faults, but what I found out is that the places where errors happen are random. Meaning that it is not in defined place I have the fault, they change very often.
Additionally, I found out that that was a bus/usage fault propagated to hard fault, when I switch to trigger explicit bus or usage fault, I get bus fault more often than usage fault. Very often I got the problem arise in mutex release fuction (i use FreeRTOS). Sometimes other places. Sometimes the error is unaligned memory accesses, sometimes undefined instruction, sometimes other type....
And this only happens when USB is connected to socket.
Could it be that I get some strange data via USB and these data are interpreted incorrectly and then code behaves strange causing faults? Or maybe (now my fanstasy works) incorrect electrical signal from USB corrupts the MCU ram memory data?
I also noticed that if I put brakepoint in the place where BDT is initialized/cleared and simply run directly after the debugger stopped, then I will not get faults and application will run (but USB would not work because timings are wrong).
What I also was thinking of, is there a change that other pins, not directly involved in USB connection may have such a side-effect on MCU? The PCB is router to support more different chips, but they are not soldered yet.
The last thing I would like to add is that the MCU I use on PCB_A is newer than on PCB_B. Could it be different MCU versions, where older can run the code and newer cannot. Old one comes from around jun 2014 and newer from oct 2014.