I want to use my first STM32 MCU in the project. The project involves a few peripherals (UART/SPI/I2C) and has a bit of math to do here and there, mainly bit shifting and/or integer computations, so I found myself an MCU with the peripherals I need, internal oscillator, enough flash program space and RAM for my application.
So I found this smol boi: STM32L051K8T6 in LQFP-32, Datasheet
I looked through the datasheet, everything seems clear, I have no problem picking up new stuff, IDE and all, however, I have a pair of questions I wasn't able to google up clear answer for, and the community can be more helpful anyway:
I would like to be able to program it via SWD. It's a 2 wire communication, right? SWDIO and SWCLK. So, in theory, provided I supply power for the MCU, I only need 2 pins to hook myself up to MCU (or maybe also reset? Grounds connected, obviously). I mean, I don't need large 10-pin connector or anything? Pretty much like Atmegas via UART (which need RX, TX and DTR pulse to MCU reset). Googling ST-Link v2 pinout showed me only these two and an unknown to me "SWIM" pin. (which is never mentioned in datasheet; I actually have an ST-Link v2 and even a nucleo board with on board programmer, but, again, it never hurts to ask smart people).
SWDIO and SWCLK are marked as "Alternate functions" of the pins. So, I assume, I won't be able to program it via SWDIO/SWCLK out of the box, because the pins are not configured as SWDIO/SWCLK by default. Is it something I need to use BOOT0 for? Does the bootloader from the internal memory activate SWD pins for me to program the flash? There is also no BOOT1 pin in this specific case (Ctrl+F "Boot1" yields no useful mentions in the entire datasheet).
I want to have user-updatable software. Via USB. It's easy to do it with ATMega, I just tossed in a USB-UART CP2102N, and it works like a charm, can update software all day. I guess I could write my own UART bootloader for STM32, it's only a matter of determination and taking pills to stay sane in the process. But if there is an easier way, I don't want to reinvent the wheel (although that programming part on the nucleo looks a lot bigger than just CP2102N chip). Found this document on using UART: STM32 Bootloader UART seems promising, it doesn't seem too difficult to use CP2102N to program STM32, I guess?
Of course I have watched a few videos on the youtube about STM32 as well, but they are basically "blinky-blinky" with nucleo, not with standalone device, so not much talk about datasheets, alternate functions, controlling stuff via registers; and setting up I2C or SPI won't be a problem anyway. Basically, I have no problem controlling the registers and stuff, I just need to get it running first. It's like I can drive a car, but I don't have a key to start the engine - or maybe I do and I'm just not aware of it. In order not to explode the car on ignition, I prefer to ask questions first.