2
\$\begingroup\$

I bought a blue pill that I tried to program using STLink on CubeMX IDE.

I got this:

Warn : UNEXPECTED idcode: 0x2ba01477 Error: expected 1 of 1: 0x1ba01477

I checked on the internet and I found that it's a fake one. I got the idea to edit the stm32f1.cfg file so I changed

set _CPUTAPID 0x2ba01477

to

set _CPUTAPID 0x1ba01477

It worked perfectly the first time, but after a couple of seconds the green LED turned on and now the problem I have is:

Error: init mode failed (unable to connect to the target)

Any help please? I can't afford another blue pill for the moment and I really need it for my studies.

\$\endgroup\$

5 Answers 5

7
\$\begingroup\$

Possibly, you have loaded a program that uses the SWD pins for other purposes than connecting a debugger or that otherwise negatively affects the SWD pins.

Set the BOOT0 jumper to 1 and restart the BluePill. That way, it starts in bootloader mode instead of starting your program. That way, you should be able to connect the STLink again and uplad a new program. After the upload, set the jumper back to 0.

Update

BTW. A BluePill usually has a STM32F103C8 chip (or clone), not a STM32F103C6. The difference is 64K vs 32K of flash. Make sure you have selected to correct chip.

\$\endgroup\$
2
  • \$\begingroup\$ thank you verry much it's working but there's something i din't understand every time i wanna program the stm32 i need to go to the bootloader mode even if i put an empty program i can't program it when the jumper is on 0 and yes it's c8 not c6 sorry \$\endgroup\$
    – Farouk YD
    Commented Jan 10, 2020 at 15:14
  • \$\begingroup\$ That's strange. Do you have the STLink connected to the SWCLK and SWDIO pins on the short side of the board? And if you use STM32CubeMX to generate the code, you might need to set System Core / SYS / Mode / Debug to Serial Wire. \$\endgroup\$
    – Codo
    Commented Jan 10, 2020 at 16:27
3
\$\begingroup\$

Simple method I use to write to fake STM32 chip or non STM32 chip, GD32 chip using STM32CubeIDE and STM32Cube programmer using ST-LINK/V2. No need to edit any system files.

  1. open STM32Cube programmer
  2. check if it is connecting to the fake or clone STM32 chip if it does then proceed
  3. open STM32CubeIDE
  4. do the coding as usual
  5. debug the code (It is ok if it shows error like "STM32 device not recognised" )
  6. open STM32Cube programmer and connect
  7. open the file -> select the ".elf" file from the project you created and debugged.
  8. click download.
  9. remove the device from USB and reconnect

Drawback: you need to eject the device and insert again to make the device work with the updated code. This method is simple and trouble free. I use this method to flash fake STM32 chip, clone chip and GD32 chip.

\$\endgroup\$
1
\$\begingroup\$

This post is the perfect answer for my fake STM32F1.

The steps I followed

  1. Debug config set to OPENOCD , Boot1 Jumper = 0
  2. The id has to be changed to 0x1ba01477 in stm32f1 cfg file
  3. set System Core / SYS / Mode / Debug to Serial Wire in CUBE ide( thanks to @code)
  4. Before starting debug do the following a. Set Reset mode to "Software system reset" b. Set Low power debug c. Set stop wdg on halt
  5. Press and hold reset in Board ( for the first time to flash this firmware with JTAG enabled in software )
  6. Press debug button on IDE
  7. Look for the debug message in console window and release the RESET during init to connect.

After doing this once , debug mode works normally.

\$\endgroup\$
1
\$\begingroup\$
  1. Debug config set to OPENOCD , Boot1 Jumper = 0
  2. Change code command #jtag scan chain set _CPUTAPID 0x1ba01477 in stm32f1x.cfg file
  3. Set System Core / SYS / Mode / Debug to Serial Wire in <your_file>.ioc
  4. Before starting debug do the following (in Debug Configurations)
    1. Set Reset mode to "Software system reset"
    2. Set Low power debug
    3. Set stop wdg on halt
    4. In connection setup choose suitable frequency value if console has error relate to Mhz
    5. In Startup enter command: monitor flash mass_erase
  5. Now you don't need hold the reset button to debug and download your code.
\$\endgroup\$
1
\$\begingroup\$

There is a much less invasive method to change the CPUTAPID from the platformio.ini. You just need to add it as upload_flags. Here is an example platformio.ini:

[env:bluepill_f103c8]

platform=ststm32
board=bluepill_f103c8
framework=libopencm3
upload_protocol=stlink
upload_flags=
    -c
    set CPUTAPID 0x2ba01477
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.