mirror of
https://github.com/IcedRooibos/py32f0-template.git
synced 2025-10-28 16:32:05 -07:00
feat: rcc examples
This commit is contained in:
parent
0543e52d59
commit
6b7ec31d73
79
Examples/LL/RCC/HSE_ClockConfigurate/main.c
Normal file
79
Examples/LL/RCC/HSE_ClockConfigurate/main.c
Normal file
@ -0,0 +1,79 @@
|
||||
#include "main.h"
|
||||
#include "py32f0xx_bsp_button.h"
|
||||
#include "py32f0xx_bsp_led.h"
|
||||
#include "py32f0xx_bsp_printf.h"
|
||||
|
||||
|
||||
static void APP_SystemClockConfig(void);
|
||||
static void APP_GPIOConfig(void);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
APP_SystemClockConfig();
|
||||
|
||||
APP_GPIOConfig();
|
||||
|
||||
BSP_USART_Config(115200);
|
||||
|
||||
LL_RCC_ConfigMCO(LL_RCC_MCO1SOURCE_SYSCLK, LL_RCC_MCO1_DIV_1);
|
||||
|
||||
printf("Clock: %ld \r\n", SystemCoreClock);
|
||||
|
||||
while (1)
|
||||
{
|
||||
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_5);
|
||||
printf("echo\r\n");
|
||||
LL_mDelay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
static void APP_SystemClockConfig(void)
|
||||
{
|
||||
LL_RCC_HSE_Enable();
|
||||
LL_RCC_HSE_SetFreqRegion(LL_RCC_HSE_16_32MHz);
|
||||
while(LL_RCC_HSE_IsReady() != 1);
|
||||
|
||||
LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
|
||||
|
||||
LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_HSE);
|
||||
while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_HSE);
|
||||
|
||||
LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
|
||||
/* Update global SystemCoreClock(or through SystemCoreClockUpdate function) */
|
||||
LL_SetSystemCoreClock(HSE_VALUE);
|
||||
/* Re-init frequency of SysTick source */
|
||||
LL_InitTick(HSE_VALUE, 1000U);
|
||||
}
|
||||
|
||||
static void APP_GPIOConfig(void)
|
||||
{
|
||||
LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA);
|
||||
LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB);
|
||||
|
||||
LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_5, LL_GPIO_MODE_OUTPUT);
|
||||
|
||||
/* PA08: MCO output */
|
||||
// Add USE_FULL_LL_DRIVER to LIB_FLAGS to enable LL_GPIO_InitTypeDef
|
||||
LL_GPIO_InitTypeDef GPIO_InitStruct;
|
||||
GPIO_InitStruct.Pin = LL_GPIO_PIN_8;
|
||||
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
|
||||
/* Alternate mode */
|
||||
GPIO_InitStruct.Alternate = LL_GPIO_AF5_MCO;
|
||||
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
||||
/* No pull */
|
||||
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
||||
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
}
|
||||
|
||||
void APP_ErrorHandler(void)
|
||||
{
|
||||
while (1);
|
||||
}
|
||||
|
||||
#ifdef USE_FULL_ASSERT
|
||||
void assert_failed(uint8_t *file, uint32_t line)
|
||||
{
|
||||
while (1);
|
||||
}
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
77
Examples/LL/RCC/HSE_PLL_ClockConfigurate/main.c
Normal file
77
Examples/LL/RCC/HSE_PLL_ClockConfigurate/main.c
Normal file
@ -0,0 +1,77 @@
|
||||
#include "main.h"
|
||||
#include "py32f0xx_bsp_button.h"
|
||||
#include "py32f0xx_bsp_led.h"
|
||||
#include "py32f0xx_bsp_printf.h"
|
||||
|
||||
|
||||
static void APP_SystemClockConfig(void);
|
||||
static void APP_GPIOConfig(void);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
APP_SystemClockConfig();
|
||||
|
||||
APP_GPIOConfig();
|
||||
|
||||
BSP_USART_Config(115200);
|
||||
|
||||
LL_RCC_ConfigMCO(LL_RCC_MCO1SOURCE_SYSCLK, LL_RCC_MCO1_DIV_1);
|
||||
|
||||
printf("Clock: %ld \r\n", SystemCoreClock);
|
||||
|
||||
while (1)
|
||||
{
|
||||
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_5);
|
||||
printf("echo\r\n");
|
||||
LL_mDelay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
static void APP_SystemClockConfig(void)
|
||||
{
|
||||
LL_UTILS_ClkInitTypeDef UTILS_ClkInitStruct;
|
||||
|
||||
LL_RCC_HSE_Enable();
|
||||
LL_RCC_HSE_SetFreqRegion(LL_RCC_HSE_16_32MHz);
|
||||
while(LL_RCC_HSE_IsReady() != 1);
|
||||
|
||||
UTILS_ClkInitStruct.AHBCLKDivider = LL_RCC_SYSCLK_DIV_1;
|
||||
UTILS_ClkInitStruct.APB1CLKDivider = LL_RCC_APB1_DIV_1;
|
||||
LL_PLL_ConfigSystemClock_HSE(24000000U, LL_UTILS_HSEBYPASS_OFF, &UTILS_ClkInitStruct);
|
||||
|
||||
/* Re-init frequency of SysTick source, reload = freq/ticks = 48000000/1000 = 48000 */
|
||||
LL_InitTick(48000000, 1000U);
|
||||
}
|
||||
|
||||
static void APP_GPIOConfig(void)
|
||||
{
|
||||
LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA);
|
||||
LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB);
|
||||
|
||||
LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_5, LL_GPIO_MODE_OUTPUT);
|
||||
|
||||
/* PA08: MCO output */
|
||||
// Add USE_FULL_LL_DRIVER to LIB_FLAGS to enable LL_GPIO_InitTypeDef
|
||||
LL_GPIO_InitTypeDef GPIO_InitStruct;
|
||||
GPIO_InitStruct.Pin = LL_GPIO_PIN_8;
|
||||
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
|
||||
/* Alternate mode */
|
||||
GPIO_InitStruct.Alternate = LL_GPIO_AF5_MCO;
|
||||
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
||||
/* No pull */
|
||||
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
||||
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
}
|
||||
|
||||
void APP_ErrorHandler(void)
|
||||
{
|
||||
while (1);
|
||||
}
|
||||
|
||||
#ifdef USE_FULL_ASSERT
|
||||
void assert_failed(uint8_t *file, uint32_t line)
|
||||
{
|
||||
while (1);
|
||||
}
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
@ -7,19 +7,23 @@
|
||||
static void APP_SystemClockConfig(void);
|
||||
static void APP_GPIOConfig(void);
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
APP_SystemClockConfig();
|
||||
|
||||
APP_GPIOConfig();
|
||||
|
||||
LL_RCC_ConfigMCO(LL_RCC_MCO1SOURCE_SYSCLK,LL_RCC_MCO1_DIV_1);
|
||||
BSP_USART_Config(115200);
|
||||
|
||||
LL_RCC_ConfigMCO(LL_RCC_MCO1SOURCE_SYSCLK, LL_RCC_MCO1_DIV_1);
|
||||
|
||||
printf("Clock: %ld \r\n", SystemCoreClock);
|
||||
|
||||
while (1)
|
||||
{
|
||||
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_5);
|
||||
printf("echo\r\n");
|
||||
LL_mDelay(500);
|
||||
LL_GPIO_TogglePin(GPIOB,LL_GPIO_PIN_5);
|
||||
}
|
||||
}
|
||||
|
||||
29
Examples/LL/RCC/HSI_Output/main.h
Normal file
29
Examples/LL/RCC/HSI_Output/main.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef __MAIN_H
|
||||
#define __MAIN_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "py32f0xx_ll_rcc.h"
|
||||
#include "py32f0xx_ll_bus.h"
|
||||
#include "py32f0xx_ll_system.h"
|
||||
#include "py32f0xx_ll_exti.h"
|
||||
#include "py32f0xx_ll_cortex.h"
|
||||
#include "py32f0xx_ll_utils.h"
|
||||
#include "py32f0xx_ll_pwr.h"
|
||||
#include "py32f0xx_ll_dma.h"
|
||||
#include "py32f0xx_ll_gpio.h"
|
||||
|
||||
#if defined(USE_FULL_ASSERT)
|
||||
#include "py32_assert.h"
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
||||
|
||||
void APP_ErrorHandler(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __MAIN_H */
|
||||
31
Examples/LL/RCC/HSI_Output/py32_assert.h
Normal file
31
Examples/LL/RCC/HSI_Output/py32_assert.h
Normal file
@ -0,0 +1,31 @@
|
||||
#ifndef __PY32_ASSERT_H
|
||||
#define __PY32_ASSERT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef USE_FULL_ASSERT
|
||||
|
||||
#include "stdint.h"
|
||||
|
||||
/**
|
||||
* @brief The assert_param macro is used for function's parameters check.
|
||||
* @param expr: If expr is false, it calls assert_failed function
|
||||
* which reports the name of the source file and the source
|
||||
* line number of the call that failed.
|
||||
* If expr is true, it returns no value.
|
||||
* @retval None
|
||||
*/
|
||||
#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__))
|
||||
|
||||
void assert_failed(uint8_t* file, uint32_t line);
|
||||
#else
|
||||
#define assert_param(expr) ((void)0U)
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __PY32_ASSERT_H */
|
||||
40
Examples/LL/RCC/HSI_Output/py32f0xx_it.c
Normal file
40
Examples/LL/RCC/HSI_Output/py32f0xx_it.c
Normal file
@ -0,0 +1,40 @@
|
||||
#include "main.h"
|
||||
#include "py32f0xx_it.h"
|
||||
|
||||
/**
|
||||
* @brief This function handles Non maskable interrupt.
|
||||
*/
|
||||
void NMI_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Hard fault interrupt.
|
||||
*/
|
||||
void HardFault_Handler(void)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles System service call via SWI instruction.
|
||||
*/
|
||||
void SVC_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Pendable request for system service.
|
||||
*/
|
||||
void PendSV_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles System tick timer.
|
||||
*/
|
||||
void SysTick_Handler(void)
|
||||
{
|
||||
}
|
||||
18
Examples/LL/RCC/HSI_Output/py32f0xx_it.h
Normal file
18
Examples/LL/RCC/HSI_Output/py32f0xx_it.h
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef __PY32F0XX_IT_H
|
||||
#define __PY32F0XX_IT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void NMI_Handler(void);
|
||||
void HardFault_Handler(void);
|
||||
void SVC_Handler(void);
|
||||
void PendSV_Handler(void);
|
||||
void SysTick_Handler(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __PY32F0XX_IT_H */
|
||||
29
Examples/LL/RCC/HSI_PLL_Output/main.h
Normal file
29
Examples/LL/RCC/HSI_PLL_Output/main.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef __MAIN_H
|
||||
#define __MAIN_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "py32f0xx_ll_rcc.h"
|
||||
#include "py32f0xx_ll_bus.h"
|
||||
#include "py32f0xx_ll_system.h"
|
||||
#include "py32f0xx_ll_exti.h"
|
||||
#include "py32f0xx_ll_cortex.h"
|
||||
#include "py32f0xx_ll_utils.h"
|
||||
#include "py32f0xx_ll_pwr.h"
|
||||
#include "py32f0xx_ll_dma.h"
|
||||
#include "py32f0xx_ll_gpio.h"
|
||||
|
||||
#if defined(USE_FULL_ASSERT)
|
||||
#include "py32_assert.h"
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
||||
|
||||
void APP_ErrorHandler(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __MAIN_H */
|
||||
31
Examples/LL/RCC/HSI_PLL_Output/py32_assert.h
Normal file
31
Examples/LL/RCC/HSI_PLL_Output/py32_assert.h
Normal file
@ -0,0 +1,31 @@
|
||||
#ifndef __PY32_ASSERT_H
|
||||
#define __PY32_ASSERT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef USE_FULL_ASSERT
|
||||
|
||||
#include "stdint.h"
|
||||
|
||||
/**
|
||||
* @brief The assert_param macro is used for function's parameters check.
|
||||
* @param expr: If expr is false, it calls assert_failed function
|
||||
* which reports the name of the source file and the source
|
||||
* line number of the call that failed.
|
||||
* If expr is true, it returns no value.
|
||||
* @retval None
|
||||
*/
|
||||
#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__))
|
||||
|
||||
void assert_failed(uint8_t* file, uint32_t line);
|
||||
#else
|
||||
#define assert_param(expr) ((void)0U)
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __PY32_ASSERT_H */
|
||||
40
Examples/LL/RCC/HSI_PLL_Output/py32f0xx_it.c
Normal file
40
Examples/LL/RCC/HSI_PLL_Output/py32f0xx_it.c
Normal file
@ -0,0 +1,40 @@
|
||||
#include "main.h"
|
||||
#include "py32f0xx_it.h"
|
||||
|
||||
/**
|
||||
* @brief This function handles Non maskable interrupt.
|
||||
*/
|
||||
void NMI_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Hard fault interrupt.
|
||||
*/
|
||||
void HardFault_Handler(void)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles System service call via SWI instruction.
|
||||
*/
|
||||
void SVC_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Pendable request for system service.
|
||||
*/
|
||||
void PendSV_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles System tick timer.
|
||||
*/
|
||||
void SysTick_Handler(void)
|
||||
{
|
||||
}
|
||||
18
Examples/LL/RCC/HSI_PLL_Output/py32f0xx_it.h
Normal file
18
Examples/LL/RCC/HSI_PLL_Output/py32f0xx_it.h
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef __PY32F0XX_IT_H
|
||||
#define __PY32F0XX_IT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void NMI_Handler(void);
|
||||
void HardFault_Handler(void);
|
||||
void SVC_Handler(void);
|
||||
void PendSV_Handler(void);
|
||||
void SysTick_Handler(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __PY32F0XX_IT_H */
|
||||
Loading…
x
Reference in New Issue
Block a user