Skip to main content
Visitor II
October 23, 2020
Solved

STM32F4 Use HSI for USB Clock

  • October 23, 2020
  • 3 replies
  • 7697 views

I want to use STM32F413 for my PCB design. I need USB data lines for communicating with a computer. Ideally, I would not have any oscillator on the PCB to save space. I noticed that's it's not possible to use HSI for the USB clock on CubeMX. Can I use pin PA8 as MCO to output HSI and route it to PH0 ? This way HSI and HSE are connected though the PCB. On CubeMX it seems possible, however, I don't know if it can work in reality. Are there some consideration hat I need to take to ensure this will work? Here are some screenshots of the CubeMX configuration and PCB schematic. Thanks

 0693W0000059C4mQAE.png0693W0000059C56QAE.png0693W0000059C5LQAU.png0693W0000059C5QQAU.png

    This topic has been closed for replies.
    Best answer by Tesla DeLorean

    Well the data you're sending might be at 115200, but the bus data is working at 12 MHz, and the clocks at each end need to be reasonably synchronized so the packets are recognized and remain intact across the link. The USB specification dictates that the host controller must send a SOF packet at a rate of 12 MHz ±500 ppm (parts per million), that is, 12 MHz ±0.05%

    The HSI is hugely unstable, both in the short and long terms, and has a wide range. Figure packet loss, random disconnection, failure to connect, general link reliability issue. Can't put USB logos on product, on meet certification requirements. Maker applications, perhaps who cares, commercial applications, likely to increase support calls and costs, as well as reputational cost.

    3 replies

    Super User
    October 23, 2020

    If you want to use HSI, you can do so without re-routing it to PH0, and doing so isn't going to increase accuracy even if the chip is technically in "HSE bypass" mode.

    HSI won't meet the accuracy requirements of USB and may or may not work, depending on your specific chip, ambient temperature, trimming values, etc. There are some chips that can use HSI along with the clock recovery system (CRS) to manage crystal-less USB, but the STM32F4 is not one of them.

    JBret.1Author
    Visitor II
    October 23, 2020

    When I select HSI as PLL clock source on "Clock Configuration" it gives me an error, so I assume it is not possible to route HSI to the PLL internally, that's why I'm trying to do it externally. 0693W0000059CApQAM.png0693W0000059CB4QAM.png

    Super User
    October 23, 2020

    > When I select HSI as PLL clock source on "Clock Configuration" it gives me an error,

    I don't see any errors shown in your screenshot. I do see that the system clock is using HSI and not PLLCLK. You'll need to select PLLCLK to use the PLL for the system clock.

    Graduate II
    October 23, 2020

    The limitation here is one enforced by CubeMX, you can just EDIT THE CODE

    The real world consequence however is that you probably won't be able to meet USB compliance testing as you're using a clock whose accuracy doesn't meet requirements, and you might encounter systems/conditions where your device will not function properly.

    For a commercial product, you should discuss the ramifications with your front-line support staff, so they don't come lynch you later.

    JBret.1Author
    Visitor II
    October 23, 2020

    What accuracy problems and malfunction should I expect to encounter? I'm routing my USB lines with width and spacing the ensure I have 90 ohms differential impedance. The device will only be used at room temperature. The USB baud rate will be 115200. Thanks!

    Graduate II
    October 23, 2020

    Well the data you're sending might be at 115200, but the bus data is working at 12 MHz, and the clocks at each end need to be reasonably synchronized so the packets are recognized and remain intact across the link. The USB specification dictates that the host controller must send a SOF packet at a rate of 12 MHz ±500 ppm (parts per million), that is, 12 MHz ±0.05%

    The HSI is hugely unstable, both in the short and long terms, and has a wide range. Figure packet loss, random disconnection, failure to connect, general link reliability issue. Can't put USB logos on product, on meet certification requirements. Maker applications, perhaps who cares, commercial applications, likely to increase support calls and costs, as well as reputational cost.

    Super User
    October 23, 2020

    If STM32 is in device role, some models can use the host (PC) SOF signals to synchronise.

    These models can run on the internal oscillator. But this won't help with other interfaces such as UARTs.

    -- pa

    JBret.1Author
    Visitor II
    October 23, 2020

    Hi, how can you setup Start of Frame signal? the STM32 will only operate in device mode so if it's possible to use SOF instead of a crystal it would be an ideal solution. From my understanding, the host sends a signal every 1 ms (LS) or 125 us (HS). How does that the SOF signal transmits to the STM32 device? The STM32 will be connected to the computer with Micro USB connector (VBUS, D+, D-, GND). Do I need to activate a function in CubeMX to sync the data with SOF? Thanks0693W0000059CpiQAE.png

    Graduate II
    October 23, 2020

    > There are some chips that can use HSI along with the clock recovery system (CRS) to manage crystal-less USB, but the STM32F4 is not one of them.

    As TDK already told you - there is no such thing in F4 series. Ir you want CRS, then take a look on L4 and G4 series.