cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F042F6 - STLINK - STM32CubeIDE programming problem

SimonVu
Associate

Hi,

I design a custom USB - UART using STM32F042F6

This is my schematic

 0693W000008GQ0fQAG.pngThis is pin configuration in Cube MX

0693W000008GQ14QAG.pngThis is the board layout

0693W000008GQ0uQAG.png 

When connect by USB cable, win10 pc recognized it as DFU device without problem.

I tried STLINK Utility to just connect to the device in attempt to flash the program, it failed

0693W000008GQ1OQAW.pngI tried combination of speeds and MCU reset options but nothing worked.

When I tried to flash the fw directly from STM32CubeIDE

0693W000008GQ3PQAW.png 

I even tried DfuSe Demo tool to force the MCU to leave DFU mode but still couldn't connect to SWD.

My last resort is to use DFU mode and DFU utility to upload the fw, but I don't know how to compile into *.dfu file.

I can flash fw on STM32F051 and STM32F303 directly from CubeIDE without problem. I can flash fw from STLINK utility as well. That is with Just with 2 pin SWDIO and SWCLK from the MCU connect to ST-Link V2 dongle. I am not sure if I need NRST to hook up to ST-Link. I don't need it on my custom STM32F051K8T6 board (this MCU doesn't has USB hardware). I'll try to hook a small wire to NRST later.

The second problem is when I change the USB device type in cubeMX into "Virtual Com Port"

0693W000008GQ6nQAG.png 0693W000008GQ2HQAW.png 

It became overflowed.

When turned on USART2 in cubeMX, now the flash became too big as well.

This STM32F042F6 has 6k of ram and 32k of flash.

There is a similar project that utilises this MCU as a USB-UART dongle, but this project is done using PlatformIO.

https://github.com/manuelbl/usb-serial

I probably can reuse the code of that project but I still cannot program the MCU.

I ran out of ideas. Any help is appreciated.

Thanks,

1 REPLY 1
SimonVu
Associate

For now I am able to get a simple app to toggle 2 LEDs on my board and upload the program over DFU.

Pin#1 or PB8 does act as BOOT0. Set to LOW to run user application, and HIGH to run built-in bootloader (auto run DFU mode when USB detected)

Still unable to debug or program this MCU via SWD.