Skip to content

Commit c029aca

Browse files
committed
fix: wrap printf in EBOOT_ENABLE_PRINTF guard for bare-metal safety
1 parent f95cf1b commit c029aca

1 file changed

Lines changed: 63 additions & 51 deletions

File tree

core/clock_init.c

Lines changed: 63 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,63 @@
1-
/**
2-
* @file clock_init.c
3-
* @brief Clock tree initialization — PLL, oscillators, bus dividers
4-
*/
5-
6-
#include "eos_clock.h"
7-
#include <stdio.h>
8-
#include <string.h>
9-
10-
static eos_clock_config_t g_clock_cfg;
11-
12-
int eos_clock_init(const eos_clock_config_t *cfg)
13-
{
14-
if (!cfg) return -1;
15-
16-
memcpy(&g_clock_cfg, cfg, sizeof(g_clock_cfg));
17-
18-
/* Platform-specific clock tree programming:
19-
* 1. Select HSE/HSI source
20-
* 2. Configure PLL (M, N, P, Q dividers)
21-
* 3. Set AHB/APB bus dividers
22-
* 4. Switch system clock to PLL
23-
* 5. Update flash wait states for new frequency
24-
*
25-
* Each board port provides the actual register programming
26-
* via the board config macros. */
27-
28-
g_clock_cfg.configured = true;
29-
return 0;
30-
}
31-
32-
uint32_t eos_clock_get_sysclk(void) { return g_clock_cfg.sysclk_hz; }
33-
uint32_t eos_clock_get_hclk(void) { return g_clock_cfg.hclk_hz; }
34-
uint32_t eos_clock_get_pclk1(void) { return g_clock_cfg.pclk1_hz; }
35-
uint32_t eos_clock_get_pclk2(void) { return g_clock_cfg.pclk2_hz; }
36-
37-
void eos_clock_dump(const eos_clock_config_t *cfg)
38-
{
39-
const char *sources[] = {"HSI","HSE","PLL","LSI","LSE"};
40-
printf("Clock: %s SYSCLK=%uMHz HCLK=%uMHz PCLK1=%uMHz PCLK2=%uMHz\n",
41-
sources[cfg->source],
42-
cfg->sysclk_hz / 1000000,
43-
cfg->hclk_hz / 1000000,
44-
cfg->pclk1_hz / 1000000,
45-
cfg->pclk2_hz / 1000000);
46-
if (cfg->use_pll) {
47-
printf(" PLL: HSE=%uMHz M=%u N=%u P=%u Q=%u\n",
48-
cfg->hse_hz / 1000000,
49-
cfg->pll_m, cfg->pll_n, cfg->pll_p, cfg->pll_q);
50-
}
51-
}
1+
/**
2+
* @file clock_init.c
3+
* @brief Clock tree initialization — PLL, oscillators, bus dividers
4+
*/
5+
6+
#include "eos_clock.h"
7+
#ifdef EBOOT_ENABLE_PRINTF
8+
#include <stdio.h>
9+
#endif
10+
#include <string.h>
11+
12+
static eos_clock_config_t g_clock_cfg;
13+
14+
int eos_clock_init(const eos_clock_config_t *cfg)
15+
{
16+
if (!cfg) return -1;
17+
18+
memcpy(&g_clock_cfg, cfg, sizeof(g_clock_cfg));
19+
20+
/* Platform-specific clock tree programming:
21+
* 1. Select HSE/HSI source
22+
* 2. Configure PLL (M, N, P, Q dividers)
23+
* 3. Set AHB/APB bus dividers
24+
* 4. Switch system clock to PLL
25+
* 5. Update flash wait states for new frequency
26+
*
27+
* Each board port provides the actual register programming
28+
* via the board config macros. */
29+
30+
g_clock_cfg.configured = true;
31+
return 0;
32+
}
33+
34+
uint32_t eos_clock_get_sysclk(void) { return g_clock_cfg.sysclk_hz; }
35+
uint32_t eos_clock_get_hclk(void) { return g_clock_cfg.hclk_hz; }
36+
uint32_t eos_clock_get_pclk1(void) { return g_clock_cfg.pclk1_hz; }
37+
uint32_t eos_clock_get_pclk2(void) { return g_clock_cfg.pclk2_hz; }
38+
39+
void eos_clock_dump(const eos_clock_config_t *cfg)
40+
{
41+
#ifdef EBOOT_ENABLE_PRINTF
42+
const char *sources[] = {"HSI","HSE","PLL","LSI","LSE"};
43+
printf("Clock: %s SYSCLK=%uMHz HCLK=%uMHz PCLK1=%uMHz PCLK2=%uMHz\n",
44+
sources[cfg->source],
45+
cfg->sysclk_hz / 1000000,
46+
cfg->hclk_hz / 1000000,
47+
cfg->pclk1_hz / 1000000,
48+
cfg->pclk2_hz / 1000000);
49+
if (cfg->use_pll) {
50+
printf(" PLL: HSE=%uMHz M=%u N=%u P=%u Q=%u\n",
51+
cfg->hse_hz / 1000000,
52+
cfg->pll_m, cfg->pll_n, cfg->pll_p, cfg->pll_q);
53+
}
54+
#else
55+
(void)cfg;
56+
#endif
57+
}
58+
cfg->pll_m, cfg->pll_n, cfg->pll_p, cfg->pll_q);
59+
}
60+
#else
61+
(void)cfg;
62+
#endif
63+
}

0 commit comments

Comments
 (0)