Mbed OS provides two entry points you as a developer to hook into:
main(void)- Default entry point. All the standard application code goes here.
mbed_main(void)- Executed directly before
main. You can define this.
When execution reaches the entry points, you can expect a fully initialized system that is ready to execute application code. The Mbed OS boot sequence consists of four phases: target setup, toolchain setup, starting the RTOS and starting the Mbed application. You can see these phases below:
- Set up target.
- Configure clocks.
- Configure watchdog (if applicable).
- Turn on RAM (if applicable).
- Jump to set up toolchain.
- Set up toolchain.
- Initialize RAM.
- Initialize standard library.
- Call mbed_init.
- Vector table copied to RAM.
- Vendor SDK initialized.
- Jump to start RTOS.
- Start RTOS.
- Create main thread.
- Start scheduler.
- Main thread calls start Mbed.
- Start Mbed.
Sequence diagram of the boot sequence:
A diagram of the Arm Mbed OS boot sequence
Mbed OS redefines multiple standard C library functions to enable them to work in a predictable and familiar way on a remote embedded target device:
stderr- These file descriptors are pointing to the serial interface to enable users to use standard input/output functions, such as
fseekand other standard file operations - Enable the user to work with the serial interface, as well as the built-in file system.
closedirand other standard directory operations - Enable users to use built in file system.
exit- It causes the board to stop current execution, flush the standard file handles, close the semihosting connection and enter an infinite loop. If the return code indicates an error, the board blinks error patterns on the built-in LED.
clock- Overloaded to use platform's microsecond ticker.