2021-06-21 11:57 AM
I've taken a look at some datasheets, and I couldn't really find confrmation of this -- but just in case I missed the right terminology: is it possible to set up an STM32 MCU (I guess, via option bytes), so that an output pin might indicate whether the MCU runs system bootloader code (for instance, outputting HIGH level if the MCU runs system bootloader code, and LOW if it doesn't)?
Solved! Go to Solution.
2021-06-21 02:36 PM
I would use an external pullup and set a pin to output low in your code to verify if your code is running. There's nothing you can do to set particular GPIO outputs when in bootloader mode.
If something needs control over getting into or out of the bootloader, it should have control over BOOT0 and NRST to force the issue. Then you don't need to guess.
2021-06-21 12:23 PM
Which STM32?
I'd expect it might configure some expectant inputs with pull-ups, perhaps look at AN2606 for potential candidates.
Then you'd need to do the converse thing which your app/code starts..
2021-06-21 12:45 PM
Many thanks, @Community member ,
> Which STM32?
I didn't have anything specific in mind, just in general - as I perceive the system bootloader as a feature of STM32 family, my initial guess was, if there was such a feature, it is probably present everywhere the system bootloader is.
> I'd expect it might configure some expectant inputs with pull-ups, perhaps look at AN2606 for potential candidates.
> Then you'd need to do the converse thing which your app/code starts..
Great suggestion, thanks - will consult AN2606!
Btw, since I'm still wrapping my head around the STM32 memory map, and what is/isn't possible, I'd like to ask this: I'm aware I can use Write Memory command in system to write pretty much anywhere in Flash; can I also use Write Memory command to write registers, so as to configure a GPIO pin as output *from the system bootloader*, and then set its value to either low or high?
EDIT: As far as I have seen from AN2606: if you configure to use say USART1, then USART1_TX is configured as out, but then it is used by the bootloader to send ACK/NACK back; other than that, I cannot see any setting what would indicate bootloader run on output pin. AN3155 says "The Write Memory command is used to write data to any valid memory address (see note below) i.e. RAM, Flash memory, or option byte area." - so, no GPIO registers writing from system bootloader (in e.g. stm32f401re, GPIO registers are at 0x4002 0000, that is, "Peripherals" section)
2021-06-21 02:36 PM
I would use an external pullup and set a pin to output low in your code to verify if your code is running. There's nothing you can do to set particular GPIO outputs when in bootloader mode.
If something needs control over getting into or out of the bootloader, it should have control over BOOT0 and NRST to force the issue. Then you don't need to guess.
2021-06-21 02:53 PM
The USART it might use as input are initially configured as TIM inputs where it measures then 0x7F (8E1) pattern so as to auto-baud, and then configures the USART in/out pins to respond with the 0x79
As @TDK suggests use a pin you want, and which the loader normally doesn't touch, it should then leave the pin in a floating state as the registers are all in a reset state, and the loader wants to tread as lightly as possible. You can have code very early in your Reset_Handler to set a GPIO flagging it's in your domain, rather than the loaders.