STM32L432KB flashes correctly, but debugging works sporadically
I have an STM32L432KB that I'm trying to use with STM32CubeIDE and an ST-LINK v3. It is on a small board, and the onboard hardware peripherals connected to the MCU are:
- USB-C connector to dedicated USB pins.
- Quad-SPI flash storage chip
- I2S audio chip
The debugger is connected to:
- Vcc
- GND
- RST
- SWCLK
- SWDIO
I haven't tried to see if the peripherals work yet because I'm just trying to get it debugging reliably. About 1 time out of 10 tries, it will break on main correctly, allow me to step through for a while, then usually will lose connection. When it loses connection, it usually loses it around
MX_USB_DEVICE_Init();or sometimes
SystemClock_Config();The other 9 out of 10 times, it does not break at all. When this happens, the IDE automatically opens a tab right after debugging begins and switches to the file called
startup_stm32l432kbux.sbut it does not break on any line in this file, except that this line is always highlighted for some reason:
Reset_Handler:
ldr sp, =_estack /* Set stack pointer */If I pause execution, it will open yet another tab with the name of a memory address, for example:
0x1fff133cand has the message:
Break at address "0x1fff133c" with no debug information available, or outside of program code.So the program seems to have gone off into never-never land, assuming the debugger is reporting things accurately.
Note that if I just flash the board and run some code I've written to print serial messages via the USB CDC driver, it works fine. I just cannot figure out why I'm having these debugging issues.
Other details:
- I had to fit it on a very small board, so I decided to forego a crystal and use the clock recovery system via USB, since my device will always be plugged into USB when in use.
- HAL_Delay() also seems to give accurate delays, but it's not clear to me if its timebase comes from the USB CRS or the internal oscillator.
- I've also gotten the I2S output from SAI1B to work

