STM32 DFU not working through UART and USB

image

Hello Y’all, I am here to present you all with a very weird situation that I am in. I made this custom STM32F411CEU6 board ( GitHub - TheLimboMan/Chongs-Cool-STM32-Board: Chong's Cool STM32 Board ) and I wanted to interface it and program it. I can easily porgram it through SWD just fine, but problem comes when I want to program it either through UART or USB C.

The UART Situation

I am interfacing the UART port through PA9 and PA10, which is typically (at least what i see) used on those WeAct BlackPill boards (whose board also hold a STM32F411CEU6), I can get the uart to output into my serial monitor just fine, hello world, sensor output, all just fine, so i assume it shouldn’t be a UART communication problem. but the problem comes when i want to interface it during DFU mode. it just doesn’t work! I used the stm32cubeprogrammer to connect to it, and it just gives out an error telling me to try and reconnect. I hooked up to my serial monitor to see if it gives out “entered bootloader mode” or anything like that, but it just gives me a blank screen!

The USB C Situation

When I connect it through USB C in DFU mode, it gives me a device descriptor request failed! i tried the “pull down PA10” trick that i was told to do, but still nothing. I even tried to pull down PA9 too, along with those SWD pins when i am connecting through USB C but NOTHING, it is still the same. What can i do to fix my situation :frowning:

Edit: I have tried pulling down the PB2 pin so that boot1 can be pulled down, still nothing :smiling_face_with_tear:

If neither the USART nor the USB bootloader seems to react, then most likely it’s not entering DFU mode correctly.

If you can connect via SWD in the STM32CubeProgrammer, can you show a screenshot of the option bytes?

If you press down SW1, do you read 3.3V on BOOT0 pin (or at the upper pin of R8) with respect to GND? have you tried pressing SW1 continously then power-cycling / replugging the USB-C cable, and it’s still not detected?

Here ya go, I think you might be onto something about the DFU not entering properly, because i used a Arduino Mega as a UART programmer by hooking up it’s TX pins to my STM32’s TX pins, then it’s RX pins to my RX pins. UART communication works fine, serial monitor shows, and the RX/TX LEDs on the Arduino Mega lights up normally, just when i enter DFU mode, it all goes dark, No blinking LEDs AT ALL! FYI I also did the whole power cycling thing that you mentioned, but it ain’t working so well either

The option bytes look good, specifically the readout protection (RDP) level is “level 1” (0xAA), which means it should be allowed to boot from “system memory bootlaoder”.

If you enter DFU mode via the button and it stops running the regular firmware, that’s actually a good sign. Do you use a dedicated USB-to-UART adapter to interface the STM32 with the PC or do you do that via the Arduino Mega? For the latter, you have to absolutely disable the Mega2560 on the Arduino Mega from driving the lines, by connecting the RESET pin to GND; That lets the USB-to-UART chip on the Arduino Mega board drive the line completely.

WOAH! You were right! i tied the reset pin to ground and now UART DFU WORKS! Thank you SO MUCH! Now it’s just the USB C not working :frowning:

Can you upload a regular Arduino-STM32 firmware that tries to establish a USB Serial connection? You have to take special care to inform the build system that your HSE crystal is 24 MHz (and not e.g. 25 MHz like used in the Blackpill F411 design).

What’s your current platformio.ini? Do you already set HSE_VALUE in it? Do you use a custom board JSON definition? Do you already use a custom clock init function that enables HSE+PLL?

In STM32CubeIDE, I’ve set the USB_DEVICE to both Virtual Port COM and DFU, both allowed me to plug in my STM32 into my computer without the need for switching to DFU Mode, but it still gives me DEVICE DESCRIPTOR FAILED in device manager :frowning:

I assume this is what you mean by uploading a firmware that can allow me to interact through USB? Because I don’t think i can find an Arduino-STM32 firmware somewhere that is compatible (at least i think they don’t) with my stm32 board since the pinouts are all different so i am doing this instead.

Edit: Clock is already configured according to my clock selection, both input clocks are set to 32.768 and 24 mhz respectively

Sorry, that means if you set it to “Virtual COM Port”, the device was able to show up as a proper COM port on your computer via USB? No “device descriptor failed” message there, but only in bootloader mode?

nope i meant that if i set it to virtual com port it also says device descriptor failed :frowning:

Edit: and just to be extra clear, i also tried the whole grounding the PA10 pin and also PB2 pin when the device is in virtual com port mode too, still nothing

Can you try uploading GitHub - maxgerhardt/pio-stm32f4-usbtest via SWD? Don’t additonally ground any pin specifically.

Nope, i uploaded it, plugged it in without entering DFU and it isn’t showing ANYTHING at all on my device manager, not even a device descriptor error, no COM port too. Thanks for the code btw

Then HSE may be dead. Is the 24 MHz crystal really correctly soldered? The loading capacitors sized as 10pF is correct? (https://blog.adafruit.com/2012/01/24/choosing-the-right-crystal-and-caps-for-your-design/)

If you change this specific part

void setup() {
    Serial.begin(115200);
    while (!Serial) {
        delay(10);
    }
}

void loop() {
    Serial.println("Hello, world!");
    delay(1000);
}

to

#define LED PB0
void setup() {
  pinMode(LED, OUTPUT);
}

void loop() {
    digitalWrite(LED, HIGH);
    delay(1000);
    digitalWrite(LED, LOW);
    delay(1000);
}

(while keeping SystemClock_Config() the same), does it blink an LED at PB0?

I have tried the blinking code (but my led is on PB13 so i call for that instead) it doesn’t seem to work :frowning:

but i think that’s a software issue because if i use STM32CUBEIDE and use their own special codes and syntaxes and all that stuff i was able to make it blink, read my gyroscope and so on

Crystal wise, i think it should be wired up correctly, I’ve been basing this board on that Phill’s lab tutorial:

I have some suspicions that the crystal is not soldered properly (i hand soldered them myself)

The crystals are quite similar to the LEDs that I’ve soldered, they both only have contact pads exclusively at their bottoms, meaning the solder can’t grip on the sides like those SMD capacitors and resistors

When i initially solder on my LEDs by just placing them onto the pad, heating them up until they move into place by themselves, they don’t seem to work, its right until i press them down while heating them up again that they seem to work

It feels like it’s a similar situation with the crystals, i think all i need to do is to reflow the solder and press down the crystals more so that they can make more contact

Man I really wish it didn’t have to come to this, pulling out my soldering kit again is such a hassle :sweat_smile:

And what happens when you only have

#define LED PB13
void setup() {
  pinMode(LED, OUTPUT);
}

void loop() {
    digitalWrite(LED, HIGH);
    delay(1000);
    digitalWrite(LED, LOW);
    delay(1000);
}

with the platformio.ini

[env:genericSTM32F411CE]
platform = ststm32
board = genericSTM32F411CE
framework = arduino

? That should try to use HSI, so not the external crystal. Does PB13 blink then?

Oh this is the weirdest part, it doesn’t work too! It really only works when i use STM32CubeIDE, with the whole

while (1)
{
    /* USER CODE END WHILE */
	 HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_13);
	 HAL_Delay(500);
    /* USER CODE BEGIN 3 */
}

thing, along with all the other function declarations and callings and stuff

I have also a suspision that the stock bootloader/firmware (or at least the compiler files) doesn’t really allow me to interface my board with anything from Arduino.h and the arduino framwork for some reason

Here is the main.c that works from STM32CubeIDE:

Try start with read Introduction to system memory boot mode on STM32 MCUs - Application note

page 187 actualy , i dont check your schematics, but USB DFU in system bootloader is described in AN2606 and next…

Do you guys think the fact that i connected up the wrong capacitors-crystal combo is causing the USB functionality to not work? I have this 12.5pF crystal, and my board connects this crystal to a 1.5pF capacitor (which i think is quite too low according to CL = (C1 * C2) / (C1 + C2) + Cstray?)

same with the 24MHz crystal btw

That should not be possible. With the firmware exactly from STM32 DFU not working through UART and USB - #15 by maxgerhardt, and using an ST-Link, can you go to the debug side bar and press “Start Debug”? If it boots up, press the “Pause” after some time. What is the call stack?