Skip to content

Initialization steps in toolchains #2917

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions platform/retarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,21 @@ static inline int openmode_to_posix(int openmode) {
return posix;
}

extern "C" WEAK void mbed_sdk_init(void);
extern "C" WEAK void mbed_sdk_init(void) {
}

extern "C" FILEHANDLE PREFIX(_open)(const char* name, int openmode) {
#if defined(__MICROLIB) && (__ARMCC_VERSION>5030000)
// Before version 5.03, we were using a patched version of microlib with proper names
// This is the workaround that the microlib author suggested us
static int n = 0;
static int mbed_sdk_inited = 0;
if (!mbed_sdk_inited) {
mbed_sdk_inited = 1;
mbed_sdk_init();
}
if (!std::strcmp(name, ":tt")) return n++;

#else
/* Use the posix convention that stdin,out,err are filehandles 0,1,2.
*/
Expand Down Expand Up @@ -501,7 +509,7 @@ extern "C" void software_init_hook(void)
mbed_die();
}
#endif/* FEATURE_UVISOR */

mbed_sdk_init();
software_init_hook_rtos();
}
#endif
Expand All @@ -516,23 +524,22 @@ extern "C" WEAK void mbed_main(void);
extern "C" WEAK void mbed_main(void) {
}

extern "C" WEAK void mbed_sdk_init(void);
extern "C" WEAK void mbed_sdk_init(void) {
}

#if defined(TOOLCHAIN_ARM)
extern "C" int $Super$$main(void);

extern "C" int $Sub$$main(void) {
mbed_sdk_init();
mbed_main();
return $Super$$main();
}

extern "C" void _platform_post_stackheap_init (void) {
mbed_sdk_init();
}

#elif defined(TOOLCHAIN_GCC)
extern "C" int __real_main(void);

extern "C" int __wrap_main(void) {
mbed_sdk_init();
mbed_main();
return __real_main();
}
Expand Down
2 changes: 2 additions & 0 deletions rtos/rtx/TARGET_CORTEX_M/RTX_CM_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ void pre_main (void)
__asm void __rt_entry (void) {

IMPORT __user_setup_stackheap
IMPORT _platform_post_stackheap_init
IMPORT os_thread_def_main
IMPORT osKernelInitialize
#ifdef __MBED_CMSIS_RTOS_CM
Expand All @@ -558,6 +559,7 @@ __asm void __rt_entry (void) {
/* Ignore return value of __user_setup_stackheap since
* this will be setup by set_stack_heap
*/
BL _platform_post_stackheap_init
BL osKernelInitialize
#ifdef __MBED_CMSIS_RTOS_CM
BL set_stack_heap
Expand Down
4 changes: 2 additions & 2 deletions targets/TARGET_STM/TARGET_STM32F0/mbed_overrides.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
void mbed_sdk_init() {
// Update the SystemCoreClock variable.
SystemCoreClockUpdate();

#if !defined(TOOLCHAIN_GCC_ARM)
// Need to restart HAL driver after the RAM is initialized
HAL_Init();

#endif
}
3 changes: 0 additions & 3 deletions targets/TARGET_STM/TARGET_STM32F0/pwmout_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,6 @@ void pwmout_period_us(pwmout_t* obj, int us) {

__HAL_TIM_DISABLE(&TimHandle);

// Update the SystemCoreClock variable
SystemCoreClockUpdate();

/* To make it simple, we use to possible prescaler values which lead to:
* pwm unit = 1us, period/pulse can be from 1us to 65535us
* or
Expand Down
4 changes: 0 additions & 4 deletions targets/TARGET_STM/TARGET_STM32F0/serial_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,6 @@ static void init_uart(serial_t *obj)
huart->Init.Mode = UART_MODE_TX_RX;
}

/* uAMR & ARM: Call to UART init is done between reset of pre-initialized variables */
/* and before HAL Init. SystemCoreClock init required here */
SystemCoreClockUpdate();

if (HAL_UART_Init(huart) != HAL_OK) {
error("Cannot initialize UART\n");
}
Expand Down
2 changes: 2 additions & 0 deletions targets/TARGET_STM/TARGET_STM32F1/mbed_overrides.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ void mbed_sdk_init()
{
// Update the SystemCoreClock variable.
SystemCoreClockUpdate();
#if !defined(TOOLCHAIN_GCC_ARM)
// Need to restart HAL driver after the RAM is initialized
HAL_Init();
#endif
}
3 changes: 0 additions & 3 deletions targets/TARGET_STM/TARGET_STM32F1/pwmout_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,6 @@ void pwmout_period_us(pwmout_t* obj, int us)

__HAL_TIM_DISABLE(&TimHandle);

// Update the SystemCoreClock variable
SystemCoreClockUpdate();

/* To make it simple, we use to possible prescaler values which lead to:
* pwm unit = 1us, period/pulse can be from 1us to 65535us
* or
Expand Down
4 changes: 0 additions & 4 deletions targets/TARGET_STM/TARGET_STM32F1/serial_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ static void init_uart(serial_t *obj)
huart->Init.Mode = UART_MODE_TX_RX;
}

/* uAMR & ARM: Call to UART init is done between reset of pre-initialized variables */
/* and before HAL Init. SystemCoreClock init required here */
SystemCoreClockUpdate();

if (HAL_UART_Init(huart) != HAL_OK) {
error("Cannot initialize UART\n");
}
Expand Down
4 changes: 0 additions & 4 deletions targets/TARGET_STM/TARGET_STM32F2/serial_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ static void init_uart(serial_t *obj)
huart->Init.Mode = UART_MODE_TX_RX;
}

/* uAMR & ARM: Call to UART init is done between reset of pre-initialized variables */
/* and before HAL Init. SystemCoreClock init required here */
SystemCoreClockUpdate();

if (HAL_UART_Init(huart) != HAL_OK) {
error("Cannot initialize UART\n");
}
Expand Down
3 changes: 0 additions & 3 deletions targets/TARGET_STM/TARGET_STM32F3/i2c_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@ void i2c_frequency(i2c_t *obj, int hz)
timeout = LONG_TIMEOUT;
while ((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0));

// Update the SystemCoreClock variable.
SystemCoreClockUpdate();

/*
Values calculated with I2C_Timing_Configuration_V1.0.1.xls file (see AN4235)
* Standard mode (up to 100 kHz)
Expand Down
2 changes: 2 additions & 0 deletions targets/TARGET_STM/TARGET_STM32F3/mbed_overrides.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ void mbed_sdk_init()
{
// Update the SystemCoreClock variable.
SystemCoreClockUpdate();
#if !defined(TOOLCHAIN_GCC_ARM)
// Need to restart HAL driver after the RAM is initialized
HAL_Init();
#endif
}
3 changes: 0 additions & 3 deletions targets/TARGET_STM/TARGET_STM32F3/serial_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ static void init_uart(serial_t *obj)
huart->Init.Mode = UART_MODE_TX_RX;
}

/* uAMR & ARM: Call to UART init is done between reset of pre-initialized variables */
/* and before HAL Init. SystemCoreClock init required here */
SystemCoreClockUpdate();

if (HAL_UART_Init(huart) != HAL_OK) {
error("Cannot initialize UART\n");
Expand Down
2 changes: 2 additions & 0 deletions targets/TARGET_STM/TARGET_STM32F4/mbed_overrides.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ void mbed_sdk_init()
{
// Update the SystemCoreClock variable.
SystemCoreClockUpdate();
#if !defined(TOOLCHAIN_GCC_ARM)
// Need to restart HAL driver after the RAM is initialized
HAL_Init();
#endif
}

/**
Expand Down
4 changes: 0 additions & 4 deletions targets/TARGET_STM/TARGET_STM32F4/serial_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ static void init_uart(serial_t *obj)
huart->Init.Mode = UART_MODE_TX_RX;
}

/* uAMR & ARM: Call to UART init is done between reset of pre-initialized variables */
/* and before HAL Init. SystemCoreClock init required here */
SystemCoreClockUpdate();

if (HAL_UART_Init(huart) != HAL_OK) {
error("Cannot initialize UART\n");
}
Expand Down
2 changes: 2 additions & 0 deletions targets/TARGET_STM/TARGET_STM32F7/mbed_overrides.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ void mbed_sdk_init()
{
// Update the SystemCoreClock variable.
SystemCoreClockUpdate();
#if !defined(TOOLCHAIN_GCC_ARM)
// Need to restart HAL driver after the RAM is initialized
HAL_Init();
#endif
}


Expand Down
4 changes: 0 additions & 4 deletions targets/TARGET_STM/TARGET_STM32F7/serial_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ static void init_uart(serial_t *obj)
huart->Init.Mode = UART_MODE_TX_RX;
}

/* uAMR & ARM: Call to UART init is done between reset of pre-initialized variables */
/* and before HAL Init. SystemCoreClock init required here */
SystemCoreClockUpdate();

if (HAL_UART_Init(huart) != HAL_OK) {
error("Cannot initialize UART\n");
}
Expand Down
4 changes: 4 additions & 0 deletions targets/TARGET_STM/TARGET_STM32L0/mbed_overrides.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ void mbed_sdk_init()
{
// Update the SystemCoreClock variable.
SystemCoreClockUpdate();
#if !defined(TOOLCHAIN_GCC_ARM)
// Need to restart HAL driver after the RAM is initialized
HAL_Init();
#endif
}
4 changes: 4 additions & 0 deletions targets/TARGET_STM/TARGET_STM32L1/mbed_overrides.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ void mbed_sdk_init()
{
// Update the SystemCoreClock variable.
SystemCoreClockUpdate();
#if !defined(TOOLCHAIN_GCC_ARM)
// Need to restart HAL driver after the RAM is initialized
HAL_Init();
#endif

#if defined(TARGET_XDOT_L151CC)
if (PWR->CSR & PWR_CSR_SBF) {
Expand Down
2 changes: 0 additions & 2 deletions targets/TARGET_STM/TARGET_STM32L1/pwmout_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,6 @@ void pwmout_period_us(pwmout_t* obj, int us)

__HAL_TIM_DISABLE(&TimHandle);

SystemCoreClockUpdate();

/* To make it simple, we use to possible prescaler values which lead to:
* pwm unit = 1us, period/pulse can be from 1us to 65535us
* or
Expand Down
4 changes: 0 additions & 4 deletions targets/TARGET_STM/TARGET_STM32L1/serial_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ static void init_uart(serial_t *obj)
huart->Init.Mode = UART_MODE_TX_RX;
}

/* uAMR & ARM: Call to UART init is done between reset of pre-initialized variables */
/* and before HAL Init. SystemCoreClock init required here */
SystemCoreClockUpdate();

if (HAL_UART_Init(huart) != HAL_OK) {
error("Cannot initialize UART\n");
}
Expand Down
4 changes: 4 additions & 0 deletions targets/TARGET_STM/TARGET_STM32L4/mbed_overrides.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ void mbed_sdk_init()
{
// Update the SystemCoreClock variable.
SystemCoreClockUpdate();
#if !defined(TOOLCHAIN_GCC_ARM)
// Need to restart HAL driver after the RAM is initialized
HAL_Init();
#endif
}
2 changes: 0 additions & 2 deletions targets/TARGET_STM/TARGET_STM32L4/pwmout_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,6 @@ void pwmout_period_us(pwmout_t* obj, int us)

__HAL_TIM_DISABLE(&TimHandle);

SystemCoreClockUpdate();

/* To make it simple, we use to possible prescaler values which lead to:
* pwm unit = 1us, period/pulse can be from 1us to 65535us
* or
Expand Down
4 changes: 0 additions & 4 deletions targets/TARGET_STM/TARGET_STM32L4/serial_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ static void init_uart(serial_t *obj)
huart->Init.Mode = UART_MODE_TX_RX;
}

/* uAMR & ARM: Call to UART init is done between reset of pre-initialized variables */
/* and before HAL Init. SystemCoreClock init required here */
SystemCoreClockUpdate();

if (HAL_UART_Init(huart) != HAL_OK) {
error("Cannot initialize UART\n");
}
Expand Down