Already spun a board? STM32 silicon errata on PB4?
Try making PB4 take turns being SPI and NJTRST. SPI mode when doing a command with readback, JTAG mode the rest of the time. don't forget to put it back in JTAG mode if you segfault. you will certainly not regret making PB4 be SPI and JTAG simultaneously.