STM32 USB CDC Demo is missing an interrupt handler

Sysprogs forums Forums VisualGDB STM32 USB CDC Demo is missing an interrupt handler

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #7786
    julianr
    Participant

    I just got a small  STM32F103C8T6 development board and I am trying to get the USB CDC Demo to run. I have no experience with the STM32 processor family (or the STM32 HAL/USB library). The HAL Blinky example works fine. The USB CDC does not. When I debug it the code it always runs to “Default_Handler()”. I defined  DEBUG_DEFAULT_INTERRUPT_HANDLERS and now the code stops at “USB_LP_CAN1_RX0_IRQHandler()”. I think there are some parts missing in the template code. I am using the latest version of Visual GDB (5.1 Build 660) and the STM32 BSP Package (3.5).

    #7799
    support
    Keymaster

    Hi,

    Yes, this looks like a bug in our example.

    Please try defining the handler as follows:

    extern "C" void USB_LP_CAN1_RX0_IRQHandler(void)
    {
      HAL_PCD_IRQHandler(&hpcd);
    }
    #7814
    julianr
    Participant

    Hi,

    I added the interrupt handler you proposed. Sadly the demo is still not working.

    The interrupt gets triggered but the PC is not able to enumerate the USB device. The clocking should be fine (I am using the standard settings). The System is running with 72Mhz and the USB with a 1.5 prescaler which should generate the required 48Mhz.

    Any Ideas what still might be wrong?

    #7815
    support
    Keymaster

    Hi,

    Yes. Please check that the interrupt handler gets invoked if not, check your USB configuration to see whether it’s initialized properly.

    If Windows does not report the device at all (not even as “Unknown device”), the firmware is not enabling the USB functionality correctly. If it’s reported as “Unknown device”, the USB logic is enabled, but cannot handle requests from the PC, indicating either a clocking error or a crash due to something else.

    You can also check where the code is running if you stop the application via Debug->Break All.

    #7834
    julianr
    Participant

    I got it to work. It was a problem with IRQ priorities. For some reason the SysTick IRQ got a lower priority than the USB IRQ wich means that the delay function was not working since the SysTick IRQ never fired to increase the delay time counter when requested inside a USB interrupt.

    I fixed this by replacing the line:

    #define  TICK_INT_PRIORITY            ((uint32_t)0x000F)

    with

    #define  TICK_INT_PRIORITY            ((uint32_t)0)

    inside the stm32f1xx_hal_conf.h file. I don’t understand the original define anyway. You define a float value with hex notation (is that even possible) and then cast it into an unsigned integer? Why not define it as a integer constant in the first place?

     

    #7839
    support
    Keymaster

    Hi,

    Good to know it worked. Note that ((uint32_t)0x000F) does not refer to a floating-point value, it simply defines a priority of 15 (0x0F).

    #7842
    julianr
    Participant

    This is very embarrassing…  😳

    Of course that is standard hex notation for integer numbers. But this is what happens when you debug unknown code on a hungover Saturday morning before the first coffee…

    The problem is still the same. The USB and SysTick IRQ have the same priority and this means the SysTick based wait function is not working inside the USB interrupt handler. You might want to correct this in your demo code together with the missing USB IRQ handler in the next release.

    • This reply was modified 8 years ago by julianr.
    #7857
    support
    Keymaster

    Hi,

    No problem. Similarly looking things are always easy to confuse. Happens to everyone.

    Regarding the priority, we are somewhat hesitant to change the code that comes from ST without testing it on the real hardware, so we’ll probably simply add a big warning in the sample or the tutorial about the interrupt priorities.

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.