Version 1.0
This commit is contained in:
140
Core/Src/DS_Button.c
Normal file
140
Core/Src/DS_Button.c
Normal file
@@ -0,0 +1,140 @@
|
||||
|
||||
#include "DS_Button.h"
|
||||
|
||||
void DS_ButtonInit(DS_Button* Button, GPIO_TypeDef *Port, uint16_t Pin)
|
||||
{
|
||||
Button->Port = Port;
|
||||
Button->Pin = Pin;
|
||||
Button->Pressed = false;
|
||||
Button->Released = false;
|
||||
Button->PrevTick = 0;
|
||||
Button->Storage = 5;
|
||||
Button->PressedLong = false;
|
||||
Button->PressStartTick = 0;
|
||||
|
||||
Button->FallingEdge = false;
|
||||
Button->RisingEdge = false;
|
||||
}
|
||||
|
||||
void DS_ButtonUpdate(DS_Button *Button)
|
||||
{
|
||||
//создаём переменную
|
||||
//устанавливаем для неё границы от 0 до 10
|
||||
//если кнопка нажата - увеличиваем значение переменной, пока не доберемся до максимального (10)
|
||||
//если отпущена - уменьшаем, стремясь к нулю
|
||||
//опрос состояния делаем не чаще чем 1 раз в 10 миллисекунд
|
||||
//первое изменение делаем большим - 5 (имитация гистерезиса)
|
||||
//по достижении нуля - устанавливаем флаг что кнопка отпущена
|
||||
//по достижении 10 - флаг кнопка нажата
|
||||
|
||||
uint32_t CurrentTick = HAL_GetTick();
|
||||
if ((CurrentTick - Button->PrevTick)<10)
|
||||
return;
|
||||
|
||||
Button->PrevTick = CurrentTick;
|
||||
|
||||
|
||||
GPIO_PinState PinState = HAL_GPIO_ReadPin(Button->Port, Button->Pin);
|
||||
if (PinState == GPIO_PIN_SET)
|
||||
{
|
||||
if(Button->Storage == 0)
|
||||
Button->Storage +=5;
|
||||
else if(Button->Storage<=10)
|
||||
Button->Storage++;
|
||||
|
||||
if(Button->PressStartTick == 0)
|
||||
Button->PressStartTick = CurrentTick;
|
||||
else if ((CurrentTick - Button->PressStartTick)>1000)
|
||||
Button->PressedLong = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(Button->Storage == 10)
|
||||
Button->Storage -=5;
|
||||
else if(Button->Storage > 0)
|
||||
Button->Storage--;
|
||||
|
||||
Button->PressStartTick = 0;
|
||||
Button->PressedLong = false;
|
||||
}
|
||||
|
||||
switch (Button->Storage)
|
||||
{
|
||||
case 0:
|
||||
|
||||
if (Button->Released == false)
|
||||
{
|
||||
Button->FallingEdge = true;
|
||||
}
|
||||
|
||||
Button->Pressed = false;
|
||||
Button->Released = true;
|
||||
break;
|
||||
case 10:
|
||||
|
||||
if (Button->Pressed == false)
|
||||
{
|
||||
Button->RisingEdge = true;
|
||||
}
|
||||
|
||||
Button->Pressed = true;
|
||||
Button->Released = false;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool DS_ButtonPressed(DS_Button *Button)
|
||||
{
|
||||
if (Button->Pressed)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DS_ButtonReleased(DS_Button *Button)
|
||||
{
|
||||
if(Button->Released)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DS_Button_PressedLong(DS_Button *Button)
|
||||
{
|
||||
if(Button->PressedLong)
|
||||
{
|
||||
Button->PressedLong = false;
|
||||
Button->PressStartTick = 0;
|
||||
return true;
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DS_ButtonRisingEdge(DS_Button *Button)
|
||||
{
|
||||
if (Button->RisingEdge)
|
||||
{
|
||||
Button->RisingEdge = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DS_ButtonFallingEdge(DS_Button *Button)
|
||||
{
|
||||
if (Button->FallingEdge)
|
||||
{
|
||||
Button->FallingEdge = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
200
Core/Src/DS_SingleDigitDisplay.c
Normal file
200
Core/Src/DS_SingleDigitDisplay.c
Normal file
@@ -0,0 +1,200 @@
|
||||
|
||||
#include "DS_SingleDigitDisplay.h"
|
||||
|
||||
void DS_SingleDisplayInit(DS_SingleDigitDisplay *Display, GPIO_TypeDef *Port_A, uint16_t Pin_A, GPIO_TypeDef *Port_B, uint16_t Pin_B, GPIO_TypeDef *Port_C, uint16_t Pin_C, GPIO_TypeDef *Port_D, uint16_t Pin_D, GPIO_TypeDef *Port_E, uint16_t Pin_E, GPIO_TypeDef *Port_F, uint16_t Pin_F, GPIO_TypeDef *Port_G, uint16_t Pin_G, GPIO_TypeDef *Port_DP, uint16_t Pin_DP)
|
||||
{
|
||||
Display->Port_A = Port_A;
|
||||
Display->Port_B = Port_B;
|
||||
Display->Port_C = Port_C;
|
||||
Display->Port_D = Port_D;
|
||||
Display->Port_E = Port_E;
|
||||
Display->Port_F = Port_F;
|
||||
Display->Port_G = Port_G;
|
||||
Display->Port_DP = Port_DP;
|
||||
|
||||
Display->Pin_A = Pin_A;
|
||||
Display->Pin_B = Pin_B;
|
||||
Display->Pin_C = Pin_C;
|
||||
Display->Pin_D = Pin_D;
|
||||
Display->Pin_E = Pin_E;
|
||||
Display->Pin_F = Pin_F;
|
||||
Display->Pin_G = Pin_G;
|
||||
Display->Pin_DP = Pin_DP;
|
||||
|
||||
DS_SingleDisplayPoint(Display, false);
|
||||
}
|
||||
|
||||
void DS_SingleDisplayPrint(DS_SingleDigitDisplay *Display, uint8_t Digit)
|
||||
{
|
||||
switch (Digit)
|
||||
{
|
||||
case 0:
|
||||
HAL_GPIO_WritePin(Display->Port_A, Display->Pin_A, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_B, Display->Pin_B, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_C, Display->Pin_C, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_D, Display->Pin_D, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_E, Display->Pin_E, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_F, Display->Pin_F, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_G, Display->Pin_G, GPIO_PIN_SET);
|
||||
break;
|
||||
case 1:
|
||||
HAL_GPIO_WritePin(Display->Port_A, Display->Pin_A, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Display->Port_B, Display->Pin_B, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_C, Display->Pin_C, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_D, Display->Pin_D, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Display->Port_E, Display->Pin_E, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Display->Port_F, Display->Pin_F, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Display->Port_G, Display->Pin_G, GPIO_PIN_SET);
|
||||
break;
|
||||
case 2:
|
||||
HAL_GPIO_WritePin(Display->Port_A, Display->Pin_A, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_B, Display->Pin_B, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_C, Display->Pin_C, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Display->Port_D, Display->Pin_D, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_E, Display->Pin_E, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_F, Display->Pin_F, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Display->Port_G, Display->Pin_G, GPIO_PIN_RESET);
|
||||
break;
|
||||
case 3:
|
||||
HAL_GPIO_WritePin(Display->Port_A, Display->Pin_A, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_B, Display->Pin_B, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_C, Display->Pin_C, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_D, Display->Pin_D, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_E, Display->Pin_E, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Display->Port_F, Display->Pin_F, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Display->Port_G, Display->Pin_G, GPIO_PIN_RESET);
|
||||
break;
|
||||
case 4:
|
||||
HAL_GPIO_WritePin(Display->Port_A, Display->Pin_A, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Display->Port_B, Display->Pin_B, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_C, Display->Pin_C, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_D, Display->Pin_D, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Display->Port_E, Display->Pin_E, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Display->Port_F, Display->Pin_F, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_G, Display->Pin_G, GPIO_PIN_RESET);
|
||||
break;
|
||||
case 5:
|
||||
HAL_GPIO_WritePin(Display->Port_A, Display->Pin_A, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_B, Display->Pin_B, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Display->Port_C, Display->Pin_C, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_D, Display->Pin_D, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_E, Display->Pin_E, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Display->Port_F, Display->Pin_F, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_G, Display->Pin_G, GPIO_PIN_RESET);
|
||||
break;
|
||||
case 6:
|
||||
HAL_GPIO_WritePin(Display->Port_A, Display->Pin_A, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_B, Display->Pin_B, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Display->Port_C, Display->Pin_C, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_D, Display->Pin_D, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_E, Display->Pin_E, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_F, Display->Pin_F, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_G, Display->Pin_G, GPIO_PIN_RESET);
|
||||
break;
|
||||
case 7:
|
||||
HAL_GPIO_WritePin(Display->Port_A, Display->Pin_A, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_B, Display->Pin_B, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_C, Display->Pin_C, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_D, Display->Pin_D, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Display->Port_E, Display->Pin_E, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Display->Port_F, Display->Pin_F, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Display->Port_G, Display->Pin_G, GPIO_PIN_SET);
|
||||
break;
|
||||
case 8:
|
||||
HAL_GPIO_WritePin(Display->Port_A, Display->Pin_A, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_B, Display->Pin_B, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_C, Display->Pin_C, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_D, Display->Pin_D, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_E, Display->Pin_E, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_F, Display->Pin_F, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_G, Display->Pin_G, GPIO_PIN_RESET);
|
||||
break;
|
||||
case 9:
|
||||
HAL_GPIO_WritePin(Display->Port_A, Display->Pin_A, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_B, Display->Pin_B, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_C, Display->Pin_C, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_D, Display->Pin_D, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_E, Display->Pin_E, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Display->Port_F, Display->Pin_F, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_G, Display->Pin_G, GPIO_PIN_RESET);
|
||||
break;
|
||||
case 10:
|
||||
HAL_GPIO_WritePin(Display->Port_A, Display->Pin_A, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_B, Display->Pin_B, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_C, Display->Pin_C, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_D, Display->Pin_D, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Display->Port_E, Display->Pin_E, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_F, Display->Pin_F, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_G, Display->Pin_G, GPIO_PIN_RESET);
|
||||
break;
|
||||
case 11:
|
||||
HAL_GPIO_WritePin(Display->Port_A, Display->Pin_A, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Display->Port_B, Display->Pin_B, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Display->Port_C, Display->Pin_C, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_D, Display->Pin_D, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_E, Display->Pin_E, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_F, Display->Pin_F, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_G, Display->Pin_G, GPIO_PIN_RESET);
|
||||
break;
|
||||
case 12:
|
||||
HAL_GPIO_WritePin(Display->Port_A, Display->Pin_A, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_B, Display->Pin_B, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Display->Port_C, Display->Pin_C, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Display->Port_D, Display->Pin_D, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_E, Display->Pin_E, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_F, Display->Pin_F, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_G, Display->Pin_G, GPIO_PIN_SET);
|
||||
break;
|
||||
case 13:
|
||||
HAL_GPIO_WritePin(Display->Port_A, Display->Pin_A, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Display->Port_B, Display->Pin_B, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_C, Display->Pin_C, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_D, Display->Pin_D, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_E, Display->Pin_E, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_F, Display->Pin_F, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Display->Port_G, Display->Pin_G, GPIO_PIN_RESET);
|
||||
break;
|
||||
case 14:
|
||||
HAL_GPIO_WritePin(Display->Port_A, Display->Pin_A, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_B, Display->Pin_B, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Display->Port_C, Display->Pin_C, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Display->Port_D, Display->Pin_D, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_E, Display->Pin_E, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_F, Display->Pin_F, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_G, Display->Pin_G, GPIO_PIN_RESET);
|
||||
break;
|
||||
case 15:
|
||||
HAL_GPIO_WritePin(Display->Port_A, Display->Pin_A, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_B, Display->Pin_B, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Display->Port_C, Display->Pin_C, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Display->Port_D, Display->Pin_D, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Display->Port_E, Display->Pin_E, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_F, Display->Pin_F, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(Display->Port_G, Display->Pin_G, GPIO_PIN_RESET);
|
||||
break;
|
||||
|
||||
default:
|
||||
HAL_GPIO_WritePin(Display->Port_A, Display->Pin_A, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Display->Port_B, Display->Pin_B, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Display->Port_C, Display->Pin_C, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Display->Port_D, Display->Pin_D, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Display->Port_E, Display->Pin_E, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Display->Port_F, Display->Pin_F, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(Display->Port_G, Display->Pin_G, GPIO_PIN_SET);
|
||||
break;
|
||||
}
|
||||
DS_SingleDisplayPoint(Display, Display->DotEnable);
|
||||
}
|
||||
|
||||
void DS_SingleDisplayPoint(DS_SingleDigitDisplay *Display, bool Enable)
|
||||
{
|
||||
Display->DotEnable = Enable;
|
||||
if (Enable)
|
||||
{
|
||||
HAL_GPIO_WritePin(Display->Port_DP, Display->Pin_DP, GPIO_PIN_RESET);
|
||||
}
|
||||
else
|
||||
{
|
||||
HAL_GPIO_WritePin(Display->Port_DP, Display->Pin_DP, GPIO_PIN_SET);
|
||||
}
|
||||
}
|
||||
260
Core/Src/main.c
Normal file
260
Core/Src/main.c
Normal file
@@ -0,0 +1,260 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : main.c
|
||||
* @brief : Main program body
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "DS_SingleDigitDisplay.h"
|
||||
#include "DS_Button.h"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PTD */
|
||||
|
||||
/* USER CODE END PTD */
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PD */
|
||||
|
||||
/* USER CODE END PD */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PM */
|
||||
|
||||
/* USER CODE END PM */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
void SystemClock_Config(void);
|
||||
static void MX_GPIO_Init(void);
|
||||
/* USER CODE BEGIN PFP */
|
||||
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/**
|
||||
* @brief The application entry point.
|
||||
* @retval int
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/* MCU Configuration--------------------------------------------------------*/
|
||||
|
||||
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
||||
HAL_Init();
|
||||
|
||||
/* USER CODE BEGIN Init */
|
||||
|
||||
/* USER CODE END Init */
|
||||
|
||||
/* Configure the system clock */
|
||||
SystemClock_Config();
|
||||
|
||||
/* USER CODE BEGIN SysInit */
|
||||
|
||||
/* USER CODE END SysInit */
|
||||
|
||||
/* Initialize all configured peripherals */
|
||||
MX_GPIO_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
DS_SingleDigitDisplay Display;
|
||||
DS_SingleDisplayInit(&Display,
|
||||
A_GPIO_Port, A_Pin,
|
||||
B_GPIO_Port, B_Pin,
|
||||
C_GPIO_Port, C_Pin,
|
||||
D_GPIO_Port, D_Pin,
|
||||
E_GPIO_Port, E_Pin,
|
||||
F_GPIO_Port, F_Pin,
|
||||
G_GPIO_Port, G_Pin,
|
||||
DP_GPIO_Port, DP_Pin);
|
||||
|
||||
|
||||
DS_Button Button;
|
||||
DS_ButtonInit(&Button, Button_GPIO_Port, Button_Pin);
|
||||
|
||||
uint8_t Counter = 0, Direction = 0;
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
/* USER CODE BEGIN WHILE */
|
||||
while (1)
|
||||
{
|
||||
|
||||
DS_ButtonUpdate(&Button);
|
||||
|
||||
|
||||
if (DS_ButtonRisingEdge(&Button)||DS_Button_PressedLong(&Button))
|
||||
{
|
||||
if (Counter <16 && Direction == 0)
|
||||
{
|
||||
Counter ++;
|
||||
}
|
||||
else if (Counter == 16 && Direction == 0)
|
||||
{
|
||||
Direction = 1;
|
||||
Counter --;
|
||||
DS_SingleDisplayPoint(&Display, !Display.DotEnable);
|
||||
}
|
||||
else if(Counter > 0 && Direction == 1)
|
||||
{
|
||||
Counter --;
|
||||
}
|
||||
else
|
||||
{
|
||||
Direction = 0;
|
||||
Counter ++;
|
||||
DS_SingleDisplayPoint(&Display, !Display.DotEnable);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
DS_SingleDisplayPrint(&Display, Counter);
|
||||
|
||||
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief System Clock Configuration
|
||||
* @retval None
|
||||
*/
|
||||
void SystemClock_Config(void)
|
||||
{
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||
|
||||
/** Initializes the RCC Oscillators according to the specified parameters
|
||||
* in the RCC_OscInitTypeDef structure.
|
||||
*/
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
|
||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/** Initializes the CPU, AHB and APB buses clocks
|
||||
*/
|
||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||
|RCC_CLOCKTYPE_PCLK1;
|
||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
|
||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
|
||||
|
||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief GPIO Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_GPIO_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||
/* USER CODE END MX_GPIO_Init_1 */
|
||||
|
||||
/* GPIO Ports Clock Enable */
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOA, B_Pin|DP_Pin|C_Pin|D_Pin
|
||||
|E_Pin|A_Pin|F_Pin|G_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pins : B_Pin DP_Pin C_Pin D_Pin
|
||||
E_Pin A_Pin F_Pin G_Pin */
|
||||
GPIO_InitStruct.Pin = B_Pin|DP_Pin|C_Pin|D_Pin
|
||||
|E_Pin|A_Pin|F_Pin|G_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : Button_Pin */
|
||||
GPIO_InitStruct.Pin = Button_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||
HAL_GPIO_Init(Button_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||
/* USER CODE END MX_GPIO_Init_2 */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 4 */
|
||||
|
||||
/* USER CODE END 4 */
|
||||
|
||||
/**
|
||||
* @brief This function is executed in case of error occurrence.
|
||||
* @retval None
|
||||
*/
|
||||
void Error_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN Error_Handler_Debug */
|
||||
/* User can add his own implementation to report the HAL error return state */
|
||||
__disable_irq();
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
/* USER CODE END Error_Handler_Debug */
|
||||
}
|
||||
|
||||
#ifdef USE_FULL_ASSERT
|
||||
/**
|
||||
* @brief Reports the name of the source file and the source line number
|
||||
* where the assert_param error has occurred.
|
||||
* @param file: pointer to the source file name
|
||||
* @param line: assert_param error line source number
|
||||
* @retval None
|
||||
*/
|
||||
void assert_failed(uint8_t *file, uint32_t line)
|
||||
{
|
||||
/* USER CODE BEGIN 6 */
|
||||
/* User can add his own implementation to report the file name and line number,
|
||||
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||
/* USER CODE END 6 */
|
||||
}
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
82
Core/Src/stm32f0xx_hal_msp.c
Normal file
82
Core/Src/stm32f0xx_hal_msp.c
Normal file
@@ -0,0 +1,82 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32f0xx_hal_msp.c
|
||||
* @brief This file provides code for the MSP Initialization
|
||||
* and de-Initialization codes.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN TD */
|
||||
|
||||
/* USER CODE END TD */
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Define */
|
||||
|
||||
/* USER CODE END Define */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Macro */
|
||||
|
||||
/* USER CODE END Macro */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* USER CODE BEGIN PFP */
|
||||
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* External functions --------------------------------------------------------*/
|
||||
/* USER CODE BEGIN ExternalFunctions */
|
||||
|
||||
/* USER CODE END ExternalFunctions */
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
/**
|
||||
* Initializes the Global MSP.
|
||||
*/
|
||||
void HAL_MspInit(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN MspInit 0 */
|
||||
|
||||
/* USER CODE END MspInit 0 */
|
||||
|
||||
__HAL_RCC_SYSCFG_CLK_ENABLE();
|
||||
__HAL_RCC_PWR_CLK_ENABLE();
|
||||
|
||||
/* System interrupt init*/
|
||||
|
||||
/* USER CODE BEGIN MspInit 1 */
|
||||
|
||||
/* USER CODE END MspInit 1 */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
145
Core/Src/stm32f0xx_it.c
Normal file
145
Core/Src/stm32f0xx_it.c
Normal file
@@ -0,0 +1,145 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32f0xx_it.c
|
||||
* @brief Interrupt Service Routines.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
#include "stm32f0xx_it.h"
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN TD */
|
||||
|
||||
/* USER CODE END TD */
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PD */
|
||||
|
||||
/* USER CODE END PD */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PM */
|
||||
|
||||
/* USER CODE END PM */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* USER CODE BEGIN PFP */
|
||||
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/* External variables --------------------------------------------------------*/
|
||||
|
||||
/* USER CODE BEGIN EV */
|
||||
|
||||
/* USER CODE END EV */
|
||||
|
||||
/******************************************************************************/
|
||||
/* Cortex-M0 Processor Interruption and Exception Handlers */
|
||||
/******************************************************************************/
|
||||
/**
|
||||
* @brief This function handles Non maskable interrupt.
|
||||
*/
|
||||
void NMI_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN NonMaskableInt_IRQn 0 */
|
||||
|
||||
/* USER CODE END NonMaskableInt_IRQn 0 */
|
||||
/* USER CODE BEGIN NonMaskableInt_IRQn 1 */
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
/* USER CODE END NonMaskableInt_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Hard fault interrupt.
|
||||
*/
|
||||
void HardFault_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN HardFault_IRQn 0 */
|
||||
|
||||
/* USER CODE END HardFault_IRQn 0 */
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE BEGIN W1_HardFault_IRQn 0 */
|
||||
/* USER CODE END W1_HardFault_IRQn 0 */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles System service call via SWI instruction.
|
||||
*/
|
||||
void SVC_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN SVC_IRQn 0 */
|
||||
|
||||
/* USER CODE END SVC_IRQn 0 */
|
||||
/* USER CODE BEGIN SVC_IRQn 1 */
|
||||
|
||||
/* USER CODE END SVC_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Pendable request for system service.
|
||||
*/
|
||||
void PendSV_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN PendSV_IRQn 0 */
|
||||
|
||||
/* USER CODE END PendSV_IRQn 0 */
|
||||
/* USER CODE BEGIN PendSV_IRQn 1 */
|
||||
|
||||
/* USER CODE END PendSV_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles System tick timer.
|
||||
*/
|
||||
void SysTick_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN SysTick_IRQn 0 */
|
||||
|
||||
/* USER CODE END SysTick_IRQn 0 */
|
||||
HAL_IncTick();
|
||||
/* USER CODE BEGIN SysTick_IRQn 1 */
|
||||
|
||||
/* USER CODE END SysTick_IRQn 1 */
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/* STM32F0xx Peripheral Interrupt Handlers */
|
||||
/* Add here the Interrupt Handlers for the used peripherals. */
|
||||
/* For the available peripheral interrupt handler names, */
|
||||
/* please refer to the startup file (startup_stm32f0xx.s). */
|
||||
/******************************************************************************/
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
176
Core/Src/syscalls.c
Normal file
176
Core/Src/syscalls.c
Normal file
@@ -0,0 +1,176 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file syscalls.c
|
||||
* @author Auto-generated by STM32CubeMX
|
||||
* @brief Minimal System calls file
|
||||
*
|
||||
* For more information about which c-functions
|
||||
* need which of these lowlevel functions
|
||||
* please consult the Newlib libc-manual
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2020-2024 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes */
|
||||
#include <sys/stat.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/times.h>
|
||||
|
||||
|
||||
/* Variables */
|
||||
extern int __io_putchar(int ch) __attribute__((weak));
|
||||
extern int __io_getchar(void) __attribute__((weak));
|
||||
|
||||
|
||||
char *__env[1] = { 0 };
|
||||
char **environ = __env;
|
||||
|
||||
|
||||
/* Functions */
|
||||
void initialise_monitor_handles()
|
||||
{
|
||||
}
|
||||
|
||||
int _getpid(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _kill(int pid, int sig)
|
||||
{
|
||||
(void)pid;
|
||||
(void)sig;
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void _exit (int status)
|
||||
{
|
||||
_kill(status, -1);
|
||||
while (1) {} /* Make sure we hang here */
|
||||
}
|
||||
|
||||
__attribute__((weak)) int _read(int file, char *ptr, int len)
|
||||
{
|
||||
(void)file;
|
||||
int DataIdx;
|
||||
|
||||
for (DataIdx = 0; DataIdx < len; DataIdx++)
|
||||
{
|
||||
*ptr++ = __io_getchar();
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
__attribute__((weak)) int _write(int file, char *ptr, int len)
|
||||
{
|
||||
(void)file;
|
||||
int DataIdx;
|
||||
|
||||
for (DataIdx = 0; DataIdx < len; DataIdx++)
|
||||
{
|
||||
__io_putchar(*ptr++);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
int _close(int file)
|
||||
{
|
||||
(void)file;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int _fstat(int file, struct stat *st)
|
||||
{
|
||||
(void)file;
|
||||
st->st_mode = S_IFCHR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _isatty(int file)
|
||||
{
|
||||
(void)file;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _lseek(int file, int ptr, int dir)
|
||||
{
|
||||
(void)file;
|
||||
(void)ptr;
|
||||
(void)dir;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _open(char *path, int flags, ...)
|
||||
{
|
||||
(void)path;
|
||||
(void)flags;
|
||||
/* Pretend like we always fail */
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _wait(int *status)
|
||||
{
|
||||
(void)status;
|
||||
errno = ECHILD;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _unlink(char *name)
|
||||
{
|
||||
(void)name;
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _times(struct tms *buf)
|
||||
{
|
||||
(void)buf;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _stat(char *file, struct stat *st)
|
||||
{
|
||||
(void)file;
|
||||
st->st_mode = S_IFCHR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _link(char *old, char *new)
|
||||
{
|
||||
(void)old;
|
||||
(void)new;
|
||||
errno = EMLINK;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _fork(void)
|
||||
{
|
||||
errno = EAGAIN;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _execve(char *name, char **argv, char **env)
|
||||
{
|
||||
(void)name;
|
||||
(void)argv;
|
||||
(void)env;
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
79
Core/Src/sysmem.c
Normal file
79
Core/Src/sysmem.c
Normal file
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file sysmem.c
|
||||
* @author Generated by STM32CubeMX
|
||||
* @brief System Memory calls file
|
||||
*
|
||||
* For more information about which C functions
|
||||
* need which of these lowlevel functions
|
||||
* please consult the newlib libc manual
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes */
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* Pointer to the current high watermark of the heap usage
|
||||
*/
|
||||
static uint8_t *__sbrk_heap_end = NULL;
|
||||
|
||||
/**
|
||||
* @brief _sbrk() allocates memory to the newlib heap and is used by malloc
|
||||
* and others from the C library
|
||||
*
|
||||
* @verbatim
|
||||
* ############################################################################
|
||||
* # .data # .bss # newlib heap # MSP stack #
|
||||
* # # # # Reserved by _Min_Stack_Size #
|
||||
* ############################################################################
|
||||
* ^-- RAM start ^-- _end _estack, RAM end --^
|
||||
* @endverbatim
|
||||
*
|
||||
* This implementation starts allocating at the '_end' linker symbol
|
||||
* The '_Min_Stack_Size' linker symbol reserves a memory for the MSP stack
|
||||
* The implementation considers '_estack' linker symbol to be RAM end
|
||||
* NOTE: If the MSP stack, at any point during execution, grows larger than the
|
||||
* reserved size, please increase the '_Min_Stack_Size'.
|
||||
*
|
||||
* @param incr Memory size
|
||||
* @return Pointer to allocated memory
|
||||
*/
|
||||
void *_sbrk(ptrdiff_t incr)
|
||||
{
|
||||
extern uint8_t _end; /* Symbol defined in the linker script */
|
||||
extern uint8_t _estack; /* Symbol defined in the linker script */
|
||||
extern uint32_t _Min_Stack_Size; /* Symbol defined in the linker script */
|
||||
const uint32_t stack_limit = (uint32_t)&_estack - (uint32_t)&_Min_Stack_Size;
|
||||
const uint8_t *max_heap = (uint8_t *)stack_limit;
|
||||
uint8_t *prev_heap_end;
|
||||
|
||||
/* Initialize heap end at first call */
|
||||
if (NULL == __sbrk_heap_end)
|
||||
{
|
||||
__sbrk_heap_end = &_end;
|
||||
}
|
||||
|
||||
/* Protect heap from growing into the reserved MSP stack */
|
||||
if (__sbrk_heap_end + incr > max_heap)
|
||||
{
|
||||
errno = ENOMEM;
|
||||
return (void *)-1;
|
||||
}
|
||||
|
||||
prev_heap_end = __sbrk_heap_end;
|
||||
__sbrk_heap_end += incr;
|
||||
|
||||
return (void *)prev_heap_end;
|
||||
}
|
||||
249
Core/Src/system_stm32f0xx.c
Normal file
249
Core/Src/system_stm32f0xx.c
Normal file
@@ -0,0 +1,249 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file system_stm32f0xx.c
|
||||
* @author MCD Application Team
|
||||
* @brief CMSIS Cortex-M0 Device Peripheral Access Layer System Source File.
|
||||
*
|
||||
* 1. This file provides two functions and one global variable to be called from
|
||||
* user application:
|
||||
* - SystemInit(): This function is called at startup just after reset and
|
||||
* before branch to main program. This call is made inside
|
||||
* the "startup_stm32f0xx.s" file.
|
||||
*
|
||||
* - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
|
||||
* by the user application to setup the SysTick
|
||||
* timer or configure other parameters.
|
||||
*
|
||||
* - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
|
||||
* be called whenever the core clock is changed
|
||||
* during program execution.
|
||||
*
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2016 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/** @addtogroup CMSIS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup stm32f0xx_system
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F0xx_System_Private_Includes
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include "stm32f0xx.h"
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F0xx_System_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F0xx_System_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
#if !defined (HSE_VALUE)
|
||||
#define HSE_VALUE ((uint32_t)8000000) /*!< Default value of the External oscillator in Hz.
|
||||
This value can be provided and adapted by the user application. */
|
||||
#endif /* HSE_VALUE */
|
||||
|
||||
#if !defined (HSI_VALUE)
|
||||
#define HSI_VALUE ((uint32_t)8000000) /*!< Default value of the Internal oscillator in Hz.
|
||||
This value can be provided and adapted by the user application. */
|
||||
#endif /* HSI_VALUE */
|
||||
|
||||
#if !defined (HSI48_VALUE)
|
||||
#define HSI48_VALUE ((uint32_t)48000000) /*!< Default value of the HSI48 Internal oscillator in Hz.
|
||||
This value can be provided and adapted by the user application. */
|
||||
#endif /* HSI48_VALUE */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F0xx_System_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F0xx_System_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
/* This variable is updated in three ways:
|
||||
1) by calling CMSIS function SystemCoreClockUpdate()
|
||||
2) by calling HAL API function HAL_RCC_GetHCLKFreq()
|
||||
3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
|
||||
Note: If you use this function to configure the system clock; then there
|
||||
is no need to call the 2 first functions listed above, since SystemCoreClock
|
||||
variable is updated automatically.
|
||||
*/
|
||||
uint32_t SystemCoreClock = 8000000;
|
||||
|
||||
const uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
|
||||
const uint8_t APBPrescTable[8] = {0, 0, 0, 0, 1, 2, 3, 4};
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F0xx_System_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F0xx_System_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Setup the microcontroller system
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SystemInit(void)
|
||||
{
|
||||
/* NOTE :SystemInit(): This function is called at startup just after reset and
|
||||
before branch to main program. This call is made inside
|
||||
the "startup_stm32f0xx.s" file.
|
||||
User can setups the default system clock (System clock source, PLL Multiplier
|
||||
and Divider factors, AHB/APBx prescalers and Flash settings).
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Update SystemCoreClock variable according to Clock Register Values.
|
||||
* The SystemCoreClock variable contains the core clock (HCLK), it can
|
||||
* be used by the user application to setup the SysTick timer or configure
|
||||
* other parameters.
|
||||
*
|
||||
* @note Each time the core clock (HCLK) changes, this function must be called
|
||||
* to update SystemCoreClock variable value. Otherwise, any configuration
|
||||
* based on this variable will be incorrect.
|
||||
*
|
||||
* @note - The system frequency computed by this function is not the real
|
||||
* frequency in the chip. It is calculated based on the predefined
|
||||
* constant and the selected clock source:
|
||||
*
|
||||
* - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*)
|
||||
*
|
||||
* - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**)
|
||||
*
|
||||
* - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**)
|
||||
* or HSI_VALUE(*) multiplied/divided by the PLL factors.
|
||||
*
|
||||
* - If SYSCLK source is HSI48, SystemCoreClock will contain the HSI48_VALUE(***)
|
||||
*
|
||||
* (*) HSI_VALUE is a constant defined in stm32f0xx_hal_conf.h file (default value
|
||||
* 8 MHz) but the real value may vary depending on the variations
|
||||
* in voltage and temperature.
|
||||
*
|
||||
* (**) HSE_VALUE is a constant defined in stm32f0xx_hal_conf.h file (its value
|
||||
* depends on the application requirements), user has to ensure that HSE_VALUE
|
||||
* is same as the real frequency of the crystal used. Otherwise, this function
|
||||
* may have wrong result.
|
||||
*
|
||||
* (***) HSI48_VALUE is a constant defined in stm32f0xx_hal_conf.h file (default value
|
||||
* 48 MHz) but the real value may vary depending on the variations
|
||||
* in voltage and temperature.
|
||||
*
|
||||
* - The result of this function could be not correct when using fractional
|
||||
* value for HSE crystal.
|
||||
*
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SystemCoreClockUpdate (void)
|
||||
{
|
||||
uint32_t tmp = 0, pllmull = 0, pllsource = 0, predivfactor = 0;
|
||||
|
||||
/* Get SYSCLK source -------------------------------------------------------*/
|
||||
tmp = RCC->CFGR & RCC_CFGR_SWS;
|
||||
|
||||
switch (tmp)
|
||||
{
|
||||
case RCC_CFGR_SWS_HSI: /* HSI used as system clock */
|
||||
SystemCoreClock = HSI_VALUE;
|
||||
break;
|
||||
case RCC_CFGR_SWS_HSE: /* HSE used as system clock */
|
||||
SystemCoreClock = HSE_VALUE;
|
||||
break;
|
||||
case RCC_CFGR_SWS_PLL: /* PLL used as system clock */
|
||||
/* Get PLL clock source and multiplication factor ----------------------*/
|
||||
pllmull = RCC->CFGR & RCC_CFGR_PLLMUL;
|
||||
pllsource = RCC->CFGR & RCC_CFGR_PLLSRC;
|
||||
pllmull = ( pllmull >> 18) + 2;
|
||||
predivfactor = (RCC->CFGR2 & RCC_CFGR2_PREDIV) + 1;
|
||||
|
||||
if (pllsource == RCC_CFGR_PLLSRC_HSE_PREDIV)
|
||||
{
|
||||
/* HSE used as PLL clock source : SystemCoreClock = HSE/PREDIV * PLLMUL */
|
||||
SystemCoreClock = (HSE_VALUE/predivfactor) * pllmull;
|
||||
}
|
||||
#if defined(STM32F042x6) || defined(STM32F048xx) || defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F091xC) || defined(STM32F098xx)
|
||||
else if (pllsource == RCC_CFGR_PLLSRC_HSI48_PREDIV)
|
||||
{
|
||||
/* HSI48 used as PLL clock source : SystemCoreClock = HSI48/PREDIV * PLLMUL */
|
||||
SystemCoreClock = (HSI48_VALUE/predivfactor) * pllmull;
|
||||
}
|
||||
#endif /* STM32F042x6 || STM32F048xx || STM32F071xB || STM32F072xB || STM32F078xx || STM32F091xC || STM32F098xx */
|
||||
else
|
||||
{
|
||||
#if defined(STM32F042x6) || defined(STM32F048xx) || defined(STM32F070x6) \
|
||||
|| defined(STM32F078xx) || defined(STM32F071xB) || defined(STM32F072xB) \
|
||||
|| defined(STM32F070xB) || defined(STM32F091xC) || defined(STM32F098xx) || defined(STM32F030xC)
|
||||
/* HSI used as PLL clock source : SystemCoreClock = HSI/PREDIV * PLLMUL */
|
||||
SystemCoreClock = (HSI_VALUE/predivfactor) * pllmull;
|
||||
#else
|
||||
/* HSI used as PLL clock source : SystemCoreClock = HSI/2 * PLLMUL */
|
||||
SystemCoreClock = (HSI_VALUE >> 1) * pllmull;
|
||||
#endif /* STM32F042x6 || STM32F048xx || STM32F070x6 ||
|
||||
STM32F071xB || STM32F072xB || STM32F078xx || STM32F070xB ||
|
||||
STM32F091xC || STM32F098xx || STM32F030xC */
|
||||
}
|
||||
break;
|
||||
default: /* HSI used as system clock */
|
||||
SystemCoreClock = HSI_VALUE;
|
||||
break;
|
||||
}
|
||||
/* Compute HCLK clock frequency ----------------*/
|
||||
/* Get HCLK prescaler */
|
||||
tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)];
|
||||
/* HCLK clock frequency */
|
||||
SystemCoreClock >>= tmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user