STM32duino + STM32F405RG on VESC bldc controller

Yeah, 3.16 does seem a bit low. This was using the 3.3V supply on the ST-Link. I’ve also tried using the 5V supply from the ST-Link to the 3.3V regulator on the board, and I’ve tried using a 4 cell LiPo (how the board was designed to be powered) which goes through a 5V regulator to the 3.3V regulator. In each case, the voltage was 3.16-3.17V as output in the debug console. Using a voltmeter, the 3.3 volt line is at about 3.27 resting.

Occasionally, it will make it past that assert and instead issue a warning: Warn : STM32 flash size failed, probe inaccurate - assuming 1024k flash. Here is the debug console output in this case:

Processing genericSTM32F405RG (platform: ststm32; board: genericSTM32F405RG; framework: arduino)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/genericSTM32F405RG.html
PLATFORM: ST STM32 7.0.0 > STM32F405RG (128k RAM. 1024k Flash)
HARDWARE: STM32F405RG 168MHz, 128KB RAM, 1MB Flash
DEBUG: Current (stlink) External (blackmagic, jlink, stlink)
PACKAGES:
 - framework-arduinoststm32 4.10900.200602 (1.9.0)
 - framework-cmsis 2.50501.200527 (5.5.1)
 - toolchain-gccarmnoneeabi 1.90201.191206 (9.2.1)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 15 compatible libraries
Scanning dependencies...
No dependencies
Building in debug mode
Checking size .pio/build/genericSTM32F405RG/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   0.7% (used 952 bytes from 131072 bytes)
Flash: [          ]   1.3% (used 13824 bytes from 1048576 bytes)
========================= [SUCCESS] Took 3.35 seconds =========================
Reading symbols from /home/levi/Documents/PlatformIO/Projects/vesc_test/.pio/build/genericSTM32F405RG/firmware.elf...
PlatformIO Unified Debugger -> http://bit.ly/pio-debug
PlatformIO: debug_tool = stlink
PlatformIO: Initializing remote target...
xPack OpenOCD, 64-bit Open On-Chip Debugger 0.10.0+dev (2019-07-17-11:25)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
hla_swd
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : tcl server disabled
Info : telnet server disabled
Info : clock speed 2000 kHz
Info : STLINK V2J37S7 (API v2) VID:PID 0483:3748
Info : Target voltage: 3.177575
Info : stm32f4x.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : accepting 'gdb' connection from pipe
target halted due to debug-request, current mode: Handler HardFault
xPSR: 0x80000003 pc: 00000000 msp: 0x2001ff48
Info : device id = 0x10076413
Warn : STM32 flash size failed, probe inaccurate - assuming 1024k flash
Info : flash size = 1024 kbytes
Info : flash size = 512 bytes
0x00000000 in ?? ()
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x080009c4 msp: 0x20020000
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
Loading section .isr_vector, size 0x188 lma 0x8000000
Loading section .text, size 0x2fdc lma 0x8000188
Loading section .rodata, size 0x58c lma 0x8003164
Loading section .ARM, size 0x8 lma 0x80036f0
Loading section .init_array, size 0x14 lma 0x80036f8
Loading section .fini_array, size 0x8 lma 0x800370c
Loading section .data, size 0x98 lma 0x8003714
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08000c10 msp: 0x20020000
Start address 0x8000c10, load size 14252
Transfer rate: 19 KB/sec, 2036 bytes/write.
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Unable to match requested speed 2000 kHz, using 1800 kHz
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08000c10 msp: 0x20020000
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08000c10 msp: 0x20020000
Temporary breakpoint 1 at 0x8000bee: file /home/levi/.platformio/packages/framework-arduinoststm32/cores/arduino/main.cpp, line 50.
PlatformIO: Initialization completed
PlatformIO: Resume the execution to `debug_init_break = tbreak main`
PlatformIO: More configuration options -> http://bit.ly/pio-debug
Note: automatically using hardware breakpoints for read-only addresses.

Program
 received signal SIGINT, Interrupt.
0x3d08b988 in ?? ()

I then paused it and it stopped on a branch instruction 0x08001516: f6 f3 d3 f0 bl 0x87f76c0 (corresponding to line 674 in stm32f4xx_hal_rcc.c if ((HAL_GetTick() - tickstart) > CLOCKSWITCH_TIMEOUT_VALUE) ) and when stepping, it stayed on the same instruction.

Info : halted: PC: 0x3d08b988
halted: PC: 0x3d08b988
Info : halted: PC: 0x3d08b988
halted: PC: 0x3d08b988
Info : halted: PC: 0x3d08b988
halted: PC: 0x3d08b988
Info : halted: PC: 0x3d08b988
halted: PC: 0x3d08b988
Info : halted: PC: 0x3d08b988
halted: PC: 0x3d08b988

The fact that the issue is inconsistent does make me think it is some how power/hardware related. Maybe a bad ST-Link? But how does st-info retrieve the correct flash size? I tried using a debugging server previously, but I don’t think I set it up correctly. I’ll try that and let you know how it goes. But there still seems to be some other underlying issue as I can’t seem to get a blink program to work… Maybe I’ll try configuring it for some other F405 based board (STM32F4Stamp or Adafruit Feather STM32F405) and see if that makes a difference.

Edit: Another thought. When it says Unable to match requested speed 2000 kHz, using 1800 kHz, is it referring to the SWD speed? That seems a bit fast for some jumper cables.