cancel
Showing results for 
Search instead for 
Did you mean: 

How to have my program run when I push the reset button on my nucleo ?

BCora.1
Associate III

Hello,

I'd developing on a Nucleo STM32L152.

For now I managed to assemble a small program that turns on a LED. When I flash the program using the command:

$ st-flash write main.bin 0x8000000

The program is flashed to, I guess, the flash memory of the microcontroller and then the user LED illuminates, so I guess my program is launched. That is good. Ultimately though, I'll want to be able to run my program without having to flash it before each use. Ultimately, I'll even want to run my program without any USB power, by powering the nucleo on a 3V battery.

So I'd like to learn how to configure the nucleo so that it starts my program each time I push the reset button.

I've been reading at boot options here:

https://www.st.com/resource/en/reference_manual/cd00240193-stm32l100xx-stm32l151xx-stm32l152xx-and-stm32l162xx-advanced-armbased-32bit-mcus-stmicroelectronics.pdf#page=50

From this I infer, that if I could set the boot0 pin to 0, and the nBFB2 option bit to 1, the device would boot on flash memory and so maybe that would work, my program would be launched when I push reset. I'm not sure about this theory but this is my theory so far.

I'd like to try what I just described but there are two obstacles for me.

First, I can't set boot0 pin to 0, because I have no idea how to set a pin to 0.

Second I can't envision how I could set the nBFB2 option bit to 1 for two reasons: first I don't know where that bit is. Second I don't know how to set its value before running any program.

Any help would be greatly appreciated.

4 REPLIES 4
KnarfB
Principal III

Once you have written your program to the flash by the above command, it stays in the flash permanently. So each time you press reset on your Nucleo board, your progam will be launched. BOOT0 pin is already pulled low (to 0) by a resistor on the Nucleo board. You can check this by studying the board schematics, see UM1724 "STM32 Nucleo-64 boards (MB1136)". Programming (flashing) the board is done via the SWD debug interface and works even when BOOT0 is low.

BOOT0 needs to be high (1) only for upgrading the code by users in-the-field. In that case, an on-chip bootloader will be started ("System memory") on reset instead of the regular firmware. The bootloader is able to download new code via UART or other interfaces, not using the Debug connection or a debug adaptor (ST-LINK).

For reading/writing the option bytes, there is a dedicated software, the STM32cubeProgrammer.

BCora.1
Associate III

Thanks for the reply. I wonder why the user led turns off when I click on reset then, since my program is supposed to turn it on (and the led does turn on as soon as I flash my program to the nucleo). I also checked flashing a "do nothing" program, in case the user led would turn on each time you flash something but this was not the case. So it really seems my program is launched when I flash it with st-flash, but not when I press reset.

I don't have STM32cubeProgrammer. From what I've read it's not available on linux.

Anybody knows of a tool that would allow me to, at least read, and even better, read and write, the option bytes from my arch linux running laptop?

TDK
Guru

> I don't have STM32cubeProgrammer. From what I've read it's not available on linux.

This is false.

If you feel a post has answered your question, please click "Accept as Solution".

Here is my version of a bare metal asm blinky using gcc for assembly and linking and using a different Nucleo board: https://gitlab.com/stm32mcu/blinky_bare-metal_asm . The LED starts blinking as soon as you release the reset button.

Having the complete STM32 tool set installed may be helpful for getting started and finding the differences to your approach.