STM32 RTOS 0.2.3
Bare-metal preemptive RTOS for STM32F446RE
Loading...
Searching...
No Matches
bsp.c
Go to the documentation of this file.
1
5#include "bsp.h"
6
11
13{
14 DriverStatus_e status;
15
17
18 /* HSE first: it is the step most likely to fail on a board (no ST-LINK
19 * MCO, solder bridges), and failing here leaves the regulator untouched. */
20 status = rccHseEnable(rcc, RCC_CR_HSEBYP);
21
22 if (status == DRIVER_STATUS_OK)
23 {
25 }
26
27 if (status == DRIVER_STATUS_OK)
28 {
29 uint32_t pll_source = RCC_PLLCFGR_PLLSRC_HSE;
30
31 status = rccPllConfig(rcc, pll_source, BSP_PLL_M, BSP_PLL_N, RCC_PLLCFGR_PLLP_DIV2);
32 }
33
34 if (status == DRIVER_STATUS_OK)
35 {
36 status = rccPllEnable(rcc);
37 }
38
39 if (status == DRIVER_STATUS_OK)
40 {
41 status = pwrWaitVoltageScaleReady(pwr);
42 }
43
44 if (status == DRIVER_STATUS_OK)
45 {
46 status = pwrEnableOverdrive(pwr);
47 }
48
49 if (status == DRIVER_STATUS_OK)
50 {
51 status =
53 }
54
55 if (status == DRIVER_STATUS_OK)
56 {
58 }
59
60 if (status == DRIVER_STATUS_OK)
61 {
62 flashEnableCaches(flash);
63 }
64
65 return status;
66}
67
NUCLEO-F446RE board support: the 180 MHz clock configuration.
#define BSP_PLL_N
PLL N: VCO output = 1 MHz x N = 360 MHz.
Definition bsp.h:43
DRIVER_MUST_CHECK DriverStatus_e bspClockInit(RccRegisters_t *rcc, PwrRegisters_t *pwr, FlashRegisters_t *flash)
Bring SYSCLK from the 16 MHz HSI reset state to 180 MHz.
Definition bsp.c:12
#define BSP_PLL_M
PLL M: VCO input = HSE / M = 1 MHz.
Definition bsp.h:42
#define BSP_FLASH_LATENCY
Flash wait states for 180 MHz at 2.7-3.6 V (RM0390 Table 5).
Definition bsp.h:46
DriverStatus_e
Outcome of a driver call: a category for control flow, not a diagnosis.
@ DRIVER_STATUS_OK
Succeeded.
void flashEnableCaches(FlashRegisters_t *flash)
Turn on prefetch and the instruction and data caches.
Definition flash.c:40
DRIVER_MUST_CHECK DriverStatus_e pwrEnableOverdrive(PwrRegisters_t *pwr)
Enable over-drive, to run above the scale's normal maximum.
Definition pwr.c:63
DRIVER_MUST_CHECK DriverStatus_e pwrWaitVoltageScaleReady(const PwrRegisters_t *pwr)
Wait until the regulator reaches the selected scale (CSR.VOSRDY).
Definition pwr.c:58
DRIVER_MUST_CHECK DriverStatus_e pwrSetVoltageScale(PwrRegisters_t *pwr, uint32_t vos)
Select the regulator voltage scale for the coming PLL frequency.
Definition pwr.c:42
#define PWR_CR_VOS_SCALE1
Scale 1: highest maximum frequency (reset value).
Definition pwr_reg.h:69
DRIVER_MUST_CHECK DriverStatus_e rccSysclkSwitch(RccRegisters_t *rcc, FlashRegisters_t *flash, uint32_t source, uint32_t latency)
Switch SYSCLK to a ready source and set the flash latency it needs.
Definition rcc.c:413
DRIVER_MUST_CHECK DriverStatus_e rccHseEnable(RccRegisters_t *rcc, uint32_t bypass)
Turn on the external oscillator (HSE) and wait until ready.
Definition rcc.c:247
DRIVER_MUST_CHECK DriverStatus_e rccBusPrescalerConfig(RccRegisters_t *rcc, uint32_t hpre, uint32_t ppre1, uint32_t ppre2)
Set the AHB, APB1 and APB2 prescalers.
Definition rcc.c:387
DRIVER_MUST_CHECK DriverStatus_e rccPllEnable(RccRegisters_t *rcc)
Turn on the PLL and wait for lock.
Definition rcc.c:323
void rccPwrClockEnable(RccRegisters_t *rcc)
Enable PWR's clock; needed before any PWR access.
Definition rcc.c:129
DRIVER_MUST_CHECK DriverStatus_e rccPllConfig(RccRegisters_t *rcc, uint32_t source, uint32_t m, uint32_t n, uint32_t p)
Set the PLL's input source and M, N and P.
Definition rcc.c:285
#define RCC_CFGR_PPRE_DIV2
HCLK / 2.
Definition rcc_reg.h:168
#define RCC_CFGR_HPRE_DIV1
SYSCLK / 1.
Definition rcc_reg.h:153
#define RCC_CR_HSEBYP
<span class="regaccess">rw</span> HSE bypass: external clock on OSC_IN.
Definition rcc_reg.h:79
#define RCC_CFGR_SYSCLK_PLL
Main PLL (P output).
Definition rcc_reg.h:147
#define RCC_PLLCFGR_PLLP_DIV2
VCO / 2.
Definition rcc_reg.h:117
#define RCC_CFGR_PPRE_DIV4
HCLK / 4.
Definition rcc_reg.h:169
#define RCC_PLLCFGR_PLLSRC_HSE
HSE feeds the PLL.
Definition rcc_reg.h:112
Flash interface register block.
Definition flash_reg.h:26
PWR register block.
Definition pwr_reg.h:23
RCC register block.
Definition rcc_reg.h:24