Browse Source

PWM входы и выходы работаю корректно.

TelenkovDmitry 11 months ago
parent
commit
240bc77192
14 changed files with 862 additions and 551 deletions
  1. 6 0
      doc/misc.txt
  2. 156 0
      modules/gpio.c
  3. 14 0
      modules/gpio.h
  4. 19 0
      modules/logic.c
  5. 12 0
      modules/logic.h
  6. 48 28
      modules/pwm_in.c
  7. 14 9
      modules/pwm_in.h
  8. 59 58
      modules/pwm_out.c
  9. BIN
      output/lasertag.bin
  10. 419 365
      project/ewarm/drone.dep
  11. 6 0
      project/ewarm/drone.ewp
  12. 6 0
      project/ewarm/drone.ewt
  13. 1 1
      project/settings/drone.wsdt
  14. 102 90
      user/main.c

+ 6 - 0
doc/misc.txt

@@ -0,0 +1,6 @@
+Вопросы:
+1. Нужна ли подтяжка выходов. Да, подтяжка к нулю.
+2. Логика по кругу.
+3. Значения PWM возвращаются обратно независимо от нажатий.
+4. Должно прийти 16 входных импульсов нужной длительности.
+5. Выход тоже сбрасывается через 1.5 секунды вместе с возвращением PWM.

+ 156 - 0
modules/gpio.c

@@ -0,0 +1,156 @@
+#include "stm32f0xx_hal.h"
+#include "gpio.h"
+
+
+#define SET_OUT_1   HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_SET)
+#define SET_OUT_2   HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET)
+#define SET_OUT_3   HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, GPIO_PIN_SET)
+#define SET_OUT_4   HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_SET)
+
+#define RESET_OUT_1   HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_RESET)
+#define RESET_OUT_2   HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET)
+#define RESET_OUT_3   HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, GPIO_PIN_RESET)
+#define RESET_OUT_4   HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET)
+
+
+static uint8_t next_out_number = 0;
+static uint8_t current_out_number = 0;
+
+
+
+//
+void gpio_init(void)
+{
+    GPIO_InitTypeDef GPIO_InitStruct = {0};
+
+    __HAL_RCC_GPIOA_CLK_ENABLE();
+    __HAL_RCC_GPIOB_CLK_ENABLE();
+    
+    GPIO_InitStruct.Pin = GPIO_PIN_12;
+    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
+    GPIO_InitStruct.Pull = GPIO_PULLDOWN;
+    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
+    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+    
+    GPIO_InitStruct.Pin = GPIO_PIN_12;
+    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+
+    // GPIO_PIN_5 - инфракрасный LED
+    GPIO_InitStruct.Pin = GPIO_PIN_1 | GPIO_PIN_3 | GPIO_PIN_4;
+    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
+    
+    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET);
+    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1 | GPIO_PIN_3 | GPIO_PIN_4, GPIO_PIN_RESET);
+}
+
+
+//
+void gpio_set_output(bool state)
+{
+    if (state == true) 
+    {
+        current_out_number = next_out_number;
+      
+        switch (next_out_number)
+        {
+            case 0:
+                SET_OUT_1;
+            break;
+        
+            case 1:
+                SET_OUT_2;
+            break;
+        
+            case 2:
+                SET_OUT_3;
+            break;
+        
+            case 3:
+                SET_OUT_4;
+            break;
+        
+            default : break;
+        }
+        
+        // При включении переключаемся на следующий выход
+        if (state == true)
+            next_out_number = next_out_number == 3 ? 0 : next_out_number + 1;
+    }
+    else
+    {
+        switch (current_out_number)
+        {
+            case 0:
+                RESET_OUT_1;
+            break;
+        
+            case 1:
+                RESET_OUT_2;
+            break;
+        
+            case 2:
+                RESET_OUT_3;
+            break;
+        
+            case 3:
+                RESET_OUT_4;
+            break;
+        
+            default : break;
+        }
+    }
+    
+    
+}
+
+
+
+#if 0
+//
+void led_togle(void)
+{
+    HAL_GPIO_TogglePin(GPIOF, GPIO_PIN_1);
+}
+
+
+// Индикация нажатия курка
+void led_signal_on(void)
+{
+    HAL_GPIO_WritePin(GPIOF, GPIO_PIN_1, GPIO_PIN_RESET);
+}
+
+
+// Индикация нажатия курка
+void led_signal_off(void)
+{
+    HAL_GPIO_WritePin(GPIOF, GPIO_PIN_1, GPIO_PIN_SET);
+}
+
+
+// Инфракрасный диод
+void led_inf_on(void)
+{
+    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
+}
+
+
+// Инфракрасный диод
+void led_inf_off(void)
+{
+    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);
+}
+
+
+// Индикация напряжения АКБ
+void led_but_on(void)
+{
+    HAL_GPIO_WritePin(GPIOF, GPIO_PIN_0, GPIO_PIN_RESET);
+}
+
+
+// Индикация напряжения АКБ
+void led_but_toggle(void)
+{
+    HAL_GPIO_TogglePin(GPIOF, GPIO_PIN_0);
+}
+#endif

+ 14 - 0
modules/gpio.h

@@ -0,0 +1,14 @@
+#ifndef __GPIO_H
+#define __GPIO_H
+
+#include <stdbool.h>
+
+  
+//
+void gpio_init(void);
+
+//
+void gpio_set_output(bool state);
+
+
+#endif

+ 19 - 0
modules/logic.c

@@ -0,0 +1,19 @@
+#include "stm32f0xx_hal.h"
+#include "logic.h"
+#include "pwm_in.h"
+#include "gpio.h"
+
+
+
+//
+void logic_main(void)
+{
+    //static uint8_t main_counter = 0;
+  
+    
+    if (get_button()) 
+    {   
+        gpio_set_output(true);
+    }   
+    
+}

+ 12 - 0
modules/logic.h

@@ -0,0 +1,12 @@
+#ifndef __LOGIC_H
+#define __LOGIC_H
+
+#include <stdbool.h>
+
+  
+//
+void logic_main(void);
+
+
+  
+#endif

+ 48 - 28
modules/pwm_in.c

@@ -5,16 +5,19 @@
 
 #define PWM_IN_TIM_FREQ     1000000
 
+#define PWM_FILTER_THR      16
+
 static TIM_HandleTypeDef       TimHandle;
 static TIM_IC_InitTypeDef      sConfig;
 static TIM_SlaveConfigTypeDef  sSlaveConfig;
 
 static uint16_t prescaler;
-static uint32_t tim_freq;
 
 __IO uint32_t cap_value_1 = 0;  // Captured Value
-__IO uint32_t uwDutyCycle = 0; // Duty Cycle Value
-__IO uint32_t uwFrequency = 0; // Frequency Value
+__IO uint32_t duty = 0;         // Duty Cycle Value
+__IO uint32_t freq = 0;         // Frequency Value
+
+uint8_t btn_pressed = 0;
 
 //
 void tim_pwm_in_init(void)
@@ -39,13 +42,12 @@ void tim_pwm_in_init(void)
     
     TimHandle.Instance = TIM3;
     TimHandle.Init.Period            = 0xFFFF;
-    TimHandle.Init.Prescaler         = 47;
+    TimHandle.Init.Prescaler         = prescaler;
     TimHandle.Init.ClockDivision     = 0;
     TimHandle.Init.CounterMode       = TIM_COUNTERMODE_UP;
     TimHandle.Init.RepetitionCounter = 0;
     TimHandle.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
     HAL_TIM_IC_Init(&TimHandle);
-    //HAL_TIM_Base_Init(&TimHandle);
 
     sConfig.ICPrescaler = TIM_ICPSC_DIV1;
     sConfig.ICFilter = 0;
@@ -73,47 +75,65 @@ void tim_pwm_in_init(void)
 //
 void tim_print_out_pwm(void)
 {
-    printf("Captured Value %u\r\n", uwIC2Value);
-    printf("Duty Cycle Value %u\r\n", uwDutyCycle);
-    printf("Frequency Value %u\r\n\n", uwFrequency);
+    printf("Captured Value %u\r\n", cap_value_1);
+    printf("Duty Cycle Value %u\r\n", duty);
+    printf("Frequency Value %u\r\n\n", freq);
 }
 
-
+//
 void TIM3_IRQHandler(void)
 {
     HAL_TIM_IRQHandler(&TimHandle);
 }
 
-
+//
 void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
 {
-    static uint32_t cnt = 0;
+    static uint8_t bt_pressed_flag = 0;
+    static uint8_t filter_cnt = 0;
     
-    cnt++;
-    
-#if 1  
     if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1)
     {
-        // Get the Input Capture value
-        uwIC2Value = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_1);
+        cap_value_1 = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_1);
 
-        if (uwIC2Value != 0)
+        if (cap_value_1 != 0)
         {
-            // Duty cycle computation
-            //uwDutyCycle = ((HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_2)) * 100) / uwIC2Value;
-          
-            uwDutyCycle = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_2);
-
-            // uwFrequency computation
-            //TIM3 counter clock = (RCC_Clocks.HCLK_Frequency)
-            uwFrequency = tim_freq/uwIC2Value;
+            // частота ШИМ в герцах (для контроля)
+            freq = PWM_IN_TIM_FREQ/cap_value_1;
+            
+            duty = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_2);
+            
+            if (duty > 1600) {
+                filter_cnt++;
+            }
+            else {
+                bt_pressed_flag = 0;
+                filter_cnt = 0;
+            }
+            
+            // Выполняется условие фильтра и было ожатие кнопки
+            if ((filter_cnt == PWM_FILTER_THR) && (bt_pressed_flag == 0)){
+                bt_pressed_flag = 1;
+                btn_pressed = true;
+            }
         }
         else
         {
-            uwDutyCycle = 0;
-            uwFrequency = 0;
+            duty = 0;
+            freq = 0;
         }
     }
-#endif    
 }
 
+
+bool get_button(void)
+{
+    return btn_pressed;
+}
+
+
+//
+void set_button(bool state)
+{
+    btn_pressed = state;
+}

+ 14 - 9
modules/pwm_in.h

@@ -1,10 +1,15 @@
-#ifndef __PWM_IN_H
-#define __PWM_IN_H
-
-//
-void tim_pwm_in_init(void);
-
-//
-void tim_print_out_pwm(void);
-
+#ifndef __PWM_IN_H
+#define __PWM_IN_H
+
+#include <stdbool.h>
+
+//
+void tim_pwm_in_init(void);
+
+//
+void tim_print_out_pwm(void);
+
+//
+bool get_button(void);
+
 #endif

+ 59 - 58
modules/pwm_out.c

@@ -1,59 +1,60 @@
-#include "stm32f0xx_hal.h"
-#include "pwm_out.h"
-#include <stdio.h>
-
-
-#define PERIOD_VALUE        1000
-#define PULSE1_VALUE        100
-#define PULSE2_VALUE        100
-
-
-static TIM_HandleTypeDef   TimHandle;
-static TIM_OC_InitTypeDef  sConfig;
-
-
-
-//
-void tim_pwm_out_init(void)
-{
-    GPIO_InitTypeDef   GPIO_InitStruct;
-    
-    uint32_t uhPrescalerValue = 0;
-    uhPrescalerValue = (uint32_t)(SystemCoreClock / 16000000) - 1;
-    
-    __HAL_RCC_GPIOA_CLK_ENABLE();
-    __HAL_RCC_TIM1_CLK_ENABLE();
-    
-    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
-    GPIO_InitStruct.Pull = GPIO_PULLUP;
-    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
-    GPIO_InitStruct.Alternate = GPIO_AF2_TIM1;
-    GPIO_InitStruct.Pin = GPIO_PIN_9 | GPIO_PIN_10;
-    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
-    
-    TimHandle.Instance = TIM1;
-    TimHandle.Init.Prescaler         = uhPrescalerValue;
-    TimHandle.Init.Period            = PERIOD_VALUE;
-    TimHandle.Init.ClockDivision     = 0;
-    TimHandle.Init.CounterMode       = TIM_COUNTERMODE_UP;
-    TimHandle.Init.RepetitionCounter = 0;
-    TimHandle.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
-    HAL_TIM_PWM_Init(&TimHandle);
-    
-    sConfig.OCMode       = TIM_OCMODE_PWM1;
-    sConfig.OCPolarity   = TIM_OCPOLARITY_HIGH;
-    sConfig.OCFastMode   = TIM_OCFAST_DISABLE;
-    sConfig.OCNPolarity  = TIM_OCNPOLARITY_HIGH;
-    sConfig.OCNIdleState = TIM_OCNIDLESTATE_RESET;
-    
-    sConfig.OCIdleState  = TIM_OCIDLESTATE_RESET;
-    
-    sConfig.Pulse = PULSE1_VALUE;
-    HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_2);
-    
-    sConfig.Pulse = PULSE2_VALUE;
-    HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_3);
-    
-    HAL_TIM_PWM_Start(&TimHandle, TIM_CHANNEL_2);
-    HAL_TIM_PWM_Start(&TimHandle, TIM_CHANNEL_3);
+#include "stm32f0xx_hal.h"
+#include "pwm_out.h"
+#include <stdio.h>
+
+#define PWM_OUT_TIM_FREQ    1000000
+#define PERIOD_VALUE        20000
+
+#define IDLE_PULSE          1552    // Начальное значение PWM до нажатий
+
+
+static TIM_HandleTypeDef   TimHandle;
+static TIM_OC_InitTypeDef  sConfig;
+
+static uint16_t prescaler;
+
+
+//
+void tim_pwm_out_init(void)
+{
+    GPIO_InitTypeDef   GPIO_InitStruct;
+    
+    
+    __HAL_RCC_GPIOA_CLK_ENABLE();
+    __HAL_RCC_TIM1_CLK_ENABLE();
+    
+    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+    GPIO_InitStruct.Pull = GPIO_PULLUP;
+    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
+    GPIO_InitStruct.Alternate = GPIO_AF2_TIM1;
+    GPIO_InitStruct.Pin = GPIO_PIN_9 | GPIO_PIN_10;
+    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+    
+    prescaler = HAL_RCC_GetHCLKFreq()/PWM_OUT_TIM_FREQ - 1;
+    
+    TimHandle.Instance = TIM1;
+    TimHandle.Init.Prescaler         = prescaler;
+    TimHandle.Init.Period            = PERIOD_VALUE;
+    TimHandle.Init.ClockDivision     = 0;
+    TimHandle.Init.CounterMode       = TIM_COUNTERMODE_UP;
+    TimHandle.Init.RepetitionCounter = 0;
+    TimHandle.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
+    HAL_TIM_PWM_Init(&TimHandle);
+    
+    sConfig.OCMode       = TIM_OCMODE_PWM1;
+    sConfig.OCPolarity   = TIM_OCPOLARITY_HIGH;
+    sConfig.OCFastMode   = TIM_OCFAST_DISABLE;
+    sConfig.OCNPolarity  = TIM_OCNPOLARITY_HIGH;
+    sConfig.OCNIdleState = TIM_OCNIDLESTATE_RESET;
+    
+    sConfig.OCIdleState  = TIM_OCIDLESTATE_RESET;
+    
+    sConfig.Pulse = IDLE_PULSE;
+    HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_2);
+    
+    sConfig.Pulse = IDLE_PULSE;
+    HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_3);
+    
+    HAL_TIM_PWM_Start(&TimHandle, TIM_CHANNEL_2);
+    HAL_TIM_PWM_Start(&TimHandle, TIM_CHANNEL_3);
 }

BIN
output/lasertag.bin


File diff suppressed because it is too large
+ 419 - 365
project/ewarm/drone.dep


+ 6 - 0
project/ewarm/drone.ewp

@@ -2275,12 +2275,18 @@
                 <configuration>Debug</configuration>
             </excluded>
         </file>
+        <file>
+            <name>$PROJ_DIR$\..\..\modules\gpio.c</name>
+        </file>
         <file>
             <name>$PROJ_DIR$\..\..\modules\led.c</name>
             <excluded>
                 <configuration>Debug</configuration>
             </excluded>
         </file>
+        <file>
+            <name>$PROJ_DIR$\..\..\modules\logic.c</name>
+        </file>
         <file>
             <name>$PROJ_DIR$\..\..\modules\misc.c</name>
             <excluded>

+ 6 - 0
project/ewarm/drone.ewt

@@ -2530,9 +2530,15 @@
         <file>
             <name>$PROJ_DIR$\..\..\modules\button.c</name>
         </file>
+        <file>
+            <name>$PROJ_DIR$\..\..\modules\gpio.c</name>
+        </file>
         <file>
             <name>$PROJ_DIR$\..\..\modules\led.c</name>
         </file>
+        <file>
+            <name>$PROJ_DIR$\..\..\modules\logic.c</name>
+        </file>
         <file>
             <name>$PROJ_DIR$\..\..\modules\misc.c</name>
         </file>

File diff suppressed because it is too large
+ 1 - 1
project/settings/drone.wsdt


+ 102 - 90
user/main.c

@@ -1,90 +1,102 @@
-#include "stm32f0xx_hal.h"
-#include "led.h"
-#include "button.h"
-#include "adc.h"
-#include "tim.h"
-#include "misc.h"
-#include "systick.h"
-#include "usart.h"
-#include "pwm_out.h"
-#include "pwm_in.h"
-#include <stdio.h>
-
-
-void SystemClock_Config(void);
-void Error_Handler(void);
-
-
-
-
-int main()
-{
-    HAL_Init();
-    SystemClock_Config();
-     
-    usart_init();
-      
-    printf("Hello world\r\n");
- 
-    //tim_pwm_out_init();
-    tim_pwm_in_init();
-    
-#if 0    
-    tim_init();
-    led_init();
-    pulse_gpio_init();
-    button_init();  
-    adc_init();
-    
-    timer_AddFunction(100, &adc_task);
-#endif    
-    
-    while(1) 
-    {
-        HAL_Delay(1000);
-        tim_print_out_pwm();
-        //led_togle();
-        timer_Main();
-    }
-}
-
-
-
-void SystemClock_Config(void)
-{
-    RCC_OscInitTypeDef RCC_OscInitStruct = {0};
-    RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
-    
-    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSI14;
-    RCC_OscInitStruct.HSIState = RCC_HSI_ON;
-    RCC_OscInitStruct.HSI14State = RCC_HSI14_ON;
-    RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
-    RCC_OscInitStruct.HSI14CalibrationValue = 16;
-    RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
-    RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
-    RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL12;
-    RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1;
-    
-    if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
-    {
-        Error_Handler();
-    }
-    
-    RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
-                                |RCC_CLOCKTYPE_PCLK1;
-    RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
-    RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
-    RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
-    
-    if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
-    {
-        Error_Handler();
-    }
-}
-
-
-void Error_Handler(void)
-{
-    __disable_irq();
-    while (1) {}
-}
+#include "stm32f0xx_hal.h"
+#include "led.h"
+#include "button.h"
+#include "adc.h"
+#include "tim.h"
+#include "misc.h"
+#include "systick.h"
+#include "usart.h"
+#include "pwm_out.h"
+#include "pwm_in.h"
+#include "gpio.h"
+#include "logic.h"
+#include <stdio.h>
+
+
+void SystemClock_Config(void);
+void Error_Handler(void);
+
+
+
+
+int main()
+{
+    HAL_Init();
+    SystemClock_Config();
+     
+    gpio_init();
+    tim_pwm_out_init();
+    tim_pwm_in_init();
+    
+    usart_init();
+    printf("FW started...\r\n");
+    
+// -----------------------------------------------------------------------------    
+// Тесты     
+#if 0
+    gpio_set_output(true);
+    gpio_set_output(false);
+    gpio_set_output(true);
+    gpio_set_output(false);
+    gpio_set_output(true);
+    gpio_set_output(false);
+    gpio_set_output(true);
+    gpio_set_output(false);
+    gpio_set_output(true);
+    gpio_set_output(false);
+
+#endif    
+    
+    
+    while(1) 
+    {
+        logic_main();
+      
+#if 0      
+        HAL_Delay(1000);
+        tim_print_out_pwm();
+        timer_Main();
+#endif        
+    }
+}
+
+
+
+void SystemClock_Config(void)
+{
+    RCC_OscInitTypeDef RCC_OscInitStruct = {0};
+    RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
+    
+    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSI14;
+    RCC_OscInitStruct.HSIState = RCC_HSI_ON;
+    RCC_OscInitStruct.HSI14State = RCC_HSI14_ON;
+    RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
+    RCC_OscInitStruct.HSI14CalibrationValue = 16;
+    RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
+    RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
+    RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL12;
+    RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1;
+    
+    if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
+    {
+        Error_Handler();
+    }
+    
+    RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
+                                |RCC_CLOCKTYPE_PCLK1;
+    RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
+    RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
+    RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
+    
+    if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
+    {
+        Error_Handler();
+    }
+}
+
+
+void Error_Handler(void)
+{
+    __disable_irq();
+    while (1) {}
+}

Some files were not shown because too many files changed in this diff