Skip to main content
Visitor II
January 31, 2025
Question

Query: STM32F4 programming with USB

  • January 31, 2025
  • 3 replies
  • 1129 views

I can program my bespoke board using a repurposed USB port. It would normally be used by a mouse.

I was under the impression that if I powered up the board with BOOT0 pin held high the MCU would be in a state to connect to USB and do it's enumeration. However, using USB Device Tree Viewer I can see the 43 error.

If I then hold the NRST pin low for a few seconds, and then release enumeration follows and I am able to program the device.

Is this expected operation? I thought simply powering up the PCB with BOOT0 high would place the MCU in the correct state ready for programming?

    This topic has been closed for replies.

    3 replies

    Technical Moderator
    January 31, 2025

    Hello,

    You need to reset the MCU after holding high the BOOT pin .

    Mike xxAuthor
    Visitor II
    January 31, 2025

    Thanks for confirming. I can't find any programming guide or application note that says that, hence the question.

    Furthermore, I find for reliable connection I have to power up in reset, remove the reset link and then attach the USB cable to the socket.

    In fact the whole process of connecting is a little unreliable depending on port and / or the USB hub.

    Technical Moderator
    January 31, 2025

    Check you cable and your hardware.

    You can either use reset or power cycle the MCU after pulling up the BOOT pin.

    You can also refer to these articles:

    DFU mode with system bootloader is not working, while USB does

    FAQ STM32 boot process

    How can I use STM32CubeProgrammer to access the USB-DFU bootloader on my STM32 board?

    Hope that helps.

     

    Super User
    January 31, 2025

    Powering up with BOOT0 held high should be sufficient. Might be running into an issue with the crystal having a startup time.

    Mike xxAuthor
    Visitor II
    January 31, 2025

    I find this using this bootloader process unreliable.

    I can put a frequency meter on the 8MHz crystal. Whether it bursts into oscillation is hit and miss. With the application running, ie BOOT0 low, it always starts up.

    If I hold the BOOT0 pin high with NRST high after power-up and the USB cable disconnected I can see the 8MHz crystal running

    If I apply power with BOOT0 pin high and NRST low, then allow NRST go high there is no 8MHz oscillation until I connect the USB cable. It seems the longer the PCB is powered the process becomes more reliable.

    I see a comment in AN2606 regarding temperature:

      "When (because of temperature variations or other conditions) the internal oscillator precision is altered above the tolerance band (1% around the theoretical value), the bootloader can calculate a wrong HSE frequency value. In this case, the bootloader DFU/CAN interfaces can malfunction, or not work at all."

    That doesn't instil much confidence in reliable programming. I was hoping to remove the JTAG connector from the build, but JTAG seems the most reliable way to go.

    Super User
    February 1, 2025

    Perhaps the crystal selection or design could be improved.

    Guidelines for oscillator design on STM8AF/AL/S and STM32 MCUs/MPUs - Application note

    What you're doing should work on ST boards.