Skip to content

Commit

Permalink
Merge pull request #28 from enzoevers/24-improve-performance-for-gpio…
Browse files Browse the repository at this point in the history
…-toggling

[Ready] Configure PLL for STM32
  • Loading branch information
enzoevers authored May 14, 2024
2 parents bb33f43 + f0cfb5d commit a146d4f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,37 @@ static auto SetupClock() -> void {
// HLCK - SYSCLK not divided
RCC->CFGR &= ~RCC_CFGR_HPRE_3;

// Select HSI for SYSCLOCK
RCC->CFGR &= ~RCC_CFGR_SW_0;
RCC->CFGR &= ~RCC_CFGR_SW_1;
//----------
// PLL
//----------

// Stop PLL
RCC->CR &= ~RCC_CR_PLLON;
while (RCC->CR & RCC_CR_PLLRDY) {
}

// Use HSI/2 as the PLL source clock
RCC->CFGR |= RCC_CFGR_PLLSRC_HSI_DIV2;

// Max allowed frequency is 72MHz.
// With a PLL input frequency of 4MHz (HSI/2 = 8MHz / 2 = 4MHz)
// the max multiplication is 72 / 4 = 18

// PLL multiplication
// SYSCLOCK = 4MHz * 10 = 40MHz
RCC->CFGR |= RCC_CFGR_PLLMUL10;

// Enable PLL
RCC->CR |= RCC_CR_PLLON;
while (!(RCC->CR & RCC_CR_PLLRDY)) {
}

//----------
// Main clock
//----------

// Select PLL for SYSCLOCK
RCC->CFGR |= RCC_CFGR_SW_PLL;

// Enable HSI clock
RCC->CR |= RCC_CR_HSION;
Expand Down
3 changes: 1 addition & 2 deletions Code/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ int main() {
latch.SetupConfiguration({&GPIOD->ODR, GPIO_ODR_14});
ledOE.SetupConfiguration({&GPIOD->ODR, GPIO_ODR_15});
}
uint32_t tim3Hertz = 8000000;
uint32_t tim3Hertz = 40000000;
auto mainDelay = DelayStm32();
mainDelay.SetupConfiguration({&TIM3->SR, &TIM3->ARR, &TIM3->CR1, &TIM3->PSC, tim3Hertz, TIM_SR_UIF, TIM_CR1_CEN});
#endif
Expand Down Expand Up @@ -70,7 +70,6 @@ int main() {

auto mainDelay = DelayDesktop();
#endif

HanoverOL037A_GPIOInterface hanoverOL037A_GPIOInterface{&clk, &clkEn, &clkSelEn, &data, &latch, &ledOE};

auto hanoverOL037A = HanoverOL037A();
Expand Down
2 changes: 1 addition & 1 deletion Scripts/Stm32/Stm32f303xc/StLinkFlash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ ValidateFileExists ${BINARY_PATH}

WRITE_ADDRESS=0x8000000

st-flash write ${BINARY_PATH} ${WRITE_ADDRESS}
st-flash --reset write ${BINARY_PATH} ${WRITE_ADDRESS}

0 comments on commit a146d4f

Please sign in to comment.