Hello.
I want to design a PCB that will have a STM32 microcontroller.
I've never used STM32, so first I bought a Blue Pill STM32F103C8T6 development board to just familiarize myself with the STM32 microcontrollers, program it, etc. I could program it with OpenOCD, debug it, and I could program it with stm32flash utility via UART from the system bootloader (BOOT0 high). Everything worked perfectly.
The next step was, I wanted to do the same I did with the Blue Pill with a raw STM32 chip. By raw I mean a chip without any board. So I bought a STM32F030C8T6 chip. Since it is in SMD package, I used a SMD-to-DIP adapter (like this) to be able to connect to the pins with jumper wires and connect them to a breadboard.
Here is how it looks (sorry, I don't have a microscope):
I use a ST-Link V2 programmer (like this).
Here is the connection scheme:
I use OpenOCD utility on linux: openocd -f interface/stlink.cfg -f target/stm32f0x.cfg
When ST-Link and the MCU are connected, the following output is produced:
Open On-Chip Debugger 0.12.0
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 1000 kHz
Info : STLINK V2J29S7 (API v2) VID:PID 0483:3748
Info : Target voltage: 3.252337
Info : [stm32f0x.cpu] Cortex-M0 r0p0 processor detected
Info : [stm32f0x.cpu] target has 4 breakpoints, 2 watchpoints
Info : starting gdb server for stm32f0x.cpu on 3333
Info : Listening on port 3333 for gdb connections
But when I connect to the openocd through telnet and try to reset the chip I get the following message:
> reset halt
Unable to match requested speed 1000 kHz, using 950 kHz
Unable to match requested speed 1000 kHz, using 950 kHz
[stm32f0x.cpu] halted due to debug-request, current mode: Thread
xPSR: 0xc1000000 pc: 0x080000c0 msp: 0x20002800
Previously on Blue Pill there was no such message "Unable to match requested speed 1000 kHz, using 950 kHz".
Writing, reading, verifying the flash memory works:
> flash write_image image.bin 0x08000000
device id = 0x20006440
flash size = 64 KiB
wrote 4096 bytes from file image.bin in 0.211623s (18.902 KiB/s)
> verify_image image.bin 0x08000000
verified 4096 bytes in 0.070256s (56.935 KiB/s)
But when I run some program via GDB on the chip, I have the following error in GDB:
Error erasing flash with vFlashErase packet
And this error in OpenOCD:
Error executing event reset-init on target stm32f0x.cpu:
embedded:startup.tcl:1193: Error:
in procedure 'ocd_process_reset'
in procedure 'ocd_process_reset_inner' called at file "embedded:startup.tcl", line 1193
Error: Target not halted
Error: failed erasing sectors 0 to 0
Error: flash_erase returned -304
Also I tried to run a simple blinky program that toggled the PC13 pin, flashed it at 0x08000000 and restarted the MCU. It didn't work. Doesn't seem like the program is running, because PC13 is not even configured as output pin, it has high impedance.
Also I compared currents when there is no program written in the flash and when there is the blinky program written. In both cases the current is around 500 uA.
Also I tried to communicate with the chip via UART while the chip is in system bootloader state (BOOT0 is high). While it worked with the Blue Pill board, it doesn't with the current setup.
The output from stm32flash:
stm32flash 0.7
http://stm32flash.sourceforge.net/
Interface serial_posix: 57600 8E1
Failed to init device, timeout.
I had a suspicion that the chip is broken. So I bought another chip, STM32F103C8T6, the same chip that Blue Pill board has. Since the chips seem to have the same pinout, the SMD-to-DIP adapter and the connection schematic is the same.
The new chip also didn't work, but for another reason. Now ST-Link just can't connect to the chip, even though the connection is the same. Here is the OpenOCD output:
Open On-Chip Debugger 0.12.0
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 1000 kHz
Info : STLINK V2J29S7 (API v2) VID:PID 0483:3748
Info : Target voltage: 3.250167
Error: init mode failed (unable to connect to the target)
UART connection doesn't work either.
To ensure the problem is not with the chip itself, I decided to desolder the perfectly working chip from the Blue Pill board and solder it on an adapter board like the other two chips. I soldered it, connected like the other two, and as expected it didn't work the same way the other STM32F103C8T6 chip, ST-Link just doesn't connect to it. UART connection doesn't work either, even though it worked while being on the Blue Pill board. So it looks like the problem is not with the chip, but rather with the soldering or the connection setup.
For all the soldered chips I made sure that no any two adjacent pins are shorted and that all the pins are have connection to the adapter board.
For all the chips I tried to pull down BOOT1 pin, left RST floating, pull up RST, pull down RST, connect RST to the ST-Link RST. Nothing helped.
I also tried to add from 1 to 5 100 nF capacitors, but I could not connect them near to the power supply pins of the MCU as recommended, rather I added them on the breadboard. It did not help either.
Do you know what could be the problem, why I can't connect to or program the chips? What should I try?
Any help is appreciated!
Thanks in advance!