summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-03-29 16:15:57 +1100
committerDamien George <damien.p.george@gmail.com>2018-03-29 16:15:57 +1100
commit7856a416bd4718dd2f63e3adcd8a595fb4fbb9e9 (patch)
treec30833e050391964014f57b4a88e411a10167c6a
parentd9e69681f5c100076aec5fb9a9ec00add3aa22b0 (diff)
stm32/main: Rename main to stm32_main and pass through first argument.
The main() function has a predefined type in C which is not so useful for embedded contexts. This patch renames main() to stm32_main() so we can define our own type signature for this function. The type signature is defined to have a single argument which is the "reset_mode" and is passed through as r0 from Reset_Handler. This allows, for example, a bootloader to pass through information into the main application.
-rw-r--r--ports/stm32/main.c4
-rw-r--r--ports/stm32/resethandler.s6
2 files changed, 7 insertions, 3 deletions
diff --git a/ports/stm32/main.c b/ports/stm32/main.c
index ccf490e36..4b5997227 100644
--- a/ports/stm32/main.c
+++ b/ports/stm32/main.c
@@ -413,7 +413,7 @@ STATIC uint update_reset_mode(uint reset_mode) {
return reset_mode;
}
-int main(void) {
+void stm32_main(uint32_t reset_mode) {
// TODO disable JTAG
/* STM32F4xx HAL library initialization:
@@ -488,7 +488,7 @@ soft_reset:
#endif
led_state(3, 0);
led_state(4, 0);
- uint reset_mode = update_reset_mode(1);
+ reset_mode = update_reset_mode(1);
// Python threading init
#if MICROPY_PY_THREAD
diff --git a/ports/stm32/resethandler.s b/ports/stm32/resethandler.s
index 6c37260dc..7f0973346 100644
--- a/ports/stm32/resethandler.s
+++ b/ports/stm32/resethandler.s
@@ -33,6 +33,9 @@
.type Reset_Handler, %function
Reset_Handler:
+ /* Save the first argument to pass through to stm32_main */
+ mov r4, r0
+
/* Load the stack pointer */
ldr sp, =_estack
@@ -61,6 +64,7 @@ Reset_Handler:
/* Initialise the system and jump to the main code */
bl SystemInit
- b main
+ mov r0, r4
+ b stm32_main
.size Reset_Handler, .-Reset_Handler