Flashing an off-the-shelf STM32L031 with ST-LINK

This is a continuation of my former post NUCLEO-L031K6 and ST-LINK SWD. What on earth did I do? in which I tried to flash a standalone STM32L031 and found some serious obstacles. Now, I have solved all issues that I found and I have been able to flash the darned MCU. The idea was to use the ST-LINK in a discovery kit with STM32L476VG MCU connected to the STM32L031 with only two pins, SWDIO and SWDCLK in the connector CN4 of the kit. The wiring is straightforward when every is tied and connected correctly. And I am stressing this because you have to be sure that you have connected all pins that have to be connected. In concrete,  pin 5 in the STM32L031 labeled as VDDA, the reference for the analogue inputs, is NOT internally tied to VDD in pins (1 and 17) so it HAS to be connected to power the MCU otherwise it would be pretty dead. With this in mind, you only have to follow the next figures to connect the ST-LINK pins to the STM32L031. First, the power supply at 3.3 V and ground which are taken from the Discovery kit.

Then the connections from CN4 to the MCU. Notice that I decided not to use the Vapp nor the SWO pins since they are not strictly necessary to flash a program.

Finally, the pins I used in the STM32L031 (LQFP32) were:

Now, I used the STM32 ST-LINK utility to program the external MCU connecting the Discovery kit to a computer via USB.

The settings to begin the communication (Target->Settings…) are:

The connection mode was selected as Normal though Hot Plug also worked seamlessly.

Selecting Target->Connect in the main window establish the communication with the STM32L031 to obtain a window similar to where the starting address of the program 0x08000000 is empty:

The MCU found can be seen in a table in the upper-right of the main windows. You should check that it corresponds to the device you are really flashing.

You may also want to check the Target->Option Bytes… before the flashing:

Then, selecting Target->Program you can select the .bin file to download to the MCU:

The main window contains now a dump of the flashed memory in a new tab:

You can check that everything was correct in the log window:

Finally, pin 31 BOOT0 ought to be connected to GND to start the program in memory. If this pin is set to high during the booting sequency, the MCU would enter in the bootloader. Therefore, do not leave it unconnected after flashing the microcontroller.