How does the STM32 board handle events written in Python after calling the main function and not terminate? #15328
-
I was investigating how the STM32 MCU operates when running Micropython on an STM32 board. Upon examining the resethandler_m0.s file, I found that after booting, the STM32 jumps to stm32_main. After checking the stm32_main code in micropython/ports/stm32/main.c, I noticed that it calls MICROPY_BOARD_BEFORE_SOFT_RESET_LOOP(&state); and then terminates. When running an example Python code, I want to know if the STM32 board will continue running and not terminate. To keep the STM32 board from terminating and to receive events, it seems necessary to jump to soft_reset:. However, I am unsure where this jump to soft_reset occurs. How does the STM32 board handle events written in Python after calling the main function and not terminate? If there is any part of the question that is unclear, please let me know. I can provide additional explanations. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
I am not sure what you mean by "terminate", but after executing If a soft-reset is invoked while the repl is running, the code will exit the repl loop and proceed to the code after the |
Beta Was this translation helpful? Give feedback.
Ah. I think I understand the misundertanding ;). If you are not familiar with the C language
goto
statements, it may appear that thestm_main()
function ends after theMICROPY_BOARD_BEFORE_SOFT_RESET_LOOP(&state);
statement. It does not. Thestm_main()
function ends at thegoto soft_reset;
on line 695 (as of current code in master branch).After the
boardctrl_before_soft_reset_loop()
function returns, execution will continue to the next line after thesoft_reset:
label statement (ie.MICROPY_BOARD_TOP_SOFT_RESET_LOOP(&state);
) and then continue through the rest of the code in thestm-main()
function. The first time through, thesoft_reset:
statement has no effect. It exists as a target fo…