rogerclarkmelbourne / STM32duino-bootloader

Bootloader for STM32F103 boards, for use with the Arduino_STM32 repo and the Arduino IDE
962 stars 497 forks source link

st-link compatibility issue with STM32duino-bootloader #103

Closed mzhboy closed 3 years ago

mzhboy commented 3 years ago

I'm new to arduino. I was trying different upload methods to bluepill board(stm32f108c8t6) on windows. This bootloader works fine, however it was failed when I tried uploading with st-link/v2(clone, mini board). So I did some investigation.

The st-link is fine because the bootloader was uploaded by st-link utility. Then I tried connect nRST pin to st-link and change resetmode to Hardware Reset in STM32 ST-LINK Utility, disconnect usb and then click "connect to the target" button. It failed connect to target.

Then I tried every combination of "mode" and "reset mode", all failed. I was depressed because I thought this board was bricked.

Any way, I didn't give up and did found out the proper procedures to connect mcu.

  1. Press and hold the reset button.
  2. Set mode to "normal" , then Click "connect" button (st-link utility/stm32cubeprogrammer)
  3. Release reset button when st-link led start flashing
  4. now st-link connected successfully and device memory content appears in st-link utility, stm32 is halting by st-link
  5. I didn't flash anything, just click "disconnect from the target". Nothing happend, it seems stm32 still in halt mode and I can connect to stm32 by clicking "connect to the target" button. A hard reset can force stm32 restart normally.

STM32_HID_Bootloader has no problem except had to reconnect usb so that Windows can recognize device.

I tried inspect code but grep didn't find any code that disable swd/jatg pins.

mzhboy commented 3 years ago

I'm sorry, it's not a STM32duino-bootloader issue but a rogerclarkmelbourne/Arduino_STM32 issue, it sseems that swd pins were disabled by Arduino_STM32 framework. stm32duino/Arduino_Core_STM32 has no problem with st-link.

mzhboy commented 3 years ago

I jsut found out the code to disable debug pins

la:~/stm32# cd Arduino_STM32/;grep -R disableDebugPorts STM32F1/cores/maple/stm32f1/wirish_debug.cpp:void disableDebugPorts(void) { STM32F1/cores/maple/wirish_debug.h:void disableDebugPorts(void); STM32F1/cores/maple/wirish_debug.h: @.see disableDebugPorts() STM32F1/variants/generic_stm32f103t/board.cpp: disableDebugPorts(); STM32F1/variants/generic_stm32f103c/board.cpp: disableDebugPorts(); STM32F1/variants/hytiny_stm32f103t/board.cpp: disableDebugPorts(); STM32F1/variants/STM32VLD/board.cpp: disableDebugPorts(); STM32F1/variants/generic_stm32f103r8/board.cpp: disableDebugPorts(); STM32F1/variants/generic_stm32f103vb/board.cpp: disableDebugPorts(); STM32F1/variants/generic_gd32f103c/board.cpp: disableDebugPorts(); STM32F1/variants/microduino/board.cpp: disableDebugPorts(); STM32F1/variants/maple_mini/board.cpp: disableDebugPorts(); STM32F4/cores/maple/wirish_debug.h:static inline void disableDebugPorts(void) { STM32F4/cores/maple/wirish_debug.h: * @.see disableDebugPorts()

enable SWD ports by define CONFIG_MAPLE_MINI_NO_DISABLE_DEBUG