Skip to main content
Visitor II
June 21, 2019
Question

STM32L412 hardfault while using minimal CubeIDE example.

  • June 21, 2019
  • 13 replies
  • 9916 views

I try to set up an USB CDC project for a STM32L412KB Nucleo32 board using CubeIDE.

I activated the USB connection and the USB middleware with the default USB CDC setup.

If I run this code, it ends in the hardfault handler with INVSTATE raised during the USB_EnableGlobalInt(hpcd) call (HAL_PCD_Start() at stm32l4xx_hal_pcd.c:1,014 0x8000d26).

The next items on the call stacks are: <signal handler called>() at 0xfffffff9, 0x0, <signal handler called>() at 0xfffffff1   and finally HardFault_Handler() at stm32l4xx_it.c:88 0x800432a.

Currently I ran out of ideas on what to do. USB CDC worked in projects set up for the STM32F072 and F103 - should we change from the L4 to another MCU?

    This topic has been closed for replies.

    13 replies

    Super User
    July 21, 2019

    > thanks for the hint Jan, but when I do singel step, it works fine until I push resume.

    > So I can single step trough the whole thing and it is fine, but when I let the processor run freely again it ends up in HardFault.

    My guess is, that the problem occurs in the USB interrupt service routine (ISR), and you have disabled interrupts during single-step (that's a common setting, otherwise it would be hard to single-step most practical programs).

    You may perhaps want to place a breakpoint into the USB ISR and single-step from there to see, where that will take you.

    Do you have a PC connected to the USB when the problem occurs?

    JW

    Graduate II
    July 22, 2019

    Should check for malloc()/free() idiocy that they like to do in interrupt context

    Visitor II
    July 22, 2019

    YESSSSS.

    ruediger1.561124119260664E12 Hade the right answer to my problem.

    Missing IRQ routine linkage .

    @RKnoe​ Thanks

    ruediger1.561124119260664E12
     
    (Community Member)
    2 hours ago
     
    Yes. For me the reason was a forgotten ISR definition in the Startup/startup_stm32l412kbux.s file. It should contain:
     
     
     
     .word 0
     
     .word COMP_IRQHandler
     
     .word LPTIM1_IRQHandler
     
     .word LPTIM2_IRQHandler
     
     .word USB_IRQHandler
     
     .word DMA2_Channel6_IRQHandler
     
     .word DMA2_Channel7_IRQHandler

    Super User
    July 22, 2019

    The USB_IRQHandler vector is present in both arm and iar version of startup code, absent only in the gcc version. IMO it's a bug. @Imen DAHMEN​  can you please have a look? Thanks.

    JW

    Technical Moderator
    August 15, 2019

    Hello All,

    This issue is raised internally for fix.

    Thanks for your contribution.

    Best Regards,

    Imen