Hello all. I am new to STM paradigm. I have a Nucleo 64 STM32L073RZT6 64 PINS board.
I was trying to configure the Systick timer, however it seems that the input Systick frequency is always divided by 2.
I am using the on-board 8MHz external crystal (which is originally used by the ST-Link interface) but the board marking that I have is MB1136 C-04. According to the hardware pdf, it means that the HSE input of the microcontroller is actually the 8MHz crystal of ST-Link.
Here is my PLL configuration (please read the comment maybe I missed something obvious):
RCC->CR |= (1 << 16); //HSE on 8mhz
RCC->CFGR |= (1 << 22); //PLL out div by 2
RCC->CFGR |= (1 << 0) | (1 << 1); //Select Sysclck as PLL
RCC->CFGR &= (~(1 << 7)); //clear bit 7 for AHB prescaler = 1
RCC->CFGR &= (~(1 << 10)); //clear bit 10 for APB1 prescaler = 1
RCC->CFGR &= (~(1 << 13)); //clear bit 13 for APB2 prescaler = 1
RCC->CFGR |= (1 << 16); //PLL source is HSE
RCC->CFGR |= (1 << 18) | (1 << 19); //PLL multuplier = 8 (i.e 8mhz hse * 8 = 64 div by 2 = 32 Sysclck maximum)
RCC->CR |= (1 << 24); //PLL on
while((RCC->CR & (1 << 25)) == 0); //wait for PLL ready
SystemCoreClockUpdate(); //SystemCoreClock variable is 32Mhz (confirmed by debugger)
And then here is my Systick configuration:
SysTick->CTRL = 0;
SysTick->LOAD = 31999; //Systick clock/1000 - 1 for 1ms systicks interrupt
NVIC_SetPriority(SysTick_IRQn, (1<<__NVIC_PRIO_BITS) -1);
SysTick->VAL = 0;
SysTick->CTRL |= SysTick_CTRL_CLKSOURCE_Msk; //choose full AHB as source clock (no div by 8)
SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk; //enable interrupt
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk; //Enable systick
I am getting a 2ms interrupt instead of 1ms. I checked the PLL clock divider in RCC-CFGR and it was indeed 0 (i.e. no division). There has to be a division by 2 somewhere that I am missing. My reference is the STM32CubeMX Clock Configuration and of course the datasheet.
I don't really know where else the problem could be. Any help would be appreciated!