mirror of
https://github.com/eddyem/stm32samples.git
synced 2026-03-22 01:31:21 +03:00
added blink for STM32G0B1, next -> add USART
This commit is contained in:
@@ -19,8 +19,6 @@
|
||||
* MA 02110-1301, USA.
|
||||
*/
|
||||
#pragma once
|
||||
#ifndef __STM32F0_H__
|
||||
#define __STM32F0_H__
|
||||
|
||||
#include "vector.h"
|
||||
#include "stm32g0xx.h"
|
||||
@@ -37,14 +35,14 @@
|
||||
* R=2..8, Q=2..8, P=2..32; N=8..86, M=1..8
|
||||
* fvco = 64..344MHz (after /M should be 2.66..16 -> for 8MHz HSE M=1..3!!!)
|
||||
* For 8MHZ:
|
||||
* fvco = (8/M)*N -> N(144)=18, M(144)=1
|
||||
* fpllp = fvco/P (<=122MHz) -> P(72)=2
|
||||
* fpllq = fvco/Q (<=128MHz) -> Q(48)=3
|
||||
* fpllr = fvco/R (<=64MHz) -> R(48)=3
|
||||
* AHB prescaler (36MHz) = 72/36 = 2
|
||||
* APB prescaler (36MHz) = 36/36 = 1
|
||||
* fvco = (8/M)*N -> N(128)=16, M(128)=1
|
||||
* fpllp = fvco/P (<=122MHz) -> P(64)=2
|
||||
* fpllq = fvco/Q (<=128MHz) -> Q(64)=2
|
||||
* fpllr = fvco/R (<=64MHz) -> R(64)=2
|
||||
* AHB prescaler (64MHz) = 1
|
||||
* APB prescaler (64MHz) = 1
|
||||
*
|
||||
* fp=fq=fr=fsys=64MHz => M=1, N=8, P=1, Q=1, R=1
|
||||
* fp=fq=fr=fsys=64MHz => M=1, N=16, P=2, Q=2, R=2
|
||||
*/
|
||||
#ifndef PLLN
|
||||
#define PLLN 16
|
||||
@@ -61,6 +59,12 @@
|
||||
#ifndef PLLR
|
||||
#define PLLR 2
|
||||
#endif
|
||||
#ifndef PPRE
|
||||
#define PPRE 1
|
||||
#endif
|
||||
#ifndef HPRE
|
||||
#define HPRE 1
|
||||
#endif
|
||||
|
||||
#define WAITWHILE(x) do{register uint32_t StartUpCounter = 0; while((x) && (++StartUpCounter < 0xffffff)){nop();}}while(0)
|
||||
TRUE_INLINE void StartHSEHSI(int isHSE){
|
||||
@@ -76,18 +80,19 @@ TRUE_INLINE void StartHSEHSI(int isHSE){
|
||||
WAITWHILE(PWR->SR2 & PWR_SR2_VOSF);
|
||||
if(isHSE){
|
||||
RCC->PLLCFGR = ((PLLR-1)<<29) | ((PLLQ-1)<<25) | ((PLLP-1)<<17) | (PLLN<<8) | ((PLLM-1)<<4)
|
||||
| RCC_PLLCFGR_PLLREN | RCC_PLLCFGR_PLLPEN /* | RCC_PLLCFGR_PLLQEN */
|
||||
| RCC_PLLCFGR_PLLREN | RCC_PLLCFGR_PLLQEN /* | RCC_PLLCFGR_PLLPEN */
|
||||
| RCC_PLLCFGR_PLLSRC_HSE;
|
||||
}else{ // 64MHz from HSI16
|
||||
RCC->PLLCFGR = (8<<8) | (1<<4)
|
||||
// enable P and/or Q if need
|
||||
| RCC_PLLCFGR_PLLREN /* | RCC_PLLCFGR_PLLPEN | RCC_PLLCFGR_PLLQEN */
|
||||
// enable P if need
|
||||
| RCC_PLLCFGR_PLLREN | RCC_PLLCFGR_PLLQEN /* | RCC_PLLCFGR_PLLPEN */
|
||||
| RCC_PLLCFGR_PLLSRC_HSI;
|
||||
}
|
||||
RCC->CR |= RCC_CR_PLLON;
|
||||
WAITWHILE(!(RCC->CR & RCC_CR_PLLRDY));
|
||||
FLASH->ACR |= FLASH_ACR_PRFTEN | FLASH_ACR_ICEN | FLASH_ACR_LATENCY_1;
|
||||
RCC->CFGR = RCC_CFGR_SW_1; // set sysclk switch to pll
|
||||
FLASH->ACR |= FLASH_ACR_PRFTEN | FLASH_ACR_ICEN | FLASH_ACR_LATENCY_2; // FLASH_ACR_LATENCY_2 for 64MHz
|
||||
// set sysclk switch to pll, setup AHB/APB
|
||||
RCC->CFGR = RCC_CFGR_SW_1 | PPRE << 12 | HPRE << 8;
|
||||
}
|
||||
|
||||
#define StartHSE() do{StartHSEHSI(1);}while(0)
|
||||
@@ -253,7 +258,3 @@ TRUE_INLINE void StartHSEHSI(int isHSE){
|
||||
|
||||
//#define do{}while(0)
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // __STM32F0_H__
|
||||
|
||||
@@ -48,43 +48,9 @@
|
||||
* @brief STM32 Family
|
||||
*/
|
||||
#if !defined (STM32G0)
|
||||
#define STM32G0
|
||||
#error "DEFINE STM32G0 first!"
|
||||
#endif /* STM32G0 */
|
||||
|
||||
/* Uncomment the line below according to the target STM32G0 device used in your
|
||||
application
|
||||
*/
|
||||
|
||||
#if !defined (STM32G071xx) && !defined (STM32G081xx) && !defined (STM32G070xx) \
|
||||
&& !defined (STM32G030xx) && !defined (STM32G031xx) && !defined (STM32G041xx) \
|
||||
&& !defined (STM32G0B0xx) && !defined (STM32G0B1xx) && !defined (STM32G0C1xx) \
|
||||
&& !defined (STM32G050xx) && !defined (STM32G051xx) && !defined (STM32G061xx)
|
||||
/* #define STM32G0B0xx */ /*!< STM32G0B0xx Devices */
|
||||
/* #define STM32G0B1xx */ /*!< STM32G0B1xx Devices */
|
||||
/* #define STM32G0C1xx */ /*!< STM32G0C1xx Devices */
|
||||
/* #define STM32G070xx */ /*!< STM32G070xx Devices */
|
||||
/* #define STM32G071xx */ /*!< STM32G071xx Devices */
|
||||
/* #define STM32G081xx */ /*!< STM32G081xx Devices */
|
||||
/* #define STM32G050xx */ /*!< STM32G050xx Devices */
|
||||
/* #define STM32G051xx */ /*!< STM32G051xx Devices */
|
||||
/* #define STM32G061xx */ /*!< STM32G061xx Devices */
|
||||
/* #define STM32G030xx */ /*!< STM32G030xx Devices */
|
||||
/* #define STM32G031xx */ /*!< STM32G031xx Devices */
|
||||
/* #define STM32G041xx */ /*!< STM32G041xx Devices */
|
||||
#endif
|
||||
|
||||
/* Tip: To avoid modifying this file each time you need to switch between these
|
||||
devices, you can define the device in your toolchain compiler preprocessor.
|
||||
*/
|
||||
#if !defined (USE_HAL_DRIVER)
|
||||
/**
|
||||
* @brief Comment the line below if you will not use the peripherals drivers.
|
||||
In this case, these drivers will not be included and the application code will
|
||||
be based on direct access to peripherals registers
|
||||
*/
|
||||
/*#define USE_HAL_DRIVER */
|
||||
#endif /* USE_HAL_DRIVER */
|
||||
|
||||
/**
|
||||
* @brief CMSIS Device version number $VERSION$
|
||||
*/
|
||||
@@ -226,10 +192,6 @@ typedef enum
|
||||
* @}
|
||||
*/
|
||||
|
||||
#if defined (USE_HAL_DRIVER)
|
||||
#include "stm32g0xx_hal.h"
|
||||
#endif /* USE_HAL_DRIVER */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
@@ -35,34 +35,36 @@ void WEAK sys_tick_handler(void);
|
||||
|
||||
#if defined STM32G0
|
||||
void WEAK wwdg_isr(void);
|
||||
void WEAK pvd_vddio2_isr(void);
|
||||
void WEAK rtc_isr(void);
|
||||
void WEAK flash_isr(void);
|
||||
void WEAK rcc_isr(void);
|
||||
void WEAK exti0_1_isr(void);
|
||||
void WEAK exti2_3_isr(void);
|
||||
void WEAK exti4_15_isr(void);
|
||||
void WEAK usb_ucpd1_2_isr(void);
|
||||
void WEAK dma1_channel1_isr(void);
|
||||
void WEAK dma1_channel2_3_isr(void);
|
||||
void WEAK dmamux_isr(void);
|
||||
void WEAK dma1_ch4_7_dma2_ch1_5_dmamux_ovr_isr(void);
|
||||
void WEAK adc_comp_isr(void);
|
||||
void WEAK tim1_brk_up_trg_com_isr(void);
|
||||
void WEAK tim1_cc_isr(void);
|
||||
void WEAK tim2_isr(void);
|
||||
void WEAK tim3_4_isr(void);
|
||||
void WEAK tim6_dac_isr(void);
|
||||
void WEAK tim7_isr(void);
|
||||
void WEAK tim6_dac_lptim1_isr(void);
|
||||
void WEAK tim7_lptim2_isr(void);
|
||||
void WEAK tim14_isr(void);
|
||||
void WEAK tim15_isr(void);
|
||||
void WEAK tim16_isr(void);
|
||||
void WEAK tim17_isr(void);
|
||||
void WEAK tim16_fdcan_it0_isr(void);
|
||||
void WEAK tim17_fdcan_it1_isr(void);
|
||||
void WEAK i2c1_isr(void);
|
||||
void WEAK i2c2_3_isr(void);
|
||||
void WEAK spi1_isr(void);
|
||||
void WEAK spi2_3_isr(void);
|
||||
void WEAK usart1_isr(void);
|
||||
void WEAK usart2_isr(void);
|
||||
void WEAK usart3_4_isr(void);
|
||||
void WEAK cec_can_isr(void);
|
||||
void WEAK usb_isr(void);
|
||||
void WEAK usart2_lpuart2_isr(void);
|
||||
void WEAK usart3_6_lpuart1_isr(void);
|
||||
void WEAK cec_isr(void);
|
||||
#else
|
||||
#error "Not supported platform"
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user