From df27dbef7a6b4004b8ea6845f11f6e6559971d53 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Wed, 10 Apr 2019 11:07:05 +0200 Subject: [PATCH] cpu: Moved stdio_init() into cpu_init() - Removed stdio_init() from newlib's _init(), as this is too late in the boot process to allow DEBUG()ing during periph_init() - Added stdio_init() to the various cpu_init() routines of the ARM CPUs just before periph_init() --- cpu/cc2538/cpu.c | 3 +++ cpu/cc26x0/cpu.c | 4 ++++ cpu/efm32/cpu.c | 4 ++++ cpu/ezr32wg/cpu.c | 3 +++ cpu/kinetis/cpu.c | 5 +++++ cpu/lm4f120/cpu.c | 4 ++++ cpu/lpc1768/cpu.c | 3 +++ cpu/nrf51/cpu.c | 3 +++ cpu/nrf52/cpu.c | 4 ++++ cpu/sam3/cpu.c | 4 ++++ cpu/samd21/cpu.c | 3 +++ cpu/samd5x/cpu.c | 4 ++++ cpu/saml1x/cpu.c | 4 ++++ cpu/saml21/cpu.c | 4 ++++ cpu/stm32_common/cpu_init.c | 3 +++ sys/newlib_syscalls_default/syscalls.c | 2 +- 16 files changed, 56 insertions(+), 1 deletion(-) diff --git a/cpu/cc2538/cpu.c b/cpu/cc2538/cpu.c index 60bf9342bf..35203832e8 100644 --- a/cpu/cc2538/cpu.c +++ b/cpu/cc2538/cpu.c @@ -21,6 +21,7 @@ #include "cpu.h" #include "periph/init.h" +#include "stdio_base.h" #define BIT(n) ( 1UL << (n) ) @@ -48,6 +49,8 @@ void cpu_init(void) SYS_CTRL->I_MAP = 1; /* initialize the clock system */ cpu_clock_init(); + /* initialize stdio prior to periph_init() to allow use of DEBUG() there */ + stdio_init(); /* trigger static peripheral initialization */ periph_init(); } diff --git a/cpu/cc26x0/cpu.c b/cpu/cc26x0/cpu.c index 232bdc343e..8ea9b38401 100644 --- a/cpu/cc26x0/cpu.c +++ b/cpu/cc26x0/cpu.c @@ -20,6 +20,7 @@ #include "cpu.h" #include "periph_conf.h" #include "periph/init.h" +#include "stdio_base.h" #ifndef HF_CLOCK_SOURCE #define HF_CLOCK_SOURCE DDI_0_OSC_CTL0_SCLK_HF_SRC_SEL_RCOSC /* set 48MHz RCOSC */ @@ -44,6 +45,9 @@ void cpu_init(void) /* initialize the system clock */ cpu_clock_init(); + /* initialize stdio prior to periph_init() to allow use of DEBUG() there */ + stdio_init(); + /* trigger static peripheral initialization */ periph_init(); } diff --git a/cpu/efm32/cpu.c b/cpu/efm32/cpu.c index abe95ecbd1..5c4a9a3835 100644 --- a/cpu/efm32/cpu.c +++ b/cpu/efm32/cpu.c @@ -22,6 +22,7 @@ #include "cpu.h" #include "periph_conf.h" #include "periph/init.h" +#include "stdio_base.h" #include "em_chip.h" #include "em_cmu.h" @@ -172,6 +173,9 @@ void cpu_init(void) /* initialize power management interface */ pm_init(); + /* initialize stdio prior to periph_init() to allow use of DEBUG() there */ + stdio_init(); + /* trigger static peripheral initialization */ periph_init(); } diff --git a/cpu/ezr32wg/cpu.c b/cpu/ezr32wg/cpu.c index afa1927184..140652b1dd 100644 --- a/cpu/ezr32wg/cpu.c +++ b/cpu/ezr32wg/cpu.c @@ -20,6 +20,7 @@ #include "cpu.h" #include "periph_conf.h" #include "periph/init.h" +#include "stdio_base.h" /** * @brief Configure clock sources and the CPU frequency @@ -60,6 +61,8 @@ void cpu_init(void) cortexm_init(); /* Initialise clock sources and generic clocks */ clk_init(); + /* initialize stdio prior to periph_init() to allow use of DEBUG() there */ + stdio_init(); /* trigger static peripheral initialization */ periph_init(); } diff --git a/cpu/kinetis/cpu.c b/cpu/kinetis/cpu.c index aff3326d2f..2e2a2a3cfa 100644 --- a/cpu/kinetis/cpu.c +++ b/cpu/kinetis/cpu.c @@ -19,6 +19,7 @@ #include "cpu.h" #include "periph/init.h" +#include "stdio_base.h" #ifdef MODULE_PERIPH_MCG #include "mcg.h" #endif @@ -41,6 +42,10 @@ void cpu_init(void) /* initialize the CPU clocking provided by the MCG module */ kinetis_mcg_init(); #endif + + /* initialize stdio prior to periph_init() to allow use of DEBUG() there */ + stdio_init(); + /* trigger static peripheral initialization */ periph_init(); } diff --git a/cpu/lm4f120/cpu.c b/cpu/lm4f120/cpu.c index ba65f4c96e..189f3e1490 100644 --- a/cpu/lm4f120/cpu.c +++ b/cpu/lm4f120/cpu.c @@ -24,6 +24,7 @@ #include "irq.h" #include "periph/init.h" #include "periph_conf.h" +#include "stdio_base.h" /** * @brief Initialize the CPU, set IRQ priorities @@ -36,6 +37,9 @@ void cpu_init(void) /* initialize the clock system */ cpu_clock_init(CLOCK_SOURCE); + /* initialize stdio prior to periph_init() to allow use of DEBUG() there */ + stdio_init(); + /* trigger static peripheral initialization */ periph_init(); } diff --git a/cpu/lpc1768/cpu.c b/cpu/lpc1768/cpu.c index 9018d8b756..f41547e19b 100644 --- a/cpu/lpc1768/cpu.c +++ b/cpu/lpc1768/cpu.c @@ -19,6 +19,7 @@ #include "cpu.h" #include "periph/init.h" +#include "stdio_base.h" /** * @brief Initialize the CPU, set IRQ priorities @@ -27,6 +28,8 @@ void cpu_init(void) { /* initialize the Cortex-M core */ cortexm_init(); + /* initialize stdio prior to periph_init() to allow use of DEBUG() there */ + stdio_init(); /* trigger static peripheral initialization */ periph_init(); } diff --git a/cpu/nrf51/cpu.c b/cpu/nrf51/cpu.c index 5413305854..28210f9a6d 100644 --- a/cpu/nrf51/cpu.c +++ b/cpu/nrf51/cpu.c @@ -21,6 +21,7 @@ #include "nrf_clock.h" #include "periph_conf.h" #include "periph/init.h" +#include "stdio_base.h" /** * @brief Initialize the CPU, set IRQ priorities @@ -31,6 +32,8 @@ void cpu_init(void) cortexm_init(); /* setup the HF clock */ clock_init_hf(); + /* initialize stdio prior to periph_init() to allow use of DEBUG() there */ + stdio_init(); /* trigger static peripheral initialization */ periph_init(); } diff --git a/cpu/nrf52/cpu.c b/cpu/nrf52/cpu.c index a4bbe57fc0..a26554023b 100644 --- a/cpu/nrf52/cpu.c +++ b/cpu/nrf52/cpu.c @@ -26,6 +26,7 @@ #include "nrf_clock.h" #include "periph_conf.h" #include "periph/init.h" +#include "stdio_base.h" /* FTPAN helper functions */ static bool ftpan_32(void); @@ -83,6 +84,9 @@ void cpu_init(void) /* enable wake up on events for __WFE CPU sleep */ SCB->SCR |= SCB_SCR_SEVONPEND_Msk; + /* initialize stdio prior to periph_init() to allow use of DEBUG() there */ + stdio_init(); + /* trigger static peripheral initialization */ periph_init(); } diff --git a/cpu/sam3/cpu.c b/cpu/sam3/cpu.c index 2b7ff7db4d..024a707c4f 100644 --- a/cpu/sam3/cpu.c +++ b/cpu/sam3/cpu.c @@ -20,6 +20,7 @@ #include "cpu.h" #include "periph_conf.h" #include "periph/init.h" +#include "stdio_base.h" /** * @brief Keys needed for editing certain PMC registers @@ -90,6 +91,9 @@ void cpu_init(void) /* wait for master clock to be ready */ while (!(PMC->PMC_SR & PMC_SR_MCKRDY)); + /* initialize stdio prior to periph_init() to allow use of DEBUG() there */ + stdio_init(); + /* trigger static peripheral initialization */ periph_init(); } diff --git a/cpu/samd21/cpu.c b/cpu/samd21/cpu.c index 5c0481c7fc..42730c3ba1 100644 --- a/cpu/samd21/cpu.c +++ b/cpu/samd21/cpu.c @@ -21,6 +21,7 @@ #include "cpu.h" #include "periph_conf.h" #include "periph/init.h" +#include "stdio_base.h" #ifndef CLOCK_8MHZ #define CLOCK_8MHZ 1 @@ -218,6 +219,8 @@ void cpu_init(void) cortexm_init(); /* Initialise clock sources and generic clocks */ clk_init(); + /* initialize stdio prior to periph_init() to allow use of DEBUG() there */ + stdio_init(); /* trigger static peripheral initialization */ periph_init(); } diff --git a/cpu/samd5x/cpu.c b/cpu/samd5x/cpu.c index 76bed05813..d7ca6ecf44 100644 --- a/cpu/samd5x/cpu.c +++ b/cpu/samd5x/cpu.c @@ -20,6 +20,7 @@ #include "cpu.h" #include "periph_conf.h" #include "periph/init.h" +#include "stdio_base.h" static void xosc32k_init(void) { @@ -137,6 +138,9 @@ void cpu_init(void) gclk_connect(6, GCLK_SOURCE_DFLL, 0); #endif + /* initialize stdio prior to periph_init() to allow use of DEBUG() there */ + stdio_init(); + /* trigger static peripheral initialization */ periph_init(); } diff --git a/cpu/saml1x/cpu.c b/cpu/saml1x/cpu.c index 80b9b5e1b6..467261ffb4 100644 --- a/cpu/saml1x/cpu.c +++ b/cpu/saml1x/cpu.c @@ -22,6 +22,7 @@ #include "periph/init.h" #include "periph_conf.h" #include "board.h" +#include "stdio_base.h" #ifdef CPU_FAM_SAML11 #define _NVMCTRL NVMCTRL_SEC @@ -115,6 +116,9 @@ void cpu_init(void) /* Setup GCLK generators */ _gclk_setup(0, GCLK_GENCTRL_GENEN | GCLK_GENCTRL_SRC_OSC16M); + /* initialize stdio prior to periph_init() to allow use of DEBUG() there */ + stdio_init(); + /* trigger static peripheral initialization */ periph_init(); } diff --git a/cpu/saml21/cpu.c b/cpu/saml21/cpu.c index 6fd326c795..fd36e6e81f 100644 --- a/cpu/saml21/cpu.c +++ b/cpu/saml21/cpu.c @@ -21,6 +21,7 @@ #include "cpu.h" #include "periph/init.h" #include "periph_conf.h" +#include "stdio_base.h" static void _gclk_setup(int gclk, uint32_t reg) { @@ -118,6 +119,9 @@ void cpu_init(void) SUPC->BOD33.bit.ENABLE=0; #endif + /* initialize stdio prior to periph_init() to allow use of DEBUG() there */ + stdio_init(); + /* trigger static peripheral initialization */ periph_init(); } diff --git a/cpu/stm32_common/cpu_init.c b/cpu/stm32_common/cpu_init.c index 769054074c..a61a52ff86 100644 --- a/cpu/stm32_common/cpu_init.c +++ b/cpu/stm32_common/cpu_init.c @@ -33,6 +33,7 @@ */ #include "cpu.h" +#include "stdio_base.h" #include "stmclk.h" #include "periph_cpu.h" #include "periph/init.h" @@ -160,6 +161,8 @@ void cpu_init(void) /* initialize DMA streams */ dma_init(); #endif + /* initialize stdio prior to periph_init() to allow use of DEBUG() there */ + stdio_init(); /* trigger static peripheral initialization */ periph_init(); } diff --git a/sys/newlib_syscalls_default/syscalls.c b/sys/newlib_syscalls_default/syscalls.c index 7eebf50109..b173233de5 100644 --- a/sys/newlib_syscalls_default/syscalls.c +++ b/sys/newlib_syscalls_default/syscalls.c @@ -69,7 +69,7 @@ char *heap_top = &_sheap + 4; */ void _init(void) { - stdio_init(); + /* nothing to do here */ } /**