rogerclarkmelbourne / STM32duino-bootloader

Bootloader for STM32F103 boards, for use with the Arduino_STM32 repo and the Arduino IDE
976 stars 497 forks source link

Unknown USB Device (Device Descriptor Request Failed) on STM32F103C8 Custom Board with STM32duino DFU Bootloader #134

Open ae-circuit opened 5 days ago

ae-circuit commented 5 days ago

Description: I'm facing an issue with my STM32F103C8 custom board. After flashing the STM32duino DFU bootloader, the device is recognized as an "Unknown USB Device (Device Descriptor Request Failed)" on Windows.

Board Specifications:

MCU: STM32F103C8 External Oscillator: 16MHz Custom Board Design: Yes

Steps Taken: Bootloader Compilation and Flashing: I downloaded the STM32duino DFU bootloader from this repository. Modified the code to set the external oscillator to 16MHz in the hardware.h file. Compiled the bootloader using make generic-pc13. Successfully flashed the bootloader onto the board using an ST-Link V2 programmer.

After Flashing: When I connect the board via USB, Windows does not recognize it correctly. It shows "Unknown USB Device (Device Descriptor Request Failed)" in Device Manager.

Troubleshooting Attempts: Checked the USB wiring on my custom board. Reflashed the bootloader to ensure no errors occurred during flashing. Verified that the 16MHz oscillator is properly connected and providing a stable clock signal. Attempted to compile with different configurations in case it was a build issue. Relevant Code Modifications: In hardware.h, I ensured the following settings to match the 16MHz external oscillator:

System Information: Host OS: Windows 10 USB Drivers: STM32 USB drivers for DFU gets detected when STM32 BluePill is flashed with relevant DFU bootloader. Request for Assistance: Could you please advise if there are additional settings or configurations required to ensure USB recognition, or if there might be another cause for this issue? Any guidance on additional steps or troubleshooting would be greatly appreciated.

Thank you for your assistance.

rogerclarkmelbourne commented 5 days ago

This isn't an issue with the unmodified code.

There are many possible reasons why your board is not working, including incorrect clock source setting, incorrect PLL chain values, or possibly even hardware problems as you have a custom PCB

Build a project using the STM32Cube IDE that has USB and get that working first, and then use those PLL settings etc in this bootloader

ae-circuit commented 5 days ago

I did write a program using STM32CubeIDE with virtual com port and it does get detected by the system when connected. But when the STM32Duino bootloader is flashed, it shows an unknown USB after being detected by the Windows. Isn't it possible to have a different repo or different folder for .bin files created after setting all things for XTAL16M? I created it but need to confirm if my steps are correct or not.

Anyways that will be helpful if you share what exact things I need to troubleshoot for Clocks and PLL chains.

rogerclarkmelbourne commented 4 days ago

Just to confirm you added a #define to specify 16MHz crystal ?

define XTAL16M

However, I don't know if anyone ever tested whether variant works

The only difference in the clock settings are

https://www.st.com/resource/en/programming_manual/cd00228163-stm32f10xxx-20xxx-21xxx-l1xxxx-cortex-m3-programming-manual-stmicroelectronics.pdf

    // 16 MHz crystal  (using the Bit 17 PLLXTPRE=1 => HSE clock divided by 2 before PLL entry)
    SET_REG(RCC_CFGR, GET_REG(RCC_CFGR) | 0x001F0400); /* pll=72Mhz(x9/2),APB1=36Mhz,AHB=72Mhz */

instead of

    // 8 MHz crystal default
    SET_REG(RCC_CFGR, GET_REG(RCC_CFGR) | 0x001D0400); /* pll=72Mhz(x9),APB1=36Mhz,AHB=72Mhz */

See

// 8 MHz crystal default
SET_REG(RCC_CFGR, GET_REG(RCC_CFGR) | 0x001D0400); /* pll=72Mhz(x9),APB1=36Mhz,AHB=72Mhz */

Look in

Reference_Manual_STM32F1.pdf

7.3.2 Clock configuration register (RCC_CFGR)

bits 16 to 23

Bit 17 is set for the 16Mhz clock and not for the 8 Mhz clock

Bit 17 PLLXTPRE: HSE divider for PLL entry Set and cleared by software to divide HSE before PLL entry. This bit can be written only when PLL is disabled. 0: HSE clock not divided 1: HSE clock divided by 2

i.e the code appears to be correct

a divider of 2 is enabled for the 16Mhz clock. I can't see what else should be needed