I am trying to connect some dots here and I am missing something (completely?). This is my understanding:
- An STM32 MCU boots from its bootloader after nRST is pulled low
- Also a power cycle will have it reboot.
- Boot pin(s) will help understand the MCU what to load into memory. E.g. from flash by default, or from USB or UART alternatively
- Flashing using SWD (system by ARM, not vendor specific) does not require nRST to be toggled low. Somehow (I miss that point) programming probes can ‘just’ start talking over the SWD ports, ‘soft’ resetting the MCU and reprogram flash.
- To me it then seems there is no role for the bootloader in ‘SWD flashing’.
The above assumptions create an OK model of reality for me. I can program and use MCUs that way (on a desk, not real world yet). But I trust not all of it is correct.
Where I become uncertain is when wanting to use SWD designated pins for GPIO. It almost seems SWD itself is an alternative function and I can move it around for larger MCUs (in CubeMX).
I have been looking through examples around this and it seems care has to be taken. But I cannot get my head around it and it is probably because my above model of reality is way too shallow. E.g. I read that it might require ‘using SWD under reset’. That doesn’t fit my model.
My basic questions are:
- Q1: How is it possible that the you can move SWD pins (in CubeMX) and program using the new location afterwards?
- Q2: Why would it matter if I reassign the SWD pins to GPIO as one of the first instructions of my program?
- Q3: How can moving SWD (or using the pins as GPIO) survive a power cycle? Is that the main point I am missing?
- Q4: Is my code actually executed before SWD flashing starts?
- Q5: Is there really no relation between the bootloader and SWD flashing?
The reason for asking is that I have ‘blocked’ some MCU’s from reprogramming when using the SWD pins for something else. Last time it happened was when using the SWD pins as UART and start a debugging session... That didn’t work. But a power cycle did not help either.
I am trying to use an 8 pin STM32G031J6 and I have to use two out of the nRST, Boot0 or SWD pins. That made me dive into the subject leading to the above simplified ‘model’ and open questions that I could not resolve.
Could you shoot at all incorrect assumptions and help me with the answers? Thank you.