Skip to content

Commit 7856a41

Browse files
committed
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.
1 parent d9e6968 commit 7856a41

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

ports/stm32/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ STATIC uint update_reset_mode(uint reset_mode) {
413413
return reset_mode;
414414
}
415415

416-
int main(void) {
416+
void stm32_main(uint32_t reset_mode) {
417417
// TODO disable JTAG
418418

419419
/* STM32F4xx HAL library initialization:
@@ -488,7 +488,7 @@ int main(void) {
488488
#endif
489489
led_state(3, 0);
490490
led_state(4, 0);
491-
uint reset_mode = update_reset_mode(1);
491+
reset_mode = update_reset_mode(1);
492492

493493
// Python threading init
494494
#if MICROPY_PY_THREAD

ports/stm32/resethandler.s

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
.type Reset_Handler, %function
3434

3535
Reset_Handler:
36+
/* Save the first argument to pass through to stm32_main */
37+
mov r4, r0
38+
3639
/* Load the stack pointer */
3740
ldr sp, =_estack
3841

@@ -61,6 +64,7 @@ Reset_Handler:
6164

6265
/* Initialise the system and jump to the main code */
6366
bl SystemInit
64-
b main
67+
mov r0, r4
68+
b stm32_main
6569

6670
.size Reset_Handler, .-Reset_Handler

0 commit comments

Comments
 (0)