2
\$\begingroup\$

I am using an STM32F4 with the Rowley CrossStudio for ARM. It is not clear to me how to have the MCU start from int main() on reset (i.e. power up the device). I thought building it in release mode would have done this, but that seems not to be the case.

Looking online, I see some people saying that you somehow change the startup vector but this may prevent future debugging?

Is there a good way to accomplish this so that I can debug if I need to and run my program without the debugger on startup?

Thank you!

\$\endgroup\$
3
  • 1
    \$\begingroup\$ What is the state of the BOOT0 pin? This controls the startup mode of most members of the STM32 family. \$\endgroup\$ Mar 2, 2018 at 19:49
  • \$\begingroup\$ Aha! By grounding the BOOT0 pin I was able to make this work. This is a good hardware solution, but shouldn't I still be able to programmatically make this work? \$\endgroup\$
    – Biff
    Mar 4, 2018 at 0:32
  • \$\begingroup\$ No, you have to use the pin, or else have something else command it to jump to flash. \$\endgroup\$ Mar 4, 2018 at 1:14

3 Answers 3

2
\$\begingroup\$

On most (but perhaps not all) members of the STM32 family, to automatically boot an application from flash you must ground the BOOT0 pin.

This is essentially so that if you have a bad application in flash, or one that does not provide a means of entering the bootloader, you can force entry to the bootloader by cycling reset with BOOT0 high (with appropriate setting of boot1 or other mode controls to select the bootloader rather than RAM).

\$\endgroup\$
2
\$\begingroup\$

If you define the macro STARTUP_FROM_RESET it should jump to the proper reset vector on startup.

The JTAG interface should still be able to gain control if you've built for debug.

\$\endgroup\$
5
  • \$\begingroup\$ So I tried #define STARTUP_FROM RESET 1 in my main.c file but it didn't seem to work? \$\endgroup\$
    – Biff
    Mar 2, 2018 at 18:59
  • \$\begingroup\$ Try in Startup.s \$\endgroup\$ Mar 2, 2018 at 19:03
  • 1
    \$\begingroup\$ You could add this as a project setting. "Build Options"->"Project Macros" if I remember correctly \$\endgroup\$
    – brhans
    Mar 2, 2018 at 22:24
  • \$\begingroup\$ Defining it in Startup.s does not work, and adding STARTUP_FROM_RESET in global macros does not work either. \$\endgroup\$
    – Biff
    Mar 4, 2018 at 0:11
  • 1
    \$\begingroup\$ In my project I put "STARTUP_FROM_RESET" into the preprocessor definitions. Before I did that, my controller wouldn't start as well. \$\endgroup\$
    – Creatronik
    Dec 14, 2022 at 16:25
0
\$\begingroup\$

If you've tried everything else and STARTUP_FROM_RESET still doesn't appear to work, chances are good you have a debug_printf("something") somewhere which is waiting on the JTAG/SW connection. Once I remove all my debug_printf's it worked as expected.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.