cancel
Showing results for 
Search instead for 
Did you mean: 

NUCLEO-L412KB : USB-CDC Initial FAIL

ARats
Associate

I have try to use the USB-VCP (Virtual COM Port) on the STM32L412KB (32-pin) but I have an issue that the code which is generated from the CubeMX got stuck at MX_USB_DEVICE_Init() and I try to debug in the Atollic TrueStudio, it causes the hard fault on HAL_PCD_init() function in USBD_Init process.

Issue: MX_USB_DEVICE_Init() got stuck

MCU: STM32L412KB (NUCLEO-32 Board)

Firmware Package Name and Version: STM32Cube FW_L4 V1.13.0

CubeMX version 5.1.0

Toolchain/IDE: Atollic TrueStudio Version 9.1.0

Please suggest, thank you very much.

P.S. I have used the USB-VCP via CubeMX on the another chip such STM32F072, STM32L053, STM32L476 with no problem.

12 REPLIES 12
NKoti
Associate

Did you manage to find a solution?

I have the same problem, the Nucleo board hangs at this line:

 /* Enabling DP Pull-UP bit to Connect internal PU resistor on USB DP line */

USBx->BCDR |= USB_BCDR_DPPU;

If I comment out this line, the USB setup completes successfully, but the board hangs when I pull up the DP pin manually with an external resistor.

TDeut
Associate II

Hello,

I had the similar problem and I think that is a bug in the CubeMX Program.

In my case the entry of the USB_IRQHandler in the Interrupt Vector Table of the file startup_stm32l412xx.s is missing. So each USB interrupt jump to an undefined memory address.

Please check in the File startup_stm32l412xx.s:

...

g_pfnVectors:

   .word   _estack

   .word   Reset_Handler

   .word   NMI_Handler

...

.word   COMP_IRQHandler

   .word   LPTIM1_IRQHandler

   .word   LPTIM2_IRQHandler

   .word   0 ; <--- put here "USB_IRQHandler"

   .word   DMA2_Channel6_IRQHandler

   .word   DMA2_Channel7_IRQHandler

   .word   LPUART1_IRQHandler

   .word   QUADSPI_IRQHandler

...

Best regards

Many thanks, that was missing indeed!

I understand there's no bug reporting/tracking system for external bug reports like this, I guess we'd just have to hope that someone at ST reads this?

You were right, the USB_IRQHandler is missing.

Thank you, that solved it for me!

Definitely a bug with STM32CubeMX that needs to be fixed.

TDeut
Associate II

Hello,

I think this bux is fixed in the CubeMX version 5.2.1.

Maybe ST has read our discussion.

Best regards

I sure hope so. I thought I updated CubeMX to the latest version yesterday before trying it out and generating code. But it could be that the startup file doesn't get updated / overwritten when generating code over old code.

Thank you again for finding the solution. I had already spent 6+ hours last week trying to learn about STM32 USB and trying understand the problem, and was prepared to spend even more. One line of code, and you fixed it!

Hello Tim,

You're right!

The bug is not fixed yet. It seems that the startup code comes directly from the firmware repository. This is why you have an older startup file date also in new projects.

In the HAL repository you will find 3 templates for the start code (ARM, GCC, IAR). The ARM and IAR versions are correct. All GCC templates lack the USB_IRQHandler.

In my yesterday's test, I checked a new project with the default setting EWARM and saw the correct function.

Maybe the error does not come from CubeMX but from the HAL firmware?

Best regards

JLojo
Associate III

I confirm the problem still exists in CubeMX 5.2.1

Thank you so much for providing this solution, I started to become crazy with that, having used many other TSM32 devices, with VCP and with no such problem at all!

jylo