RCC_ClockConfig Example Description

Configuration of the system clock (SYSCLK) and modification of the clock settings in Run mode, using the RCC HAL API.

In this example, after startup SYSCLK is configured to the max frequency using the HSI as clock source, the User push-button (connected to EXTI_Line13) will be used to change the clock source:

- from HSI to HSIUSB48
- from HSIUSB48 to HSE
- from HSE to HSI

Each time the User push-button is pressed EXTI_Line13 interrupt is generated and in the ISR the clock source is checked using __HAL_RCC_GET_SYSCLK_SOURCE() macro:

LED1 is toggled with a timing defined by the HAL_Delay() API.

Notes

  1. Care must be taken when using HAL_Delay(), this function provides accurate delay (in milliseconds) based on variable incremented in SysTick ISR. This implies that if HAL_Delay() is called from a peripheral ISR process, then the SysTick interrupt must have higher priority (numerically lower) than the peripheral interrupt. Otherwise the caller ISR process will be blocked. To change the SysTick interrupt priority you have to use HAL_NVIC_SetPriority() function.

  2. The application needs to ensure that the SysTick time base is always set to 1 millisecond to have correct HAL operation.

Keywords

RCC, System, Clock Configuration, HSE, HSI, HSIUSB48, System clock, Oscillator

Directory contents

- RCC/RCC_ClockConfig/Inc/stm32c0xx_hal_conf.h    HAL configuration file
- RCC/RCC_ClockConfig/Inc/stm32c0xx_it.h          Interrupt handlers header file
- RCC/RCC_ClockConfig/Inc/main.h                  Header for main.c module
- RCC/RCC_ClockConfig/Src/stm32c0xx_it.c          Interrupt handlers
- RCC/RCC_ClockConfig/Src/main.c                  Main program
- RCC/RCC_ClockConfig/Src/system_stm32c0xx.c      STM32C0xx system source file
- RCC/RCC_ClockConfig/Src/stm32c0xx_hal_msp.c     HAL MSP module

Hardware and Software environment

How to use it ?

In order to make the program work, you must do the following :