0

I created a custom board with an STM32F103C8T6 microprocessor and Iwant to use the USB to program the board using the STM32CubeProgrammer. I found out thanks to a user on Stack Exchange that it is not possible to make it work for the STM32F103 without a DFU or bootloader (see datasheet).

I tried different ways to make it work, see the following points:

  • Using the STMFlashLoader and a bootloader from GitHub (always recommended by YouTube videos, the boot loader by Rodger Clark)
  • Using the STM42CubeProgrammer and the same bootloader.

For more ways, see Programming STM32F103c using USB.

The Problem

Working 1

I always get to the point, where I can upload a program using the STM32CubeProgrammer over the USART1 connector. After setting the Boot0 pin back to 0 and reseting the board, and then connecting the board back using the power/COM port, the device gets recognised but as an UNKNOWN DEVICE.

Working 2

I also tried to enable the USB. That works a little. When the program got flashed via USART1 (like described above) and reconnected, the COM-Port is listed under the COM-Ports (in windows 11 > Device Manager).

Where I am now?

Currently I try and fail, and not really getting anywhere.

What the problem could be:

  • Wrong bootloader
    Should use the right one! Have the PC13 as an LED output (like the boot loader)
  • Wrong schematic connection
  • Wrong way to use the CubeProgrammer and the uploader (did it like in the tutorials)

Maybe somebody encountered the same or a similar problem and can help me fix this.


See my other questions on this topic for additions:

brhans
  • 14,373
  • 3
  • 34
  • 49
Y-E-Quit
  • 111
  • 8
  • 1
    So may I again ask under this question, why exactly you think your hardware and bootloader are compatible with each other? – Justme Apr 11 '23 at 16:38
  • 1
    Did you check if your STM chip has a protocol or script that allows it to be programmed over USB? On Atmel chips, I've used BOSSAC and SAMBA to upload firmware to ICs directly over USB. I am unsure if STM has an equivalent script. Furthermore, many STM dev boards I've used have a STLINK embedded onto the board, this might be because direct USB programming is not possible. In that case you will need a USB to Serial cable or an FTDI chip on board. – md-raz Apr 11 '23 at 16:39
  • @Justme, I think so because I use the same chip and mostly same pinouts as the blue pill. The only difference could be that I instead of an 8MHz Oscillator a 16MHz Oscillator is used. – Y-E-Quit Apr 11 '23 at 16:46
  • 1
    @md-raz That was the introduction to the actual question; this MCU does not support USB unless the MCU is programmed with a custom bootloader that does support USB. – Justme Apr 11 '23 at 16:48

1 Answers1

1

So you answered the reason - It does not work if you have 16 MHz oscillator and the bootloader requires a 8 MHz oscillator.

You also don't have a button to trigger the bootloader to go into USB mode instead of jumping to run the main program, but that depends on if the bootloader requires it or not.

Justme
  • 127,425
  • 3
  • 97
  • 261
  • But would the whole bootloader not work then? Because the LED lights up yes, but in a very strange frequency – Y-E-Quit Apr 11 '23 at 16:52
  • @Y-E-Quit The MCU is clocked by the crystal. If you have double the frequency you are supposed to use, everything in the MCU will run at double the speed. So it can't blink the LED at correct frequency, or communicate over USB at correct frequency, and if the frequency is over the rate the MCU will work properly, it won't even work properly. – Justme Apr 11 '23 at 16:57
  • In which file, do I usually have to change the Clock settings? Do you know what I have to look for? – Y-E-Quit Apr 12 '23 at 07:38
  • 1
    It seems the code supports compiling with 16M speed option if given the correct defines, so it is easy, but you need to set up the build environment for compiling it. Other option is for you to change to 8 MHz crystal. But like I said, you need a button pin to trigger the bootloader to start USB instead of calling application code. And you need to compile the application code to reside at higher address so it does not overwrite your bootloader. – Justme Apr 12 '23 at 08:22
  • Can I use any free pin for the Button? Also what is ment with 'to start USB instead of calling application code'? Thought when goging back from Boot0 High to Boot0 low and then reseting the board would be enought. – Y-E-Quit Apr 12 '23 at 08:38
  • 1
    Do you understand what a bootloader does? It starts and if a button is not pushed, it jumps to execute your application program, and if a button was pushed, it stays in the bootloader and commumicates via USB to allow to reflash the application program. Boot0 has used to enter factory bootloader, it has nothing to do with your custom uploaded bootloader. – Justme Apr 12 '23 at 08:40