|
@@ -1,4 +1,8 @@
|
|
|
#include "board.h"
|
|
|
+#include "stm32g0xx_ll_rcc.h"
|
|
|
+#include "stm32g0xx_ll_bus.h"
|
|
|
+#include "stm32g0xx_ll_gpio.h"
|
|
|
+#include "stm32g0xx_ll_usart.h"
|
|
|
|
|
|
/* private functions */
|
|
|
static void TIM1_Init(void);
|
|
@@ -6,38 +10,11 @@ static void TIM3_Init(void);
|
|
|
static void TIM14_Init(void);
|
|
|
static void TIM16_Init(void);
|
|
|
static void TIM17_Init(void);
|
|
|
+static void USART1_UART_Init(void);
|
|
|
|
|
|
/* Board perephireal Configuration */
|
|
|
void Board_Init(void)
|
|
|
{
|
|
|
- /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
|
|
- RCC->APBENR2 |= RCC_APBENR2_SYSCFGEN;
|
|
|
- RCC->APBENR1 |= RCC_APBENR1_PWREN;
|
|
|
-
|
|
|
- /* Peripheral interrupt init*/
|
|
|
- /* RCC_IRQn interrupt configuration */
|
|
|
- NVIC_SetPriority(RCC_IRQn, 0);
|
|
|
- NVIC_EnableIRQ(RCC_IRQn);
|
|
|
-
|
|
|
- /* Configure the system clock */
|
|
|
- SystemClock_Config();
|
|
|
-
|
|
|
- /* Processor uses sleep as its low power mode */
|
|
|
- SCB->SCR &= ~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);
|
|
|
- /* DisableSleepOnExit */
|
|
|
- SCB->SCR &= ~((uint32_t)SCB_SCR_SLEEPONEXIT_Msk);
|
|
|
-
|
|
|
- /* в дейтвительности нигде не используеться? */
|
|
|
- //LL_RCC_GetSystemClocksFreq(&rcc_clocks); :::
|
|
|
- /* Get SYSCLK frequency */
|
|
|
- ///RCC_Clocks->SYSCLK_Frequency = RCC_GetSystemClockFreq();
|
|
|
- /* HCLK clock frequency */
|
|
|
- ///RCC_Clocks->HCLK_Frequency = RCC_GetHCLKClockFreq(RCC_Clocks->SYSCLK_Frequency);
|
|
|
- /* PCLK1 clock frequency */
|
|
|
- ///RCC_Clocks->PCLK1_Frequency = RCC_GetPCLK1ClockFreq(RCC_Clocks->HCLK_Frequency);
|
|
|
-
|
|
|
- /* Initialize all configured peripherals */
|
|
|
-
|
|
|
/* Start RGB & Tube Power PWM */
|
|
|
TIM1_Init();
|
|
|
TIM3_Init();
|
|
@@ -46,6 +23,8 @@ void Board_Init(void)
|
|
|
|
|
|
//TIM16_Init();
|
|
|
//TIM17_Init();
|
|
|
+
|
|
|
+ USART1_UART_Init();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -55,49 +34,38 @@ void Board_Init(void)
|
|
|
void SystemClock_Config(void)
|
|
|
{
|
|
|
/* HSI configuration and activation */
|
|
|
- RCC->CR |= RCC_CR_HSIKERON; // Enable HSI even in stop mode
|
|
|
- while((RCC->CR & RCC_CR_HSIRDY) == 0)
|
|
|
+ LL_RCC_HSI_Enable();
|
|
|
+ while(LL_RCC_HSI_IsReady() != 1)
|
|
|
{
|
|
|
}
|
|
|
|
|
|
/* Main PLL configuration and activation */
|
|
|
- RCC->PLLCFGR &= ~(RCC_PLLCFGR_PLLSRC | RCC_PLLCFGR_PLLM | RCC_PLLCFGR_PLLN | RCC_PLLCFGR_PLLR);
|
|
|
- RCC->PLLCFGR |= (RCC_PLLCFGR_PLLSRC_HSI | (9 << RCC_PLLCFGR_PLLN_Pos) | RCC_PLLCFGR_PLLR_2 | RCC_PLLCFGR_PLLR_0);
|
|
|
- RCC->PLLCFGR |= RCC_PLLCFGR_PLLREN; // RCC_PLL_EnableDomain_SYS
|
|
|
- RCC->CR |= RCC_CR_PLLON; // RCC_PLL_Enable
|
|
|
- while((RCC->CR & RCC_CR_PLLRDY) == 0)
|
|
|
+ LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_2, 9, LL_RCC_PLLR_DIV_3);
|
|
|
+ LL_RCC_PLL_Enable();
|
|
|
+ LL_RCC_PLL_EnableDomain_SYS();
|
|
|
+ while(LL_RCC_PLL_IsReady() != 1)
|
|
|
{
|
|
|
}
|
|
|
|
|
|
/* Set AHB prescaler*/
|
|
|
- //RCC->CFGR &= ~(RCC_CFGR_HPRE);
|
|
|
- //RCC->CFGR |= 0x00000000U;
|
|
|
+ LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
|
|
|
|
|
|
/* Sysclk activation on the main PLL */
|
|
|
- RCC->CFGR &= RCC_CFGR_SW;
|
|
|
- RCC->CFGR |= RCC_CFGR_SW_1;
|
|
|
- while((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_1)
|
|
|
+ LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL);
|
|
|
+ while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL)
|
|
|
{
|
|
|
}
|
|
|
|
|
|
- /* Set APB1 prescaler !!! uncorrect !!! */
|
|
|
- //RCC->CFGR &= RCC_CFGR_PPRE;
|
|
|
- //RCC->CFGR |= 0x00000000U;
|
|
|
+ /* Set APB1 prescaler*/
|
|
|
+ LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
|
|
|
|
|
|
-#ifdef USES_SYSTICK
|
|
|
- /* Configure the SysTick to have interrupt in 1ms time base */
|
|
|
- SysTick->LOAD = (uint32_t)((24000000 / 1000) - 1UL); /* set reload register */
|
|
|
- SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
|
|
|
- SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
|
|
|
- SysTick_CTRL_ENABLE_Msk; /* Enable the Systick Timer */
|
|
|
-#endif
|
|
|
+ LL_Init1msTick(24000000);
|
|
|
|
|
|
/* Update CMSIS variable (which can be updated also through SystemCoreClockUpdate function) */
|
|
|
- SystemCoreClock = 24000000;
|
|
|
+ LL_SetSystemCoreClock(24000000);
|
|
|
|
|
|
- /* SetI2CClockSource */
|
|
|
- RCC->CCIPR &= ~(RCC_CCIPR_I2C1SEL);
|
|
|
- RCC->CCIPR |= RCC_CCIPR_I2C1SEL_1;
|
|
|
+ /* Select I2C clock source */
|
|
|
+ LL_RCC_SetI2CClockSource(LL_RCC_I2C1_CLKSOURCE_HSI);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -348,3 +316,40 @@ static void TIM17_Init(void)
|
|
|
/* Enable IRQ */
|
|
|
TIM17->DIER = TIM_DIER_UIE;
|
|
|
}
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief USART1 Initialization Function
|
|
|
+ * @param None
|
|
|
+ * @retval None
|
|
|
+ */
|
|
|
+static void USART1_UART_Init(void)
|
|
|
+{
|
|
|
+ /* Peripheral clock enable */
|
|
|
+ RCC->APBENR2 |= RCC_APBENR2_USART1EN;
|
|
|
+ RCC->IOPENR |= RCC_IOPENR_GPIOBEN;
|
|
|
+
|
|
|
+ /**USART1 GPIO Configuration
|
|
|
+ PB6 ------> USART1_TX
|
|
|
+ PB7 ------> USART1_RX
|
|
|
+ */
|
|
|
+ GPIO_SetPinMode(GPIOB, GPIO_PIN_6, GPIO_MODE_AFF);
|
|
|
+ GPIO_SetPinSpeed(GPIOB, GPIO_PIN_6, GPIO_OSPEED_HI);
|
|
|
+
|
|
|
+ GPIO_SetPinMode(GPIOB, GPIO_PIN_7, GPIO_MODE_AFF);
|
|
|
+ GPIO_SetPinSpeed(GPIOB, GPIO_PIN_7, GPIO_OSPEED_HI);
|
|
|
+
|
|
|
+ /* USART1 interrupt Init */
|
|
|
+ NVIC_SetPriority(USART1_IRQn, 0);
|
|
|
+ NVIC_EnableIRQ(USART1_IRQn);
|
|
|
+
|
|
|
+ USART1->CR1 |= (USART_CR1_TE |USART_CR1_RE);
|
|
|
+ USART1->BRR = 138;
|
|
|
+
|
|
|
+ /* USART1 Enable */
|
|
|
+ USART1->CR1 |= USART_CR1_UE;
|
|
|
+
|
|
|
+ /* Polling USART1 initialisation */
|
|
|
+ while((!(USART1->ISR & USART_ISR_TEACK)) || (!(USART1->ISR & USART_ISR_REACK)))
|
|
|
+ {
|
|
|
+ }
|
|
|
+}
|