Skip to content

Commit 2665d5b

Browse files
author
Bogdan Marinescu
committed
Modified call-before-main mechanism
Added a new function (mbed_sdk_init) that can be used by the SDK itself to do initializations before main() is called.
1 parent 74409cb commit 2665d5b

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

libraries/mbed/common/retarget.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,22 +398,31 @@ extern "C" WEAK void __cxa_pure_virtual(void) {
398398

399399
// ****************************************************************************
400400
// mbed_main is a function that is called before main()
401+
// mbed_sdk_init() is also a function that is called before main(), but unlike
402+
// mbed_main(), it is not meant for user code, but for the SDK itself to perform
403+
// initializations before main() is called.
401404

402405
extern "C" WEAK void mbed_main(void);
403406
extern "C" WEAK void mbed_main(void) {
404407
}
405408

409+
extern "C" WEAK void mbed_sdk_init(void);
410+
extern "C" WEAK void mbed_sdk_init(void) {
411+
}
412+
406413
#if defined(TOOLCHAIN_ARM)
407414
extern "C" int $Super$$main(void);
408415

409416
extern "C" int $Sub$$main(void) {
417+
mbed_sdk_init();
410418
mbed_main();
411419
return $Super$$main();
412420
}
413421
#elif defined(TOOLCHAIN_GCC)
414422
extern "C" int __real_main(void);
415423

416424
extern "C" int __wrap_main(void) {
425+
mbed_sdk_init();
417426
mbed_main();
418427
return __real_main();
419428
}
@@ -424,6 +433,7 @@ extern "C" int __wrap_main(void) {
424433
// code will call a function to setup argc and argv (__iar_argc_argv) if it is defined.
425434
// Since mbed doesn't use argc/argv, we use this function to call our mbed_main.
426435
extern "C" void __iar_argc_argv() {
436+
mbed_sdk_init();
427437
mbed_main();
428438
}
429439
#endif

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/platform_init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "wait_api.h"
44

55
// called before main
6-
void mbed_main()
6+
void mbed_sdk_init()
77
{
88
gpio_t modemEn, modemRst, modemPwrOn, modemLvlOe, modemILvlOe, modemUsbDet;
99
gpio_t gpsEn, gpsRst, led, modemRts;

0 commit comments

Comments
 (0)