Skip to main content
William Huang
Associate II
December 22, 2016
Solved

Nucleo-STM32F303K8 board

  • December 22, 2016
  • 5 replies
  • 1634 views
Posted on December 22, 2016 at 05:14

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);
 }
}
�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

    This topic has been closed for replies.
    Best answer by Khouloud GARSI
    Posted on December 22, 2016 at 17:52

    Hi William,

    I advise you to take a look on

    http://www.st.com/content/ccc/resource/technical/document/user_manual/e3/0e/88/05/e8/74/43/a0/DM00231744.pdf/files/DM00231744.pdf/jcr:content/translations/en.DM00231744.pdf

    : user manual for STM32 Nucleo-32 board.

    On table 5, the OSC clock configurations is given.

    Please verify the following solder bridges connections:
    • SB4 : ON
    • SB17 : OFF
    • SB6 : OFF
    • SB8 : ON
    • SB5 and SB7 : OFF

    This configuration connects the MCO from ST-LINK to OSCIN(PF0) -> HSE BYPASS

    The figure below contains the HSE probed on MCO_PA8 pin.

                       0690X00000605pJQAQ.png

     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 

    :)

     .

    5 replies

    Khouloud GARSI
    ST Employee
    December 22, 2016
    Posted on December 22, 2016 at 13:12

    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.
    William Huang
    Associate II
    December 22, 2016
    Posted on December 22, 2016 at 14:23

    Hi khouloud, yes it's being blocked at waiting for the hse ready flag to be set 

    Khouloud GARSI
    Khouloud GARSIBest answer
    ST Employee
    December 22, 2016
    Posted on December 22, 2016 at 17:52

    Hi William,

    I advise you to take a look on

    http://www.st.com/content/ccc/resource/technical/document/user_manual/e3/0e/88/05/e8/74/43/a0/DM00231744.pdf/files/DM00231744.pdf/jcr:content/translations/en.DM00231744.pdf

    : user manual for STM32 Nucleo-32 board.

    On table 5, the OSC clock configurations is given.

    Please verify the following solder bridges connections:
    • SB4 : ON
    • SB17 : OFF
    • SB6 : OFF
    • SB8 : ON
    • SB5 and SB7 : OFF

    This configuration connects the MCO from ST-LINK to OSCIN(PF0) -> HSE BYPASS

    The figure below contains the HSE probed on MCO_PA8 pin.

                       0690X00000605pJQAQ.png

     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 

    :)

     .
    William Huang
    Associate II
    December 23, 2016
    Posted on December 23, 2016 at 20:10

    Thank you and Jaroslav, I see where the problem is now and have a better understanding!

    Jaroslav BECKA
    ST Employee
    December 23, 2016
    Posted on December 23, 2016 at 15:00

    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 */
     }
    }�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?