Basic Experiment-Based on Provincial Game Resource Set
RCC clock selection experiment
The purpose of the experiment: master the selection method of the RCC clock.
Experimental content: Press the button to switch the clock source selection and output on the PA8 pin. The clock sources are PLL (24MHz), HIS (16M), MSI (4.194MHz).
Experimental phenomenon: Press the USER button, the clock of the chip switches between PLL (24MHz), HIS (16M), MSI (4.194MHz).
STM32CubeMX configuration
- Target selection
- Pin assignment
- Peripheral configuration
- Clock configuration
- Engineering configuration
1. Target selection
New project
selection MCU input STM32L071KB
2. Pin assignment
PC15 pin: GPIO_Output (output mode)
PC14 pin: GPIO_Input (input mode)
PA8 pin: RCC_MCO (output internal clock)
3. Peripheral configuration
PC14 pin configuration
GPIO mode: input mode
GPIO pull-up resistor / pull-down resistor: no pull-up resistor / pull-down resistor
PA8 pin configuration
GPIO mode: Alternative function push-pull output
pullup GPIO / pull-down resistance: pull-up resistor / pull-down resistor
output speed: Very fast
4. Clock configuration
Clock source: Bypass clock source
Clock frequency: PLL (24MHz), HIS (16M), MSI (4.194MHz)
5. Engineering configuration
Keil5 programming
1. Select STM32L071KBUx chip
2. Add code
In the USER CODE BEGIN PM and the USER CODE END PM added at between macro definitions
in the USER CODE BEGIN 1 and USER CODE END 1 add the following code between
the USER CODE BEGIN 3 and the USER CODE END 3 add the following code between
3. HAL library function analysis
GPIO input read function: HAL_GPIO_ReadPin (GPIOx, GPIO_Pin)
GPIOx: GPIO port (GPIOA ~ GPIOC )
GPIO_Pin: Pin number corresponding to this port (0 ~ 15)