Skip to content

Commit 02ba7ea

Browse files
committed
IAR - Initialize RTOS before standard library
Initialize the RTOS before initializing the standard library. This allows C++ constructors to be called in a well defined thread context.
1 parent fa8dc64 commit 02ba7ea

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

core/mbed-rtos/rtx/TARGET_CORTEX_M/RTX_CM_lib.h

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -568,29 +568,40 @@ extern void __iar_dynamic_initialization(void);
568568
extern void mbed_sdk_init(void);
569569
extern void exit(int arg);
570570

571+
static uint8_t low_level_init_needed;
572+
573+
void pre_main(void) {
574+
if (low_level_init_needed) {
575+
__iar_dynamic_initialization();
576+
}
577+
main();
578+
}
579+
571580
#pragma required=__vector_table
572581
void __iar_program_start( void )
573582
{
574583
#ifdef __MBED_CMSIS_RTOS_CM
575584
__iar_init_core();
576585
__iar_init_vfp();
577586

578-
int a;
587+
uint8_t low_level_init_needed_local;
579588

580-
if (__low_level_init() != 0) {
589+
low_level_init_needed_local = __low_level_init();
590+
if (low_level_init_needed_local) {
581591
__iar_data_init3();
582592
mbed_sdk_init();
583-
__iar_dynamic_initialization();
584593
}
594+
/* Store in a global variable after RAM has been initialized */
595+
low_level_init_needed = low_level_init_needed_local;
585596
#endif
586597
osKernelInitialize();
587598
#ifdef __MBED_CMSIS_RTOS_CM
588599
set_main_stack();
589600
#endif
590601
osThreadCreate(&os_thread_def_main, NULL);
591-
a = osKernelStart();
592-
exit(a);
593-
602+
osKernelStart();
603+
/* osKernelStart should not return */
604+
while (1);
594605
}
595606

596607
#endif

0 commit comments

Comments
 (0)