-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsystem.c
45 lines (35 loc) · 1011 Bytes
/
system.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stm32l433xx.h>
#include "usb.h"
#include "floppy.h"
#define nop() __asm__ __volatile__ ("nop" ::)
void SystemInitError(uint8_t error_source) {
while(1);
}
void SystemInit() {
// Enable FPU
SCB->CPACR |= 0xf00000;
RCC->CR |= (1<<8);
/* Wait until HSI ready */
while ((RCC->CR & RCC_CR_HSIRDY) == 0);
/* Disable main PLL */
RCC->CR &= ~(RCC_CR_PLLON);
/* Wait until PLL ready (disabled) */
while ((RCC->CR & RCC_CR_PLLRDY) != 0);
/* Configure Main PLL */
RCC->PLLCFGR = (1<<24)|(10<<8)|2;
/* PLL On */
RCC->CR |= RCC_CR_PLLON;
/* Wait until PLL is locked */
while ((RCC->CR & RCC_CR_PLLRDY) == 0);
/*
* FLASH configuration block
* enable instruction cache
* enable prefetch
* set latency to 2WS (3 CPU cycles)
*/
FLASH->ACR |= FLASH_ACR_ICEN | FLASH_ACR_PRFTEN | FLASH_ACR_LATENCY_2WS;
/* Set clock source to PLL */
RCC->CFGR |= RCC_CFGR_SW_PLL;
/* Check clock source */
while ((RCC->CFGR & RCC_CFGR_SWS_PLL) != RCC_CFGR_SWS_PLL);
}