From 7856a416bd4718dd2f63e3adcd8a595fb4fbb9e9 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 29 Mar 2018 16:15:57 +1100 Subject: [PATCH] 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. --- ports/stm32/main.c | 4 ++-- ports/stm32/resethandler.s | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ports/stm32/main.c b/ports/stm32/main.c index ccf490e36b..4b5997227c 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 6c37260dcb..7f0973346e 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