2016-12-21 08:14 PM
Hi, I just got the stm32f303k8 nucleo board to play with! I'm trying to enable the HSE in order for the board to use the on-board oscillator (X2), however it doesn't seem like it wants to turn ON. I'm using Keil as the IDE and here's my code:
#include 'stm32f303x8.h'
void HSEConfig(unsigned char status);
int main(void)
{
HSEConfig(1);
for(;;);
return 0;
}
void HSEConfig(unsigned char status)
{
if(status)
{
// Let System Clock to use HSE
RCC->CFGR |= RCC_CFGR_SW_HSE;
// Enable High Speed External Oscilator
// and wait for the clock to stabilize
RCC->CR |= RCC_CR_HSEON;
while( (RCC->CR & RCC_CR_HSERDY) == 0);
// Disable HSI
RCC->CR &= ~RCC_CR_HSION;
while(RCC->CR & RCC_CR_HSIRDY);
}
}
�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
Solved! Go to Solution.
2016-12-22 08:52 AM
Hi William,
I advise you to take a look on
: user manual for STM32 Nucleo-32 board.On table 5, the OSC clock configurations is given.Please verify the following solder bridges connections:This configuration connects the MCO from ST-LINK to OSCIN(PF0) -> HSE BYPASS
The figure below contains the HSE probed on MCO_PA8 pin.
As you can see, a 8MHz clock is provided.
Verify the solder bridges state and give me your feedback.
Khouloud.
If this solves your issue, please click on correct
:)
.2016-12-22 04:12 AM
Hello William,
In your description you said: 'however it doesn't seem like it wants to turn ON.'
Could you please be more precise. What are the encountered symptoms? Is your program stay blocked in this loop:while( (RCC->CR & RCC_CR_HSERDY) == 0); ?Best regards,
Khouloud.2016-12-22 06:23 AM
Hi khouloud, yes it's being blocked at waiting for the hse ready flag to be set
2016-12-22 08:52 AM
Hi William,
I advise you to take a look on
: user manual for STM32 Nucleo-32 board.On table 5, the OSC clock configurations is given.Please verify the following solder bridges connections:This configuration connects the MCO from ST-LINK to OSCIN(PF0) -> HSE BYPASS
The figure below contains the HSE probed on MCO_PA8 pin.
As you can see, a 8MHz clock is provided.
Verify the solder bridges state and give me your feedback.
Khouloud.
If this solves your issue, please click on correct
:)
.2016-12-23 06:00 AM
Hello William
The order of the operations which you do in the HSEConfig() function is obviously wrong.
At first you set the turned off oscillator as system clock and then you are trying to turn it on.
I would recommend to have a look at our examples to see the correct flow.
Please find below the code snippet from STM32F0 HSE_Start example (basically the same for STM32F3).
Note that there is the bypass mode used, because the nucleo-F303K8 board doesn't have an external crystal assembled.
The high speed clock is provided from the ST-Link MCU via MCO (Microcontroller Clock Output).
/**
* @brief This function enables the interrupton HSE ready,
* and start the HSE as external clock.
* @param None
* @retval None
*/
__INLINE void StartHSE(void)
{
/* Configure NVIC for RCC */
/* (1) Enable Interrupt on RCC */
/* (2) Set priority for RCC */
NVIC_EnableIRQ(RCC_CRS_IRQn); /* (1)*/
NVIC_SetPriority(RCC_CRS_IRQn,0); /* (2) */
/* (1) Enable interrupt on HSE ready */
/* (2) Enable the CSS
Enable the HSE and set HSEBYP to use the external clock
instead of an oscillator
Enable HSE */
/* Note : the clock is switched to HSE in the RCC_CRS_IRQHandler ISR */
RCC->CIR |= RCC_CIR_HSERDYIE; /* (1) */
RCC->CR |= RCC_CR_CSSON | RCC_CR_HSEBYP | RCC_CR_HSEON; /* (2) */
}
/**
* @brief This function handles RCC interrupt request
* and switch the system clock to HSE.
* @param None
* @retval None
*/
void RCC_CRS_IRQHandler(void)
{
/* (1) Check the flag HSE ready */
/* (2) Clear the flag HSE ready */
/* (3) Switch the system clock to HSE */
if ((RCC->CIR & RCC_CIR_HSERDYF) != 0) /* (1) */
{
RCC->CIR |= RCC_CIR_HSERDYC; /* (2) */
RCC->CFGR = ((RCC->CFGR & (~RCC_CFGR_SW)) | RCC_CFGR_SW_0); /* (3) */
}
else
{
error = ERROR_UNEXPECTED_RCC_IRQ; /* Report an error */
}
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
2016-12-23 12:10 PM
Thank you and Jaroslav, I see where the problem is now and have a better understanding!