I have a very minimal setup for a STM32L412KBT6
It's hooked up on a prototyping board:
The circuit is done according to the official reference guide and effectively looks like this:
(Sorry for the amateurish schematic)
I have a basic blink project written in C++ using PlatformIO with the Arduino core. Here is my program:
#include <Arduino.h> #define LED_PIN PA5 void setup() { pinMode(LED_PIN, OUTPUT); } void loop() { digitalWrite(LED_PIN, HIGH); delay(1000); digitalWrite(LED_PIN, LOW); delay(1000); } And my platformio.ini:
[env:nucleo_l412kb] platform = ststm32 board = nucleo_l412kb framework = arduino upload_protocol = stlink ;build_flags = -DCONFIG_DISABLE_DEBUG=1 Uploading the code with my STLinkV2 works fine and returns:
CURRENT: upload_protocol = stlink Uploading .pio\build\nucleo_l412kb\firmware.elf xPack OpenOCD, x86_64 Open On-Chip Debugger 0.10.0+dev-00378-ge5be992df (2020-06-26-09:29) Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html debug_level: 1 srst_only separate srst_nogate srst_open_drain connect_deassert_srst target halted due to debug-request, current mode: Thread xPSR: 0x01000000 pc: 0x1fff31f8 msp: 0x20001bb0 ** Programming Started ** Warn : Adding extra erase range, 0x08002a80 .. 0x08002fff ** Programming Finished ** ** Verify Started ** ** Verified OK ** ** Resetting Target ** shutdown command invoked And looking at the program flash in STM32CubeProgrammer seems to have some data written to it:
The configuration byte is left as default:
However, it seems really unreliable whether the program boots. After programming usually nothing happens, and resetting the MCU does nothing either. Messing with the NRST pin and disconnecting the STLinkV2 USB power sometimes causes the program to start running correctly, but this isn't always the case. I've also tried this with a broken-out nucleo STLink programmer with same results. I've also tried 3 different MCU:s just to make sure the MCU or it's breakout board solder joints aren't faulty. I've also tried every combination of the option bits: nBOOT1, nSWBOOT0 and nBOOT0. Bypassing the PH3/BOOT0 pin with nSWBOOT0 also sometimes makes the program boot right after applying the option byte, but this too is very inconcistent and only works on about 1/10 attempts. My circuit's VCC is at 3.3V.
In short: My MCU seldom boots into it's program memory with given PlatformIO setup and schematic. Setup has been tried with multiple MCU:s and 2 different STLink progrmmers with no difference.